Browse Source

Fixed package crawler failing on dev version updates

Jordi Boggiano 14 years ago
parent
commit
ce1ef8f488

+ 22 - 3
src/Packagist/WebBundle/Command/UpdatePackagesCommand.php

@@ -76,6 +76,7 @@ EOF
                         // Strip -dev that could have been left over accidentally in a tag
                         $data['version'] = preg_replace('{-?dev$}i', '', $data['version']);
                         $this->updateInformation($output, $doctrine, $package, $repository, $identifier, $data);
+                        $doctrine->getEntityManager()->flush();
                     }
                 }
 
@@ -95,6 +96,7 @@ EOF
                         $data['version'] = $parsedVersion['version'].'-'.$parsedVersion['type'].'-dev';
 
                         $this->updateInformation($output, $doctrine, $package, $repository, $identifier, $data);
+                        $doctrine->getEntityManager()->flush();
                     }
                 }
 
@@ -188,12 +190,14 @@ EOF
             $version->setExtra($data['extra']);
         }
 
+        $version->getTags()->clear();
         if (isset($data['keywords'])) {
             foreach ($data['keywords'] as $keyword) {
                 $version->addTags(Tag::getByName($em, $keyword, true));
             }
         }
 
+        $version->getAuthors()->clear();
         if (isset($data['authors'])) {
             foreach ($data['authors'] as $authorData) {
                 $author = null;
@@ -216,19 +220,34 @@ EOF
                     }
                 }
                 $author->setUpdatedAt(new \DateTime);
-                $version->addAuthors($author);
-                $author->addVersions($version);
+                if (!$version->getAuthors()->contains($author)) {
+                    $version->addAuthors($author);
+                }
+                if (!$author->getVersions()->contains($version)) {
+                    $author->addVersions($version);
+                }
+            }
+        }
+
+        foreach ($version->getRequirements() as $req) {
+            // clear requirements that have changed/disappeared (for updates)
+            if (!isset($data['require'][$req->getPackageName()]) || $data['require'][$req->getPackageName()] !== $req->getPackageVersion()) {
+                $version->getRequirements()->removeElement($req);
+                $em->remove($req);
+            } else {
+                // clear those that are already set
+                unset($data['require'][$req->getPackageName()]);
             }
         }
 
         if (isset($data['require'])) {
             foreach ($data['require'] as $requireName => $requireVersion) {
                 $requirement = new Requirement();
-                $em->persist($requirement);
                 $requirement->setPackageName($requireName);
                 $requirement->setPackageVersion($requireVersion);
                 $version->addRequirements($requirement);
                 $requirement->setVersion($version);
+                $em->persist($requirement);
             }
         }
     }

+ 5 - 0
src/Packagist/WebBundle/Entity/Requirement.php

@@ -118,4 +118,9 @@ class Requirement
     {
         return $this->version;
     }
+
+    public function __toString()
+    {
+        return $this->packageName.' '.$this->packageVersion;
+    }
 }

+ 2 - 0
src/Packagist/WebBundle/Entity/Version.php

@@ -140,6 +140,8 @@ class Version
     public function __construct()
     {
         $this->tags = new \Doctrine\Common\Collections\ArrayCollection();
+        $this->requirements = new \Doctrine\Common\Collections\ArrayCollection();
+        $this->authors = new \Doctrine\Common\Collections\ArrayCollection();
         $this->createdAt = new \DateTime;
         $this->updatedAt = new \DateTime;
     }

+ 2 - 1
src/Packagist/WebBundle/Resources/views/About/about.html.twig

@@ -15,7 +15,8 @@
 // Monolog is a library, so the vendor name is the complete package name.
 monolog
 
-// That could be the name of a drupal module.
+// That could be the name of a drupal module (maintained/provided by monolog,
+// if the drupal team did it, the vendor would be drupal).
 monolog/monolog-drupal-module
 
 // Acme is a company or person here, they can name their package with a common name (Email).