Skip to content

Commit c63afc7

Browse files
committed
Disable incompatible pw-module installer with event listener in plugin
1 parent 15967c1 commit c63afc7

File tree

4 files changed

+44
-17
lines changed

4 files changed

+44
-17
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [1.0.4] - 2020-10-20
11+
12+
### Changed
13+
- Revert part of previous release and disable incompatible pw-module installer using event listener in plugin.
14+
1015
## [1.0.3] - 2020-10-20
1116

1217
### Fixed

composer.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@
1717
"hari/pw-module": "^1.0.0"
1818
},
1919
"autoload": {
20-
"psr-0": {
21-
"PW\\Composer\\": "src/"
22-
},
2320
"psr-4": {
24-
"wireframe\\": "src/"
21+
"wireframe\\ComposerInstaller\\": "src/ComposerInstaller/"
2522
}
2623
},
2724
"extra": {

src/ComposerInstaller/Plugin.php

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
namespace wireframe\ComposerInstaller;
44

55
use Composer\Composer;
6+
use Composer\EventDispatcher\EventSubscriberInterface;
67
use Composer\IO\IOInterface;
78
use Composer\Plugin\PluginInterface;
9+
use Composer\Installer\PackageEvent;
10+
use Composer\Installer\PackageEvents;
811

912
/**
1013
* The Plugin class
@@ -14,7 +17,7 @@
1417
* @author Teppo Koivula <[email protected]>
1518
* @license Mozilla Public License v2.0 http://mozilla.org/MPL/2.0/
1619
*/
17-
class Plugin implements PluginInterface
20+
class Plugin implements PluginInterface, EventSubscriberInterface
1821
{
1922
/**
2023
* Register custom installers for ProcessWire modules and site profiles.
@@ -28,4 +31,38 @@ public function activate(Composer $composer, IOInterface $io)
2831
$installationManager->addInstaller(new ModuleInstaller($io, $composer));
2932
$installationManager->addInstaller(new SiteProfileInstaller($io, $composer));
3033
}
34+
35+
/**
36+
* Register pre package install event listener
37+
*
38+
* @return array
39+
*/
40+
public static function getSubscribedEvents()
41+
{
42+
return [
43+
PackageEvents::PRE_PACKAGE_INSTALL => [
44+
array('prePackageInstall', 0)
45+
],
46+
];
47+
}
48+
49+
/**
50+
* Pre package install event listener
51+
*
52+
* wireframe-framework/processwire-composer-installer and hari/pw-module are not fully compatible,
53+
* which means that when wireframe-framework/processwire-composer-installer is enabled, we need to
54+
* disable the hari/pw-module SystemInstaller composer-installer.
55+
*
56+
* @param PackageEvent $event
57+
*/
58+
public static function prePackageInstall(PackageEvent $event)
59+
{
60+
$package = $event->getOperation()->getPackage();
61+
if ($package->getType() !== 'pw-module') return;
62+
$installationManager = $event->getComposer()->getInstallationManager();
63+
$moduleInstaller = $installationManager->getInstaller('pw-module');
64+
if (strpos(get_class($moduleInstaller), 'PW\Composer\SystemInstaller') === 0) {
65+
$installationManager->removeInstaller($moduleInstaller);
66+
}
67+
}
3168
}

src/PW/Composer/SystemInstaller.php

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)