Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Transaction.php

function Transaction::calculateOperations

Return value

OperationInterface[]

1 call to Transaction::calculateOperations()
Transaction::__construct in vendor/composer/composer/src/Composer/DependencyResolver/Transaction.php

File

vendor/composer/composer/src/Composer/DependencyResolver/Transaction.php, line 103

Class

Transaction
@author Nils Adermann <naderman@naderman.de> @internal

Namespace

Composer\DependencyResolver

Code

protected function calculateOperations() : array {
    $operations = [];
    $presentPackageMap = [];
    $removeMap = [];
    $presentAliasMap = [];
    $removeAliasMap = [];
    foreach ($this->presentPackages as $package) {
        if ($package instanceof AliasPackage) {
            $presentAliasMap[$package->getName() . '::' . $package->getVersion()] = $package;
            $removeAliasMap[$package->getName() . '::' . $package->getVersion()] = $package;
        }
        else {
            $presentPackageMap[$package->getName()] = $package;
            $removeMap[$package->getName()] = $package;
        }
    }
    $stack = $this->getRootPackages();
    $visited = [];
    $processed = [];
    while (\count($stack) > 0) {
        $package = array_pop($stack);
        if (isset($processed[spl_object_hash($package)])) {
            continue;
        }
        if (!isset($visited[spl_object_hash($package)])) {
            $visited[spl_object_hash($package)] = true;
            $stack[] = $package;
            if ($package instanceof AliasPackage) {
                $stack[] = $package->getAliasOf();
            }
            else {
                foreach ($package->getRequires() as $link) {
                    $possibleRequires = $this->getProvidersInResult($link);
                    foreach ($possibleRequires as $require) {
                        $stack[] = $require;
                    }
                }
            }
        }
        elseif (!isset($processed[spl_object_hash($package)])) {
            $processed[spl_object_hash($package)] = true;
            if ($package instanceof AliasPackage) {
                $aliasKey = $package->getName() . '::' . $package->getVersion();
                if (isset($presentAliasMap[$aliasKey])) {
                    unset($removeAliasMap[$aliasKey]);
                }
                else {
                    $operations[] = new Operation\MarkAliasInstalledOperation($package);
                }
            }
            else {
                if (isset($presentPackageMap[$package->getName()])) {
                    $source = $presentPackageMap[$package->getName()];
                    // do we need to update?
                    // TODO different for lock?
                    if ($package->getVersion() !== $presentPackageMap[$package->getName()]
                        ->getVersion() || $package->getDistReference() !== $presentPackageMap[$package->getName()]
                        ->getDistReference() || $package->getSourceReference() !== $presentPackageMap[$package->getName()]
                        ->getSourceReference()) {
                        $operations[] = new Operation\UpdateOperation($source, $package);
                    }
                    unset($removeMap[$package->getName()]);
                }
                else {
                    $operations[] = new Operation\InstallOperation($package);
                    unset($removeMap[$package->getName()]);
                }
            }
        }
    }
    foreach ($removeMap as $name => $package) {
        array_unshift($operations, new Operation\UninstallOperation($package));
    }
    foreach ($removeAliasMap as $nameVersion => $package) {
        $operations[] = new Operation\MarkAliasUninstalledOperation($package);
    }
    $operations = $this->movePluginsToFront($operations);
    // TODO fix this:
    // we have to do this again here even though the above stack code did it because moving plugins moves them before uninstalls
    $operations = $this->moveUninstallsToFront($operations);
    // TODO skip updates which don't update? is this needed? we shouldn't schedule this update in the first place?
    
    /*
            if ('update' === $opType) {
                $targetPackage = $operation->getTargetPackage();
                if ($targetPackage->isDev()) {
                    $initialPackage = $operation->getInitialPackage();
                    if ($targetPackage->getVersion() === $initialPackage->getVersion()
                        && (!$targetPackage->getSourceReference() || $targetPackage->getSourceReference() === $initialPackage->getSourceReference())
                        && (!$targetPackage->getDistReference() || $targetPackage->getDistReference() === $initialPackage->getDistReference())
                    ) {
                        $this->io->writeError('  - Skipping update of ' . $targetPackage->getPrettyName() . ' to the same reference-locked version', true, IOInterface::DEBUG);
                        $this->io->writeError('', true, IOInterface::DEBUG);
    
                        continue;
                    }
                }
            }*/
    return $this->operations = $operations;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal