fix(pre-update-event): use it to change repo only on update or install
This commit is contained in:
parent
9e6d84e085
commit
817ba4501d
@ -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
|
||||
{
|
||||
|
||||
/**
|
||||
|
@ -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,9 +50,19 @@ 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
@ -59,6 +71,7 @@ class Plugin extends ParentPlugin
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get config.json File from root path
|
||||
@ -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'
|
||||
];
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user