Skip to content

Commit

Permalink
Merge pull request #27 from humanmade/fix-installer-order
Browse files Browse the repository at this point in the history
Register composer installer on init
  • Loading branch information
joehoyle authored May 17, 2019
2 parents afe093b + b6b846f commit a80681b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
12 changes: 11 additions & 1 deletion inc/composer/class-installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,18 @@
use Composer\Package\PackageInterface;

class Installer extends BaseInstaller {
public function getInstallPath( PackageInterface $package, $framework_type = '' ) {

/**
* Check if the installer supports a given type.
*
* @param string $type
* @return bool
*/
public function supports( $type ) {
return in_array( $type, [ 'wordpress-plugin', 'wordpress-muplugin' ], true );
}

public function getInstallPath( PackageInterface $package, $framework_type = '' ) {
/**
* Allow specific wordpress-plugin packages to skip the wordpress-plugin
* installer. We use this to stop plugins that are bundled with modules are
Expand Down
37 changes: 29 additions & 8 deletions inc/composer/class-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
namespace Altis\Composer;

use Composer\Composer;
use Composer\EventDispatcher\EventSubscriberInterface;
use Composer\IO\IOInterface;
use Composer\Plugin\PluginInterface;

class Plugin implements PluginInterface {
class Plugin implements PluginInterface, EventSubscriberInterface {

/**
* Called when the plugin is activated.
Expand All @@ -15,14 +16,34 @@ class Plugin implements PluginInterface {
* @param IOInterface $io
*/
public function activate( Composer $composer, IOInterface $io ) {
$default_installer = $composer->getInstallationManager()->getInstaller( 'library' );
$current_installer = $composer->getInstallationManager()->getInstaller( 'wordpress-plugin' );
if ( $current_installer && $current_installer !== $default_installer ) {
$composer->getInstallationManager()->removeInstaller( $current_installer );
}
$this->composer = $composer;
$this->io = $io;

$installer = new Installer( $io, $composer );
$composer->getInstallationManager()->addInstaller( $installer );
$installer = new Installer( $this->io, $this->composer );
$this->composer->getInstallationManager()->addInstaller( $installer );
}

/**
* Get the events the plugin subscribed to.
*
* @return array
*/
public static function getSubscribedEvents() {
return [
'init' => 'init',
];
}

/**
* Register the installer on the `init` hook.
*
* We want to register later than the composer-installers installer
* as the last-added installer takes precedence. This event only runs
* on update (if this plugin is already present), so we have to add it
* in addition to the $this->activate() method.
*/
public function init() {
$installer = new Installer( $this->io, $this->composer );
$this->composer->getInstallationManager()->addInstaller( $installer );
}
}

0 comments on commit a80681b

Please sign in to comment.