getgrav / grav

Modern, Crazy Fast, Ridiculously Easy and Amazingly Powerful Flat-File CMS powered by PHP, Markdown, Twig, and Symfony
https://getgrav.org
MIT License
14.54k stars 1.41k forks source link

GPM Uninstall script stops working after upgrade to 1.7 #3172

Closed giloliveira-nmi closed 3 years ago

giloliveira-nmi commented 3 years ago

I've searched around some time but can't seem to find clues to solving this puzzle. After upgrading my GRAV installation to 1.7 through CLI, the bin/gpm uninstall command seems to be broken.

I've tested the command with two plugins: mobile-detect and problems, with the same result for both plugins.

To see what caused the issue, I rolled back some updates of composer packages and GRAV to v1.6. I tested the script after each step and found that it only stopped working after upgrading GRAV to v1.7. I hope someone could point me in the right direction, since it doesn't seem to be a common issue.

Fatal error:  Uncaught TypeError: Grav\Console\Gpm\UninstallCommand::checkDestination(): Argument #2 ($package) must be of type Grav\Common\GPM\Remote\Package, Grav\Common\GPM\Local\Package given, called in wwwroot/system/src/Grav/Console/Gpm/UninstallCommand.php on line 118 and defined in wwwroot/system/src/Grav/Console/Gpm/UninstallCommand.php:254
Stack trace:
#0 wwwroot/system/src/Grav/Console/Gpm/UninstallCommand.php(118): Grav\Console\Gpm\UninstallCommand->checkDestination('problems', Object(Grav\Common\GPM\Local\Package))
#1 wwwroot/system/src/Grav/Console/GpmCommand.php(41): Grav\Console\Gpm\UninstallCommand->serve()
#2 wwwroot/vendor/symfony/console/Command/Command.php(255): Grav\Console\GpmCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#3 wwwroot/vendor/symfony/console/Application.php(1009): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#4 wwwroot/vendor/symfony/console/Application.php(273): Symfony\Component\Console\Application->doRunCommand(Object(Grav\Console\Gpm\UninstallCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#5 wwwroot/vendor/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#6 wwwroot/bin/gpm(49): Symfony\Component\Console\Application->run()
#7 {main}
  thrown in wwwroot/system/src/Grav/Console/Gpm/UninstallCommand.php on line 254
pamtbaau commented 3 years ago

@mahagr, I've noticed before that if any plugin fails after upgrade, the CLI will not work anymore and throws an Exception.

For example:

Here is the code for CadPHP: https://github.com/cadjou/grav-plugin-cadphp/blob/master/cadphp.php

w00fz commented 3 years ago

I think it’s just the type not generic enough, should be expecting any BasePackage not just RemotePackage types.

mahagr commented 3 years ago

Yeah, fixing...

mahagr commented 3 years ago

Can you try if the fixed code works for you?

pamtbaau commented 3 years ago

Preparing to uninstall Cadphp [v1] |- Checking destination... ok |- Uninstalling Cadphp package... ok '- Success! PHP Fatal error: require(): Failed opening required '/path/to/site-dev/user/plugins/cadphp/classes/Cadphp.php' (include_path='.:/usr/share/php') in /path/to/site-dev/user/plugins/cadphp/cadphp.php on line 11 PHP Stack trace: PHP 1. {main}() /path/to/grav-admin/bin/gpm:0 PHP 2. Grav\Console\Application\GpmApplication->run() /path/to/grav-admin/bin/gpm:49 PHP 3. Grav\Console\Application\GpmApplication->doRun() /path/to/grav-admin/vendor/symfony/console/Application.php:149 PHP 4. Grav\Console\Application\GpmApplication->doRunCommand() /path/to/grav-admin/vendor/symfony/console/Application.php:273 PHP 5. Grav\Console\Gpm\UninstallCommand->run() /path/to/grav-admin/vendor/symfony/console/Application.php:1009 PHP 6. Grav\Console\Gpm\UninstallCommand->execute() /path/to/grav-admin/vendor/symfony/console/Command/Command.php:255 PHP 7. Grav\Console\Gpm\UninstallCommand->serve() /path/to/grav-admin/system/src/Grav/Console/GpmCommand.php:41 PHP 8. Grav\Console\Gpm\UninstallCommand->clearCache() /path/to/grav-admin/system/src/Grav/Console/Gpm/UninstallCommand.php:137 PHP 9. Grav\Console\Cli\ClearCacheCommand->run() /path/to/grav-admin/system/src/Grav/Console/ConsoleTrait.php:307 PHP 10. Grav\Console\Cli\ClearCacheCommand->execute() /path/to/grav-admin/vendor/symfony/console/Command/Command.php:255 PHP 11. Grav\Console\Cli\ClearCacheCommand->serve() /path/to/grav-admin/system/src/Grav/Console/GravCommand.php:39 PHP 12. Grav\Console\Cli\ClearCacheCommand->initializePlugins() /path/to/grav-admin/system/src/Grav/Console/Cli/ClearCacheCommand.php:55 PHP 13. Grav\Common\Grav->fireEvent() /path/to/grav-admin/system/src/Grav/Console/ConsoleTrait.php:181 PHP 14. Symfony\Component\EventDispatcher\EventDispatcher->dispatch() /path/to/grav-admin/system/src/Grav/Common/Grav.php:537 PHP 15. Symfony\Component\EventDispatcher\EventDispatcher->callListeners() /path/to/grav-admin/vendor/symfony/event-dispatcher/EventDispatcher.php:73 PHP 16. Symfony\Component\EventDispatcher\EventDispatcher->doDispatch() /path/to/grav-admin/vendor/symfony/event-dispatcher/EventDispatcher.php:239 PHP 17. Grav\Plugin\CadphpPlugin->onPluginsInitialized() /path/to/grav-admin/vendor/symfony/event-dispatcher/EventDispatcher.php:264

