public function perform()
 {
     $package = Addon::get()->byID($this->args['id']);
     $builder = Injector::inst()->get('AddonBuilder');
     $builder->build($package);
     $package->BuildQueued = false;
     $package->write();
 }
 public function run($request)
 {
     $addons = Addon::get();
     if ($request->getVar('addons')) {
         $addons = $addons->filter('Name', explode(',', $request->getVar('addons')));
     }
     foreach ($addons as $addon) {
         $this->log(sprintf('Building "%s"', $addon->Name));
         try {
             $this->builder->build($addon);
         } catch (RuntimeException $e) {
             $this->log('Error: ' . $e->getMessage());
         }
         $addon->BuildQueued = false;
         $addon->write();
     }
 }
 public function run($request)
 {
     $dateOneWeekAgo = date('Y-m-d', strtotime('-1 week'));
     $addons = Addon::get()->filter('LastUpdated:LessThan', $dateOneWeekAgo);
     foreach ($addons as $addon) {
         try {
             $addon->Keywords()->removeAll();
             $addon->Screenshots()->removeAll();
             $addon->CompatibleVersions()->removeAll();
             foreach ($addon->Versions() as $version) {
                 $version->Authors()->removeAll();
                 $version->Keywords()->removeAll();
                 $version->CompatibleVersions()->removeAll();
                 $version->delete();
             }
             $addon->delete();
         } catch (Elastica\Exception\NotFoundException $e) {
             // no-op
         }
     }
 }
 private function updateLinks(AddonVersion $version, CompletePackage $package)
 {
     $getLink = function ($name, $type) use($version) {
         $link = null;
         if ($version->isInDB()) {
             $link = $version->Links()->filter('Name', $name)->filter('Type', $type)->first();
         }
         if (!$link) {
             $link = new AddonLink();
             $link->Name = $name;
             $link->Type = $type;
         }
         return $link;
     };
     $types = array('require' => 'getRequire', 'require-dev' => 'getRequireDev', 'provide' => 'getProvide', 'conflict' => 'getConflict', 'replace' => 'getReplace');
     foreach ($types as $type => $method) {
         if ($linked = $package->{$method}()) {
             foreach ($linked as $link => $constraint) {
                 $name = $link;
                 $addon = Addon::get()->filter('Name', $name)->first();
                 $local = $getLink($name, $type);
                 $local->Constraint = $constraint;
                 if ($addon) {
                     $local->TargetID = $addon->ID;
                 }
                 $version->Links()->add($local);
             }
         }
     }
     //to-do api have no method to get this.
     /*$suggested = $package->getSuggests();
     
     		if ($suggested) foreach ($suggested as $package => $description) {
     			$link = $getLink($package, 'suggest');
     			$link->Description = $description;
     
     			$version->Links()->add($link);
     		}*/
 }
 public function RandomAddons($limit = 10)
 {
     return Addon::get()->sort(DB::getConn()->random(), 'DESC')->limit($limit);
 }
 public function Addons()
 {
     return Addon::get()->filter('ID', $this->Versions()->column('AddonID'));
 }
 public function rss($request, $limit = 10)
 {
     $addons = Addon::get()->sort('Released', 'DESC')->limit($limit);
     $rss = new RSSFeed($addons, $this->Link(), "Newest addons on addons.silverstripe.org", null, 'RSSTitle');
     return $rss->outputToBrowser();
 }