123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- <?php
- /*
- * This file is part of Composer.
- *
- * (c) Nils Adermann <naderman@naderman.de>
- * Jordi Boggiano <j.boggiano@seld.be>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- namespace Composer\DependencyResolver;
- use Composer\Repository\RepositoryInterface;
- use Composer\Package\PackageInterface;
- use Composer\Package\AliasPackage;
- use Composer\DependencyResolver\Operation;
- /**
- * @author Nils Adermann <naderman@naderman.de>
- */
- class Transaction
- {
- protected $policy;
- protected $pool;
- protected $installedMap;
- protected $decisionMap;
- protected $decisionQueue;
- protected $decisionQueueWhy;
- public function __construct($policy, $pool, $installedMap, $decisionMap, array $decisionQueue, $decisionQueueWhy)
- {
- $this->policy = $policy;
- $this->pool = $pool;
- $this->installedMap = $installedMap;
- $this->decisionMap = $decisionMap;
- $this->decisionQueue = $decisionQueue;
- $this->decisionQueueWhy = $decisionQueueWhy;
- }
- public function getOperations()
- {
- $transaction = array();
- $installMeansUpdateMap = array();
- foreach ($this->decisionQueue as $i => $literal) {
- $package = $literal->getPackage();
- // !wanted & installed
- if (!$literal->isWanted() && isset($this->installedMap[$package->getId()])) {
- $updates = $this->policy->findUpdatePackages($this->pool, $this->installedMap, $package);
- $literals = array(new Literal($package, true));
- foreach ($updates as $update) {
- $literals[] = new Literal($update, true);
- }
- foreach ($literals as $updateLiteral) {
- if (!$updateLiteral->equals($literal)) {
- $installMeansUpdateMap[$updateLiteral->getPackageId()] = $package;
- }
- }
- }
- }
- foreach ($this->decisionQueue as $i => $literal) {
- $package = $literal->getPackage();
- // wanted & installed || !wanted & !installed
- if ($literal->isWanted() == (isset($this->installedMap[$package->getId()]))) {
- continue;
- }
- if ($literal->isWanted()) {
- if ($package instanceof AliasPackage) {
- $transaction[] = new Operation\MarkAliasInstalledOperation(
- $package, $this->decisionQueueWhy[$i]
- );
- continue;
- }
- if (isset($installMeansUpdateMap[$literal->getPackageId()])) {
- $source = $installMeansUpdateMap[$literal->getPackageId()];
- $transaction[] = new Operation\UpdateOperation(
- $source, $package, $this->decisionQueueWhy[$i]
- );
- // avoid updates to one package from multiple origins
- unset($installMeansUpdateMap[$literal->getPackageId()]);
- $ignoreRemove[$source->getId()] = true;
- } else {
- $transaction[] = new Operation\InstallOperation(
- $package, $this->decisionQueueWhy[$i]
- );
- }
- } else if (!isset($ignoreRemove[$package->getId()])) {
- if ($package instanceof AliasPackage) {
- $transaction[] = new Operation\MarkAliasInstalledOperation(
- $package, $this->decisionQueueWhy[$i]
- );
- } else {
- $transaction[] = new Operation\UninstallOperation(
- $package, $this->decisionQueueWhy[$i]
- );
- }
- }
- }
- $allDecidedMap = $this->decisionMap;
- foreach ($this->decisionMap as $packageId => $decision) {
- if ($decision != 0) {
- $package = $this->pool->packageById($packageId);
- if ($package instanceof AliasPackage) {
- $allDecidedMap[$package->getAliasOf()->getId()] = $decision;
- }
- }
- }
- foreach ($allDecidedMap as $packageId => $decision) {
- if ($packageId === 0) {
- continue;
- }
- if (0 == $decision && isset($this->installedMap[$packageId])) {
- $package = $this->pool->packageById($packageId);
- if ($package instanceof AliasPackage) {
- $transaction[] = new Operation\MarkAliasInstalledOperation(
- $package, null
- );
- } else {
- $transaction[] = new Operation\UninstallOperation(
- $package, null
- );
- }
- $this->decisionMap[$packageId] = -1;
- }
- }
- foreach ($this->decisionMap as $packageId => $decision) {
- if ($packageId === 0) {
- continue;
- }
- if (0 == $decision && isset($this->installedMap[$packageId])) {
- $package = $this->pool->packageById($packageId);
- if ($package instanceof AliasPackage) {
- $transaction[] = new Operation\MarkAliasInstalledOperation(
- $package, null
- );
- } else {
- $transaction[] = new Operation\UninstallOperation(
- $package, null
- );
- }
- $this->decisionMap[$packageId] = -1;
- }
- }
- return array_reverse($transaction);
- }
- }
|