public function update()
 {
     $versions = $this->packagist->getPackageVersions('silverstripe/framework');
     foreach ($versions as $package) {
         $version = $package->getVersion();
         // Replace version by branch alias if applicable
         $extra = $package->getExtra();
         if (isset($extra['branch-alias'][$version])) {
             $version = $extra['branch-alias'][$version];
         }
         $stability = VersionParser::parseStability($version);
         $isDev = $stability === 'dev';
         if (!$isDev || in_array($version, $this->versionBlacklist)) {
             continue;
         }
         $match = preg_match('/^([0-9]+)\\.([0-9]+)\\.x-dev$/', $version, $matches);
         if (!$match) {
             continue;
         }
         $major = $matches[1];
         $minor = $matches[2];
         $record = SilverStripeVersion::get()->filter('Major', $major)->filter('Minor', $minor)->first();
         if (!$record) {
             $record = new SilverStripeVersion();
             $record->Name = "{$major}.{$minor}";
             $record->Major = $major;
             $record->Minor = $minor;
             $record->write();
         }
     }
 }
 /**
  * Updates all add-ons.
  *
  * @param Boolean Clear existing addons before updating them.
  * Will also clear their search index, and cascade the delete for associated data.
  * @param Array Limit to specific addons, using their name incl. vendor prefix.
  */
 public function update($clear = false, $limitAddons = null)
 {
     if ($clear && !$limitAddons) {
         Addon::get()->removeAll();
         AddonAuthor::get()->removeAll();
         AddonKeyword::get()->removeAll();
         AddonLink::get()->removeAll();
         AddonVendor::get()->removeAll();
         AddonVersion::get()->removeAll();
     }
     foreach (SilverStripeVersion::get() as $version) {
         $this->silverstripes[$version->ID] = $version->getConstraint();
     }
     // This call to packagist can be expensive. Requests are served from a cache if usePackagistCache() returns true
     $cache = SS_Cache::factory('addons');
     if ($this->usePackagistCache() && ($packages = $cache->load('packagist'))) {
         $packages = unserialize($packages);
     } else {
         $packages = $this->packagist->getPackages();
         $cache->save(serialize($packages), 'packagist');
     }
     $this->elastica->startBulkIndex();
     foreach ($packages as $package) {
         $name = $package->getName();
         $versions = $package->getVersions();
         if ($limitAddons && !in_array($name, $limitAddons)) {
             continue;
         }
         $addon = Addon::get()->filter('Name', $name)->first();
         if (!$addon) {
             $addon = new Addon();
             $addon->Name = $name;
             $addon->write();
         }
         usort($versions, function ($a, $b) {
             return version_compare($a->getVersionNormalized(), $b->getVersionNormalized());
         });
         $this->updateAddon($addon, $package, $versions);
     }
     $this->elastica->endBulkIndex();
 }
 public function AddonsSearchForm()
 {
     $form = new Form($this, 'AddonsSearchForm', new FieldList(array(TextField::create('search', 'Search for')->setValue($this->request->getVar('search'))->addExtraClass('input-block-level'), DropdownField::create('sort', 'Sort by')->setSource(array('name' => 'Name', 'downloads' => 'Most downloaded', 'newest' => 'Newest'))->setEmptyString('Best match')->setValue($this->request->getVar('sort'))->addExtraClass('input-block-level'), DropdownField::create('type', 'Add-on type')->setSource(array('module' => 'Modules', 'theme' => 'Themes'))->setEmptyString('Modules and themes')->setValue($this->request->getVar('type'))->addExtraClass('input-block-level'), CheckboxSetField::create('compatibility', 'Compatible SilverStripe versions')->setSource(SilverStripeVersion::get()->map('Name', 'Name'))->setValue($this->request->getVar('compatibility'))->setTemplate('AddonsSearchCheckboxSetField'))), new FieldList());
     return $form->setFormMethod('GET')->setFormAction($this->Link());
 }