Skip to content

Commit 333abcf

Browse files
committed
bug #978 [Bug] Fix Flex not installing recipes while it is being upgraded (weaverryan)
This PR was squashed before being merged into the 1.x branch. Discussion ---------- [Bug] Fix Flex not installing recipes while it is being upgraded Fixes #977 Here's the lifecycle: A) Packages are installed/updated and `Flex::recordOperations()` is called. B) Composer sees that `symfony/flex` is updated and unloads the plugin and reloads it under a new `Symfony\Flex\Flex_composer_tmp0` class. This results in the `Flex::$operations` property being lost. C) And so, no recipes are installed. This PR "stashes" the operations directly on `Symfony/Flex/Flex` where we then read them later. Tested locally. Amazing, it seems to work perfectly. Also, backports #976 to 1.x - my fault for making the PR on the wrong branch. Cheers! Commits ------- 62f7874 [Bug] Fix Flex not installing recipes while it is being upgraded
2 parents a2554c7 + 62f7874 commit 333abcf

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/Flex.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
*/
6161
class Flex implements PluginInterface, EventSubscriberInterface
6262
{
63+
public static $storedOperations = [];
64+
6365
/**
6466
* @var Composer
6567
*/
@@ -129,6 +131,13 @@ class_exists(__NAMESPACE__.str_replace('/', '\\', substr($file, \strlen(__DIR__)
129131
$this->config = $composer->getConfig();
130132
$this->options = $this->initOptions();
131133

134+
// if Flex is being upgraded, the original operations from the original Flex
135+
// instance are stored in the static property, so we can reuse them now.
136+
if (property_exists(self::class, 'storedOperations') && self::$storedOperations) {
137+
$this->operations = self::$storedOperations;
138+
self::$storedOperations = [];
139+
}
140+
132141
$symfonyRequire = preg_replace('/\.x$/', '.x-dev', getenv('SYMFONY_REQUIRE') ?: ($composer->getPackage()->getExtra()['symfony']['require'] ?? ''));
133142

134143
if ($composer2 = version_compare('2.0.0', PluginInterface::PLUGIN_API_VERSION, '<=')) {
@@ -299,6 +308,8 @@ class_exists(__NAMESPACE__.str_replace('/', '\\', substr($file, \strlen(__DIR__)
299308
*/
300309
public function deactivate(Composer $composer, IOInterface $io)
301310
{
311+
// store operations in case Flex is being upgraded
312+
self::$storedOperations = $this->operations;
302313
self::$activated = false;
303314
}
304315

@@ -550,10 +561,12 @@ function ($value) {
550561
}
551562
}
552563

553-
foreach ($postInstallRecipes as $recipe) {
554-
$this->configurator->postInstall($recipe, $this->lock, [
555-
'force' => $event instanceof UpdateEvent && $event->force(),
556-
]);
564+
if (method_exists($this->configurator, 'postInstall')) {
565+
foreach ($postInstallRecipes as $recipe) {
566+
$this->configurator->postInstall($recipe, $this->lock, [
567+
'force' => $event instanceof UpdateEvent && $event->force(),
568+
]);
569+
}
557570
}
558571

559572
if (null !== $manifest) {

0 commit comments

Comments
 (0)