Removed the option to disallowed downgrades and simplifed some places where it was used
parent
e7441edcf1
commit
5fdca19880
|
@ -26,11 +26,6 @@ class DefaultPolicy implements PolicyInterface
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function allowDowngrade()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function versionCompare(PackageInterface $a, PackageInterface $b, $operator)
|
public function versionCompare(PackageInterface $a, PackageInterface $b, $operator)
|
||||||
{
|
{
|
||||||
$constraint = new VersionConstraint($operator, $b->getVersion());
|
$constraint = new VersionConstraint($operator, $b->getVersion());
|
||||||
|
@ -39,16 +34,11 @@ class DefaultPolicy implements PolicyInterface
|
||||||
return $constraint->matchSpecific($version);
|
return $constraint->matchSpecific($version);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function findUpdatePackages(Solver $solver, Pool $pool, array $installedMap, PackageInterface $package, $allowAll = false)
|
public function findUpdatePackages(Solver $solver, Pool $pool, array $installedMap, PackageInterface $package)
|
||||||
{
|
{
|
||||||
$packages = array();
|
$packages = array();
|
||||||
|
|
||||||
foreach ($pool->whatProvides($package->getName()) as $candidate) {
|
foreach ($pool->whatProvides($package->getName()) as $candidate) {
|
||||||
// skip old packages unless downgrades are an option
|
|
||||||
if (!$allowAll && !$this->allowDowngrade() && $this->versionCompare($package, $candidate, '>')) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($candidate !== $package) {
|
if ($candidate !== $package) {
|
||||||
$packages[] = $candidate;
|
$packages[] = $candidate;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,9 +21,8 @@ use Composer\Package\PackageInterface;
|
||||||
interface PolicyInterface
|
interface PolicyInterface
|
||||||
{
|
{
|
||||||
function allowUninstall();
|
function allowUninstall();
|
||||||
function allowDowngrade();
|
|
||||||
function versionCompare(PackageInterface $a, PackageInterface $b, $operator);
|
function versionCompare(PackageInterface $a, PackageInterface $b, $operator);
|
||||||
function findUpdatePackages(Solver $solver, Pool $pool, array $installedMap, PackageInterface $package, $allowAll);
|
function findUpdatePackages(Solver $solver, Pool $pool, array $installedMap, PackageInterface $package);
|
||||||
function installable(Solver $solver, Pool $pool, array $installedMap, PackageInterface $package);
|
function installable(Solver $solver, Pool $pool, array $installedMap, PackageInterface $package);
|
||||||
function selectPreferedPackages(Pool $pool, array $installedMap, array $literals);
|
function selectPreferedPackages(Pool $pool, array $installedMap, array $literals);
|
||||||
}
|
}
|
||||||
|
|
|
@ -375,9 +375,9 @@ class Solver
|
||||||
* be added
|
* be added
|
||||||
* @param bool $allowAll Whether downgrades are allowed
|
* @param bool $allowAll Whether downgrades are allowed
|
||||||
*/
|
*/
|
||||||
private function addRulesForUpdatePackages(PackageInterface $package, $allowAll)
|
private function addRulesForUpdatePackages(PackageInterface $package)
|
||||||
{
|
{
|
||||||
$updates = $this->policy->findUpdatePackages($this, $this->pool, $this->installedMap, $package, $allowAll);
|
$updates = $this->policy->findUpdatePackages($this, $this->pool, $this->installedMap, $package);
|
||||||
|
|
||||||
$this->addRulesForPackage($package);
|
$this->addRulesForPackage($package);
|
||||||
|
|
||||||
|
@ -965,7 +965,7 @@ class Solver
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($installedPackages as $package) {
|
foreach ($installedPackages as $package) {
|
||||||
$this->addRulesForUpdatePackages($package, true);
|
$this->addRulesForUpdatePackages($package);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -983,31 +983,15 @@ class Solver
|
||||||
// solver_addrpmrulesforweak(solv, &addedmap);
|
// solver_addrpmrulesforweak(solv, &addedmap);
|
||||||
|
|
||||||
foreach ($installedPackages as $package) {
|
foreach ($installedPackages as $package) {
|
||||||
// create a feature rule which allows downgrades
|
$updates = $this->policy->findUpdatePackages($this, $this->pool, $this->installedMap, $package);
|
||||||
$updates = $this->policy->findUpdatePackages($this, $this->pool, $this->installedMap, $package, true);
|
|
||||||
$featureRule = $this->createUpdateRule($package, $updates, self::RULE_INTERNAL_ALLOW_UPDATE, (string) $package);
|
|
||||||
|
|
||||||
// create an update rule which does not allow downgrades
|
|
||||||
$updates = $this->policy->findUpdatePackages($this, $this->pool, $this->installedMap, $package, false);
|
|
||||||
$rule = $this->createUpdateRule($package, $updates, self::RULE_INTERNAL_ALLOW_UPDATE, (string) $package);
|
$rule = $this->createUpdateRule($package, $updates, self::RULE_INTERNAL_ALLOW_UPDATE, (string) $package);
|
||||||
|
|
||||||
if ($rule->equals($featureRule)) {
|
if ($this->policy->allowUninstall()) {
|
||||||
if ($this->policy->allowUninstall()) {
|
|
||||||
$featureRule->setWeak(true);
|
|
||||||
$this->addRule(RuleSet::TYPE_FEATURE, $featureRule);
|
|
||||||
$this->packageToFeatureRule[$package->getId()] = $rule;
|
|
||||||
} else {
|
|
||||||
$this->addRule(RuleSet::TYPE_UPDATE, $rule);
|
|
||||||
$this->packageToUpdateRule[$package->getId()] = $rule;
|
|
||||||
}
|
|
||||||
} else if ($this->policy->allowUninstall()) {
|
|
||||||
$featureRule->setWeak(true);
|
|
||||||
$rule->setWeak(true);
|
$rule->setWeak(true);
|
||||||
|
|
||||||
$this->addRule(RuleSet::TYPE_FEATURE, $featureRule);
|
$this->addRule(RuleSet::TYPE_FEATURE, $featureRule);
|
||||||
$this->addRule(RuleSet::TYPE_UPDATE, $rule);
|
|
||||||
|
|
||||||
$this->packageToFeatureRule[$package->getId()] = $rule;
|
$this->packageToFeatureRule[$package->getId()] = $rule;
|
||||||
|
} else {
|
||||||
|
$this->addRule(RuleSet::TYPE_UPDATE, $rule);
|
||||||
$this->packageToUpdateRule[$package->getId()] = $rule;
|
$this->packageToUpdateRule[$package->getId()] = $rule;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue