Process all jobs in one method and remove lock jobs which are not used

main
Nils Adermann 12 years ago
parent 3fcd042fd4
commit 70e306f055

@ -20,7 +20,6 @@ class Rule
const RULE_INTERNAL_ALLOW_UPDATE = 1;
const RULE_JOB_INSTALL = 2;
const RULE_JOB_REMOVE = 3;
const RULE_JOB_LOCK = 4;
const RULE_PACKAGE_CONFLICT = 6;
const RULE_PACKAGE_REQUIRES = 7;
const RULE_PACKAGE_OBSOLETES = 8;
@ -196,9 +195,6 @@ class Rule
case self::RULE_JOB_REMOVE:
return "Remove command rule ($ruleText)";
case self::RULE_JOB_LOCK:
return "Lock command rule ($ruleText)";
case self::RULE_PACKAGE_CONFLICT:
$package1 = $this->literals[0]->getPackage();
$package2 = $this->literals[1]->getPackage();

@ -481,91 +481,71 @@ class Solver
}
}
public function solve(Request $request)
protected function addRulesForJobs()
{
$this->jobs = $request->getJobs();
$this->setupInstalledMap();
if (version_compare(PHP_VERSION, '5.3.4', '>=')) {
$this->decisionMap = new \SplFixedArray($this->pool->getMaxId() + 1);
} else {
$this->decisionMap = array_fill(0, $this->pool->getMaxId() + 1, 0);
}
foreach ($this->jobs as $job) {
foreach ($job['packages'] as $package) {
switch ($job['cmd']) {
case 'update':
switch ($job['cmd']) {
case 'update':
foreach ($job['packages'] as $package) {
if (isset($this->installedMap[$package->getId()])) {
$this->updateMap[$package->getId()] = true;
}
break;
}
}
}
break;
switch ($job['cmd']) {
case 'update-all':
foreach ($this->installedMap as $package) {
$this->updateMap[$package->getId()] = true;
}
break;
}
}
foreach ($this->installedMap as $package) {
$this->addRulesForPackage($package);
$this->addRulesForUpdatePackages($package);
}
foreach ($this->jobs as $job) {
foreach ($job['packages'] as $package) {
switch ($job['cmd']) {
case 'install':
$this->installCandidateMap[$package->getId()] = true;
$this->addRulesForPackage($package);
break;
}
}
}
foreach ($this->jobs as $job) {
switch ($job['cmd']) {
case 'install':
if (empty($job['packages'])) {
$problem = new Problem();
$problem->addJobRule($job);
$this->problems[] = $problem;
} else {
foreach ($job['packages'] as $package) {
if (!isset($this->installedMap[$package->getId()])) {
$this->addRulesForPackage($package);
}
}
$rule = $this->createInstallOneOfRule($job['packages'], Rule::RULE_JOB_INSTALL, $job['packageName']);
$this->addRule(RuleSet::TYPE_JOB, $rule);
$this->ruleToJob[$rule->getId()] = $job;
}
break;
break;
case 'remove':
// remove all packages with this name including uninstalled
// ones to make sure none of them are picked as replacements
// todo: cleandeps
foreach ($job['packages'] as $package) {
$rule = $this->createRemoveRule($package, Rule::RULE_JOB_REMOVE);
$this->addRule(RuleSet::TYPE_JOB, $rule);
$this->ruleToJob[$rule->getId()] = $job;
}
break;
case 'lock':
foreach ($job['packages'] as $package) {
if (isset($this->installedMap[$package->getId()])) {
$rule = $this->createInstallRule($package, Rule::RULE_JOB_LOCK);
} else {
$rule = $this->createRemoveRule($package, Rule::RULE_JOB_LOCK);
}
$this->addRule(RuleSet::TYPE_JOB, $rule);
$this->ruleToJob[$rule->getId()] = $job;
}
break;
}
}
}
public function solve(Request $request)
{
$this->jobs = $request->getJobs();
$this->setupInstalledMap();
if (version_compare(PHP_VERSION, '5.3.4', '>=')) {
$this->decisionMap = new \SplFixedArray($this->pool->getMaxId() + 1);
} else {
$this->decisionMap = array_fill(0, $this->pool->getMaxId() + 1, 0);
}
foreach ($this->installedMap as $package) {
$this->addRulesForPackage($package);
$this->addRulesForUpdatePackages($package);
}
$this->addRulesForJobs();
foreach ($this->rules as $rule) {
$this->addWatchesToRule($rule);

Loading…
Cancel
Save