Skip to content
Snippets Groups Projects
Commit 03410ec2 authored by totten's avatar totten
Browse files

AssetPlugin - Check if installed alongside RE plugin. Politely bow out.

parent 54a66e81
No related branches found
No related tags found
No related merge requests found
......@@ -20,6 +20,11 @@ use Composer\Script\ScriptEvents;
*/
class AssetPlugin implements PluginInterface, EventSubscriberInterface, Capable {
/**
* @var \Composer\Composer
*/
protected $composer;
/**
* @var \Composer\IO\IOInterface
*/
......@@ -42,10 +47,16 @@ class AssetPlugin implements PluginInterface, EventSubscriberInterface, Capable
*/
protected $queue;
/**
* @var bool|null
*/
protected $conflicted = NULL;
/**
* {@inheritdoc}
*/
public function activate(Composer $composer, IOInterface $io) {
$this->composer = $composer;
$this->io = $io;
$this->publisher = new Publisher($composer, $io);
$this->queue = [];
......@@ -107,6 +118,9 @@ class AssetPlugin implements PluginInterface, EventSubscriberInterface, Capable
* @param \Composer\Script\Event $event
*/
public function onAutoloadDump(Event $event) {
if ($this->checkConflicted()) {
return;
}
$this->io->write(" - <info>CiviCRM asset map</info>");
$file = $this->publisher->createAssetMap();
......@@ -117,6 +131,10 @@ class AssetPlugin implements PluginInterface, EventSubscriberInterface, Capable
}
public function runQueue(Event $event) {
if ($this->checkConflicted()) {
return;
}
if (empty($this->queue)) {
return;
}
......@@ -141,4 +159,38 @@ class AssetPlugin implements PluginInterface, EventSubscriberInterface, Capable
];
}
/**
* Determine if there is a conflict that prevents us from syncing assets.
*
* On the first invocation, this will assess the conflict and print an appropriate warning.
*
* Note that it is preferable to run this late (eg `POST_INSTALL_CMD`) rather
* than early (eg `PRE_PACKAGE_INSTALL`) so that we have a clear view is
* (or is not) installed.
*
* @return bool
* TRUE if there is a conflict
*/
protected function checkConflicted() {
if ($this->conflicted === NULL) {
$this->conflicted = NULL !== $this->composer->getRepositoryManager()->getLocalRepository()->findPackage('roundearth/civicrm-composer-plugin', '*');
if ($this->conflicted) {
// We are likely to get in this situation if (1) a site originally installed with an early
// Civi-D8 tutorial/template using RE/CCP and (2) later upgraded to Civi 5.31+ which bundles C/CAP.
$url = 'https://civicrm.stackexchange.com/q/35921';
$this->io->write("");
$this->io->write("<warning>WARNING</warning>: <comment>civicrm/civicrm-asset-plugin</comment> skipped due to conflict with <comment>roundearth/civicrm-composer-plugin</comment>.");
$this->io->write("");
$this->io->write("Both plugins are installed. They overlap insofar as both publish assets " .
"for CiviCRM-D8, but they are not interoperable. To ensure consistency, " .
"<comment>civicrm/civicrm-asset-plugin</comment> will defer to " .
"<comment>roundearth/civicrm-composer-plugin</comment>. If you prefer to migrate, see: " .
"<comment>$url</comment>\n"
);
}
}
return $this->conflicted;
}
}
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