diff --git a/extensions/package-manager/js/src/admin/components/TaskOutputModal.tsx b/extensions/package-manager/js/src/admin/components/TaskOutputModal.tsx index a1f6b008fd..aa509dcc16 100644 --- a/extensions/package-manager/js/src/admin/components/TaskOutputModal.tsx +++ b/extensions/package-manager/js/src/admin/components/TaskOutputModal.tsx @@ -19,12 +19,22 @@ export default class TaskOutputModal
+
+ +
+ {(this.attrs.task.guessedCause() && + app.translator.trans('flarum-package-manager.admin.exceptions.guessed_cause.' + this.attrs.task.guessedCause())) || + app.translator.trans('flarum-package-manager.admin.sections.queue.output_modal.cause_unknown')} +
+
+
$ composer {this.attrs.task.command()}
+
diff --git a/extensions/package-manager/js/src/admin/index.tsx b/extensions/package-manager/js/src/admin/index.tsx index fb0a0ac730..67fe6672b5 100755 --- a/extensions/package-manager/js/src/admin/index.tsx +++ b/extensions/package-manager/js/src/admin/index.tsx @@ -18,6 +18,10 @@ app.initializers.add('flarum-package-manager', (app) => { app.packageManager = new PackageManagerState(); + if (app.data['flarum-package-manager.using_sync_queue']) { + app.data.settings['flarum-package-manager.queue_jobs'] = '0'; + } + app.extensionData .for('flarum-package-manager') .registerSetting({ @@ -33,10 +37,8 @@ app.initializers.add('flarum-package-manager', (app) => { }) ) ), - default: false, type: 'boolean', disabled: app.data['flarum-package-manager.using_sync_queue'], - // @todo async to sync while setting is enabled }) .registerSetting({ setting: 'flarum-package-manager.task_retention_days', diff --git a/extensions/package-manager/js/src/admin/models/Task.ts b/extensions/package-manager/js/src/admin/models/Task.ts index 26769f5c87..9b7a1eae9f 100644 --- a/extensions/package-manager/js/src/admin/models/Task.ts +++ b/extensions/package-manager/js/src/admin/models/Task.ts @@ -32,6 +32,10 @@ export default class Task extends Model { return Model.attribute('output').call(this); } + guessedCause() { + return Model.attribute('guessedCause').call(this); + } + createdAt() { return Model.attribute('createdAt', Model.transformDate).call(this); } diff --git a/extensions/package-manager/locale/en.yml b/extensions/package-manager/locale/en.yml index 7ee7a516c9..4dcdc76877 100755 --- a/extensions/package-manager/locale/en.yml +++ b/extensions/package-manager/locale/en.yml @@ -75,7 +75,9 @@ flarum-package-manager: update_minor: Minor update why_not: Analyze why a package cannot be updated output_modal: + cause_unknown: Unknown command: Composer Command + guessed_cause: Cause output: Output refresh: Refresh tasks list statuses: diff --git a/extensions/package-manager/migrations/2023_12_09_000000_add_guessed_cause_column_to_package_manager_tasks_table.php b/extensions/package-manager/migrations/2023_12_09_000000_add_guessed_cause_column_to_package_manager_tasks_table.php new file mode 100644 index 0000000000..f0a09e3b0b --- /dev/null +++ b/extensions/package-manager/migrations/2023_12_09_000000_add_guessed_cause_column_to_package_manager_tasks_table.php @@ -0,0 +1,7 @@ + ['type' => 'string', 'length' => 255, 'nullable' => true, 'after' => 'output'], +]); diff --git a/extensions/package-manager/src/Api/Serializer/TaskSerializer.php b/extensions/package-manager/src/Api/Serializer/TaskSerializer.php index dfce8ab471..8ba662c26f 100644 --- a/extensions/package-manager/src/Api/Serializer/TaskSerializer.php +++ b/extensions/package-manager/src/Api/Serializer/TaskSerializer.php @@ -40,6 +40,7 @@ protected function getDefaultAttributes($model) 'command' => $model->command, 'package' => $model->package, 'output' => $model->output, + 'guessedCause' => $model->guessed_cause, 'createdAt' => $model->created_at, 'startedAt' => $model->started_at, 'finishedAt' => $model->finished_at, diff --git a/extensions/package-manager/src/Command/UpdateExtensionHandler.php b/extensions/package-manager/src/Command/UpdateExtensionHandler.php index dde622d851..22781cdf6f 100755 --- a/extensions/package-manager/src/Command/UpdateExtensionHandler.php +++ b/extensions/package-manager/src/Command/UpdateExtensionHandler.php @@ -96,6 +96,7 @@ public function handle(UpdateExtension $command) ]); } + // @todo: soft update and hard update instead of directly hard updating? $output = $this->composer->run( new StringInput("require $extension->name:*"), $command->task ?? null diff --git a/extensions/package-manager/src/Job/ComposerCommandJob.php b/extensions/package-manager/src/Job/ComposerCommandJob.php index 21d1485688..a4e0befd12 100644 --- a/extensions/package-manager/src/Job/ComposerCommandJob.php +++ b/extensions/package-manager/src/Job/ComposerCommandJob.php @@ -12,6 +12,7 @@ use Flarum\Bus\Dispatcher; use Flarum\PackageManager\Command\AbstractActionCommand; use Flarum\PackageManager\Composer\ComposerAdapter; +use Flarum\PackageManager\Exception\ComposerCommandFailedException; use Flarum\Queue\AbstractJob; use Illuminate\Contracts\Queue\ShouldBeUnique; use Illuminate\Queue\Middleware\WithoutOverlapping; @@ -56,12 +57,16 @@ public function abort(Throwable $exception) $this->command->task->output = $exception->getMessage(); } + if ($exception instanceof ComposerCommandFailedException) { + $this->command->task->guessed_cause = $exception->guessCause(); + } + $this->command->task->end(false); } public function failed(Throwable $exception): void { - $this->command->task->end(false); + $this->abort($exception); } public function middleware(): array diff --git a/extensions/package-manager/src/Task/Task.php b/extensions/package-manager/src/Task/Task.php index fb90e4e1ce..eac38963c8 100644 --- a/extensions/package-manager/src/Task/Task.php +++ b/extensions/package-manager/src/Task/Task.php @@ -19,6 +19,7 @@ * @property string $command * @property string $package * @property string $output + * @property string|null $guessed_cause * @property Carbon $created_at * @property Carbon|null $started_at * @property Carbon|null $finished_at @@ -50,7 +51,7 @@ class Task extends AbstractModel protected $table = 'package_manager_tasks'; - protected $fillable = ['command', 'output']; + protected $guarded = ['id']; public $timestamps = true;