Execute operations in batches to make sure plugins install in the expected order

main
Jordi Boggiano 4 years ago
parent 9f380d606c
commit 87a0fc5506
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC

@ -62,6 +62,7 @@ abstract class ArchiveDownloader extends FileDownloader
} while (is_dir($temporaryDir)); } while (is_dir($temporaryDir));
$this->addCleanupPath($package, $temporaryDir); $this->addCleanupPath($package, $temporaryDir);
$this->addCleanupPath($package, $path);
$this->filesystem->ensureDirectoryExists($temporaryDir); $this->filesystem->ensureDirectoryExists($temporaryDir);
$fileName = $this->getFileName($package, $path); $fileName = $this->getFileName($package, $path);
@ -77,6 +78,7 @@ abstract class ArchiveDownloader extends FileDownloader
$filesystem->removeDirectory($path); $filesystem->removeDirectory($path);
$filesystem->removeDirectory($temporaryDir); $filesystem->removeDirectory($temporaryDir);
$self->removeCleanupPath($package, $temporaryDir); $self->removeCleanupPath($package, $temporaryDir);
$self->removeCleanupPath($package, $path);
}; };
$promise = null; $promise = null;
@ -142,6 +144,7 @@ abstract class ArchiveDownloader extends FileDownloader
$filesystem->removeDirectory($temporaryDir); $filesystem->removeDirectory($temporaryDir);
$self->removeCleanupPath($package, $temporaryDir); $self->removeCleanupPath($package, $temporaryDir);
$self->removeCleanupPath($package, $path);
}, function ($e) use ($cleanup) { }, function ($e) use ($cleanup) {
$cleanup(); $cleanup();

@ -272,6 +272,52 @@ class InstallationManager
$this->loop->wait($promises); $this->loop->wait($promises);
} }
// execute operations in batches to make sure every plugin is installed in the
// right order and activated before the packages depending on it are installed
while ($operations) {
$batch = array();
foreach ($operations as $index => $operation) {
unset($operations[$index]);
$batch[$index] = $operation;
if (in_array($operation->getOperationType(), array('update', 'install'), true)) {
$package = $operation->getOperationType() === 'update' ? $operation->getTargetPackage() : $operation->getPackage();
if ($package->getType() === 'composer-plugin' || $package->getType() === 'composer-installer') {
break;
}
}
}
$this->executeBatch($repo, $batch, $cleanupPromises, $devMode, $runScripts);
}
} catch (\Exception $e) {
$runCleanup();
if ($handleInterruptsUnix) {
pcntl_signal(SIGINT, $prevHandler);
}
if ($handleInterruptsWindows) {
sapi_windows_set_ctrl_handler($prevHandler, false);
}
throw $e;
}
if ($handleInterruptsUnix) {
pcntl_signal(SIGINT, $prevHandler);
}
if ($handleInterruptsWindows) {
sapi_windows_set_ctrl_handler($prevHandler, false);
}
// do a last write so that we write the repository even if nothing changed
// as that can trigger an update of some files like InstalledVersions.php if
// running a new composer version
$repo->write($devMode, $this);
}
private function executeBatch(RepositoryInterface $repo, array $operations, array $cleanupPromises, $devMode, $runScripts)
{
foreach ($operations as $index => $operation) { foreach ($operations as $index => $operation) {
$opType = $operation->getOperationType(); $opType = $operation->getOperationType();
@ -302,7 +348,6 @@ class InstallationManager
$dispatcher = $this->eventDispatcher; $dispatcher = $this->eventDispatcher;
$installManager = $this; $installManager = $this;
$loop = $this->loop;
$io = $this->io; $io = $this->io;
$promise = $installer->prepare($opType, $package, $initialPackage); $promise = $installer->prepare($opType, $package, $initialPackage);
@ -332,7 +377,7 @@ class InstallationManager
// execute all prepare => installs/updates/removes => cleanup steps // execute all prepare => installs/updates/removes => cleanup steps
if (!empty($promises)) { if (!empty($promises)) {
$progress = null; $progress = null;
if ($io instanceof ConsoleIO && !$io->isDebug()) { if ($io instanceof ConsoleIO && !$io->isDebug() && count($promises) > 1) {
$progress = $io->getProgressBar(); $progress = $io->getProgressBar();
} }
$this->loop->wait($promises, $progress); $this->loop->wait($promises, $progress);
@ -340,30 +385,6 @@ class InstallationManager
$progress->clear(); $progress->clear();
} }
} }
} catch (\Exception $e) {
$runCleanup();
if ($handleInterruptsUnix) {
pcntl_signal(SIGINT, $prevHandler);
}
if ($handleInterruptsWindows) {
sapi_windows_set_ctrl_handler($prevHandler, false);
}
throw $e;
}
if ($handleInterruptsUnix) {
pcntl_signal(SIGINT, $prevHandler);
}
if ($handleInterruptsWindows) {
sapi_windows_set_ctrl_handler($prevHandler, false);
}
// do a last write so that we write the repository even if nothing changed
// as that can trigger an update of some files like InstalledVersions.php if
// running a new composer version
$repo->write($devMode, $this);
} }
/** /**

Loading…
Cancel
Save