Skip to content

Commit

Permalink
chore: track
Browse files Browse the repository at this point in the history
  • Loading branch information
SychO9 committed Dec 7, 2023
1 parent 480093d commit 34a66a8
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ export default class ExtensionItem<Attrs extends ExtensionItemAttrs = ExtensionI
}

version(v: string): string {
return 'v' + v.replace('v', '');
return v.charAt(0) === 'v' ? v.substring(1) : v;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import WhyNotModal from './WhyNotModal';
import ExtensionItem from './ExtensionItem';
import { AsyncBackendResponse } from '../shims';
import jumpToQueue from '../utils/jumpToQueue';
import classList from "flarum/common/utils/classList";

export interface MajorUpdaterAttrs extends ComponentAttrs {
coreUpdate: UpdatedPackage;
Expand All @@ -33,7 +34,12 @@ export default class MajorUpdater<T extends MajorUpdaterAttrs = MajorUpdaterAttr
view(): Mithril.Children {
// @todo move Form-group--danger class to core for reuse
return (
<div className="Form-group Form-group--danger PackageManager-majorUpdate">
<div
className={classList('Form-group Form-group--danger PackageManager-majorUpdate', {
'PackageManager-majorUpdate--failed': this.updateState.status === 'failure',
'PackageManager-majorUpdate--incompatibleExtensions': this.updateState.incompatibleExtensions.length,
})}
>
<img alt="flarum logo" src={app.forum.attribute('baseUrl') + '/assets/extensions/flarum-package-manager/flarum.svg'} />
<label>{app.translator.trans('flarum-package-manager.admin.major_updater.title', { version: this.attrs.coreUpdate['latest-major'] })}</label>
<p className="helpText">{app.translator.trans('flarum-package-manager.admin.major_updater.description')}</p>
Expand Down
14 changes: 7 additions & 7 deletions extensions/package-manager/js/src/admin/components/Updater.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,23 @@ export default class Updater extends Component<IUpdaterAttrs> {
);
}

if (!(state.extensionUpdates.length || state.coreUpdate)) {
const hasMinorCoreUpdate = state.coreUpdate && state.coreUpdate.package['latest-minor'];

if (!(state.extensionUpdates.length || hasMinorCoreUpdate)) {
return (
<div className="PackageManager-extensions">
<Alert type="success" dismissible={false}>
{app.translator.trans('flarum-package-manager.admin.updater.up_to_date')}
</Alert>
<span className="helpText">{app.translator.trans('flarum-package-manager.admin.updater.up_to_date')}</span>
</div>
);
}

return (
<div className="PackageManager-extensions">
<div className="PackageManager-extensions-grid">
{state.coreUpdate ? (
{hasMinorCoreUpdate ? (
<ExtensionItem
extension={state.coreUpdate.extension}
updates={state.coreUpdate.package}
extension={state.coreUpdate!.extension}
updates={state.coreUpdate!.package}
isCore={true}
onClickUpdate={() => state.updateCoreMinor()}
whyNotWarning={state.lastUpdateRun.limitedPackages().includes('flarum/core')}
Expand Down
43 changes: 38 additions & 5 deletions extensions/package-manager/less/admin/ControlSection.less
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
}

.PackageManager-extensions {
width: 100%;

&-grid {
--gap: 12px;
display: grid;
grid-template-columns: repeat(auto-fit, calc(~"100% / 3 - var(--gap)"));
grid-template-columns: repeat(auto-fit, 310px);
gap: var(--gap);
}
}
Expand Down Expand Up @@ -86,12 +88,35 @@
grid-template-areas:
"title logo"
"helpText logo"
"controls logo"
"extensions extensions"
"failure failure";
grid-gap: 0 var(--space);
"controls logo";
column-gap: 0 var(--space);
align-items: center;

&--failed&--incompatibleExtensions {
grid-template-areas:
"title logo"
"helpText logo"
"controls logo"
"extensions extensions"
"failure failure";
}

&--failed {
grid-template-areas:
"title logo"
"helpText logo"
"controls logo"
"failure failure";
}

&--incompatibleExtensions {
grid-template-areas:
"title logo"
"helpText logo"
"controls logo"
"extensions extensions";
}

> img {
grid-area: logo;
}
Expand All @@ -116,6 +141,10 @@
padding-top: var(--space);
border-top: 1px solid var(--control-bg);
}

.PackageManager-updaterControls {
margin: 0;
}
}

.WhyNotModal {
Expand All @@ -131,3 +160,7 @@
width: 300px;
}
}

.PackageManager-controlSection .container {
max-width: 1030px;
}
4 changes: 3 additions & 1 deletion extensions/package-manager/locale/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ flarum-package-manager:
The package manager requires read and write permissions on the following files and directories: composer.json, composer.lock, vendor, storage, storage/.composer
major_updater:
description: Major Flarum updates are not backwards compatible, meaning that some of your currently installed extensions, and manually made modifications might not work with this new version.
description: >
Major Flarum updates are not backwards compatible, meaning that some of your currently installed extensions, and manually made modifications might not work with this new version.
Please make sure to make a backup of your database and files before proceeding.
dry_run: Dry Run
dry_run_help: A dry run emulates the update to see if your current setup can safely update, this does not mean that your manual made custom modifications will work in the newer version.
failure:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Flarum\Http\RequestUtil;
use Flarum\Http\UrlGenerator;
use Flarum\PackageManager\Api\Serializer\TaskSerializer;
use Flarum\PackageManager\Task\TaskRepository;
use Flarum\PackageManager\Task\Task;
use Psr\Http\Message\ServerRequestInterface;
use Tobscure\JsonApi\Document;

Expand All @@ -29,15 +29,9 @@ class ListTasksController extends AbstractListController
*/
protected $url;

/**
* @var TaskRepository
*/
protected $repository;

public function __construct(UrlGenerator $url, TaskRepository $repository)
public function __construct(UrlGenerator $url)
{
$this->url = $url;
$this->repository = $repository;
}

protected function data(ServerRequestInterface $request, Document $document)
Expand All @@ -49,14 +43,13 @@ protected function data(ServerRequestInterface $request, Document $document)
$limit = $this->extractLimit($request);
$offset = $this->extractOffset($request);

$results = $this->repository
->query()
$results = Task::query()
->latest()
->offset($offset)
->limit($limit)
->get();

$total = $this->repository->query()->count();
$total = Task::query()->count();

$document->addMeta('total', (string) $total);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use Flarum\PackageManager\Composer\ComposerAdapter;
use Flarum\PackageManager\Exception\ComposerCommandFailedException;
use Flarum\PackageManager\Extension\ExtensionUtils;
use Flarum\PackageManager\Settings\LastUpdateCheck;
use Symfony\Component\Console\Input\ArrayInput;

Expand Down Expand Up @@ -58,7 +59,7 @@ public function handle(CheckForUpdates $command)
$majorUpdates = false;

foreach ($firstOutput['installed'] as $package) {
if (isset($package['latest-status']) && $package['latest-status'] === 'update-possible') {
if (isset($package['latest-status']) && $package['latest-status'] === 'update-possible' && ExtensionUtils::isMajorUpdate($package['version'], $package['latest'])) {
$majorUpdates = true;
break;
}
Expand All @@ -76,7 +77,7 @@ public function handle(CheckForUpdates $command)
foreach ($firstOutput['installed'] as &$mainPackageUpdate) {
$mainPackageUpdate['latest-minor'] = $mainPackageUpdate['latest-major'] = null;

if (isset($mainPackageUpdate['latest-status']) && $mainPackageUpdate['latest-status'] === 'update-possible') {
if (isset($mainPackageUpdate['latest-status']) && $mainPackageUpdate['latest-status'] === 'update-possible' && ExtensionUtils::isMajorUpdate($mainPackageUpdate['version'], $mainPackageUpdate['latest'])) {
$mainPackageUpdate['latest-major'] = $mainPackageUpdate['latest'];

$minorPackageUpdate = array_filter($secondOutput['installed'], function ($package) use ($mainPackageUpdate) {
Expand Down
3 changes: 0 additions & 3 deletions extensions/package-manager/src/Command/MajorUpdateHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ public function handle(MajorUpdate $command)
);
}

/**
* @todo change minimum stability to 'stable' and any other similar params
*/
protected function updateComposerJson(string $majorVersion): void
{
$versionNumber = str_replace('v', '', $majorVersion);
Expand Down
21 changes: 21 additions & 0 deletions extensions/package-manager/src/Extension/ExtensionUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,25 @@ public static function nameToId(string $name): string

return "$vendor-$package";
}

public static function isMajorUpdate(string $currentVersion, string $latestVersion): bool
{
// Drop any v prefixes
if(str_starts_with($currentVersion, 'v')) {
$currentVersion = substr($currentVersion, 1);
}

$currentVersion = explode('.', $currentVersion);
$latestVersion = explode('.', $latestVersion);

if (! is_numeric($currentVersion[0]) || ! is_numeric($latestVersion[0])) {
return false;
}

if (intval($currentVersion[0]) < intval($latestVersion[0])) {
return true;
}

return false;
}
}

0 comments on commit 34a66a8

Please sign in to comment.