Skip to content

Commit

Permalink
Disable incompatible pw-module installer with event listener in plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
teppokoivula committed Oct 19, 2020
1 parent 15967c1 commit c63afc7
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 17 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.0.4] - 2020-10-20

### Changed
- Revert part of previous release and disable incompatible pw-module installer using event listener in plugin.

## [1.0.3] - 2020-10-20

### Fixed
Expand Down
5 changes: 1 addition & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@
"hari/pw-module": "^1.0.0"
},
"autoload": {
"psr-0": {
"PW\\Composer\\": "src/"
},
"psr-4": {
"wireframe\\": "src/"
"wireframe\\ComposerInstaller\\": "src/ComposerInstaller/"
}
},
"extra": {
Expand Down
39 changes: 38 additions & 1 deletion src/ComposerInstaller/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
namespace wireframe\ComposerInstaller;

use Composer\Composer;
use Composer\EventDispatcher\EventSubscriberInterface;
use Composer\IO\IOInterface;
use Composer\Plugin\PluginInterface;
use Composer\Installer\PackageEvent;
use Composer\Installer\PackageEvents;

/**
* The Plugin class
Expand All @@ -14,7 +17,7 @@
* @author Teppo Koivula <[email protected]>
* @license Mozilla Public License v2.0 http://mozilla.org/MPL/2.0/
*/
class Plugin implements PluginInterface
class Plugin implements PluginInterface, EventSubscriberInterface
{
/**
* Register custom installers for ProcessWire modules and site profiles.
Expand All @@ -28,4 +31,38 @@ public function activate(Composer $composer, IOInterface $io)
$installationManager->addInstaller(new ModuleInstaller($io, $composer));
$installationManager->addInstaller(new SiteProfileInstaller($io, $composer));
}

/**
* Register pre package install event listener
*
* @return array
*/
public static function getSubscribedEvents()
{
return [
PackageEvents::PRE_PACKAGE_INSTALL => [
array('prePackageInstall', 0)
],
];
}

/**
* Pre package install event listener
*
* wireframe-framework/processwire-composer-installer and hari/pw-module are not fully compatible,
* which means that when wireframe-framework/processwire-composer-installer is enabled, we need to
* disable the hari/pw-module SystemInstaller composer-installer.
*
* @param PackageEvent $event
*/
public static function prePackageInstall(PackageEvent $event)
{
$package = $event->getOperation()->getPackage();
if ($package->getType() !== 'pw-module') return;
$installationManager = $event->getComposer()->getInstallationManager();
$moduleInstaller = $installationManager->getInstaller('pw-module');
if (strpos(get_class($moduleInstaller), 'PW\Composer\SystemInstaller') === 0) {
$installationManager->removeInstaller($moduleInstaller);
}
}
}
12 changes: 0 additions & 12 deletions src/PW/Composer/SystemInstaller.php

This file was deleted.

0 comments on commit c63afc7

Please sign in to comment.