Skip to content

Commit 62f7874

Browse files
weaverryanfabpot
authored andcommitted
[Bug] Fix Flex not installing recipes while it is being upgraded
1 parent 49059a1 commit 62f7874

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
*/
@@ -126,6 +128,13 @@ class_exists(__NAMESPACE__.str_replace('/', '\\', substr($file, \strlen(__DIR__)
126128
$this->config = $composer->getConfig();
127129
$this->options = $this->initOptions();
128130

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

131140
if ($composer2 = version_compare('2.0.0', PluginInterface::PLUGIN_API_VERSION, '<=')) {
@@ -293,6 +302,8 @@ class_exists(__NAMESPACE__.str_replace('/', '\\', substr($file, \strlen(__DIR__)
293302

294303
public function deactivate(Composer $composer, IOInterface $io)
295304
{
305+
// store operations in case Flex is being upgraded
306+
self::$storedOperations = $this->operations;
296307
self::$activated = false;
297308
}
298309

@@ -544,10 +555,12 @@ function ($value) {
544555
}
545556
}
546557

547-
foreach ($postInstallRecipes as $recipe) {
548-
$this->configurator->postInstall($recipe, $this->lock, [
549-
'force' => $event instanceof UpdateEvent && $event->force(),
550-
]);
558+
if (method_exists($this->configurator, 'postInstall')) {
559+
foreach ($postInstallRecipes as $recipe) {
560+
$this->configurator->postInstall($recipe, $this->lock, [
561+
'force' => $event instanceof UpdateEvent && $event->force(),
562+
]);
563+
}
551564
}
552565

553566
if (null !== $manifest) {

0 commit comments

Comments
 (0)