Browse Source

Always update the master branch regardless if it is already in cache, refs #1062

Jordi Boggiano 5 years ago
parent
commit
4bcc21ceb4

+ 11 - 1
src/Packagist/WebBundle/Package/Updater.php

@@ -31,6 +31,7 @@ use Packagist\WebBundle\Entity\VersionRepository;
 use Packagist\WebBundle\Entity\SuggestLink;
 use Symfony\Bridge\Doctrine\RegistryInterface;
 use Doctrine\DBAL\Connection;
+use Packagist\WebBundle\Service\VersionCache;
 
 /**
  * @author Jordi Boggiano <j.boggiano@seld.be>
@@ -92,7 +93,7 @@ class Updater
      * @param RepositoryInterface $repository the repository instance used to update from
      * @param int $flags a few of the constants of this class
      */
-    public function update(IOInterface $io, Config $config, Package $package, RepositoryInterface $repository, $flags = 0, array $existingVersions = null): Package
+    public function update(IOInterface $io, Config $config, Package $package, RepositoryInterface $repository, $flags = 0, array $existingVersions = null, VersionCache $versionCache = null): Package
     {
         $rfs = new RemoteFilesystem($io, $config);
 
@@ -143,6 +144,13 @@ class Updater
             $rootIdentifier = $repository->getDriver()->getRootIdentifier();
         }
 
+        // always update the master branch / root identifier, as in case a package gets archived
+        // we want to mark it abandoned automatically, but there will not be a new commit to trigger
+        // an update
+        if ($rootIdentifier && $versionCache) {
+            $versionCache->clearVersion($rootIdentifier);
+        }
+
         $versions = $repository->getPackages();
         usort($versions, function ($a, $b) {
             $aVersion = $a->getVersion();
@@ -273,6 +281,8 @@ class Updater
                 $source['reference'] !== $data->getSourceReference()
                 // or if the right flag is set
                 || ($flags & self::UPDATE_EQUAL_REFS)
+                // or if the package must be marked abandoned from composer.json
+                || ($data->isAbandoned() && !$package->isAbandoned())
             ) {
                 $version = $versionRepo->findOneById($existingVersion['id']);
             } elseif ($existingVersion['needs_author_migration']) {

+ 1 - 1
src/Packagist/WebBundle/Service/UpdaterWorker.php

@@ -129,7 +129,7 @@ class UpdaterWorker
             $repository->setLoader($loader);
 
             // perform the actual update (fetch and re-scan the repository's source)
-            $package = $this->updater->update($io, $config, $package, $repository, $flags, $existingVersions);
+            $package = $this->updater->update($io, $config, $package, $repository, $flags, $existingVersions, $versionCache);
 
             $emptyRefCache = $em->merge($emptyRefCache);
             $emptyRefCache->setEmptyReferences($repository->getEmptyReferences());

+ 10 - 0
src/Packagist/WebBundle/Service/VersionCache.php

@@ -40,4 +40,14 @@ class VersionCache implements VersionCacheInterface
 
         return null;
     }
+
+    public function clearVersion($version)
+    {
+        foreach (array_keys($this->versionCache) as $v) {
+            if (preg_replace('{dev-|(\.x)?-dev}', '', $v) === $version) {
+                unset($this->versionCache[$v]);
+                break;
+            }
+        }
+    }
 }