diff --git a/CHANGELOG.md b/CHANGELOG.md index d19ce9c49..f07a26054 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ 1. [](#improved) * Improve detection of home path. Also allow ~/.grav on Windows, drop ConsoleTrait::isWindows() method, used only for that [#1204](https://github.com/getgrav/grav/pull/1204) * Reworked PHP CLI router [#1219](https://github.com/getgrav/grav/pull/1219) + * More robust theme/plugin logic in `bin/gpm direct-install` 1. [](#bugfix) * Fixed case where extracting a package would cause an error during rename * Fix issue with using Yaml::parse direcly on a filename, now deprecated diff --git a/system/src/Grav/Console/Gpm/DirectInstallCommand.php b/system/src/Grav/Console/Gpm/DirectInstallCommand.php index 54b98d552..49ad97bb7 100644 --- a/system/src/Grav/Console/Gpm/DirectInstallCommand.php +++ b/system/src/Grav/Console/Gpm/DirectInstallCommand.php @@ -84,6 +84,7 @@ class DirectInstallCommand extends ConsoleCommand $this->output->write("\x0D"); $this->output->writeln(" |- Extracting package... ok"); + $type = $this->getPackageType($extracted); if (!$type) { @@ -238,6 +239,9 @@ class DirectInstallCommand extends ConsoleCommand */ protected function getPackageType($source) { + $plugin_regex = '/^class\\s{1,}[a-zA-Z0-9]{1,}\\s{1,}extends.+Plugin/m'; + $theme_regex = '/^class\\s{1,}[a-zA-Z0-9]{1,}\\s{1,}extends.+Theme/m'; + if ( file_exists($source . 'system/defines.php') && file_exists($source . 'system/config/system.yaml') @@ -258,9 +262,9 @@ class DirectInstallCommand extends ConsoleCommand } foreach (glob($source . "*.php") as $filename) { $contents = file_get_contents($filename); - if (Utils::contains($contents, 'Grav\Common\Theme')) { + if (preg_match($theme_regex, $contents)) { return 'theme'; - } elseif (Utils::contains($contents, 'Grav\Common\Plugin')) { + } elseif (preg_match($plugin_regex, $contents)) { return 'plugin'; } }