Skip to content

Commit

Permalink
[Bug] Fix Flex not installing recipes while it is being upgraded
Browse files Browse the repository at this point in the history
  • Loading branch information
weaverryan authored and fabpot committed Oct 22, 2023
1 parent 49059a1 commit 62f7874
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/Flex.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
*/
class Flex implements PluginInterface, EventSubscriberInterface
{
public static $storedOperations = [];

/**
* @var Composer
*/
Expand Down Expand Up @@ -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, '<=')) {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 62f7874

Please sign in to comment.