diff --git a/src/installer/ParentPlugin.php b/src/installer/ParentPlugin.php index 02f528b..2da433e 100644 --- a/src/installer/ParentPlugin.php +++ b/src/installer/ParentPlugin.php @@ -8,13 +8,14 @@ namespace Seacms\ComposerInstaller; use Composer\Composer; +use Composer\EventDispatcher\EventSubscriberInterface; use Composer\IO\IOInterface; use Composer\Plugin\Capable; use Composer\Plugin\PluginInterface; use TopFloor\ComposerCleanupVcsDirs\Plugin as TopFloorPlugin; if (class_exists(TopFloorPlugin::class,true)){ - abstract class ParentPlugin extends TopFloorPlugin implements Capable + abstract class ParentPlugin extends TopFloorPlugin implements Capable, EventSubscriberInterface { /** * const to test if TopFloorPlugin @@ -23,7 +24,7 @@ if (class_exists(TopFloorPlugin::class,true)){ protected const IS_TOP_FLOOR_PLUGIN = true; } } else { - abstract class ParentPlugin implements PluginInterface, Capable + abstract class ParentPlugin implements PluginInterface, Capable, EventSubscriberInterface { /** diff --git a/src/installer/Plugin.php b/src/installer/Plugin.php index 8ae1988..b225ad8 100644 --- a/src/installer/Plugin.php +++ b/src/installer/Plugin.php @@ -15,6 +15,8 @@ use Composer\Repository\PathRepository; use Composer\Repository\RepositoryManager; use Composer\Repository\VcsRepository; use Exception; +use Composer\Script\Event as ScriptEvent; +use Composer\Script\ScriptEvents; use Seacms\ComposerInstaller\Handler; use Seacms\ComposerInstaller\NotFoundFileException; use Seacms\ComposerInstaller\ParentPlugin; @@ -48,15 +50,26 @@ class Plugin extends ParentPlugin $this->io = $io; if (!self::IS_TOP_FLOOR_PLUGIN){ // do nothing + $this->handler = null; return ; } $this->handler = new Handler($composer, $io); - try { - list('config' => $config,'path' => $path) = $this->getConfigJsonFile(); - $this->updateRepositoryManager($config); - // $composer->getInstallationManager()->addInstaller(new LocalInstaller($io,$composer)); - } catch (NotFoundFileException $ex){ - // do nothing + } + + /** + * manage preupdate event + * @param ScriptEvent $event + */ + public function onPreUpdate(ScriptEvent $event) + { + if (!is_null($this->handler)){ + try { + list('config' => $config,'path' => $path) = $this->getConfigJsonFile(); + $this->updateRepositoryManager($config); + // $composer->getInstallationManager()->addInstaller(new LocalInstaller($io,$composer)); + } catch (NotFoundFileException $ex){ + // do nothing + } } } @@ -223,4 +236,11 @@ class Plugin extends ParentPlugin 'Composer\Plugin\Capability\CommandProvider' => 'Seacms\\Command\\Command', ]; } + /* === implements EventsSubscriberInterface === */ + public static function getSubscribedEvents() + { + return [ + ScriptEvents::PRE_UPDATE_CMD => 'onPreUpdate' + ]; + } } \ No newline at end of file