1
0
Fork 0

Sort package installs using Transaction

pull/9915/head
Jordi Boggiano 2021-05-31 17:09:10 +02:00
parent 500efbe233
commit 5737a34e53
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
1 changed files with 17 additions and 6 deletions

View File

@ -14,6 +14,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\Package\BasePackage; use Composer\Package\BasePackage;
use Composer\Plugin\CommandEvent; use Composer\Plugin\CommandEvent;
use Composer\Plugin\PluginEvents; use Composer\Plugin\PluginEvents;
@ -69,14 +70,16 @@ EOT
$composer = $this->getComposer(true, $input->getOption('no-plugins')); $composer = $this->getComposer(true, $input->getOption('no-plugins'));
$localRepo = $composer->getRepositoryManager()->getLocalRepository(); $localRepo = $composer->getRepositoryManager()->getLocalRepository();
$packages = array(); $packagesToReinstall = array();
$packageNamesToReinstall = array();
foreach ($input->getArgument('packages') as $pattern) { foreach ($input->getArgument('packages') as $pattern) {
$patternRegexp = BasePackage::packageNameToRegexp($pattern); $patternRegexp = BasePackage::packageNameToRegexp($pattern);
$matched = false; $matched = false;
foreach ($localRepo->getCanonicalPackages() as $package) { foreach ($localRepo->getCanonicalPackages() as $package) {
if (preg_match($patternRegexp, $package->getName())) { if (preg_match($patternRegexp, $package->getName())) {
$matched = true; $matched = true;
$packages[] = $package; $packagesToReinstall[] = $package;
$packageNamesToReinstall[] = $package->getName();
} }
} }
@ -85,18 +88,26 @@ EOT
} }
} }
if (!$packages) { if (!$packagesToReinstall) {
$io->writeError('<warning>Found no packages to reinstall, aborting.</warning>'); $io->writeError('<warning>Found no packages to reinstall, aborting.</warning>');
return 1; return 1;
} }
$installOperations = array();
$uninstallOperations = array(); $uninstallOperations = array();
foreach ($packages as $package) { foreach ($packagesToReinstall as $package) {
$uninstallOperations[] = new UninstallOperation($package); $uninstallOperations[] = new UninstallOperation($package);
$installOperations[] = new InstallOperation($package);
} }
$presentPackages = $localRepo->getPackages();
$resultPackages = $presentPackages;
foreach ($presentPackages as $index => $package) {
if (in_array($package->getName(), $packageNamesToReinstall, true)) {
unset($presentPackages[$index]);
}
}
$transaction = new Transaction($presentPackages, $resultPackages);
$installOperations = $transaction->getOperations();
$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);