Example #1
0
 public function testUpdateAll()
 {
     $pool = new Pool();
     $request = new Request($pool);
     $request->updateAll();
     $this->assertEquals(array(array('cmd' => 'update-all', 'packages' => array())), $request->getJobs());
 }
Example #2
0
 public function printRules(Request $request)
 {
     $this->jobs = $request->getJobs();
     $this->setupInstalledMap();
     $this->decisions = new Decisions($this->pool);
     $this->rules = $this->ruleSetGenerator->getRulesFor($this->jobs, $this->installedMap);
     $this->watchGraph = new RuleWatchGraph();
     foreach ($this->rules as $rule) {
         printf("%s\n", $rule);
         // print_r( $rule->getLiterals() );
     }
 }
Example #3
0
 /**
  * @param  Request $request
  * @param  bool    $ignorePlatformReqs
  * @return array
  */
 public function solve(Request $request, $ignorePlatformReqs = false)
 {
     $this->jobs = $request->getJobs();
     $this->setupInstalledMap();
     $this->rules = $this->ruleSetGenerator->getRulesFor($this->jobs, $this->installedMap, $ignorePlatformReqs);
     $this->checkForRootRequireProblems($ignorePlatformReqs);
     $this->decisions = new Decisions($this->pool);
     $this->watchGraph = new RuleWatchGraph();
     foreach ($this->rules as $rule) {
         $this->watchGraph->insert(new RuleWatchNode($rule));
     }
     /* make decisions based on job/update assertions */
     $this->makeAssertionRuleDecisions();
     $this->io->writeError('Resolving dependencies through SAT', true, IOInterface::DEBUG);
     $before = microtime(true);
     $this->runSat(true);
     $this->io->writeError(sprintf('Dependency resolution completed in %.3f seconds', microtime(true) - $before), true, IOInterface::VERBOSE);
     // decide to remove everything that's installed and undecided
     foreach ($this->installedMap as $packageId => $void) {
         if ($this->decisions->undecided($packageId)) {
             $this->decisions->decide(-$packageId, 1, null);
         }
     }
     if ($this->problems) {
         throw new SolverProblemsException($this->problems, $this->installedMap);
     }
     $transaction = new Transaction($this->policy, $this->pool, $this->installedMap, $this->decisions);
     return $transaction->getOperations();
 }
Example #4
0
 public function solve(Request $request, $ignorePlatformReqs = false)
 {
     $this->jobs = $request->getJobs();
     $this->setupInstalledMap();
     $this->rules = $this->ruleSetGenerator->getRulesFor($this->jobs, $this->installedMap, $ignorePlatformReqs);
     $this->checkForRootRequireProblems($ignorePlatformReqs);
     $this->decisions = new Decisions($this->pool);
     $this->watchGraph = new RuleWatchGraph();
     foreach ($this->rules as $rule) {
         $this->watchGraph->insert(new RuleWatchNode($rule));
     }
     $this->makeAssertionRuleDecisions();
     $this->runSat(true);
     foreach ($this->installedMap as $packageId => $void) {
         if ($this->decisions->undecided($packageId)) {
             $this->decisions->decide(-$packageId, 1, null);
         }
     }
     if ($this->problems) {
         throw new SolverProblemsException($this->problems, $this->installedMap);
     }
     $transaction = new Transaction($this->policy, $this->pool, $this->installedMap, $this->decisions);
     return $transaction->getOperations();
 }
Example #5
0
 public function solve(Request $request)
 {
     $this->jobs = $request->getJobs();
     $this->setupInstalledMap();
     $this->decisions = new Decisions($this->pool);
     $this->rules = $this->ruleSetGenerator->getRulesFor($this->jobs, $this->installedMap);
     $this->watchGraph = new RuleWatchGraph();
     foreach ($this->rules as $rule) {
         $this->watchGraph->insert(new RuleWatchNode($rule));
     }
     /* make decisions based on job/update assertions */
     $this->makeAssertionRuleDecisions();
     $this->runSat(true);
     // decide to remove everything that's installed and undecided
     foreach ($this->installedMap as $packageId => $void) {
         if ($this->decisions->undecided($packageId)) {
             $this->decisions->decide(-$packageId, 1, null);
         }
     }
     if ($this->problems) {
         throw new SolverProblemsException($this->problems, $this->installedMap);
     }
     $transaction = new Transaction($this->policy, $this->pool, $this->installedMap, $this->decisions);
     return $transaction->getOperations();
 }
