Skip to content

[Bug] Fix Flex not installing recipes while it is being upgraded #978

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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