1
0
Fork 0

Extract POST_PACKAGE_* events to be executed all at once and not in parallel with async code to avoid edge cases, fixes #9463

pull/9471/head
Jordi Boggiano 2020-11-12 15:14:02 +01:00
parent 45f7036745
commit b0d308319e
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
1 changed files with 13 additions and 6 deletions

View File

@ -370,6 +370,7 @@ class InstallationManager
private function executeBatch(RepositoryInterface $repo, array $operations, array $cleanupPromises, $devMode, $runScripts, array $allOperations)
{
$promises = array();
$postExecCallbacks = array();
foreach ($operations as $index => $operation) {
$opType = $operation->getOperationType();
@ -411,19 +412,21 @@ class InstallationManager
$promise = $promise->then(function () use ($opType, $installManager, $repo, $operation) {
return $installManager->$opType($repo, $operation);
})->then($cleanupPromises[$index])
->then(function () use ($opType, $runScripts, $dispatcher, $installManager, $devMode, $repo, $allOperations, $operation) {
->then(function () use ($installManager, $devMode, $repo) {
$repo->write($devMode, $installManager);
$event = 'Composer\Installer\PackageEvents::POST_PACKAGE_'.strtoupper($opType);
if (defined($event) && $runScripts && $dispatcher) {
$dispatcher->dispatchPackageEvent(constant($event), $devMode, $repo, $allOperations, $operation);
}
}, function ($e) use ($opType, $package, $io) {
$io->writeError(' <error>' . ucfirst($opType) .' of '.$package->getPrettyName().' failed</error>');
throw $e;
});
$postExecCallbacks[] = function () use ($opType, $runScripts, $dispatcher, $devMode, $repo, $allOperations, $operation) {
$event = 'Composer\Installer\PackageEvents::POST_PACKAGE_'.strtoupper($opType);
if (defined($event) && $runScripts && $dispatcher) {
$dispatcher->dispatchPackageEvent(constant($event), $devMode, $repo, $allOperations, $operation);
}
};
$promises[] = $promise;
}
@ -431,6 +434,10 @@ class InstallationManager
if (count($promises)) {
$this->waitOnPromises($promises);
}
foreach ($postExecCallbacks as $cb) {
$cb();
}
}
private function waitOnPromises(array $promises)