Browse Source

Move some methods back to command.

xaav 13 years ago
parent
commit
6baf541c80

+ 4 - 2
src/Packagist/WebBundle/Command/UpdatePackagesCommand.php

@@ -104,8 +104,10 @@ EOF
                     $version->setPackage($package);
                     $version->setUpdatedAt(new \DateTime);
                     $version->setReleasedAt(new \DateTime($data['time']));
-                    $version->setSource($repo->getSource());
-                    $version->setDist($repo->getDist($uniqid));
+                    $version->setSource(array('type' => $repo->getType(), 'url' => $repo->getUrl()));
+
+                    $checksum = hash_file('sha1', $data['download']);
+                    $version->setDist(array('type' => 'zip', 'url' => $data['download'], 'shasum' => $checksum ?: ''));
 
                     if (isset($data['keywords'])) {
                         foreach ($data['keywords'] as $keyword) {

+ 7 - 7
src/Packagist/WebBundle/Repository/Repository/GitRepository.php

@@ -19,9 +19,9 @@ class GitRepository implements RepositoryInterface
         return json_decode(file_get_contents('http://github.com/api/v2/json/repos/show/'.$this->owner.'/'.$this->repository), true);
     }
 
-    public function getSource()
+    public function getType()
     {
-        return array('type' => 'git', 'url' => $this->getUrl());
+        return 'git';
     }
 
     public function getUrl()
@@ -29,13 +29,11 @@ class GitRepository implements RepositoryInterface
         return 'http://github.com/'.$this->owner.'/'.$this->repository.'.git';
     }
 
-    public function getDist($tag)
+    protected function getDist($tag)
     {
         $repoData = $this->getRepoData();
         if ($repoData['repository']['has_downloads']) {
-            $downloadUrl = 'https://github.com/'.$this->owner.'/'.$this->repository.'/zipball/'.$tag;
-            $checksum = hash_file('sha1', $downloadUrl);
-            return array('type' => 'zip', 'url' => $downloadUrl, 'shasum' => $checksum ?: '');
+            return 'https://github.com/'.$this->owner.'/'.$this->repository.'/zipball/'.$tag;
         } else {
             // TODO clone the repo and build/host a zip ourselves. Not sure if this can happen, but it'll be needed for non-GitHub repos anyway
         }
@@ -43,7 +41,7 @@ class GitRepository implements RepositoryInterface
 
     public function getAllComposerFiles()
     {
-        if(!$this->getRepoData()) {
+        if(!$repoData = $this->getRepoData()) {
             throw new \Exception();
         }
 
@@ -58,6 +56,8 @@ class GitRepository implements RepositoryInterface
                     $file['time'] = $commit['commit']['committed_date'];
                 }
 
+                $file['download'] = $this->getDist($tag);
+
                 $files[$tag] = $file;
             }
         }

+ 5 - 3
src/Packagist/WebBundle/Repository/Repository/RepositoryInterface.php

@@ -11,11 +11,13 @@ interface RepositoryInterface
      */
     public function getAllComposerFiles();
 
-    //TODO: This doesn't seem very clean.
-    public function getDist($uniqid);
-
     /**
      * Return the URL of the Repository
      */
     public function getUrl();
+
+    /**
+     * Return the type of the repository
+     */
+    public function getType();
 }