Skip to content
Snippets Groups Projects
Commit 8768877f authored by totten's avatar totten
Browse files

AssetPlugin - Fail gracefully during uninstall

Before this patch, when uninstalling the plugin on composer v1, it would raise an error like:

```
Writing lock file
Generating autoload files
  - CiviCRM asset map
PHP Fatal error:  Uncaught Error: Class 'Civi\AssetPlugin\BasicAssetRule' not found in /home/me/src/sandbox/vendor/civicrm/civicrm-asset-plugin/src/Publisher.php:187
Stack trace:
0 /home/me/src/sandbox/vendor/civicrm/civicrm-asset-plugin/src/Publisher.php(215): Civi\AssetPlugin\Publisher->createAssetRule(Object(Composer\Package\CompletePackage))
1 /home/me/src/sandbox/vendor/civicrm/civicrm-asset-plugin/src/Publisher.php(98): Civi\AssetPlugin\Publisher->createAllAssetRules()
2 phar:///home/me/bknix/bin/composer/src/Composer/Plugin/PluginManager.php(196) : eval()'d code(125): Civi\AssetPlugin\Publisher->createAssetMap()
3 [internal function]: Civi\AssetPlugin\AssetPlugin_composer_tmp2->onAutoloadDump(Object(Composer\Script\Event))
4 phar:///home/me/bknix/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php(164): call_user_func(Array, Object(Composer\Script\Event))
5 phar:///home/me/bknix/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php(96): Composer\EventDispatcher\Event in /home/me/src/sandbox/vendor/civicrm/civicrm-asset-plugin/src/Publisher.php on line 187
```
parent 03410ec2
No related branches found
No related tags found
No related merge requests found
......@@ -118,7 +118,7 @@ class AssetPlugin implements PluginInterface, EventSubscriberInterface, Capable
* @param \Composer\Script\Event $event
*/
public function onAutoloadDump(Event $event) {
if ($this->checkConflicted()) {
if ($this->checkConflicted() || $this->checkRemoved()) {
return;
}
$this->io->write(" - <info>CiviCRM asset map</info>");
......@@ -131,7 +131,7 @@ class AssetPlugin implements PluginInterface, EventSubscriberInterface, Capable
}
public function runQueue(Event $event) {
if ($this->checkConflicted()) {
if ($this->checkConflicted() || $this->checkRemoved()) {
return;
}
......@@ -193,4 +193,33 @@ class AssetPlugin implements PluginInterface, EventSubscriberInterface, Capable
return $this->conflicted;
}
/**
* In composer v1, the plugin class is loaded and activated before removal.
* This leaves us in a dangling state where uninstallation may raise errors.
*
* @return bool
* TRUE if it appears that this has been removed.
*/
protected function checkRemoved() {
try {
$pkg = $this->composer->getRepositoryManager()->getLocalRepository()->findPackage('civicrm/civicrm-asset-plugin', '*');
}
catch (\Exception $e) {
return TRUE;
}
if ($pkg === NULL) {
return TRUE;
}
try {
$path = $this->composer->getInstallationManager()->getInstallPath($pkg);
}
catch (\Exception $e) {
return TRUE;
}
return !is_readable($path);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment