Skip to content

Commit

Permalink
refactor(shopware): Optimize getPlugins to use json output (#3780)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mralexandernickel authored Feb 16, 2024
1 parent ff69fd2 commit 51e8e82
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 36 deletions.
14 changes: 7 additions & 7 deletions docs/recipe/shopware.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,23 +225,23 @@ 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)






### 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)






### 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)



Expand All @@ -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.

Expand All @@ -276,23 +276,23 @@ 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)






### 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)






### 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)



Expand Down
34 changes: 5 additions & 29 deletions recipe/shopware.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,42 +105,18 @@

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;
}

task('sw:plugin:update:all', static function () {
$plugins = getPlugins();
foreach ($plugins as $plugin) {
if ($plugin['Installed'] === 'Yes') {
writeln("<info>Running plugin update for " . $plugin['Plugin'] . "</info>\n");
run("cd {{release_path}} && {{bin/console}} plugin:update " . $plugin['Plugin']);
if ($plugin->installedAt && $plugin->upgradeVersion) {
writeln("<info>Running plugin update for " . $plugin->name . "</info>\n");
run("cd {{release_path}} && {{bin/console}} plugin:update " . $plugin->name);
}
}
});
Expand Down

0 comments on commit 51e8e82

Please sign in to comment.