Example #6
0
 public function solve(Request $request)
 {
     $this->jobs = $request->getJobs();
     $installedPackages = $this->installed->getPackages();
     $this->installedMap = array();
     foreach ($installedPackages as $package) {
         $this->installedMap[$package->getId()] = $package;
     }
     if (version_compare(PHP_VERSION, '5.3.3', '>')) {
         $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 'fix':
                     if (isset($this->installedMap[$package->getId()])) {
                         $this->fixMap[$package->getId()] = true;
                     }
                     break;
                 case 'update':
                     if (isset($this->installedMap[$package->getId()])) {
                         $this->updateMap[$package->getId()] = true;
                     }
                     break;
             }
         }
         switch ($job['cmd']) {
             case 'update-all':
                 foreach ($installedPackages as $package) {
                     $this->updateMap[$package->getId()] = true;
                 }
                 break;
         }
     }
     foreach ($installedPackages as $package) {
         $this->addRulesForPackage($package);
     }
     foreach ($installedPackages as $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;
             }
         }
     }
     // solver_addrpmrulesforweak(solv, &addedmap);
     foreach ($installedPackages as $package) {
         $updates = $this->policy->findUpdatePackages($this, $this->pool, $this->installedMap, $package);
         $rule = $this->createUpdateRule($package, $updates, self::RULE_INTERNAL_ALLOW_UPDATE, (string) $package);
         $rule->setWeak(true);
         $this->addRule(RuleSet::TYPE_FEATURE, $rule);
         $this->packageToFeatureRule[$package->getId()] = $rule;
     }
     foreach ($this->jobs as $job) {
         switch ($job['cmd']) {
             case 'install':
                 if (empty($job['packages'])) {
                     $this->problems[] = array($job);
                 } else {
                     $rule = $this->createInstallOneOfRule($job['packages'], self::RULE_JOB_INSTALL, $job['packageName']);
                     $this->addRule(RuleSet::TYPE_JOB, $rule);
                     $this->ruleToJob[$rule->getId()] = $job;
                 }
                 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, self::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, self::RULE_JOB_LOCK);
                     } else {
                         $rule = $this->createRemoveRule($package, self::RULE_JOB_LOCK);
                     }
                     $this->addRule(RuleSet::TYPE_JOB, $rule);
                     $this->ruleToJob[$rule->getId()] = $job;
                 }
                 break;
         }
     }
     $this->addChoiceRules();
     foreach ($this->rules as $rule) {
         $this->addWatchesToRule($rule);
     }
     /* disable update rules that conflict with our job */
     $this->disablePolicyRules();
     /* make decisions based on job/update assertions */
     $this->makeAssertionRuleDecisions();
     $installRecommended = 0;
     $this->runSat(true, $installRecommended);
     //$this->printDecisionMap();
     //findrecommendedsuggested(solv);
     //solver_prepare_solutions(solv);
     if ($this->problems) {
         throw new SolverProblemsException($this->problems, $this->learnedPool);
     }
     return $this->createTransaction();
 }
Example #7
0
 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);
     }
     $this->rules = $this->ruleSetGenerator->getRulesFor($this->jobs, $this->installedMap);
     $this->watchGraph = new RuleWatchGraph();
     foreach ($this->rules as $rule) {
         $this->watchGraph->insert(new RuleWatchNode($rule));
     }
     /* make decisions based on job/update assertions */
     $this->makeAssertionRuleDecisions();
     $this->runSat(true);
     if ($this->problems) {
         throw new SolverProblemsException($this->problems);
     }
     $transaction = new Transaction($this->policy, $this->pool, $this->installedMap, $this->decisionMap, $this->decisionQueue, $this->decisionQueueWhy);
     return $transaction->getOperations();
 }
Example #8
0
 public function testUpdateAll()
 {
     $request = new Request();
     $request->updateAll();
     $this->assertEquals(array(array('cmd' => 'update-all')), $request->getJobs());
 }