1
0
Fork 0

Sort uninstalls in reverse order from installs

pull/9915/head
Jordi Boggiano 2021-05-31 17:18:47 +02:00
parent 5737a34e53
commit 4dbdae3ada
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
1 changed files with 13 additions and 0 deletions

View File

@ -15,6 +15,7 @@ namespace Composer\Command;
use Composer\DependencyResolver\Operation\InstallOperation; use Composer\DependencyResolver\Operation\InstallOperation;
use Composer\DependencyResolver\Operation\UninstallOperation; use Composer\DependencyResolver\Operation\UninstallOperation;
use Composer\DependencyResolver\Transaction; use Composer\DependencyResolver\Transaction;
use Composer\Package\AliasPackage;
use Composer\Package\BasePackage; use Composer\Package\BasePackage;
use Composer\Plugin\CommandEvent; use Composer\Plugin\CommandEvent;
use Composer\Plugin\PluginEvents; use Composer\Plugin\PluginEvents;
@ -98,6 +99,7 @@ EOT
$uninstallOperations[] = new UninstallOperation($package); $uninstallOperations[] = new UninstallOperation($package);
} }
// make sure we have a list of install operations ordered by dependency/plugins
$presentPackages = $localRepo->getPackages(); $presentPackages = $localRepo->getPackages();
$resultPackages = $presentPackages; $resultPackages = $presentPackages;
foreach ($presentPackages as $index => $package) { foreach ($presentPackages as $index => $package) {
@ -108,6 +110,17 @@ EOT
$transaction = new Transaction($presentPackages, $resultPackages); $transaction = new Transaction($presentPackages, $resultPackages);
$installOperations = $transaction->getOperations(); $installOperations = $transaction->getOperations();
// reverse-sort the uninstalls based on the install order
$installOrder = array();
foreach ($installOperations as $index => $op) {
if ($op instanceof InstallOperation && !$op->getPackage() instanceof AliasPackage) {
$installOrder[$op->getPackage()->getName()] = $index;
}
}
usort($uninstallOperations, function ($a, $b) use ($installOrder) {
return $installOrder[$b->getPackage()->getName()] - $installOrder[$a->getPackage()->getName()];
});
$commandEvent = new CommandEvent(PluginEvents::COMMAND, 'reinstall', $input, $output); $commandEvent = new CommandEvent(PluginEvents::COMMAND, 'reinstall', $input, $output);
$composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent); $composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);