Example #1
0
 public function setGitTags($tags, $stable = null)
 {
     // delete all current tags which are obsolete
     $currentTags = array();
     foreach ($this->getPluginTags() as $gitTag) {
         $currentTags[] = $gitTag->getName();
     }
     $deleteTags = array_diff($currentTags, $tags);
     foreach ($deleteTags as $tag) {
         $criteria = new Criteria();
         $criteria->add(PluginTagPeer::PLUGIN_ID, $this->getId());
         $criteria->add(PluginTagPeer::NAME, $tag);
         PluginTagPeer::doDelete($criteria);
     }
     foreach ($tags as $i => $tag) {
         if (!trim($tag)) {
             continue;
         }
         $existent = $this->getGitTagByName($tag);
         // if it was marked as stable and it's not the currently stable one, unmark it
         if ($existent && $existent->isCurrent() && $stable && $existent->getName(true) !== $stable) {
             $existent->setCurrent(false);
             $existent->save();
         }
         if (!$existent) {
             $t = new PluginTag();
             $t->setPluginId($this->getId());
             $t->setName($tag);
             if ($stable === null && $i + 1 == sizeof($tags) || floatval($tag) == $stable) {
                 $t->setCurrent(true);
             }
             $t->save();
             if ($t->isCurrent()) {
                 $this->stable_tag = $t;
             }
         }
     }
 }
 public function doValidate($validator, $values)
 {
     foreach ((array) $values['files'] as $file) {
         try {
             $parser = new ForgeJSParser(file_get_contents($file));
         } catch (ForgeJSParserException $e) {
             throw new sfValidatorError($validator, $e->getMessage() . sprintf(' (%s)', basename($file)));
         }
         $data = $parser->getData();
         // check for *presence* of required fields
         $requiredFields = array('provides', 'authors');
         foreach ($requiredFields as $required) {
             if (!isset($data[$required])) {
                 throw new sfValidatorError($validator, sprintf('`%s` field missing or empty in %s', $required, basename($file)));
             }
         }
         // check for well formed dependencies
         if (isset($data['requires'])) {
             if (!is_array($data['requires'])) {
                 $data['requires'] = array($data['requires']);
             }
             foreach ($data['requires'] as $a => $b) {
                 if (is_string($b) && preg_match('/([^:]+):([^\\/]*)\\/(.+)/', $b, $match)) {
                     $pluginName = $match[0];
                     $version = $match[1];
                     $b = $match[2];
                 } else {
                     if (strstr($a, '/') || strstr($a, ':')) {
                         $pieces = explode(strstr($a, '/') ? '/' : ':', $a);
                         $pluginName = $pieces[0];
                         $version = $pieces[1];
                     } else {
                         if (is_numeric($a)) {
                             $pluginName = '_self_';
                             $version = '_current_';
                         } else {
                             throw new sfValidatorError($validator, sprintf('Dependency "%s" is invalid. The format should be <b>plugin-uid</b>/<b>release</b>: [<b>provided-component</b>, ...]', $a . ': ' . $b));
                         }
                     }
                 }
                 $plugin = PluginPeer::retrieveBySlug($pluginName);
                 if (!is_array($b)) {
                     $b = array($b);
                 }
                 foreach ($b as $dep) {
                     if ($plugin) {
                         $c = new Criteria();
                         $c->add(PluginTagPeer::PLUGIN_ID, $plugin->getId());
                         $plugintag = PluginTagPeer::retrieveByName($dep, $c);
                         if ($plugintag) {
                             $plugin_tag_id = $plugintag->getId();
                         } else {
                             $plugin_tag_id = null;
                         }
                     } else {
                         $plugin_tag_id = null;
                     }
                     $this->dependencies[] = array('scope' => $pluginName, 'version' => $version, 'component' => $dep, 'plugin_tag_id' => $plugin_tag_id);
                 }
             }
         }
     }
 }