From 51e8e82c0726b0386d2989c42df003899d35af8a Mon Sep 17 00:00:00 2001 From: Alexander Nickel Date: Fri, 16 Feb 2024 12:51:35 +0100 Subject: [PATCH] refactor(shopware): Optimize `getPlugins` to use json output (#3780) Refactoring the `getPlugins` function to not parse regular commandline output anymore, instead use the --json flag `plugin:list`. Refactoring 'sw:plugin:update:all' to not upgrade every installed plugin, but every installed plugin that in fact is upgradable. --- docs/recipe/shopware.md | 14 +++++++------- recipe/shopware.php | 34 +++++----------------------------- 2 files changed, 12 insertions(+), 36 deletions(-) diff --git a/docs/recipe/shopware.md b/docs/recipe/shopware.md index 144e2be7..4a5edfb6 100644 --- a/docs/recipe/shopware.md +++ b/docs/recipe/shopware.md @@ -225,7 +225,7 @@ to build the theme remotely instead of locally. ### sw:plugin:update:all -[Source](https://github.com/deployphp/deployer/blob/master/recipe/shopware.php#L138) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/shopware.php#L114) @@ -233,7 +233,7 @@ to build the theme remotely instead of locally. ### sw:writable:jwt -[Source](https://github.com/deployphp/deployer/blob/master/recipe/shopware.php#L148) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/shopware.php#L124) @@ -241,7 +241,7 @@ to build the theme remotely instead of locally. ### sw:deploy -[Source](https://github.com/deployphp/deployer/blob/master/recipe/shopware.php#L155) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/shopware.php#L131) @@ -259,7 +259,7 @@ This task is group task which contains next tasks: ### deploy -[Source](https://github.com/deployphp/deployer/blob/master/recipe/shopware.php#L166) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/shopware.php#L142) Deploys your project. @@ -276,7 +276,7 @@ This task is group task which contains next tasks: ### sw-build-without-db:get-remote-config -[Source](https://github.com/deployphp/deployer/blob/master/recipe/shopware.php#L175) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/shopware.php#L151) @@ -284,7 +284,7 @@ This task is group task which contains next tasks: ### sw-build-without-db:build -[Source](https://github.com/deployphp/deployer/blob/master/recipe/shopware.php#L188) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/shopware.php#L164) @@ -292,7 +292,7 @@ This task is group task which contains next tasks: ### sw-build-without-db -[Source](https://github.com/deployphp/deployer/blob/master/recipe/shopware.php#L192) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/shopware.php#L168) diff --git a/recipe/shopware.php b/recipe/shopware.php index 11c8c2f0..7c3854a1 100644 --- a/recipe/shopware.php +++ b/recipe/shopware.php @@ -105,32 +105,8 @@ task('sw:theme:compile', function () { function getPlugins(): array { - $output = explode("\n", run('cd {{release_path}} && {{bin/console}} plugin:list')); - - // Take line over headlines and count "-" to get the size of the cells. - $lengths = array_filter(array_map('strlen', explode(' ', $output[4]))); - $splitRow = function ($row) use ($lengths) { - $columns = []; - foreach ($lengths as $length) { - $columns[] = trim(substr($row, 0, $length)); - $row = substr($row, $length + 1); - } - return $columns; - }; - $headers = $splitRow($output[5]); - $splitRowIntoStructure = function ($row) use ($splitRow, $headers) { - $columns = $splitRow($row); - return array_combine($headers, $columns); - }; - - // Ignore first seven lines (headline, title, table, ...). - $rows = array_slice($output, 7, -3); - - $plugins = []; - foreach ($rows as $row) { - $pluginInformation = $splitRowIntoStructure($row); - $plugins[] = $pluginInformation; - } + $output = run('cd {{release_path}} && {{bin/console}} plugin:list --json'); + $plugins = json_decode($output); return $plugins; } @@ -138,9 +114,9 @@ function getPlugins(): array task('sw:plugin:update:all', static function () { $plugins = getPlugins(); foreach ($plugins as $plugin) { - if ($plugin['Installed'] === 'Yes') { - writeln("Running plugin update for " . $plugin['Plugin'] . "\n"); - run("cd {{release_path}} && {{bin/console}} plugin:update " . $plugin['Plugin']); + if ($plugin->installedAt && $plugin->upgradeVersion) { + writeln("Running plugin update for " . $plugin->name . "\n"); + run("cd {{release_path}} && {{bin/console}} plugin:update " . $plugin->name); } } });