public function doValidate($validator, $values)
 {
     if ($values['id']) {
         $plugin = PluginPeer::retrieveByPk($values['id']);
         if (!sfContext::getInstance()->getUser()->ownsPlugin($plugin)) {
             throw new sfValidatorError($validator, 'You don\'t own the plugin you\'re trying to edit');
         }
     }
     if (substr_count($values['repository'], '.git') > 0) {
         $values['repository'] = substr($values['repository'], 0, strrpos($values['repository'], '.'));
     }
     $tags = GitHubFetcher::fetchContent(sprintf('/repos/%s/%s/tags', $values['user'], $values['repository']));
     if (($tagsArr = @json_decode($tags)) !== null) {
         foreach ((array) $tagsArr as $tag) {
             $this->gitTags[] = $tag->name;
         }
         usort($this->gitTags, 'version_compare');
     } else {
         throw new sfValidatorError($validator, 'Bad GitHub response. Try again later.');
     }
     if (empty($this->gitTags)) {
         throw new sfValidatorError($validator, 'GitHub repository has no tags. At least one tag is required.');
     }
     return $values;
 }
 public function doValidate($validator, $values)
 {
     if ($values['id']) {
         $plugin = PluginPeer::retrieveByPk($values['id']);
         if (!sfContext::getInstance()->getUser()->ownsPlugin($plugin)) {
             throw new sfValidatorError($validator, 'You don\'t own the plugin you\'re trying to edit');
         }
     }
     $tags = $this->fetch(sprintf('http://github.com/api/v2/json/repos/show/%s/%s/tags', $values['user'], $values['repository']));
     if ($tagsArr = @json_decode($tags)) {
         $this->gitTags = array_keys((array) $tagsArr->tags);
         usort($this->gitTags, 'version_compare');
     } else {
         throw new sfValidatorError($validator, 'Bad GitHub response. Try again later.');
     }
     if (empty($this->gitTags)) {
         throw new sfValidatorError($validator, 'GitHub repository has no tags. At least one tag is required.');
     }
     return $values;
 }
Ejemplo n.º 3
0
 /**
  * Completes adding
  *
  * @author Guillermo Rauch
  **/
 public function executeAdd6(sfWebRequest $request)
 {
     if ($request->isMethod('post')) {
         $addid = $request->getParameter('addid');
         $this->checkStep(5, $addid);
         $gitPath = $this->getUser()->getAttribute('github.path', '', 'plugin.add.' . $addid);
         $files = sfFinder::type('file')->name('*.js')->in($gitPath . '/Source');
         $form = new PluginAddStep6Form();
         $form->bind(array('files' => $files));
         if ($form->isValid()) {
             $params = $this->getUser()->getAttribute('github.params', array(), 'plugin.add.' . $addid);
             unset($params['author']);
             $params['dependencies'] = $form->getDependencies();
             $params['githubuser'] = $this->getUser()->getAttribute('github.user', '', 'plugin.add.' . $addid);
             $params['githubrepo'] = $this->getUser()->getAttribute('github.repository', '', 'plugin.add.' . $addid);
             $id = $this->getUser()->getAttribute('id', false, 'plugin.add.' . $addid);
             if ($id) {
                 $plugin = PluginPeer::retrieveByPk($id);
                 // clear cache
                 $cacheManager = sfContext::getInstance()->getViewCacheManager();
                 $cacheManager->remove('plugin/view?slug=' . $plugin->getSlug());
                 // for propel unique validator isUpdate check
                 $params['id'] = $id;
                 $form = new PluginAddForm($plugin);
                 $result = $form->bindAndSave($params);
             } else {
                 $form = new PluginAddForm();
                 $form->bindAndSave($params);
                 // clear index cache
                 $cacheManager = sfContext::getInstance()->getViewCacheManager();
                 $cacheManager->remove('default/index');
             }
             if (!$form->isValid()) {
                 return $this->renderJson($form->toJson());
             }
             $this->getUser()->getAttributeHolder()->remove('plugin.add.' . $addid);
             return $this->renderJson(array('success' => true, 'status' => 'Done!' . (!$id ? sprintf(' <a href="%s">See it here</a>', $this->getContext()->getRouting()->generate('plugin', array('slug' => $form->getObject()->getSlug()))) : '')));
         } else {
             return $this->renderJson($form->toJson());
         }
     }
 }