From f78b8f6d57c4827f212b20945eb340b0143f715c Mon Sep 17 00:00:00 2001 From: Ahmet Bora Date: Fri, 23 Feb 2024 10:48:51 +0300 Subject: [PATCH] New `plugin:upgrade` command --- commands/plugin/upgrade.php | 39 +++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 commands/plugin/upgrade.php diff --git a/commands/plugin/upgrade.php b/commands/plugin/upgrade.php new file mode 100644 index 0000000..6f75b9c --- /dev/null +++ b/commands/plugin/upgrade.php @@ -0,0 +1,39 @@ + 'Upgrades a kirby plugin', + 'args' => [ + 'repo' => [ + 'description' => 'The Kirby plugin registry name (i.e. getkirby/kql)', + 'required' => true + ], + 'version' => [ + 'description' => 'The version corresponding with the tag name in the repo', + 'defaultValue' => 'latest' + ] + ], + 'command' => static function (CLI $cli): void { + $repo = $cli->arg('repo'); + $version = $cli->arg('version'); + + if ($plugin = $cli->kirby()->plugin($repo)) { + try { + // move plugin directory to prevent overwrite + Dir::move($plugin->root(), $plugin->root() . '.bak'); + $cli->run('plugin:install', $repo, $version); + Dir::remove($plugin->root() . '.bak'); + $cli->success('The ' . $repo . ' plugin has been updated to ' . $version . ' version'); + } catch (Throwable) { + Dir::move($plugin->root() . '.bak', $plugin->root()); + $cli->error('The ' . $repo . ' plugin could not updated'); + } + } else { + $cli->error('The ' . $repo . ' plugin could not found'); + } + } +];