Skip to content

Commit

Permalink
installer: v.2.6.2 (developer preview)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonix committed Aug 4, 2022
1 parent 633d792 commit a076e09
Show file tree
Hide file tree
Showing 43 changed files with 458 additions and 282 deletions.
2 changes: 1 addition & 1 deletion wa-apps/installer/css/app.installer.css

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions wa-apps/installer/lib/config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
'description' => 'Install new apps from the Webasyst Store',
'icon' => 'img/installer.svg',
'mobile' => false,
'version' => '2.6.0',
'critical' => '2.6.0',
'version' => '2.6.2',
'critical' => '2.6.2',
'system' => true,
'vendor' => 'webasyst',
'csrf' => true,
Expand Down
24 changes: 20 additions & 4 deletions wa-apps/installer/lib/config/installerConfig.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public function getTokenData($actual = false)

protected function loadAnnouncements()
{
$cache = new waVarExportCache('announcements', self::ANNOUNCE_CACHE_TTL, 'installer');
$cache = $this->getAnnouncementsCache();
if ($cache->isCached() && ($res = $cache->get())) {
return;
}
Expand Down Expand Up @@ -307,9 +307,7 @@ protected function loadAnnouncements()
$wasm = new waAppSettingsModel();

if (!$res['data']) {
$wcsm = new waContactSettingsModel();
$wasm->exec("DELETE FROM {$wasm->getTableName()} WHERE app_id = 'installer' AND name LIKE 'a-%'");
$wcsm->exec("DELETE FROM {$wcsm->getTableName()} WHERE app_id = 'installer' AND name LIKE 'a-%'");
$this->clearBanners();
return;
}
$ads = (array)$res['data'];
Expand Down Expand Up @@ -343,6 +341,24 @@ protected function loadAnnouncements()
}
}

public function clearAnnouncementsCache()
{
$this->clearBanners();
$this->getAnnouncementsCache()->delete();
}

protected function clearBanners()
{
$m = new waModel();
$m->exec("DELETE FROM wa_app_settings WHERE app_id = 'installer' AND name LIKE 'a-%'");
$m->exec("DELETE FROM wa_contact_settings WHERE app_id = 'installer' AND name LIKE 'a-%'");
}

protected function getAnnouncementsCache()
{
return new waVarExportCache('announcements', self::ANNOUNCE_CACHE_TTL, 'installer');
}

public function loadLicenses()
{
$cache = new waVarExportCache('licenses', self::LICENSE_CACHE_TTL, $this->getApplication());
Expand Down
103 changes: 75 additions & 28 deletions wa-apps/installer/lib/handlers/webasyst.backend_header.handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,49 +87,96 @@ protected function getSlugsToSwitchOff($top_header_list, $notification_list)
return array_keys($slugs);
}

protected function getProductsLeaseStatus($slugs)
{
try {
$installer = installerHelper::getInstaller();
$domain = $installer->getDomain();
$hash = $installer->getHash();
$url = $installer->getCheckProductLeaseStatusUrl();

$net_options = [
'timeout' => 20,
'format' => waNet::FORMAT_JSON,
'request_format' => waNet::FORMAT_RAW,
'expected_http_code' => null
];

$net = new waNet($net_options);
$params = [
'domain' => $domain,
'hash' => $hash,
'slug' => array_values($slugs),
];

$result = [];
foreach($slugs as $slug) {
$result[$slug] = 'unknown';
}
$response = $net->query($url, $params, waNet::METHOD_POST);
$response = is_array($response) && isset($response['data']['statuses']) && is_array($response['data']['statuses']) ? $response['data']['statuses'] : [];
foreach($response as $slug => $arr) {
$result[$slug] = ifset($arr, 'status', 'unknown');
}
return $result;
} catch (waException $e) {
return [];
}
}

