From e3553e231d5c11747ea27adafd395701cc0d3b08 Mon Sep 17 00:00:00 2001 From: Sami Mazouz Date: Thu, 7 Dec 2023 14:23:38 +0100 Subject: [PATCH] chore: light tweaks --- .../src/admin/components/ControlSection.tsx | 5 ++- .../js/src/admin/components/MajorUpdater.tsx | 8 +++- .../js/src/admin/components/Updater.tsx | 14 +++--- .../less/admin/ControlSection.less | 43 ++++++++++++++++--- extensions/package-manager/locale/en.yml | 4 +- .../Api/Controller/ListTasksController.php | 8 ++-- .../src/Command/AbstractActionCommand.php | 3 +- .../src/Command/CheckForUpdates.php | 6 +-- .../src/Command/GlobalUpdate.php | 6 +-- .../src/Command/MajorUpdate.php | 6 +-- .../src/Command/MinorUpdate.php | 6 +-- .../src/Command/RemoveExtension.php | 6 +-- .../src/Command/RequireExtension.php | 6 +-- .../src/Command/UpdateExtension.php | 6 +-- .../package-manager/src/Command/WhyNot.php | 6 +-- .../package-manager/src/Job/Dispatcher.php | 2 +- .../package-manager/src/Task/Operation.php | 15 +++++++ .../package-manager/src/Task/Status.php | 11 +++++ extensions/package-manager/src/Task/Task.php | 34 ++++----------- .../src/Task/TaskRepository.php | 29 ------------- 20 files changed, 122 insertions(+), 102 deletions(-) create mode 100644 extensions/package-manager/src/Task/Operation.php create mode 100644 extensions/package-manager/src/Task/Status.php delete mode 100644 extensions/package-manager/src/Task/TaskRepository.php diff --git a/extensions/package-manager/js/src/admin/components/ControlSection.tsx b/extensions/package-manager/js/src/admin/components/ControlSection.tsx index 946ba1b273..13444c4452 100644 --- a/extensions/package-manager/js/src/admin/components/ControlSection.tsx +++ b/extensions/package-manager/js/src/admin/components/ControlSection.tsx @@ -6,6 +6,7 @@ import { ComponentAttrs } from 'flarum/common/Component'; import Installer from './Installer'; import Updater from './Updater'; import Mithril from 'mithril'; +import Form from 'flarum/common/components/Form'; export default class ControlSection extends Component { oninit(vnode: Mithril.Vnode) { @@ -22,10 +23,10 @@ export default class ControlSection extends Component {
{app.data['flarum-package-manager.writable_dirs'] ? ( - <> +
- + ) : (
diff --git a/extensions/package-manager/js/src/admin/components/MajorUpdater.tsx b/extensions/package-manager/js/src/admin/components/MajorUpdater.tsx index e9c5cf8233..8d5157bf77 100644 --- a/extensions/package-manager/js/src/admin/components/MajorUpdater.tsx +++ b/extensions/package-manager/js/src/admin/components/MajorUpdater.tsx @@ -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; @@ -33,7 +34,12 @@ export default class MajorUpdater +
flarum logo

{app.translator.trans('flarum-package-manager.admin.major_updater.description')}

diff --git a/extensions/package-manager/js/src/admin/components/Updater.tsx b/extensions/package-manager/js/src/admin/components/Updater.tsx index 9cf086fda5..cd0d5732d2 100755 --- a/extensions/package-manager/js/src/admin/components/Updater.tsx +++ b/extensions/package-manager/js/src/admin/components/Updater.tsx @@ -56,12 +56,12 @@ export default class Updater extends Component { ); } - if (!(state.extensionUpdates.length || state.coreUpdate)) { + const hasMinorCoreUpdate = state.coreUpdate && state.coreUpdate.package['latest-minor']; + + if (!(state.extensionUpdates.length || hasMinorCoreUpdate)) { return (
- - {app.translator.trans('flarum-package-manager.admin.updater.up_to_date')} - + {app.translator.trans('flarum-package-manager.admin.updater.up_to_date')}
); } @@ -69,10 +69,10 @@ export default class Updater extends Component { return (
- {state.coreUpdate ? ( + {hasMinorCoreUpdate ? ( state.updateCoreMinor()} whyNotWarning={state.lastUpdateRun.limitedPackages().includes('flarum/core')} diff --git a/extensions/package-manager/less/admin/ControlSection.less b/extensions/package-manager/less/admin/ControlSection.less index 14eafb5f1a..ab058207f7 100644 --- a/extensions/package-manager/less/admin/ControlSection.less +++ b/extensions/package-manager/less/admin/ControlSection.less @@ -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); } } @@ -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; } @@ -116,6 +141,10 @@ padding-top: var(--space); border-top: 1px solid var(--control-bg); } + + .PackageManager-updaterControls { + margin: 0; + } } .WhyNotModal { @@ -131,3 +160,7 @@ width: 300px; } } + +.PackageManager-controlSection .container { + max-width: 900px; +} diff --git a/extensions/package-manager/locale/en.yml b/extensions/package-manager/locale/en.yml index 607449dfb0..19b7252115 100755 --- a/extensions/package-manager/locale/en.yml +++ b/extensions/package-manager/locale/en.yml @@ -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: diff --git a/extensions/package-manager/src/Api/Controller/ListTasksController.php b/extensions/package-manager/src/Api/Controller/ListTasksController.php index 804bd3a586..0781654d29 100644 --- a/extensions/package-manager/src/Api/Controller/ListTasksController.php +++ b/extensions/package-manager/src/Api/Controller/ListTasksController.php @@ -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; @@ -23,7 +23,6 @@ class ListTasksController extends AbstractListController public function __construct( protected UrlGenerator $url, - protected TaskRepository $repository ) { } @@ -36,14 +35,13 @@ protected function data(ServerRequestInterface $request, Document $document): it $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); diff --git a/extensions/package-manager/src/Command/AbstractActionCommand.php b/extensions/package-manager/src/Command/AbstractActionCommand.php index 29565deb0a..cf7b40a7c8 100644 --- a/extensions/package-manager/src/Command/AbstractActionCommand.php +++ b/extensions/package-manager/src/Command/AbstractActionCommand.php @@ -9,6 +9,7 @@ namespace Flarum\PackageManager\Command; +use Flarum\PackageManager\Task\Operation; use Flarum\PackageManager\Task\Task; abstract class AbstractActionCommand @@ -16,5 +17,5 @@ abstract class AbstractActionCommand public ?Task $task = null; public ?string $package = null; - abstract public function getOperationName(): string; + abstract public function getOperationName(): Operation; } diff --git a/extensions/package-manager/src/Command/CheckForUpdates.php b/extensions/package-manager/src/Command/CheckForUpdates.php index 8f91a8ffbf..c5d27b3028 100755 --- a/extensions/package-manager/src/Command/CheckForUpdates.php +++ b/extensions/package-manager/src/Command/CheckForUpdates.php @@ -9,7 +9,7 @@ namespace Flarum\PackageManager\Command; -use Flarum\PackageManager\Task\Task; +use Flarum\PackageManager\Task\Operation; use Flarum\User\User; class CheckForUpdates extends AbstractActionCommand @@ -19,8 +19,8 @@ public function __construct( ) { } - public function getOperationName(): string + public function getOperationName(): Operation { - return Task::UPDATE_CHECK; + return Operation::UPDATE_CHECK; } } diff --git a/extensions/package-manager/src/Command/GlobalUpdate.php b/extensions/package-manager/src/Command/GlobalUpdate.php index 610a92e34c..45a7c1d0fd 100644 --- a/extensions/package-manager/src/Command/GlobalUpdate.php +++ b/extensions/package-manager/src/Command/GlobalUpdate.php @@ -9,7 +9,7 @@ namespace Flarum\PackageManager\Command; -use Flarum\PackageManager\Task\Task; +use Flarum\PackageManager\Task\Operation; use Flarum\User\User; class GlobalUpdate extends AbstractActionCommand @@ -19,8 +19,8 @@ public function __construct( ) { } - public function getOperationName(): string + public function getOperationName(): Operation { - return Task::UPDATE_GLOBAL; + return Operation::UPDATE_GLOBAL; } } diff --git a/extensions/package-manager/src/Command/MajorUpdate.php b/extensions/package-manager/src/Command/MajorUpdate.php index 58970e028b..785151bf3d 100644 --- a/extensions/package-manager/src/Command/MajorUpdate.php +++ b/extensions/package-manager/src/Command/MajorUpdate.php @@ -9,7 +9,7 @@ namespace Flarum\PackageManager\Command; -use Flarum\PackageManager\Task\Task; +use Flarum\PackageManager\Task\Operation; use Flarum\User\User; class MajorUpdate extends AbstractActionCommand @@ -20,8 +20,8 @@ public function __construct( ) { } - public function getOperationName(): string + public function getOperationName(): Operation { - return Task::UPDATE_MAJOR; + return Operation::UPDATE_MAJOR; } } diff --git a/extensions/package-manager/src/Command/MinorUpdate.php b/extensions/package-manager/src/Command/MinorUpdate.php index c32c521834..113c244cf7 100755 --- a/extensions/package-manager/src/Command/MinorUpdate.php +++ b/extensions/package-manager/src/Command/MinorUpdate.php @@ -9,7 +9,7 @@ namespace Flarum\PackageManager\Command; -use Flarum\PackageManager\Task\Task; +use Flarum\PackageManager\Task\Operation; use Flarum\User\User; class MinorUpdate extends AbstractActionCommand @@ -19,8 +19,8 @@ public function __construct( ) { } - public function getOperationName(): string + public function getOperationName(): Operation { - return Task::UPDATE_MINOR; + return Operation::UPDATE_MINOR; } } diff --git a/extensions/package-manager/src/Command/RemoveExtension.php b/extensions/package-manager/src/Command/RemoveExtension.php index a33f23ed07..e616589de9 100755 --- a/extensions/package-manager/src/Command/RemoveExtension.php +++ b/extensions/package-manager/src/Command/RemoveExtension.php @@ -9,7 +9,7 @@ namespace Flarum\PackageManager\Command; -use Flarum\PackageManager\Task\Task; +use Flarum\PackageManager\Task\Operation; use Flarum\User\User; class RemoveExtension extends AbstractActionCommand @@ -20,8 +20,8 @@ public function __construct( ) { } - public function getOperationName(): string + public function getOperationName(): Operation { - return Task::EXTENSION_REMOVE; + return Operation::EXTENSION_REMOVE; } } diff --git a/extensions/package-manager/src/Command/RequireExtension.php b/extensions/package-manager/src/Command/RequireExtension.php index 7d18474eac..de1b4ec5f5 100755 --- a/extensions/package-manager/src/Command/RequireExtension.php +++ b/extensions/package-manager/src/Command/RequireExtension.php @@ -9,7 +9,7 @@ namespace Flarum\PackageManager\Command; -use Flarum\PackageManager\Task\Task; +use Flarum\PackageManager\Task\Operation; use Flarum\User\User; class RequireExtension extends AbstractActionCommand @@ -20,8 +20,8 @@ public function __construct( ) { } - public function getOperationName(): string + public function getOperationName(): Operation { - return Task::EXTENSION_INSTALL; + return Operation::EXTENSION_INSTALL; } } diff --git a/extensions/package-manager/src/Command/UpdateExtension.php b/extensions/package-manager/src/Command/UpdateExtension.php index f07399db6e..2d3b1fefea 100755 --- a/extensions/package-manager/src/Command/UpdateExtension.php +++ b/extensions/package-manager/src/Command/UpdateExtension.php @@ -9,7 +9,7 @@ namespace Flarum\PackageManager\Command; -use Flarum\PackageManager\Task\Task; +use Flarum\PackageManager\Task\Operation; use Flarum\User\User; class UpdateExtension extends AbstractActionCommand @@ -20,8 +20,8 @@ public function __construct( ) { } - public function getOperationName(): string + public function getOperationName(): Operation { - return Task::EXTENSION_UPDATE; + return Operation::EXTENSION_UPDATE; } } diff --git a/extensions/package-manager/src/Command/WhyNot.php b/extensions/package-manager/src/Command/WhyNot.php index b8374f406f..587b41ffca 100755 --- a/extensions/package-manager/src/Command/WhyNot.php +++ b/extensions/package-manager/src/Command/WhyNot.php @@ -9,7 +9,7 @@ namespace Flarum\PackageManager\Command; -use Flarum\PackageManager\Task\Task; +use Flarum\PackageManager\Task\Operation; use Flarum\User\User; class WhyNot extends AbstractActionCommand @@ -21,8 +21,8 @@ public function __construct( ) { } - public function getOperationName(): string + public function getOperationName(): Operation { - return Task::WHY_NOT; + return Operation::WHY_NOT; } } diff --git a/extensions/package-manager/src/Job/Dispatcher.php b/extensions/package-manager/src/Job/Dispatcher.php index 7eecadf6f9..39dea43abf 100644 --- a/extensions/package-manager/src/Job/Dispatcher.php +++ b/extensions/package-manager/src/Job/Dispatcher.php @@ -23,7 +23,7 @@ class Dispatcher * Runs synchronously regardless of user setting if set true. * Asynchronously if set false. */ - protected ?bool $runSyncOverride; + protected ?bool $runSyncOverride = null; public function __construct( protected Bus $bus, diff --git a/extensions/package-manager/src/Task/Operation.php b/extensions/package-manager/src/Task/Operation.php new file mode 100644 index 0000000000..c2b689ed62 --- /dev/null +++ b/extensions/package-manager/src/Task/Operation.php @@ -0,0 +1,15 @@ + 'datetime', 'started_at' => 'datetime', 'finished_at' => 'datetime', + 'status' => Status::class, + 'operation' => Operation::class, ]; - public static function build(string $operation, ?string $package): self + public static function build(Operation $operation, ?string $package): self { $task = new static; $task->operation = $operation; $task->package = $package; - $task->status = static::PENDING; + $task->status = Status::PENDING; $task->created_at = Carbon::now(); $task->save(); @@ -76,7 +58,7 @@ public static function build(string $operation, ?string $package): self public function start(): bool { - $this->status = static::RUNNING; + $this->status = Status::RUNNING; $this->started_at = Carbon::now(); return $this->save(); @@ -84,7 +66,7 @@ public function start(): bool public function end(bool $success): bool { - $this->status = $success ? static::SUCCESS : static::FAILURE; + $this->status = $success ? Status::SUCCESS : Status::FAILURE; $this->finished_at = Carbon::now(); $this->peak_memory_used = round(memory_get_peak_usage() / 1024); diff --git a/extensions/package-manager/src/Task/TaskRepository.php b/extensions/package-manager/src/Task/TaskRepository.php deleted file mode 100644 index 2895d2732b..0000000000 --- a/extensions/package-manager/src/Task/TaskRepository.php +++ /dev/null @@ -1,29 +0,0 @@ -