Browse Source

Fix selection of best package to force update of dev packages, fixes #1252

Jordi Boggiano 12 năm trước cách đây
mục cha
commit
9856e9e3f5
1 tập tin đã thay đổi với 12 bổ sung6 xóa
  1. 12 6
      src/Composer/Installer.php

+ 12 - 6
src/Composer/Installer.php

@@ -429,25 +429,31 @@ class Installer
                         continue;
                     }
 
-                    $newPackage = null;
+                    // find similar packages (name/version) in all repositories
                     $matches = $pool->whatProvides($package->getName(), new VersionConstraint('=', $package->getVersion()));
-                    foreach ($matches as $match) {
+                    foreach ($matches as $index => $match) {
                         // skip local packages
                         if (!in_array($match->getRepository(), $repositories, true)) {
+                            unset($matches[$index]);
                             continue;
                         }
 
                         // skip providers/replacers
                         if ($match->getName() !== $package->getName()) {
+                            unset($matches[$index]);
                             continue;
                         }
 
-                        $newPackage = $match;
-                        break;
+                        $matches[$index] = $match->getId();
                     }
 
-                    if ($newPackage && $newPackage->getSourceReference() !== $package->getSourceReference()) {
-                        $operations[] = new UpdateOperation($package, $newPackage);
+                    // select prefered package according to policy rules
+                    if ($matches = $policy->selectPreferedPackages($pool, array(), $matches)) {
+                        $newPackage = $pool->literalToPackage($matches[0]);
+
+                        if ($newPackage && $newPackage->getSourceReference() !== $package->getSourceReference()) {
+                            $operations[] = new UpdateOperation($package, $newPackage);
+                        }
                     }
                 }