function DownloadManager::update
Updates package from initial to target version.
@phpstan-return PromiseInterface<void|null>
Parameters
PackageInterface $initial initial package version:
PackageInterface $target target package version:
string $targetDir target dir:
Throws
\InvalidArgumentException if initial package is not installed
File
-
vendor/
composer/ composer/ src/ Composer/ Downloader/ DownloadManager.php, line 289
Class
- DownloadManager
- Downloaders manager.
Namespace
Composer\DownloaderCode
public function update(PackageInterface $initial, PackageInterface $target, string $targetDir) : PromiseInterface {
$targetDir = $this->normalizeTargetDir($targetDir);
$downloader = $this->getDownloaderForPackage($target);
$initialDownloader = $this->getDownloaderForPackage($initial);
// no downloaders present means update from metapackage to metapackage, nothing to do
if (!$initialDownloader && !$downloader) {
return \React\Promise\resolve(null);
}
// if we have a downloader present before, but not after, the package became a metapackage and its files should be removed
if (!$downloader) {
return $initialDownloader->remove($initial, $targetDir);
}
$initialType = $this->getDownloaderType($initialDownloader);
$targetType = $this->getDownloaderType($downloader);
if ($initialType === $targetType) {
try {
return $downloader->update($initial, $target, $targetDir);
} catch (\RuntimeException $e) {
if (!$this->io
->isInteractive()) {
throw $e;
}
$this->io
->writeError('<error> Update failed (' . $e->getMessage() . ')</error>');
if (!$this->io
->askConfirmation(' Would you like to try reinstalling the package instead [<comment>yes</comment>]? ')) {
throw $e;
}
}
}
// if downloader type changed, or update failed and user asks for reinstall,
// we wipe the dir and do a new install instead of updating it
$promise = $initialDownloader->remove($initial, $targetDir);
return $promise->then(function ($res) use ($target, $targetDir) : PromiseInterface {
return $this->install($target, $targetDir);
});
}