Skip to content

Commit

Permalink
Hooked up old update checker ui with new update system
Browse files Browse the repository at this point in the history
  • Loading branch information
jaxwilko committed Jan 3, 2025
1 parent 8593b0b commit e6dc1ad
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 37 deletions.
49 changes: 37 additions & 12 deletions modules/system/controllers/Updates.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Backend\Classes\Controller;
use Backend\Facades\Backend;
use Backend\Facades\BackendMenu;
use Cms\Classes\Theme;
use Cms\Classes\ThemeManager;
use Exception;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Response as HttpResponse;
Expand Down Expand Up @@ -220,17 +222,40 @@ public function onLoadUpdates(): string
public function onCheckForUpdates(): array
{
try {
$manager = UpdateManager::instance();
$result = $manager->requestUpdateList();

$result = $this->processUpdateLists($result);
$result = $this->processImportantUpdates($result);

$this->vars['core'] = array_get($result, 'core', false);
$this->vars['hasUpdates'] = array_get($result, 'hasUpdates', false);
$this->vars['hasImportantUpdates'] = array_get($result, 'hasImportantUpdates', false);
$this->vars['pluginList'] = array_get($result, 'plugins', []);
$this->vars['themeList'] = array_get($result, 'themes', []);
$updates = UpdateManager::instance()->availableUpdates();

$this->vars['core'] = $updates['modules'] ? [
'updates' => $updates['modules'],
'isImportant' => true
] : false;

$this->vars['pluginList'] = $updates['plugins']
? array_reduce(array_keys($updates['plugins']), function (array $carry, string $code) use ($updates) {
$carry[$code] = array_merge(PluginManager::instance()->get($code)->pluginDetails(), [
'isImportant' => false,
'old_version' => $updates['plugins'][$code]['from'],
'new_version' => $updates['plugins'][$code]['to'],
]);
return $carry;
}, [])
: false;

$this->vars['themeList'] = $updates['themes']
? array_reduce(array_keys($updates['themes']), function (array $carry, string $code) use ($updates) {
$theme = ThemeManager::instance()->get($code);
$carry[$code] = [
'name' => $theme['name'],
'isImportant' => false,
'old_version' => $updates['themes'][$code]['from'],
'new_version' => $updates['themes'][$code]['to'],
];
return $carry;
}, [])
: false;

$this->vars['hasImportantUpdates'] = !!count($updates['modules']);

$this->vars['hasUpdates'] = $this->vars['core'] || $this->vars['pluginList'] || $this->vars['themeList'];
}
catch (Exception $ex) {
$this->handleError($ex);
Expand Down Expand Up @@ -540,7 +565,7 @@ protected function buildUpdateSteps($core, $plugins, $themes, $isInstallationReq
public function onLoadChangelog(): string
{
try {
$fetchedContent = UpdateManager::instance()->requestChangelog();
$fetchedContent = MarketPlaceApi::instance()->requestChangelog();

$changelog = array_get($fetchedContent, 'history');

Expand Down
30 changes: 5 additions & 25 deletions modules/system/controllers/updates/_update_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,10 @@ class="form-control custom-select select-no-search"
</h5>
</div>
<dl>
<?php foreach (array_get($core, 'updates', []) as $build => $description): ?>
<dt><?= e(trans('system::lang.updates.core_build', ['build'=>$build])) ?></dt>
<?php if (is_array($description)): ?>
<dd>
<span class="important-update-label">
<?= e(trans('system::lang.updates.important_action_required')) ?>
</span>
<?= e($description[0]) ?>
<a href="<?= $description[1] ?>" target="_blank">
<?= e(trans('system::lang.updates.important_view_release_notes')) ?>
<i class="icon-external-link"></i>
</a>
</dd>
<?php else: ?>
<dd><?= e($description) ?></dd>
<?php endif ?>
<?php foreach (array_get($core, 'updates', []) as $module => $versions): ?>
<dt><?= e(trans('system::lang.updates.core_build', ['build' => $module])) ?></dt>
<?php endforeach ?>
<?php if ($core['old_build']): ?>
<dt class="text-muted"><?= e(trans('system::lang.updates.core_build', ['build'=>$core['old_build']])) ?></dt>
<dd class="text-muted"><?= e(trans('system::lang.updates.core_current_build')) ?></dd>
<?php endif ?>
</dl>
<input type="hidden" name="hash" value="<?= e($core['hash']) ?>" />
<input type="hidden" name="build" value="<?= e($core['build']) ?>" />
</div>
<?php endif ?>

Expand All @@ -66,11 +46,11 @@ class="form-control custom-select select-no-search"
</h5>
</div>
<dl>
<dt><?= e(array_get($theme, 'version', 'v1.0.0')) ?></dt>
<dt><?= e(array_get($theme, 'old_version', 'v1.0.0')) ?></dt>
<dd><?= e(trans('system::lang.updates.theme_new_install')) ?></dd>
</dl>

<input type="hidden" name="themes[<?= e($this->encodeCode($code)) ?>]" value="<?= e($theme['hash']) ?>" />
<input type="hidden" name="themes[<?= e($this->encodeCode($code)) ?>]" value="<?= e($theme['new_version']) ?>" />
</div>
<?php endforeach ?>

Expand Down Expand Up @@ -131,7 +111,7 @@ class="form-control custom-select select-no-search"
<?php endif ?>
</dl>

<input type="hidden" name="plugins[<?= e($this->encodeCode($code)) ?>]" value="<?= e($plugin['hash']) ?>" />
<input type="hidden" name="plugins[<?= e($this->encodeCode($code)) ?>]" value="<?= e($plugin['new_version']) ?>" />
</div>
<?php endforeach ?>

Expand Down

0 comments on commit e6dc1ad

Please sign in to comment.