Fixed bin/gpm index erroring out [#3158]

This commit is contained in:
Matias Griese
2021-01-20 09:58:31 +02:00
parent 3d5b54515a
commit 3a31d54600
2 changed files with 18 additions and 13 deletions

View File

@@ -4,6 +4,7 @@
1. [](#bugfix)
* Fixed fatal error when `site.taxonomies` contains a bad value
* Sanitize valid Page extensions from `Page::template_format()`
* Fixed `bin/gpm index` erroring out [#3158](https://github.com/getgrav/grav/issues/3158)
# v1.7.0
## 01/19/2021

View File

@@ -9,14 +9,16 @@
namespace Grav\Console\Gpm;
use Grav\Common\GPM\Remote\AbstractPackageCollection;
use Grav\Common\GPM\Remote\Package;
use Grav\Common\GPM\GPM;
use Grav\Common\GPM\Remote\Packages;
use Grav\Common\GPM\Remote\Plugins;
use Grav\Common\GPM\Remote\Themes;
use Grav\Common\Utils;
use Grav\Console\GpmCommand;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Style\SymfonyStyle;
use function count;
/**
@@ -78,9 +80,9 @@ class IndexCommand extends GpmCommand
->addOption(
'sort',
's',
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
'Allows to sort (ASC) the results based on one or multiple keys. SORT can be either "name", "slug", "author", "date"',
['date']
InputOption::VALUE_REQUIRED,
'Allows to sort (ASC) the results. SORT can be either "name", "slug", "author", "date"',
'date'
)
->addOption(
'desc',
@@ -249,22 +251,24 @@ class IndexCommand extends GpmCommand
}
/**
* @param Packages $packages
* @return Packages
* @param AbstractPackageCollection|Plugins|Themes $packages
* @return array
*/
public function sort(Packages $packages): Packages
public function sort(AbstractPackageCollection $packages): array
{
foreach ($this->options['sort'] as $key) {
$packages = $packages->sort(function ($a, $b) use ($key) {
$key = $this->options['sort'];
// Sorting only works once.
return $packages->sort(
function ($a, $b) use ($key) {
switch ($key) {
case 'author':
return strcmp($a->{$key}['name'], $b->{$key}['name']);
default:
return strcmp($a->$key, $b->$key);
}
}, $this->options['desc'] ? true : false);
}
return $packages;
},
$this->options['desc'] ? true : false
);
}
}