PhileCMS / Phile

A flat file CMS with a swappable parser and template engine.
https://philecms.github.io/
Other
257 stars 49 forks source link

Phile plugins don't install properly using composer #303

Closed reallyohwell closed 6 years ago

reallyohwell commented 7 years ago

Phile Issue: plugin install does not work using composer require.

Expected behavior

Let’s use as a test case phile/twig-filters, which is an example plugin. Let the env variable CmsRoot be e.g., /var/www/phile. Apparently the plugin is supposed to install to CmsRoot/plugins/phile/twigFilters. That is, the phile plugin installer redirects plugin code to CmsRoot/plugins as opposed to the default composer location which would be CmsRoot/lib/vendor/phile/twig-filters. The phile plugin installer does the redirect, and gets rid of dashes, and camel cases the item name with a leading lowercase. If one clones the plugin repository and manually puts it in the expected place, the plugin will work.

Actual behavior

The problem is that an install under composer does not work. The php code files are installed to CmsRoot/lib/vendor/phile/twig-filters. That is the wrong place, and phile will blow up if the plugin is active within config.php.

Steps to reproduce the behavior

I took the file CmsRoot/lib/vendor/phile-cms/plugin-installer-plugin/src/Phile/Composer/PluginInstaller.php and overrode every function I could, so see what is being called and what is not. Now try this: CmsRoot: php composer.phar require "phile/twig-filters:*" and get this output (slightly cleaned up): PluginInstallerPlugin: HI PluginInstaller._construct(): HI. ./composer.json has been updated PluginInstallerPlugin: HI PluginInstaller._construct(): HI. Loading composer repositories with package information Updating dependencies (including require-dev) Package operations: 1 install, 0 updates, 0 removals PluginInstaller.supports(phile-plugin): ret is true. PluginInstaller.install(): HI. PluginInstaller.getInstallPath(): returning /home/me/temp/bile/lib/vendor/phile/twig-filters. PluginInstaller.installCode(): HI. PluginInstaller.getInstallPath(): returning /home/me/temp/bile/lib/vendor/phile/twig-filters.

Now try this: CmsRoot: php /var/www/composer.phar remove phile/twig-filters PluginInstallerPlugin: HI PluginInstaller._construct(): HI. PluginInstaller.supports(phile-plugin): ret is true. PluginInstaller.isInstalled(): HI. PluginInstaller.getInstallPath(): returning /home/me/temp/bile/lib/vendor/phile/twig-filters. PluginInstallerPlugin: HI PluginInstaller._construct(): HI. PluginInstaller.supports(phile-plugin): ret is true. PluginInstaller.isInstalled(): HI. PluginInstaller.getInstallPath(): returning /home/me/temp/bile/lib/vendor/phile/twig-filters. Dependency "phile-cms/plugin-installer-plugin" is also a root requirement, but is not explicitly whitelisted. Ignoring. Loading composer repositories with package information Updating dependencies (including require-dev) Package operations: 0 installs, 0 updates, 1 removal PluginInstaller.getInstallPath(): returning /home/me/temp/bile/lib/vendor/phile/twig-filters. PluginInstaller.getPackageBasePath(): superclass ret is /home/me/temp/bile/lib/vendor/phile/twig-filters. PluginInstaller.getPackageBasePath(): returning plugins/phile/twigFilters.

Additional information

-> If one moves and renames the improperly installed package to the right place, it will work, and the remove command will in fact remove the files. The remove command will not remove the files from the improper install location -- they remain there and composer does not flag this. -> I can run phile and my own plugin within the netbeans debugger, although the debugger is flaky. I can’t debug when composer.phar is involved -- breakpoints don’t work. -> Tweaking of version numbers on the require command make zero difference. This appears to be some kind of issue within composer. -> In netbeans the class declaration line for PluginInstallerPlugin says “is not abstract and does not override abstract method detach() found in zend\EventManager\ListenerAggregateInterface. This makes no sense to me. -> Note that the dump above shows the superclass result of getPackageBasePath(), and the phile result which overrides the superclass result. Note that one of them is a full path of one of them is not. Could that be significant.?

Schlaefer commented 6 years ago

It's seems to be affected by this issue: https://github.com/composer/composer/issues/4648

I have to take a closer look to be 100% sure what Composer does or did change, but implementing getInstallPath() instead of getPackageBasePath() in the plugin-installer should fix this issue.

Schlaefer commented 6 years ago

PhileCMS/ComposerPluginInstaller was updated, so a composer update run on the current release should fetch the latest version (1.0.4+) with this issue fixed.

Thanks for the detailed report. 👍 And sorry for the late response. 😢

I'm closing this in favor of #305, which should also ship the fix in a future release.