protected function switchOffSlugs($slugs)
{
// Filter $slugs: only keep app plugins that are actually still enabled
$slugs = array_filter($slugs, function($slug) {
try {
if (preg_match('~^([^/]+)/plugins/([^/]+)$~', $slug, $matches)) {
list($_, $app_id, $plugin_id) = $matches;
if (wa()->appExists($app_id)) {
$app_plugins = wa($app_id)->getConfig()->getPlugins();
return isset($app_plugins[$plugin_id]);
}
}
} catch (waException $e) {
}
return false;
});

if ($slugs) {
// Ask WA server again if client has licenses:
// they might have fixed licensing since last banner update.
$lease_status = $this->getProductsLeaseStatus($slugs);
$slugs = array_filter($slugs, function($slug) use ($lease_status) {
return ifset($lease_status, $slug, null) == 'blocked';
});
}
if (!$slugs) {
return;
}

$old_app_id = wa()->getApp();
wa('installer', true);

$something_changed = false;
$installer = new waInstallerApps();

foreach($slugs as $slug) {
if (preg_match('~^([^/]+)/plugins/([^/]+)$~', $slug, $matches)) {
list($_, $app_id, $plugin_id) = $matches;
try {
// Make sure plugin is actually turned on before trying to disable it
if (!wa()->appExists($app_id)) {
continue;
}
$app_plugins = wa($app_id)->getConfig()->getPlugins();
if (!isset($app_plugins[$plugin_id])) {
continue;
}

// Disable plugin
$something_changed = true;
$installer->updateAppPluginsConfig($app_id, $plugin_id, false);
(new waLogModel())->add('item_disable', [
'type' => 'plugins',
'id' => sprintf('%s/%s', $app_id, $plugin_id),
'reason' => 'license',
], null, 0);
} catch (waException $e) {
}
} else {
// Yaarrr!
if (!preg_match('~^([^/]+)/plugins/([^/]+)$~', $slug, $matches)) {
continue;
}
list($_, $app_id, $plugin_id) = $matches;
try {
// Disable plugin
$installer->updateAppPluginsConfig($app_id, $plugin_id, false);
(new waLogModel())->add('item_disable', [
'type' => 'plugins',
'id' => sprintf('%s/%s', $app_id, $plugin_id),
'reason' => 'license',
], null, 0);
} catch (waException $e) {
}
}

if ($something_changed) {
installerHelper::flushCache();
}
wa('installer')->getConfig()->clearAnnouncementsCache();
installerHelper::flushCache();

wa($old_app_id, true);
}
Expand Down
2 changes: 2 additions & 0 deletions wa-apps/installer/templates/actions/assets/Assets.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ <h2 class="state-{$message.result}">
<script type="text/javascript">
document.title = {$title|json_encode};

$('.js-assets-row:not(.i-assets-disabled)').find('.js-switch-remove').show();

$('.js-remove-item').on('click', function(e) {
e.preventDefault();

Expand Down
14 changes: 2 additions & 12 deletions wa-apps/installer/templates/actions/assets/Assets.row.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,8 @@
{/if}
{/if}

{if
empty($item.system)
&&
(
!in_array($item_type,['app','plugin'])
||
( $item_type =='plugin' && !empty($app.virtual))
||
!empty($item.enabled)
)
}
<span class="js-switch-remove">
{if empty($item.system)}
<span class="js-switch-remove"{if in_array($item_type,['plugin','app']) && empty($app.virtual)} style="display: none;"{/if}>
<a href="{$wa_app_url}assets/" class="js-remove-item button light-gray circle" title="[`Delete`]">
<i class="fas fa-trash-alt text-red js-remove-item-icon"></i>
<i class="fas fa-spinner wa-animation-spin speed-1500 hidden js-remove-item-spinner"></i>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@
</a>
</li>
{/foreach}
{foreach $_sidebar_item.TOP.extra as $_item}
<li>
<a href="{$_item.url|escape}">
<i class="{$_item.icon|escape}"></i>
<span style="margin-right:4px;">{$_item.name|escape}</span>
{if !empty($_item.badge)}
<span class="indicator red" style="color:#fff !important;top:0;font-size: 12px;">{$_item.badge}</span>
{/if}
</a>
</li>
{/foreach}
</ul>
{/if}
{/foreach}
Expand Down Expand Up @@ -146,7 +157,7 @@
<span>[`Settings`]</span>
</a>
</li>

</ul>
</div>

Expand Down
8 changes: 8 additions & 0 deletions wa-apps/installer/templates/layouts/BackendStoreSidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
</a>
</li>
{/foreach}
{foreach $_sidebar_item.TOP.extra as $_item}
<li>
<a href="{$_item.url|escape}" class="flexbox middle">
<span class="icon"><i class="{$_item.icon|escape}"></i></span>
<span class="semibold">{$_item.name|escape}{if !empty($_item.badge)} <i class="badge small bold rounded red">{$_item.badge}</i>{/if}</span>
</a>
</li>
{/foreach}
</ul>
{/foreach}

Expand Down
2 changes: 1 addition & 1 deletion wa-content/css/wa/wa-2.0.css
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ html { line-height: 1.15; -webkit-text-size-adjust: 100%; }
body { margin: 0; }
main { display: block; }
hr { box-sizing: content-box; height: 0; overflow: visible; }
pre { font-family: monospace, monospace; font-size: 1em; }
pre { font-family: monospace, monospace; font-size: 1em; white-space: pre-wrap; }
a { background-color: transparent; }
abbr[title] { border-bottom: none; text-decoration: underline; text-decoration: underline dotted; }
b, strong { font-weight: bolder; }
Expand Down
2 changes: 1 addition & 1 deletion wa-content/js/jquery-wa/wa.js
Original file line number Diff line number Diff line change
Expand Up @@ -2361,7 +2361,7 @@
that.wa_url = window.wa_url || '/';

//
that.options.arrow = false;
that.options.arrow = that.options.arrow || false;
if (that.icon) {
that.options.allowHTML = true;
}
Expand Down
49 changes: 29 additions & 20 deletions wa-system/config/waAppConfig.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ public function init()

public function checkUpdates()
{
$is_from_template = waConfig::get('is_template');
$disable_exception_log = waConfig::get('disable_exception_log');
waConfig::set('disable_exception_log', true);
try {
$app_settings_model = new waAppSettingsModel();
} catch (waDbException $e) {
Expand All @@ -259,9 +262,11 @@ public function checkUpdates()
// 'webasyst' system app is not automatically started in frontend (as opposed to backend).
// When framework is first launched via frontend, wa_* tables do not exist yet.
// So we launch the app to give it a chance to install properly.
waConfig::set('disable_exception_log', $disable_exception_log);
$this->initWebasystApp();
$app_settings_model = new waAppSettingsModel();
} else {
waLog::log($e->real_message."\n".$e->getFullTraceAsString(), 'db.log');
throw $e;
}
} catch (waException $e) {
Expand All @@ -272,6 +277,8 @@ public function checkUpdates()
} else {
throw $e;
}
} finally {
waConfig::set('disable_exception_log', $disable_exception_log);
}
if (!empty($app_settings_model)) {
$time = $app_settings_model->get($this->application, 'update_time', null);
Expand All @@ -280,19 +287,20 @@ public function checkUpdates()
// Install the app and remember to skip all updates
// if this is the first launch.
$is_first_launch = false;
$is_from_template = waConfig::get('is_template');
if (empty($time)) {
$time = null;
$is_first_launch = true;

waConfig::set('disable_exception_log', true);
waConfig::set('is_template', null);
try {
waConfig::set('is_template', null);
$this->install();
waConfig::set('is_template', $is_from_template);
} catch (waException $e) {
waLog::log("Error installing application ".$this->application." at first run:\n".$e->getMessage()." (".$e->getCode().")\n".$e->getTraceAsString());
waConfig::set('is_template', $is_from_template);
throw $e;
} finally {
waConfig::set('disable_exception_log', $disable_exception_log);
waConfig::set('is_template', $is_from_template);
}

if (empty($app_settings_model)) {
Expand Down Expand Up @@ -334,28 +342,29 @@ public function checkUpdates()
// Force load locale
$this->setLocale(wa()->getLocale());
}
waConfig::set('disable_exception_log', true);
waConfig::set('is_template', null);
waConfig::get('disable_exception_log', true);
$cache_database_dir = $this->getPath('cache').'/db';
foreach ($files as $t => $file) {
try {
try {
foreach ($files as $t => $file) {
try {

if (waSystemConfig::isDebug()) {
waLog::dump(sprintf('Try include file %s by app %s', $file, $this->application), 'meta_update.log');
}
if (waSystemConfig::isDebug()) {
waLog::dump(sprintf('Try include file %s by app %s', $file, $this->application), 'meta_update.log');
}

$this->includeUpdate($file);
waFiles::delete($cache_database_dir, true);
$app_settings_model->set($this->application, 'update_time', $t);
} catch (Exception $e) {
waLog::log("Error running update of ".$this->application.": {$file}\n".$e->getMessage()." (".$e->getCode().")\n".$e->getTraceAsString());
waConfig::get('disable_exception_log', false);
waConfig::set('is_template', $is_from_template);
throw new waException(sprintf(_ws('Error while running update of %s app: %s'), $this->application, $file), 500, $e);
$this->includeUpdate($file);
waFiles::delete($cache_database_dir, true);
$app_settings_model->set($this->application, 'update_time', $t);
} catch (Exception $e) {
waLog::log("Error running update of ".$this->application.": {$file}\n".$e->getMessage()." (".$e->getCode().")\n".$e->getTraceAsString());
throw new waException(sprintf(_ws('Error while running update of %s app: %s'), $this->application, $file), 500, $e);
}
}
} finally {
waConfig::set('disable_exception_log', $disable_exception_log);
waConfig::set('is_template', $is_from_template);
}
waConfig::get('disable_exception_log', false);
waConfig::set('is_template', $is_from_template);
}

}
Expand Down
Loading

0 comments on commit a076e09

Please sign in to comment.