Avoid reverting the composer.json in case of a composer require/remove failure that is unrelated to the Solver
Fixes #6821 and adds a different fix to #3464 which is getting revertedpull/6728/merge
parent
4c4f516ea2
commit
b4df2c9517
|
@ -374,6 +374,9 @@ EOT
|
||||||
$requirement['version'],
|
$requirement['version'],
|
||||||
$requirement['name']
|
$requirement['name']
|
||||||
));
|
));
|
||||||
|
} else {
|
||||||
|
// check that the specified version/constraint exists before we proceed
|
||||||
|
$this->findBestVersionForPackage($input, $requirement['name'], $phpVersion, $preferredStability, $requirement['version']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$result[] = $requirement['name'] . ' ' . $requirement['version'];
|
$result[] = $requirement['name'] . ' ' . $requirement['version'];
|
||||||
|
@ -631,13 +634,18 @@ EOT
|
||||||
* @throws \InvalidArgumentException
|
* @throws \InvalidArgumentException
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function findBestVersionForPackage(InputInterface $input, $name, $phpVersion, $preferredStability = 'stable')
|
private function findBestVersionForPackage(InputInterface $input, $name, $phpVersion, $preferredStability = 'stable', $requiredVersion = null)
|
||||||
{
|
{
|
||||||
// find the latest version allowed in this pool
|
// find the latest version allowed in this pool
|
||||||
$versionSelector = new VersionSelector($this->getPool($input));
|
$versionSelector = new VersionSelector($this->getPool($input));
|
||||||
$package = $versionSelector->findBestCandidate($name, null, $phpVersion, $preferredStability);
|
$package = $versionSelector->findBestCandidate($name, $requiredVersion, $phpVersion, $preferredStability);
|
||||||
|
|
||||||
if (!$package) {
|
if (!$package) {
|
||||||
|
if ($requiredVersion && $versionSelector->findBestCandidate($name, null, $phpVersion, $preferredStability)) {
|
||||||
|
throw new \InvalidArgumentException(sprintf(
|
||||||
|
'Could not find package %s in a version matching %s', $name, $requiredVersion
|
||||||
|
));
|
||||||
|
}
|
||||||
// Check whether the PHP version was the problem
|
// Check whether the PHP version was the problem
|
||||||
if ($phpVersion && $versionSelector->findBestCandidate($name)) {
|
if ($phpVersion && $versionSelector->findBestCandidate($name)) {
|
||||||
throw new \InvalidArgumentException(sprintf(
|
throw new \InvalidArgumentException(sprintf(
|
||||||
|
|
|
@ -136,19 +136,11 @@ EOT
|
||||||
->setRunScripts(!$input->getOption('no-scripts'))
|
->setRunScripts(!$input->getOption('no-scripts'))
|
||||||
;
|
;
|
||||||
|
|
||||||
$exception = null;
|
|
||||||
try {
|
|
||||||
$status = $install->run();
|
$status = $install->run();
|
||||||
} catch (\Exception $exception) {
|
|
||||||
$status = 1;
|
|
||||||
}
|
|
||||||
if ($status !== 0) {
|
if ($status !== 0) {
|
||||||
$io->writeError("\n".'<error>Removal failed, reverting '.$file.' to its original content.</error>');
|
$io->writeError("\n".'<error>Removal failed, reverting '.$file.' to its original content.</error>');
|
||||||
file_put_contents($jsonFile->getPath(), $composerBackup);
|
file_put_contents($jsonFile->getPath(), $composerBackup);
|
||||||
}
|
}
|
||||||
if ($exception) {
|
|
||||||
throw $exception;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $status;
|
return $status;
|
||||||
}
|
}
|
||||||
|
|
|
@ -175,12 +175,7 @@ EOT
|
||||||
->setPreferLowest($input->getOption('prefer-lowest'))
|
->setPreferLowest($input->getOption('prefer-lowest'))
|
||||||
;
|
;
|
||||||
|
|
||||||
$exception = null;
|
|
||||||
try {
|
|
||||||
$status = $install->run();
|
$status = $install->run();
|
||||||
} catch (\Exception $exception) {
|
|
||||||
$status = 1;
|
|
||||||
}
|
|
||||||
if ($status !== 0) {
|
if ($status !== 0) {
|
||||||
if ($newlyCreated) {
|
if ($newlyCreated) {
|
||||||
$io->writeError("\n".'<error>Installation failed, deleting '.$file.'.</error>');
|
$io->writeError("\n".'<error>Installation failed, deleting '.$file.'.</error>');
|
||||||
|
@ -190,9 +185,6 @@ EOT
|
||||||
file_put_contents($json->getPath(), $composerBackup);
|
file_put_contents($json->getPath(), $composerBackup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($exception) {
|
|
||||||
throw $exception;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $status;
|
return $status;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue