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

Breadcrumb

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

function Transaction::movePluginsToFront

Workaround: if your packages depend on plugins, we must be sure that those are installed / updated first; else it would lead to packages being installed multiple times in different folders, when running Composer twice.

While this does not fix the root-causes of https://github.com/composer/composer/issues/1147, it at least fixes the symptoms and makes usage of composer possible (again) in such scenarios.

Parameters

OperationInterface[] $operations:

Return value

OperationInterface[] reordered operation list

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

File

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

Class

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

Namespace

Composer\DependencyResolver

Code

private function movePluginsToFront(array $operations) : array {
    $dlModifyingPluginsNoDeps = [];
    $dlModifyingPluginsWithDeps = [];
    $dlModifyingPluginRequires = [];
    $pluginsNoDeps = [];
    $pluginsWithDeps = [];
    $pluginRequires = [];
    foreach (array_reverse($operations, true) as $idx => $op) {
        if ($op instanceof Operation\InstallOperation) {
            $package = $op->getPackage();
        }
        elseif ($op instanceof Operation\UpdateOperation) {
            $package = $op->getTargetPackage();
        }
        else {
            continue;
        }
        $extra = $package->getExtra();
        $isDownloadsModifyingPlugin = $package->getType() === 'composer-plugin' && isset($extra['plugin-modifies-downloads']) && $extra['plugin-modifies-downloads'] === true;
        // is this a downloads modifying plugin or a dependency of one?
        if ($isDownloadsModifyingPlugin || \count(array_intersect($package->getNames(), $dlModifyingPluginRequires)) > 0) {
            // get the package's requires, but filter out any platform requirements
            $requires = array_filter(array_keys($package->getRequires()), static function ($req) : bool {
                return !PlatformRepository::isPlatformPackage($req);
            });
            // is this a plugin with no meaningful dependencies?
            if ($isDownloadsModifyingPlugin && 0 === \count($requires)) {
                // plugins with no dependencies go to the very front
                array_unshift($dlModifyingPluginsNoDeps, $op);
            }
            else {
                // capture the requirements for this package so those packages will be moved up as well
                $dlModifyingPluginRequires = array_merge($dlModifyingPluginRequires, $requires);
                // move the operation to the front
                array_unshift($dlModifyingPluginsWithDeps, $op);
            }
            unset($operations[$idx]);
            continue;
        }
        // is this package a plugin?
        $isPlugin = $package->getType() === 'composer-plugin' || $package->getType() === 'composer-installer';
        // is this a plugin or a dependency of a plugin?
        if ($isPlugin || \count(array_intersect($package->getNames(), $pluginRequires)) > 0) {
            // get the package's requires, but filter out any platform requirements
            $requires = array_filter(array_keys($package->getRequires()), static function ($req) : bool {
                return !PlatformRepository::isPlatformPackage($req);
            });
            // is this a plugin with no meaningful dependencies?
            if ($isPlugin && 0 === \count($requires)) {
                // plugins with no dependencies go to the very front
                array_unshift($pluginsNoDeps, $op);
            }
            else {
                // capture the requirements for this package so those packages will be moved up as well
                $pluginRequires = array_merge($pluginRequires, $requires);
                // move the operation to the front
                array_unshift($pluginsWithDeps, $op);
            }
            unset($operations[$idx]);
        }
    }
    return array_merge($dlModifyingPluginsNoDeps, $dlModifyingPluginsWithDeps, $pluginsNoDeps, $pluginsWithDeps, $operations);
}

API Navigation

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