mirror of
https://github.com/getgrav/grav.git
synced 2026-07-04 10:57:30 +02:00
Merge branch 'feature/gpm-index-enhancements' of https://github.com/jgonyea/grav into jgonyea-feature/gpm-index-enhancements
This commit is contained in:
@@ -139,6 +139,32 @@ class GPM extends Iterator
|
||||
return $this->installed['plugins'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the plugin's enabled state
|
||||
*
|
||||
* @param string $slug
|
||||
* @return bool True if the Plugin is Enabled. False if manually set to enable:false. Null otherwise.
|
||||
*/
|
||||
public function isPluginEnabled($slug)
|
||||
{
|
||||
$result = null;
|
||||
$grav = new Grav();
|
||||
$config = $grav::instance()['config']['plugins'];
|
||||
$installed = $this->isPluginInstalled($slug);
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a Plugin is installed
|
||||
*
|
||||
@@ -182,6 +208,28 @@ class GPM extends Iterator
|
||||
return $this->installed['themes'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public function isThemeEnabled($slug)
|
||||
{
|
||||
$grav = new Grav();
|
||||
$result = null;
|
||||
$current_theme = $grav::instance()['config']['system']['pages']['theme'];
|
||||
$theme_installed = $this->isThemeInstalled($slug);
|
||||
|
||||
if ($current_theme == $slug) {
|
||||
$result = true;
|
||||
} elseif ($theme_installed) {
|
||||
$result = false;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a Theme is installed
|
||||
*
|
||||
@@ -1023,7 +1071,6 @@ class GPM extends Iterator
|
||||
|
||||
//Factor in the package dependencies too
|
||||
$dependencies = $this->calculateMergedDependenciesOfPackage($dependencyName, $dependencies);
|
||||
|
||||
} elseif ($dependencyVersion !== '*') {
|
||||
// Dependency already added by another package
|
||||
// If this package requires a version higher than the currently stored one, store this requirement instead
|
||||
@@ -1059,7 +1106,7 @@ class GPM extends Iterator
|
||||
$dependencies[$dependencyName] = $dependencyVersion;
|
||||
}
|
||||
} else {
|
||||
$compatible = $this->checkNextSignificantReleasesAreCompatible($currently_stored_version_number,$current_package_version_number);
|
||||
$compatible = $this->checkNextSignificantReleasesAreCompatible($currently_stored_version_number, $current_package_version_number);
|
||||
if (!$compatible) {
|
||||
throw new RuntimeException("Dependency {$dependencyName} is required in two incompatible versions", 2);
|
||||
}
|
||||
|
||||
@@ -90,6 +90,18 @@ class IndexCommand extends GpmCommand
|
||||
InputOption::VALUE_NONE,
|
||||
'Reverses the order of the output.'
|
||||
)
|
||||
->addOption(
|
||||
'enabled',
|
||||
'e',
|
||||
InputOption::VALUE_NONE,
|
||||
'Filters the results to only enabled Themes and Plugins.'
|
||||
)
|
||||
->addOption(
|
||||
'disabled',
|
||||
'd',
|
||||
InputOption::VALUE_NONE,
|
||||
'Filters the results to only disabled Themes and Plugins.'
|
||||
)
|
||||
->setDescription('Lists the plugins and themes available for installation')
|
||||
->setHelp('The <info>index</info> command lists the plugins and themes available for installation')
|
||||
;
|
||||
@@ -129,7 +141,7 @@ class IndexCommand extends GpmCommand
|
||||
if (!empty($packages)) {
|
||||
$io->section('Packages table');
|
||||
$table = new Table($io);
|
||||
$table->setHeaders(['Count', 'Name', 'Slug', 'Version', 'Installed']);
|
||||
$table->setHeaders(['Count', 'Name', 'Slug', 'Version', 'Installed', 'Enabled']);
|
||||
|
||||
$index = 0;
|
||||
foreach ($packages as $slug => $package) {
|
||||
@@ -138,7 +150,8 @@ class IndexCommand extends GpmCommand
|
||||
'Name' => '<cyan>' . Utils::truncate($package->name, 20, false, ' ', '...') . '</cyan> ',
|
||||
'Slug' => $slug,
|
||||
'Version'=> $this->version($package),
|
||||
'Installed' => $this->installed($package)
|
||||
'Installed' => $this->installed($package),
|
||||
'Enabled' => $this->enabled($package),
|
||||
];
|
||||
|
||||
$table->addRow($row);
|
||||
@@ -195,6 +208,28 @@ class IndexCommand extends GpmCommand
|
||||
return !$installed ? '<magenta>not installed</magenta>' : '<cyan>installed</cyan>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Package $package
|
||||
* @return string
|
||||
*/
|
||||
private function enabled(Package $package): string
|
||||
{
|
||||
$package = $list[$package->slug] ?? $package;
|
||||
$type = ucfirst(preg_replace('/s$/', '', $package->package_type));
|
||||
$method = 'is' . $type . 'Enabled';
|
||||
$enabled = $this->gpm->{$method}($package->slug);
|
||||
|
||||
if ($enabled === null) {
|
||||
$result = '';
|
||||
} elseif ($enabled === true) {
|
||||
$result = '<cyan>enabled</cyan>';
|
||||
} elseif ($enabled === false) {
|
||||
$result = '<red>disabled</red>';
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Packages $data
|
||||
* @return Packages
|
||||
@@ -210,10 +245,12 @@ class IndexCommand extends GpmCommand
|
||||
}
|
||||
|
||||
$filter = [
|
||||
$this->options['desc'],
|
||||
$this->options['disabled'],
|
||||
$this->options['enabled'],
|
||||
$this->options['filter'],
|
||||
$this->options['installed-only'],
|
||||
$this->options['updates-only'],
|
||||
$this->options['desc']
|
||||
];
|
||||
|
||||
if (count(array_filter($filter))) {
|
||||
@@ -240,6 +277,29 @@ class IndexCommand extends GpmCommand
|
||||
$filter = $this->gpm->{$function}($package->slug);
|
||||
}
|
||||
|
||||
// Filtering enabled only
|
||||
if ($filter && $this->options['enabled']) {
|
||||
$method = ucfirst(preg_replace('/s$/', '', $package->package_type));
|
||||
|
||||
// Check if packaged is enabled.
|
||||
$function = 'is' . $method . 'Enabled';
|
||||
$filter = $this->gpm->{$function}($package->slug);
|
||||
}
|
||||
|
||||
// Filtering disabled only
|
||||
if ($filter && $this->options['disabled']) {
|
||||
$method = ucfirst(preg_replace('/s$/', '', $package->package_type));
|
||||
|
||||
// Check if package is disabled.
|
||||
$function = 'is' . $method . 'Enabled';
|
||||
$enabled_filter = $this->gpm->{$function}($package->slug);
|
||||
|
||||
// Apply filtering results.
|
||||
if (!( $enabled_filter === false)) {
|
||||
$filter = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$filter) {
|
||||
unset($data[$type][$slug]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user