Skip to content

Commit 907b504

Browse files
author
Leonid Vakulenko
committed
Webasyst Framework v.3.8.0
* Updated integration with web push notifications service Firebase. * Improved user interface on the dashboard when writing announcements with AI. * Fixed a few found errors. * For developers: * Included HTML code to display favicons in the result returned by helper {$wa->head()}. * Added new hook search_content for system app 'webasyst'
1 parent ecb33b5 commit 907b504

File tree

47 files changed

+1099
-252
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1099
-252
lines changed

wa-apps/installer/lib/classes/installerHelper.class.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ public static function getUpdates($vendor = null)
157157
);
158158
$app_settings_model = new waAppSettingsModel();
159159
$errors = (array)json_decode($app_settings_model->get('installer', 'errors', '[]'));
160+
self::getInstaller()->syncSourcesEndpoints();
160161
$items = self::getInstaller()->getUpdates($vendor);
161162
$changed = false;
162163
$actions = array(

wa-apps/installer/lib/classes/installerServicesApi.class.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,15 +334,27 @@ public function getSystemToken($force_refresh = false)
334334
public function getUserToken($force_refresh = false)
335335
{
336336
if (self::$user_token === null || $force_refresh) {
337+
338+
$lock_name = 'wa_get_user_token_' . wa()->getUser()->getId();
339+
$locking_model = new waAppSettingsModel();
340+
try {
341+
$locking_model->exec("SELECT GET_LOCK(?, -1)", [ $lock_name ]);
342+
} catch (Exception $e) {
343+
return null;
344+
}
345+
337346
$token_params = wa()->getUser()->getWebasystTokenParams();
338347
if (empty($token_params)) {
348+
$locking_model->exec("SELECT RELEASE_LOCK(?)", [ $lock_name ]);
339349
return null;
340350
}
351+
341352
if ($force_refresh) {
342353
$ok = $this->refreshedTokenParams($token_params, wa()->getUser()->getId());
343354
} else {
344355
$ok = $this->refreshTokenWhenExpired($token_params, wa()->getUser()->getId());
345356
}
357+
$locking_model->exec("SELECT RELEASE_LOCK(?)", [ $lock_name ]);
346358
if (!$ok) {
347359
return null;
348360
}

wa-apps/installer/lib/config/app.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
'description' => 'Install new apps from the Webasyst Store',
55
'icon' => 'img/installer.svg',
66
'mobile' => false,
7-
'version' => '3.7.0',
8-
'critical' => '3.7.0',
7+
'version' => '3.8.0',
8+
'critical' => '3.8.0',
99
'system' => true,
1010
'vendor' => 'webasyst',
1111
'csrf' => true,

wa-apps/installer/lib/config/installerConfig.class.php

Lines changed: 75 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class installerConfig extends waAppConfig
2222
const INIT_DATA_CACHE_TTL = 10800; // 3 hours
2323
const INIT_DATA_CACHE_TTL_DEBUG = 900; // 15 mins
2424

25+
private static $model;
26+
2527
protected $application_config = array();
2628

2729
public function init()
@@ -44,7 +46,7 @@ public function onCount()
4446
$args = func_get_args();
4547
$force = array_shift($args);
4648

47-
$model = new waAppSettingsModel();
49+
$model = self::getAppSettingsModel();
4850
$app_id = $this->getApplication();
4951
$count = null;
5052

@@ -76,7 +78,7 @@ public function onCount()
7678

7779
public function setCount($n = null)
7880
{
79-
$model = new waAppSettingsModel();
81+
$model = self::getAppSettingsModel();
8082
$model->ping();
8183
$app_id = $this->getApplication();
8284
$model->set($app_id, 'update_counter', $n);
@@ -171,23 +173,18 @@ public function explainLogs($logs)
171173
*/
172174
public function loadInitData($locale)
173175
{
174-
$net_options = array(
175-
'timeout' => 7,
176-
'format' => waNet::FORMAT_JSON,
177-
);
178-
$net = new waNet($net_options);
176+
return installerHelper::getInstaller()->zonedNetQuery([$this, 'getInitDataUrl'], 7, $locale);
177+
}
179178

179+
public function getInitDataUrl($locale)
180+
{
180181
$wa_installer = installerHelper::getInstaller();
181-
182-
$init_url_params = array(
182+
$init_url_params = [
183183
'locale' => $locale,
184184
'hash' => $wa_installer->getHash(),
185185
'domain' => $this->getDomainFromRouting(),
186-
);
187-
188-
$init_url = $wa_installer->getInstallerInitUrl();
189-
$init_url .= '?'.http_build_query($init_url_params);
190-
return $net->query($init_url);
186+
];
187+
return $wa_installer->getInstallerInitUrl().'?'.http_build_query($init_url_params);
191188
}
192189

193190
/**
@@ -216,6 +213,11 @@ public function getInitData($locale = null)
216213
return $function_cache->call($locale);
217214
}
218215

216+
public function clearInitDataCache()
217+
{
218+
waFunctionCache::clearNamespace('installer/init_data');
219+
}
220+
219221
/**
220222
* Load token from remote Update server, required to initialize the Installer app.
221223
* Received data is recommended to be cached. For example using waFunctionCache (see method getToken).
@@ -225,37 +227,28 @@ public function getInitData($locale = null)
225227
*/
226228
protected function loadTokenData()
227229
{
228-
$net_options = array(
229-
'timeout' => 7,
230-
'format' => waNet::FORMAT_JSON,
231-
);
232-
$net = new waNet($net_options);
233-
234-
$wa_installer = installerHelper::getInstaller();
235-
236-
$init_url_params = array(
237-
'hash' => $wa_installer->getHash(),
238-
'domain' => $this->getDomainFromRouting(),
239-
);
240-
if ($previous_hash = $wa_installer->getGenericConfig('previous_hash')) {
241-
$init_url_params['previous_hash'] = $previous_hash;
242-
}
243-
244-
$init_url = $wa_installer->getInstallerTokenUrl();
245-
$init_url .= '?'.http_build_query($init_url_params);
246-
$res = $net->query($init_url);
230+
$res = installerHelper::getInstaller()->zonedNetQuery([$this, 'getTokenDataUrl'], 7);
247231

248232
if (!empty($res['token'])) {
249233
// Save the last received token in the app settings
250234
$token_data = array('token' => $res['token']['key'], 'expire_datetime' => $res['token']['expire_datetime']);
251-
$asm = new waAppSettingsModel();
252235
$app_id = $this->getApplication();
253-
$asm->set($app_id, 'token_data', json_encode($token_data));
236+
self::getAppSettingsModel()->set($app_id, 'token_data', json_encode($token_data));
254237
}
255238

256239
return $res;
257240
}
258241

242+
public function getTokenDataUrl()
243+
{
244+
$wa_installer = installerHelper::getInstaller();
245+
$init_url_params = [
246+
'hash' => $wa_installer->getHash(),
247+
'domain' => $this->getDomainFromRouting(),
248+
];
249+
return $wa_installer->getInstallerTokenUrl().'?'.http_build_query($init_url_params);
250+
}
251+
259252
/**
260253
* The method of caching and receiving the installation token
261254
* for working with a remote Store.
@@ -296,37 +289,15 @@ protected function loadAnnouncements()
296289
return;
297290
}
298291

299-
$net_options = array(
300-
'timeout' => 7,
301-
'format' => waNet::FORMAT_JSON,
302-
);
303-
$net = new waNet($net_options);
304-
305-
$wa_installer = installerHelper::getInstaller();
306-
307-
$url_params = array(
308-
'hash' => $wa_installer->getHash(),
309-
'domain' => $this->getDomainFromRouting(),
310-
'locale' => wa()->getLocale(),
311-
);
312-
$token_data = (new waAppSettingsModel())->get('installer', 'token_data', false);
313-
if ($token_data) {
314-
$token_data = waUtils::jsonDecode($token_data, true);
315-
$url_params['token'] = ifset($token_data, 'token', null);
316-
}
317-
318-
$init_url = $wa_installer->getInstallerAnnounceUrl();
319-
$init_url .= '?'.http_build_query($url_params);
320-
321-
$res = $net->query($init_url);
292+
$res = installerHelper::getInstaller()->zonedNetQuery([$this, 'getAnnouncementsUrl'], 7);
322293
if (!$res || !array_key_exists('data', $res)) {
323294
return;
324295
}
325296
$cache->get();
326297

327298
$cache->set($res);
328299

329-
$wasm = new waAppSettingsModel();
300+
$wasm = self::getAppSettingsModel();
330301

331302
if (!$res['data']) {
332303
$this->clearBanners();
@@ -363,6 +334,22 @@ protected function loadAnnouncements()
363334
}
364335
}
365336

337+
public function getAnnouncementsUrl()
338+
{
339+
$wa_installer = installerHelper::getInstaller();
340+
$init_url_params = [
341+
'hash' => $wa_installer->getHash(),
342+
'domain' => $this->getDomainFromRouting(),
343+
'locale' => wa()->getLocale(),
344+
];
345+
$token_data = self::getAppSettingsModel()->get('installer', 'token_data', false);
346+
if ($token_data) {
347+
$token_data = waUtils::jsonDecode($token_data, true);
348+
$init_url_params['token'] = ifset($token_data, 'token', null);
349+
}
350+
return $wa_installer->getInstallerAnnounceUrl().'?'.http_build_query($init_url_params);
351+
}
352+
366353
public function clearAnnouncementsCache()
367354
{
368355
$this->clearBanners();
@@ -386,44 +373,39 @@ public function loadLicenses()
386373
$cache = new waVarExportCache('licenses', self::LICENSE_CACHE_TTL, $this->getApplication());
387374
$cache_data = $cache->get();
388375
if (!$cache->isCached() || time() - ifempty($cache_data, 'timestamp', 0) >= self::LICENSE_CACHE_TTL) {
389-
$net_options = array(
390-
'timeout' => 7,
391-
'format' => waNet::FORMAT_JSON,
392-
);
393-
$net = new waNet($net_options);
394-
$wa_installer = installerHelper::getInstaller();
395-
396-
$init_url_params = array(
397-
'hash' => $wa_installer->getHash(),
398-
'domain' => $this->getDomainFromRouting(),
399-
);
400-
if ($previous_hash = $wa_installer->getGenericConfig('previous_hash')) {
401-
$init_url_params['previous_hash'] = $previous_hash;
402-
}
403-
$app_settings_model = new waAppSettingsModel();
404-
$token_data = $app_settings_model->get('installer', 'token_data', false);
405-
if ($token_data) {
406-
$token_data = waUtils::jsonDecode($token_data, true);
407-
$init_url_params['token'] = ifset($token_data, 'token', null);
408-
}
409-
410-
$init_url = $wa_installer->getInstallerLicenseUrl();
411-
$init_url .= '?' . http_build_query($init_url_params);
412-
$res = $net->query($init_url);
376+
$res = installerHelper::getInstaller()->zonedNetQuery([$this, 'getLicensesUrl'], 7);
413377

414378
if (!empty($res['data'])) {
415379
$data = [
416380
'data' => $res['data'],
417381
'timestamp' => time()
418382
];
419383
$cache->set($data);
420-
$app_settings_model->set('installer', 'licenses_data', json_encode($data));
384+
self::getAppSettingsModel()->set('installer', 'licenses_data', json_encode($data));
421385
}
422386

423387
return $res;
424388
}
425389
}
426390

391+
public function getLicensesUrl()
392+
{
393+
$wa_installer = installerHelper::getInstaller();
394+
$init_url_params = [
395+
'hash' => $wa_installer->getHash(),
396+
'domain' => $this->getDomainFromRouting(),
397+
];
398+
if ($previous_hash = $wa_installer->getGenericConfig('previous_hash')) {
399+
$init_url_params['previous_hash'] = $previous_hash;
400+
}
401+
$token_data = self::getAppSettingsModel()->get('installer', 'token_data', false);
402+
if ($token_data) {
403+
$token_data = waUtils::jsonDecode($token_data, true);
404+
$init_url_params['token'] = ifset($token_data, 'token', null);
405+
}
406+
return $wa_installer->getInstallerLicenseUrl().'?'.http_build_query($init_url_params);
407+
}
408+
427409
/** @since 2.9.0 */
428410
public function getDomainFromRouting()
429411
{
@@ -445,8 +427,7 @@ public function getDomainFromRouting()
445427
}
446428

447429
protected function getLocale() {
448-
$app_settings_model = new waAppSettingsModel();
449-
$locale = $app_settings_model->get('webasyst', 'locale');
430+
$locale = self::getAppSettingsModel()->get('webasyst', 'locale');
450431
if (empty($locale)) {
451432
$locale = wa()->getLocale();
452433
}
@@ -455,4 +436,12 @@ protected function getLocale() {
455436
}
456437
return $locale;
457438
}
439+
440+
protected static function getAppSettingsModel()
441+
{
442+
if (!self::$model) {
443+
self::$model = new waAppSettingsModel();
444+
}
445+
return self::$model;
446+
}
458447
}
262 Bytes
Binary file not shown.

wa-apps/installer/locale/ru_RU/LC_MESSAGES/installer.po

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ msgstr ""
1212
"Plural-Forms: nplurals=3; plural=((((n%10)==1)&&((n%100)!=11))?(0):(((((n%10)>=2)&&((n%10)<=4))&&(((n%100)<10)||((n%100)>=20)))?(1):2));\n"
1313
"X-Poedit-SourceCharset: utf-8\n"
1414
"X-Poedit-Basepath: .\n"
15-
"X-Generator: Poedit 2.4.3\n"
15+
"X-Generator: Poedit 3.4.2\n"
1616
"X-Poedit-SearchPath-0: .\n"
1717
"X-Poedit-SearchPath-1: .\n"
1818

@@ -600,3 +600,12 @@ msgstr "Службы"
600600

601601
msgid "Home"
602602
msgstr "Главная"
603+
604+
msgid "Response code: %s."
605+
msgstr "Код ответа: %s."
606+
607+
msgid "Remaining Webasyst AI prompts: %s."
608+
msgstr "Доступно запросов к Webasyst AI: %s."
609+
610+
msgid "Webasyst CRON API error."
611+
msgstr "Ошибка Webasyst CRON API."

wa-apps/installer/templates/actions/services/Services.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ <h4 class="custom-mb-8">
2727
{$ai_params = webasystHelper::getAiParams()}
2828

2929
<p class="small">
30-
<span>{sprintf_wp('Remaining Webasyst AI prompts: %s', '<strong>'|cat:$ai_params.remaining_count|cat:'</strong>')}</span>
30+
<span>{sprintf_wp('Remaining Webasyst AI prompts: %s.', '<strong>'|cat:$ai_params.remaining_count|cat:'</strong>')}</span>
3131
</p>
3232

3333
<p class="custom-mt-8 custom-mb-4">

0 commit comments

Comments
 (0)