@@ -87,6 +87,7 @@ class Flex implements PluginInterface, EventSubscriberInterface
87
87
private $ rfs ;
88
88
private $ progress = true ;
89
89
private $ dryRun = false ;
90
+ private $ reinstall ;
90
91
private static $ activated = true ;
91
92
private static $ repoReadingCommands = [
92
93
'create-project ' => true ,
@@ -346,6 +347,13 @@ public function configureProject(Event $event)
346
347
$ this ->updateComposerLock ();
347
348
}
348
349
350
+ public function recordFlexInstall (PackageEvent $ event )
351
+ {
352
+ if (null === $ this ->reinstall && 'symfony/flex ' === $ event ->getOperation ()->getPackage ()->getName ()) {
353
+ $ this ->reinstall = true ;
354
+ }
355
+ }
356
+
349
357
public function record (PackageEvent $ event )
350
358
{
351
359
if ($ this ->shouldRecordOperation ($ event ->getOperation (), $ event ->isDevMode (), $ event ->getComposer ())) {
@@ -388,7 +396,7 @@ public function update(Event $event, $operations = [])
388
396
$ contents = file_get_contents ($ file );
389
397
$ json = JsonFile::parseJson ($ contents );
390
398
391
- if (!isset ($ json ['flex-require ' ]) && !isset ($ json ['flex-require-dev ' ])) {
399
+ if (!$ this -> reinstall && ! isset ($ json ['flex-require ' ]) && !isset ($ json ['flex-require-dev ' ])) {
392
400
$ this ->unpack ($ event );
393
401
394
402
return ;
@@ -400,17 +408,18 @@ public function update(Event $event, $operations = [])
400
408
$ symfonyVersion = $ json ['extra ' ]['symfony ' ]['require ' ] ?? null ;
401
409
$ versions = $ symfonyVersion ? $ this ->downloader ->getVersions () : null ;
402
410
foreach (['require ' , 'require-dev ' ] as $ type ) {
403
- if (isset ($ json ['flex- ' .$ type ])) {
404
- foreach ( $ json [ ' flex- ' . $ type ] as $ package => $ constraint ) {
405
- if ( $ symfonyVersion && ' * ' === $ constraint && isset ( $ versions [ ' splits ' ][ $ package ])) {
406
- // replace unbounded constraints for symfony/* packages by extra.symfony.require
407
- $ constraint = $ symfonyVersion ;
408
- }
409
- $ manipulator -> addLink ( $ type , $ package , $ constraint , $ sortPackages ) ;
411
+ if (! isset ($ json ['flex- ' .$ type ])) {
412
+ continue ;
413
+ }
414
+ foreach ( $ json [ ' flex- ' . $ type ] as $ package => $ constraint ) {
415
+ if ( $ symfonyVersion && ' * ' === $ constraint && isset ( $ versions [ ' splits ' ][ $ package ])) {
416
+ // replace unbounded constraints for symfony/* packages by extra.symfony.require
417
+ $ constraint = $ symfonyVersion ;
410
418
}
411
-
412
- $ manipulator ->removeMainKey ('flex- ' .$ type );
419
+ $ manipulator ->addLink ($ type , $ package , $ constraint , $ sortPackages );
413
420
}
421
+
422
+ $ manipulator ->removeMainKey ('flex- ' .$ type );
414
423
}
415
424
416
425
file_put_contents ($ file , $ manipulator ->getContents ());
@@ -891,7 +900,7 @@ private function formatOrigin(Recipe $recipe): string
891
900
892
901
private function shouldRecordOperation (OperationInterface $ operation , bool $ isDevMode , Composer $ composer = null ): bool
893
902
{
894
- if ($ this ->dryRun ) {
903
+ if ($ this ->dryRun || $ this -> reinstall ) {
895
904
return false ;
896
905
}
897
906
@@ -994,6 +1003,7 @@ private function unpack(Event $event)
994
1003
995
1004
private function reinstall (Event $ event , bool $ update )
996
1005
{
1006
+ $ this ->reinstall = false ;
997
1007
$ event ->stopPropagation ();
998
1008
999
1009
$ ed = $ this ->composer ->getEventDispatcher ();
@@ -1045,7 +1055,7 @@ public static function getSubscribedEvents(): array
1045
1055
1046
1056
if (version_compare ('2.0.0 ' , PluginInterface::PLUGIN_API_VERSION , '> ' )) {
1047
1057
$ events += [
1048
- PackageEvents::POST_PACKAGE_INSTALL => ' record ' ,
1058
+ PackageEvents::POST_PACKAGE_INSTALL => [[ ' recordFlexInstall ' ], [ ' record ']] ,
1049
1059
PackageEvents::POST_PACKAGE_UPDATE => [['record ' ], ['enableThanksReminder ' ]],
1050
1060
PackageEvents::POST_PACKAGE_UNINSTALL => 'record ' ,
1051
1061
InstallerEvents::PRE_DEPENDENCIES_SOLVING => [['populateProvidersCacheDir ' , \PHP_INT_MAX ]],
@@ -1057,6 +1067,7 @@ public static function getSubscribedEvents(): array
1057
1067
} else {
1058
1068
$ events += [
1059
1069
PackageEvents::POST_PACKAGE_UPDATE => 'enableThanksReminder ' ,
1070
+ PackageEvents::POST_PACKAGE_INSTALL => 'recordFlexInstall ' ,
1060
1071
InstallerEvents::PRE_OPERATIONS_EXEC => 'recordOperations ' ,
1061
1072
PluginEvents::PRE_POOL_CREATE => 'truncatePackages ' ,
1062
1073
];
0 commit comments