diff --git a/src/Flex.php b/src/Flex.php index 17703259d..e437e8e46 100644 --- a/src/Flex.php +++ b/src/Flex.php @@ -60,6 +60,8 @@ */ class Flex implements PluginInterface, EventSubscriberInterface { + public static $storedOperations = []; + /** * @var Composer */ @@ -126,6 +128,13 @@ class_exists(__NAMESPACE__.str_replace('/', '\\', substr($file, \strlen(__DIR__) $this->config = $composer->getConfig(); $this->options = $this->initOptions(); + // if Flex is being upgraded, the original operations from the original Flex + // instance are stored in the static property, so we can reuse them now. + if (property_exists(self::class, 'storedOperations') && self::$storedOperations) { + $this->operations = self::$storedOperations; + self::$storedOperations = []; + } + $symfonyRequire = preg_replace('/\.x$/', '.x-dev', getenv('SYMFONY_REQUIRE') ?: ($composer->getPackage()->getExtra()['symfony']['require'] ?? '')); if ($composer2 = version_compare('2.0.0', PluginInterface::PLUGIN_API_VERSION, '<=')) { @@ -293,6 +302,8 @@ class_exists(__NAMESPACE__.str_replace('/', '\\', substr($file, \strlen(__DIR__) public function deactivate(Composer $composer, IOInterface $io) { + // store operations in case Flex is being upgraded + self::$storedOperations = $this->operations; self::$activated = false; } @@ -544,10 +555,12 @@ function ($value) { } } - foreach ($postInstallRecipes as $recipe) { - $this->configurator->postInstall($recipe, $this->lock, [ - 'force' => $event instanceof UpdateEvent && $event->force(), - ]); + if (method_exists($this->configurator, 'postInstall')) { + foreach ($postInstallRecipes as $recipe) { + $this->configurator->postInstall($recipe, $this->lock, [ + 'force' => $event instanceof UpdateEvent && $event->force(), + ]); + } } if (null !== $manifest) {