mahagr commented 3 years ago

Ok, that was unexpected. I fixed clearcache already elsewhere, but looks like I need to do it here, too.

giloliveira-nmi commented 3 years ago

@mahagr your fix worked for me as well, as I could successfully uninstall the Problems plugin. @pamtbaau already noticed the issue that arose afterwards, which also happens for me with said plugin. Just fyi

PHP Fatal error:  require(): Failed opening required 'wwwroot/user/plugins/problems/vendor/autoload.php' (include_path='.:/usr/local/Cellar/php@7.3/7.3.26_1/share/php@7.3/pear') in wwwroot/user/plugins/problems/problems.php on line 37
PHP Stack trace:
PHP   1. {main}() wwwroot/bin/gpm:0
PHP   2. Grav\Console\Application\GpmApplication->run() wwwroot/bin/gpm:49
PHP   3. Grav\Console\Application\GpmApplication->doRun() wwwroot/vendor/symfony/console/Application.php:149
PHP   4. Grav\Console\Application\GpmApplication->doRunCommand() wwwroot/vendor/symfony/console/Application.php:273
PHP   5. Grav\Console\Gpm\UninstallCommand->run() wwwroot/vendor/symfony/console/Application.php:1009
PHP   6. Grav\Console\Gpm\UninstallCommand->execute() wwwroot/vendor/symfony/console/Command/Command.php:255
PHP   7. Grav\Console\Gpm\UninstallCommand->serve() wwwroot/system/src/Grav/Console/GpmCommand.php:41
PHP   8. Grav\Console\Gpm\UninstallCommand->clearCache() wwwroot/system/src/Grav/Console/Gpm/UninstallCommand.php:137
PHP   9. Grav\Console\Cli\ClearCacheCommand->run() wwwroot/system/src/Grav/Console/ConsoleTrait.php:307
PHP  10. Grav\Console\Cli\ClearCacheCommand->execute() wwwroot/vendor/symfony/console/Command/Command.php:255
PHP  11. Grav\Console\Cli\ClearCacheCommand->initializeGrav() wwwroot/system/src/Grav/Console/GravCommand.php:36
PHP  12. Grav\Common\Processors\InitializeProcessor::initializeCli() wwwroot/system/src/Grav/Console/ConsoleTrait.php:132
PHP  13. Grav\Common\Processors\InitializeProcessor->processCli() wwwroot/system/src/Grav/Common/Processors/InitializeProcessor.php:58
PHP  14. Grav\Common\Processors\InitializeProcessor->initializePlugins() wwwroot/system/src/Grav/Common/Processors/InitializeProcessor.php:150
PHP  15. Grav\Common\Plugins->init() wwwroot/system/src/Grav/Common/Processors/InitializeProcessor.php:376
PHP  16. Grav\Plugin\ProblemsPlugin->autoload() wwwroot/system/src/Grav/Common/Plugins.php:133
mahagr commented 3 years ago

That error should be fixed, too.

giloliveira-nmi commented 3 years ago

Thanks for your effort @mahagr! Unfortunately, I am still getting the same error as before after uninstalling the plugin problems. Tried at 1.7.5 and verified that your latest commit was present in my build. The errors differ though, for different plugins. The plugin error didn't return any issues, but git-sync did return the following. Not sure if it is related.

Fatal error: Uncaught TypeError: Argument 2 passed to Grav\Console\Gpm\UninstallCommand::packageExists() must be an instance of Grav\Common\GPM\Local\Package, instance of Grav\Common\GPM\Remote\Package given, called in /Users/Gil/Sites/Movements/movements/wwwroot/system/src/Grav/Console/Gpm/UninstallCommand.php on line 205 and defined in /Users/Gil/Sites/Movements/movements/wwwroot/system/src/Grav/Console/Gpm/UninstallCommand.php:303
Stack trace:
#0 /Users/Gil/Sites/Movements/movements/wwwroot/system/src/Grav/Console/Gpm/UninstallCommand.php(205): Grav\Console\Gpm\UninstallCommand->packageExists('form', Object(Grav\Common\GPM\Remote\Package))
#1 /Users/Gil/Sites/Movements/movements/wwwroot/system/src/Grav/Console/Gpm/UninstallCommand.php(132): Grav\Console\Gpm\UninstallCommand->uninstallPackage('git-sync', Object(Grav\Common\GPM\Local\Package))
#2 /Users/Gil/Sites/Movements/movements/wwwroot/system/src/Grav/Console/GpmCommand.php(41): Grav\Console\Gpm\UninstallCommand->serve()
#3 /Users/Gil/Sites/Movements/movements/wwwro in /Users/Gil/Sites/Movements/movements/wwwroot/system/src/Grav/Console/Gpm/UninstallCommand.php on line 303

On a side note; my IDE (intelephense) seems to point at the lines 205 and 214 with the following notice for $dependencyPackage:

Expected type 'Grav\Common\GPM\Local\Package'. Found 'Grav\Common\GPM\Remote\Package|false'

mahagr commented 3 years ago

Should be fixed in #3207