Separate transaction generation from solving and properly identify updates
parent
f46aa495da
commit
0f6fb9b692
|
@ -1069,8 +1069,31 @@ class Solver
|
|||
//findrecommendedsuggested(solv);
|
||||
//solver_prepare_solutions(solv);
|
||||
|
||||
return $this->createTransaction();
|
||||
}
|
||||
|
||||
protected function createTransaction()
|
||||
{
|
||||
$transaction = array();
|
||||
|
||||
$installMeansUpdateMap = array();
|
||||
$ignoreRemoveMap = array();
|
||||
|
||||
foreach ($this->decisionQueue as $i => $literal) {
|
||||
$package = $literal->getPackage();
|
||||
|
||||
// !wanted & installed
|
||||
if (!$literal->isWanted() && $this->installed === $package->getRepository()) {
|
||||
$updateRule = $this->packageToUpdateRule[$package->getId()];
|
||||
|
||||
foreach ($updateRule->getLiterals() as $updateLiteral) {
|
||||
if (!$updateLiteral->equals($literal)) {
|
||||
$installMeansUpdateMap[$updateLiteral->getPackageId()] = $package;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->decisionQueue as $i => $literal) {
|
||||
$package = $literal->getPackage();
|
||||
|
||||
|
@ -1079,12 +1102,35 @@ class Solver
|
|||
continue;
|
||||
}
|
||||
|
||||
if ($literal->isWanted()) {
|
||||
if (isset($installMeansUpdateMap[$literal->getPackageId()])) {
|
||||
$source = $installMeansUpdateMap[$literal->getPackageId()];
|
||||
|
||||
$transaction[] = array(
|
||||
'job' => ($literal->isWanted()) ? 'install' : 'remove',
|
||||
'job' => 'update',
|
||||
'from' => $source,
|
||||
'to' => $package,
|
||||
'why' => $this->decisionQueueWhy[$i],
|
||||
);
|
||||
|
||||
// avoid updates to one package from multiple origins
|
||||
unset($installMeansUpdateMap[$literal->getPackageId()]);
|
||||
$ignoreRemove[$source->getId()] = true;
|
||||
} else {
|
||||
$transaction[] = array(
|
||||
'job' => 'install',
|
||||
'package' => $package,
|
||||
'why' => $this->decisionQueueWhy[$i],
|
||||
);
|
||||
}
|
||||
} else if (!isset($ignoreRemove[$package->getId()])) {
|
||||
$transaction[] = array(
|
||||
'job' => 'remove',
|
||||
'package' => $package,
|
||||
'why' => $this->decisionQueueWhy[$i],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return array_reverse($transaction);
|
||||
}
|
||||
|
|
|
@ -124,9 +124,7 @@ class SolverTest extends \PHPUnit_Framework_TestCase
|
|||
$this->request->update('A');
|
||||
|
||||
$this->checkSolverResult(array(
|
||||
//array('job' => 'update', 'from' => $packageA, 'to' => $newPackageA),
|
||||
array('job' => 'remove', 'package' => $packageA),
|
||||
array('job' => 'install', 'package' => $newPackageA),
|
||||
array('job' => 'update', 'from' => $packageA, 'to' => $newPackageA),
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -143,8 +141,6 @@ class SolverTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
public function testSolverFull()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
|
||||
$this->repoInstalled->addPackage($packageD = new MemoryPackage('D', '1.0'));
|
||||
$this->repoInstalled->addPackage($oldPackageC = new MemoryPackage('C', '1.0'));
|
||||
|
||||
|
@ -162,10 +158,10 @@ class SolverTest extends \PHPUnit_Framework_TestCase
|
|||
$this->request->remove('D');
|
||||
|
||||
$this->checkSolverResult(array(
|
||||
array('job' => 'install', 'package' => $packageB),
|
||||
array('job' => 'install', 'package' => $packageA),
|
||||
array('job' => 'remove', 'package' => $packageD),
|
||||
array('job' => 'update', 'from' => $oldPackageC, 'to' => $packageC),
|
||||
array('job' => 'install', 'package' => $packageB),
|
||||
array('job' => 'remove', 'package' => $packageD),
|
||||
array('job' => 'install', 'package' => $packageA),
|
||||
));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue