mirror of
https://github.com/getgrav/grav.git
synced 2026-06-12 03:22:08 +02:00
Added ability to filter enabled or disabled with bin/gpm index [#3187]
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
* Updated bundled `composer.phar` binary to latest version `2.0.9`
|
||||
* Improved session fixation handling in PHP 7.4+ (cannot fix it in PHP 7.3 due to PHP bug)
|
||||
* Added optional password/database attributes for redis in `system.yaml`
|
||||
* Added ability to filter enabled or disabled with bin/gpm index [#3187](https://github.com/getgrav/grav/pull/3187)
|
||||
1. [](#bugfix)
|
||||
* Fixed CLI progressbar in `backup` and `security` commands to use styled output [#3198](https://github.com/getgrav/grav/issues/3198)
|
||||
* Fixed page save failing because of uploaded images [#3191](https://github.com/getgrav/grav/issues/3191)
|
||||
|
||||
@@ -146,23 +146,11 @@ class GPM extends Iterator
|
||||
* @param string $slug
|
||||
* @return bool True if the Plugin is Enabled. False if manually set to enable:false. Null otherwise.
|
||||
*/
|
||||
public function isPluginEnabled($slug)
|
||||
public function isPluginEnabled($slug): bool
|
||||
{
|
||||
$result = null;
|
||||
$grav = new Grav();
|
||||
$config = $grav::instance()['config']['plugins'];
|
||||
$installed = $this->isPluginInstalled($slug);
|
||||
$grav = Grav::instance();
|
||||
|
||||
$enabled = isset($config[$slug]) && ((bool)$config[$slug]['enabled'] == true);
|
||||
$disabled = isset($config[$slug]['enabled']) && ((bool)$config[$slug]['enabled'] === false);
|
||||
|
||||
if ($enabled) {
|
||||
$result = true;
|
||||
}
|
||||
if ($disabled) {
|
||||
$result = false;
|
||||
}
|
||||
return $result;
|
||||
return ($grav['config']['plugins'][$slug]['enabled'] ?? false) === true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -171,7 +159,7 @@ class GPM extends Iterator
|
||||
* @param string $slug The slug of the Plugin
|
||||
* @return bool True if the Plugin has been installed. False otherwise
|
||||
*/
|
||||
public function isPluginInstalled($slug)
|
||||
public function isPluginInstalled($slug): bool
|
||||
{
|
||||
return isset($this->installed['plugins'][$slug]);
|
||||
}
|
||||
@@ -212,22 +200,15 @@ class GPM extends Iterator
|
||||
* Checks if a Theme is enabled
|
||||
*
|
||||
* @param string $slug The slug of the Theme
|
||||
* @return bool
|
||||
* True if the Theme has been set to the default theme. False if installed, but not enabled. Null otherwise.
|
||||
* @return bool True if the Theme has been set to the default theme. False if installed, but not enabled. Null otherwise.
|
||||
*/
|
||||
public function isThemeEnabled($slug)
|
||||
public function isThemeEnabled($slug): bool
|
||||
{
|
||||
$grav = new Grav();
|
||||
$result = null;
|
||||
$current_theme = $grav::instance()['config']['system']['pages']['theme'];
|
||||
$theme_installed = $this->isThemeInstalled($slug);
|
||||
$grav = Grav::instance();
|
||||
|
||||
if ($current_theme == $slug) {
|
||||
$result = true;
|
||||
} elseif ($theme_installed) {
|
||||
$result = false;
|
||||
}
|
||||
return $result;
|
||||
$current_theme = $grav['config']['system']['pages']['theme'] ?? null;
|
||||
|
||||
return $current_theme === $slug;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -236,7 +217,7 @@ class GPM extends Iterator
|
||||
* @param string $slug The slug of the Theme
|
||||
* @return bool True if the Theme has been installed. False otherwise
|
||||
*/
|
||||
public function isThemeInstalled($slug)
|
||||
public function isThemeInstalled($slug): bool
|
||||
{
|
||||
return isset($this->installed['themes'][$slug]);
|
||||
}
|
||||
|
||||
@@ -216,15 +216,19 @@ class IndexCommand extends GpmCommand
|
||||
{
|
||||
$package = $list[$package->slug] ?? $package;
|
||||
$type = ucfirst(preg_replace('/s$/', '', $package->package_type));
|
||||
$method = 'is' . $type . 'Enabled';
|
||||
$enabled = $this->gpm->{$method}($package->slug);
|
||||
$method = 'is' . $type . 'Installed';
|
||||
$installed = $this->gpm->{$method}($package->slug);
|
||||
|
||||
if ($enabled === null) {
|
||||
if ($installed) {
|
||||
$method = 'is' . $type . 'Enabled';
|
||||
$enabled = $this->gpm->{$method}($package->slug);
|
||||
if ($enabled === true) {
|
||||
$result = '<cyan>enabled</cyan>';
|
||||
} elseif ($enabled === false) {
|
||||
$result = '<red>disabled</red>';
|
||||
}
|
||||
} else {
|
||||
$result = '';
|
||||
} elseif ($enabled === true) {
|
||||
$result = '<cyan>enabled</cyan>';
|
||||
} elseif ($enabled === false) {
|
||||
$result = '<red>disabled</red>';
|
||||
}
|
||||
|
||||
return $result;
|
||||
@@ -264,7 +268,7 @@ class IndexCommand extends GpmCommand
|
||||
}
|
||||
|
||||
// Filtering updatables only
|
||||
if ($filter && $this->options['installed-only']) {
|
||||
if ($filter && ($this->options['installed-only'] || $this->options['enabled'] || $this->options['disabled'])) {
|
||||
$method = ucfirst(preg_replace('/s$/', '', $package->package_type));
|
||||
$function = 'is' . $method . 'Installed';
|
||||
$filter = $this->gpm->{$function}($package->slug);
|
||||
|
||||
Reference in New Issue
Block a user