1919use Composer \DependencyResolver \Operation \UninstallOperation ;
2020use Composer \DependencyResolver \Operation \UpdateOperation ;
2121use Composer \DependencyResolver \Pool ;
22+ use Composer \DependencyResolver \Transaction ;
2223use Composer \Downloader \FileDownloader ;
2324use Composer \EventDispatcher \EventSubscriberInterface ;
2425use Composer \Factory ;
3536use Composer \Package \BasePackage ;
3637use Composer \Package \Comparer \Comparer ;
3738use Composer \Package \Locker ;
39+ use Composer \Package \Package ;
3840use Composer \Package \PackageInterface ;
3941use Composer \Plugin \PluginEvents ;
4042use Composer \Plugin \PluginInterface ;
4547use Composer \Repository \RepositoryManager ;
4648use Composer \Script \Event ;
4749use Composer \Script \ScriptEvents ;
50+ use Composer \Semver \VersionParser ;
4851use Symfony \Component \Console \Input \ArgvInput ;
4952use Symfony \Component \Filesystem \Filesystem ;
5053use Symfony \Flex \Event \UpdateEvent ;
@@ -341,11 +344,34 @@ public function configureProject(Event $event)
341344
342345 public function record (PackageEvent $ event )
343346 {
344- if ($ this ->shouldRecordOperation ($ event )) {
347+ if ($ this ->shouldRecordOperation ($ event-> getOperation (), $ event -> isDevMode (), $ event -> getComposer () )) {
345348 $ this ->operations [] = $ event ->getOperation ();
346349 }
347350 }
348351
352+ public function recordOperations (InstallerEvent $ event )
353+ {
354+ if (!$ event ->isExecutingOperations ()) {
355+ return ;
356+ }
357+
358+ $ versionParser = new VersionParser ();
359+ $ packages = [];
360+ foreach ($ this ->lock ->all () as $ name => $ info ) {
361+ $ packages [] = new Package ($ name , $ versionParser ->normalize ($ info ['version ' ]), $ info ['version ' ]);
362+ }
363+
364+ $ transation = \Closure::bind (function () use ($ packages , $ event ) {
365+ return new Transaction ($ packages , $ event ->getTransaction ()->resultPackageMap );
366+ }, null , Transaction::class)();
367+
368+ foreach ($ transation ->getOperations () as $ operation ) {
369+ if ($ this ->shouldRecordOperation ($ operation , $ event ->isDevMode (), $ event ->getComposer ())) {
370+ $ this ->operations [] = $ operation ;
371+ }
372+ }
373+ }
374+
349375 public function update (Event $ event , $ operations = [])
350376 {
351377 if ($ operations ) {
@@ -854,18 +880,21 @@ private function formatOrigin(Recipe $recipe): string
854880 return sprintf ('<info>%s</> (<comment>>=%s</>): From %s ' , $ matches [1 ], $ matches [2 ], 'auto-generated recipe ' === $ matches [3 ] ? '<comment> ' .$ matches [3 ].'</> ' : $ matches [3 ]);
855881 }
856882
857- private function shouldRecordOperation (PackageEvent $ event ): bool
883+ private function shouldRecordOperation (OperationInterface $ operation , bool $ isDevMode , Composer $ composer = null ): bool
858884 {
859- $ operation = $ event ->getOperation ();
885+ if ($ this ->dryRun ) {
886+ return false ;
887+ }
888+
860889 if ($ operation instanceof UpdateOperation) {
861890 $ package = $ operation ->getTargetPackage ();
862891 } else {
863892 $ package = $ operation ->getPackage ();
864893 }
865894
866895 // when Composer runs with --no-dev, ignore uninstall operations on packages from require-dev
867- if (!$ event -> isDevMode () && $ operation instanceof UninstallOperation) {
868- foreach ($ event -> getComposer ( )->getLocker ()->getLockData ()['packages-dev ' ] as $ p ) {
896+ if (!$ isDevMode && $ operation instanceof UninstallOperation) {
897+ foreach (( $ composer ?? $ this -> composer )->getLocker ()->getLockData ()['packages-dev ' ] as $ p ) {
869898 if ($ package ->getName () === $ p ['name ' ]) {
870899 return false ;
871900 }
@@ -993,9 +1022,6 @@ public static function getSubscribedEvents(): array
9931022 }
9941023
9951024 $ events = [
996- PackageEvents::POST_PACKAGE_INSTALL => 'record ' ,
997- PackageEvents::POST_PACKAGE_UPDATE => [['record ' ], ['enableThanksReminder ' ]],
998- PackageEvents::POST_PACKAGE_UNINSTALL => 'record ' ,
9991025 ScriptEvents::POST_CREATE_PROJECT_CMD => 'configureProject ' ,
10001026 ScriptEvents::POST_INSTALL_CMD => 'install ' ,
10011027 ScriptEvents::PRE_UPDATE_CMD => 'configureInstaller ' ,
@@ -1005,14 +1031,21 @@ public static function getSubscribedEvents(): array
10051031
10061032 if (version_compare ('2.0.0 ' , PluginInterface::PLUGIN_API_VERSION , '> ' )) {
10071033 $ events += [
1034+ PackageEvents::POST_PACKAGE_INSTALL => 'record ' ,
1035+ PackageEvents::POST_PACKAGE_UPDATE => [['record ' ], ['enableThanksReminder ' ]],
1036+ PackageEvents::POST_PACKAGE_UNINSTALL => 'record ' ,
10081037 InstallerEvents::PRE_DEPENDENCIES_SOLVING => [['populateProvidersCacheDir ' , \PHP_INT_MAX ]],
10091038 InstallerEvents::POST_DEPENDENCIES_SOLVING => [['populateFilesCacheDir ' , \PHP_INT_MAX ]],
10101039 PackageEvents::PRE_PACKAGE_INSTALL => [['populateFilesCacheDir ' , ~\PHP_INT_MAX ]],
10111040 PackageEvents::PRE_PACKAGE_UPDATE => [['populateFilesCacheDir ' , ~\PHP_INT_MAX ]],
10121041 PluginEvents::PRE_FILE_DOWNLOAD => 'onFileDownload ' ,
10131042 ];
10141043 } else {
1015- $ events += [PluginEvents::PRE_POOL_CREATE => 'truncatePackages ' ];
1044+ $ events += [
1045+ PackageEvents::POST_PACKAGE_UPDATE => 'enableThanksReminder ' ,
1046+ InstallerEvents::PRE_OPERATIONS_EXEC => 'recordOperations ' ,
1047+ PluginEvents::PRE_POOL_CREATE => 'truncatePackages ' ,
1048+ ];
10161049 }
10171050
10181051 return $ events ;
0 commit comments