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;
|
namespace Seacms\ComposerInstaller;
|
||||||
|
|
||||||
use Composer\Composer;
|
use Composer\Composer;
|
||||||
|
use Composer\EventDispatcher\EventSubscriberInterface;
|
||||||
use Composer\IO\IOInterface;
|
use Composer\IO\IOInterface;
|
||||||
use Composer\Plugin\Capable;
|
use Composer\Plugin\Capable;
|
||||||
use Composer\Plugin\PluginInterface;
|
use Composer\Plugin\PluginInterface;
|
||||||
use TopFloor\ComposerCleanupVcsDirs\Plugin as TopFloorPlugin;
|
use TopFloor\ComposerCleanupVcsDirs\Plugin as TopFloorPlugin;
|
||||||
|
|
||||||
if (class_exists(TopFloorPlugin::class,true)){
|
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
|
* const to test if TopFloorPlugin
|
||||||
@ -23,7 +24,7 @@ if (class_exists(TopFloorPlugin::class,true)){
|
|||||||
protected const IS_TOP_FLOOR_PLUGIN = true;
|
protected const IS_TOP_FLOOR_PLUGIN = true;
|
||||||
}
|
}
|
||||||
} else {
|
} 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\RepositoryManager;
|
||||||
use Composer\Repository\VcsRepository;
|
use Composer\Repository\VcsRepository;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use Composer\Script\Event as ScriptEvent;
|
||||||
|
use Composer\Script\ScriptEvents;
|
||||||
use Seacms\ComposerInstaller\Handler;
|
use Seacms\ComposerInstaller\Handler;
|
||||||
use Seacms\ComposerInstaller\NotFoundFileException;
|
use Seacms\ComposerInstaller\NotFoundFileException;
|
||||||
use Seacms\ComposerInstaller\ParentPlugin;
|
use Seacms\ComposerInstaller\ParentPlugin;
|
||||||
@ -48,15 +50,26 @@ class Plugin extends ParentPlugin
|
|||||||
$this->io = $io;
|
$this->io = $io;
|
||||||
if (!self::IS_TOP_FLOOR_PLUGIN){
|
if (!self::IS_TOP_FLOOR_PLUGIN){
|
||||||
// do nothing
|
// do nothing
|
||||||
|
$this->handler = null;
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
$this->handler = new Handler($composer, $io);
|
$this->handler = new Handler($composer, $io);
|
||||||
try {
|
}
|
||||||
list('config' => $config,'path' => $path) = $this->getConfigJsonFile();
|
|
||||||
$this->updateRepositoryManager($config);
|
/**
|
||||||
// $composer->getInstallationManager()->addInstaller(new LocalInstaller($io,$composer));
|
* manage preupdate event
|
||||||
} catch (NotFoundFileException $ex){
|
* @param ScriptEvent $event
|
||||||
// do nothing
|
*/
|
||||||
|
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',
|
'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