Extract POST_PACKAGE_* events to be executed all at once and not in parallel with async code to avoid edge cases, fixes #9463
parent
45f7036745
commit
b0d308319e
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue