public function build(Addon $addon)
 {
     $composer = $this->packagist->getComposer();
     $downloader = $composer->getDownloadManager();
     $packageVersions = $this->packagist->getPackageVersions($addon->Name);
     $time = time();
     if (!$packageVersions) {
         throw new Exception('Could not find corresponding Packagist versions');
     }
     // Get the latest local and packagist version pair.
     $version = $addon->Versions()->filter('Development', true)->first();
     foreach ($packageVersions as $packageVersion) {
         if ($packageVersion->getVersionNormalized() != $version->Version) {
             continue;
         }
         $path = implode('/', array(TEMP_FOLDER, self::ADDONS_DIR, $addon->Name));
         // Convert PackagistAPI result into class compatible with Composer logic
         $package = new Package($addon->Name, $packageVersion->getVersionNormalized(), $packageVersion->getVersion());
         $package->setExtra($packageVersion->getExtra());
         if ($source = $packageVersion->getSource()) {
             $package->setSourceUrl($source->getUrl());
             $package->setSourceType($source->getType());
             $package->setSourceReference($source->getReference());
         }
         if ($dist = $packageVersion->getDist()) {
             $package->setDistUrl($dist->getUrl());
             $package->setDistType($dist->getType());
             $package->setDistReference($dist->getReference());
         }
         $this->download($package, $path);
         $this->buildReadme($addon, $path);
         $this->buildScreenshots($addon, $package, $path);
     }
     $addon->LastBuilt = $time;
     $addon->write();
 }
 private function updateVersion(Addon $addon, Version $package)
 {
     $version = null;
     if ($addon->isInDB()) {
         $version = $addon->Versions()->filter('Version', $package->getVersionNormalized())->first();
     }
     if (!$version) {
         $version = new AddonVersion();
     }
     $version->Name = $package->getName();
     $version->Type = str_replace('silverstripe-', '', $package->getType());
     $version->Description = $package->getDescription();
     $version->Released = strtotime($package->getTime());
     $keywords = $package->getKeywords();
     if ($keywords) {
         foreach ($keywords as $keyword) {
             $keyword = AddonKeyword::get_by_name($keyword);
             $addon->Keywords()->add($keyword);
             $version->Keywords()->add($keyword);
         }
     }
     $version->Version = $package->getVersionNormalized();
     $version->PrettyVersion = $package->getVersion();
     $stability = VersionParser::parseStability($package->getVersion());
     $isDev = $stability === 'dev';
     $version->Development = $isDev;
     $version->SourceType = $package->getSource()->getType();
     $version->SourceUrl = $package->getSource()->getUrl();
     $version->SourceReference = $package->getSource()->getReference();
     if ($package->getDist()) {
         $version->DistType = $package->getDist()->getType();
         $version->DistUrl = $package->getDist()->getUrl();
         $version->DistReference = $package->getDist()->getReference();
         $version->DistChecksum = $package->getDist()->getShasum();
     }
     $version->Extra = $package->getExtra();
     $version->Homepage = $package->getHomepage();
     $version->License = $package->getLicense();
     // $version->Support = $package->getSupport();
     $addon->Versions()->add($version);
     $this->updateLinks($version, $package);
     $this->updateCompatibility($addon, $version, $package);
     $this->updateAuthors($version, $package);
 }