Skip to content

Commit eb4a389

Browse files
committed
Stashing changes to avoid losing them on upgrade
1 parent a883a28 commit eb4a389

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/Flex.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
*/
6161
class Flex implements PluginInterface, EventSubscriberInterface
6262
{
63+
public static $storedOperations = null;
6364
/**
6465
* @var Composer
6566
*/
@@ -126,6 +127,15 @@ class_exists(__NAMESPACE__.str_replace('/', '\\', substr($file, \strlen(__DIR__)
126127
$this->config = $composer->getConfig();
127128
$this->options = $this->initOptions();
128129

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

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

294304
public function deactivate(Composer $composer, IOInterface $io)
295305
{
306+
// store operations in case Flex is being upgraded
307+
self::$storedOperations = $this->operations;
296308
self::$activated = false;
297309
}
298310

0 commit comments

Comments
 (0)