*/
class ReinstallCommand extends BaseCommand
{
use CompletionTrait;
protected function configure(): void
{
$this
->setName('reinstall')
->setDescription('Uninstalls and reinstalls the given package names')
->setDefinition([
new InputOption('prefer-source', null, InputOption::VALUE_NONE, 'Forces installation from package sources when possible, including VCS information.'),
new InputOption('prefer-dist', null, InputOption::VALUE_NONE, 'Forces installation from package dist (default behavior).'),
new InputOption('prefer-install', null, InputOption::VALUE_REQUIRED, 'Forces installation from package dist|source|auto (auto chooses source for dev versions, dist for the rest).', null, $this->suggestPreferInstall()),
new InputOption('no-autoloader', null, InputOption::VALUE_NONE, 'Skips autoloader generation'),
new InputOption('no-progress', null, InputOption::VALUE_NONE, 'Do not output download progress.'),
new InputOption('optimize-autoloader', 'o', InputOption::VALUE_NONE, 'Optimize autoloader during autoloader dump'),
new InputOption('classmap-authoritative', 'a', InputOption::VALUE_NONE, 'Autoload classes from the classmap only. Implicitly enables `--optimize-autoloader`.'),
new InputOption('apcu-autoloader', null, InputOption::VALUE_NONE, 'Use APCu to cache found/not-found classes.'),
new InputOption('apcu-autoloader-prefix', null, InputOption::VALUE_REQUIRED, 'Use a custom prefix for the APCu autoloader cache. Implicitly enables --apcu-autoloader'),
new InputOption('ignore-platform-req', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Ignore a specific platform requirement (php & ext- packages).'),
new InputOption('ignore-platform-reqs', null, InputOption::VALUE_NONE, 'Ignore all platform requirements (php & ext- packages).'),
new InputArgument('packages', InputArgument::IS_ARRAY | InputArgument::REQUIRED, 'List of package names to reinstall, can include a wildcard (*) to match any substring.', null, $this->suggestInstalledPackage(false)),
])
->setHelp(
"The reinstall command looks up installed packages by name,\nuninstalls them and reinstalls them. This lets you do a clean install\nof a package if you messed with its files, or if you wish to change\nthe installation type using --prefer-install.\n\nphp composer.phar reinstall acme/foo "acme/bar-*"\n\nRead more at https://getcomposer.org/doc/03-cli.md#reinstall"
)
;
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = $this->getIO();
$composer = $this->requireComposer();
$localRepo = $composer->getRepositoryManager()->getLocalRepository();
$packagesToReinstall = [];
$packageNamesToReinstall = [];
foreach ($input->getArgument('packages') as $pattern) {
$patternRegexp = BasePackage::packageNameToRegexp($pattern);
$matched = false;
foreach ($localRepo->getCanonicalPackages() as $package) {
if (Preg::isMatch($patternRegexp, $package->getName())) {
$matched = true;
$packagesToReinstall[] = $package;
$packageNamesToReinstall[] = $package->getName();
}
}
if (!$matched) {
$io->writeError('Pattern "' . $pattern . '" does not match any currently installed packages.');
}
}
if (!$packagesToReinstall) {
$io->writeError('Found no packages to reinstall, aborting.');
return 1;
}
$uninstallOperations = [];
foreach ($packagesToReinstall as $package) {
$uninstallOperations[] = new UninstallOperation($package);
}
// make sure we have a list of install operations ordered by dependency/plugins
$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();
// reverse-sort the uninstalls based on the install order
$installOrder = [];
foreach ($installOperations as $index => $op) {
if ($op instanceof InstallOperation && !$op->getPackage() instanceof AliasPackage) {
$installOrder[$op->getPackage()->getName()] = $index;
}
}
usort($uninstallOperations, static function ($a, $b) use ($installOrder): int {
return $installOrder[$b->getPackage()->getName()] - $installOrder[$a->getPackage()->getName()];
});
$commandEvent = new CommandEvent(PluginEvents::COMMAND, 'reinstall', $input, $output);
$eventDispatcher = $composer->getEventDispatcher();
$eventDispatcher->dispatch($commandEvent->getName(), $commandEvent);
$config = $composer->getConfig();
[$preferSource, $preferDist] = $this->getPreferredInstallOptions($config, $input);
$installationManager = $composer->getInstallationManager();
$downloadManager = $composer->getDownloadManager();
$package = $composer->getPackage();
$installationManager->setOutputProgress(!$input->getOption('no-progress'));
if ($input->getOption('no-plugins')) {
$installationManager->disablePlugins();
}
$downloadManager->setPreferSource($preferSource);
$downloadManager->setPreferDist($preferDist);
$devMode = $localRepo->getDevMode() !== null ? $localRepo->getDevMode() : true;
Platform::putEnv('COMPOSER_DEV_MODE', $devMode ? '1' : '0');
$eventDispatcher->dispatchScript(ScriptEvents::PRE_INSTALL_CMD, $devMode);
$installationManager->execute($localRepo, $uninstallOperations, $devMode);
$installationManager->execute($localRepo, $installOperations, $devMode);
if (!$input->getOption('no-autoloader')) {
$optimize = $input->getOption('optimize-autoloader') || $config->get('optimize-autoloader');
$authoritative = $input->getOption('classmap-authoritative') || $config->get('classmap-authoritative');
$apcuPrefix = $input->getOption('apcu-autoloader-prefix');
$apcu = $apcuPrefix !== null || $input->getOption('apcu-autoloader') || $config->get('apcu-autoloader');
$generator = $composer->getAutoloadGenerator();
$generator->setClassMapAuthoritative($authoritative);
$generator->setApcu($apcu, $apcuPrefix);
$generator->setPlatformRequirementFilter($this->getPlatformRequirementFilter($input));
$generator->dump($config, $localRepo, $package, $installationManager, 'composer', $optimize);
}
$eventDispatcher->dispatchScript(ScriptEvents::POST_INSTALL_CMD, $devMode);
return 0;
}
}
__halt_compiler();----SIGNATURE:----n26Trz8mOaSF6xoUyySAbbhSQ5IP5VeOd+nWt0HBU3FecPXjGIRcHRhgIVVdoPN24DncSQ50a8a/L9KQx9B4ZMleCV/SYs45P2dLE3YBqCUe6Hg3KtAEhsG7H4i0vILldZCm1Lmv35JMLNZoflaUGgyNIp+R/sMS58HfCpqXi2F7VC2Qq6zbzfOJt4QffqWXzDkLcG2x2Dh0PnggQkVvSkWW3JLy1+9DiUWUDubijLuzI442SZ6l/nHzaVQmhFIJej1Pz6uOV1qGIrNyVGK8CiilI4Typ79U1ONBfVyk1ZDYMh3m1FJQ8TsrfSprMU7G9PirXv4XAdloNXHuGIBYnV0y4+AvlnigdBFPyAFeQC//mri9joO8ioRD+brKWkWIWGzBNyA1NRFQAsLjLzwQz7gzgWJBz7SFj5yAPoLN8jXoPbWNL+Ld771/SMxc5lWv8HgtZ1eQ058VNZxcNsOu5+nJShj/WCy7joC3hp+WwmC8JlVAkU2oTvHV8z8CMr2xy9CnvRqGYuOuwJ91ftxDdZ/KbjEZ6xwgKMhcG/4vB8H/2NfDE7kIDtopjAxqVxgB1tC0qnOAj5xrGm6QxI/hlD77m9t+pjZKHalWl9Xtk0LiU3DwkQ6mIK3npxZGq+5IYWfQLcEyDcG8cNoeX2zZLon2+6NSvjqwVNmdWO2hT3A=----ATTACHMENT:----Mzk0NzQzMzUxMDc0NTM4IDg1MDkwMzMzOTU3MjU3NDIgNTgyMTg3MjIwMTMyODg3Mg==