public function executeDownload(sfWebRequest $request) { $project = PluginPeer::retrieveBySlug($request->getParameter('project')); $this->forward404Unless($project); $tag = $project->getGitTagByName($request->getParameter('tag')); $this->forward404Unless($tag); $project->sumDownload(); $tag->sumDownload(); header('Location: ' . $tag->getDownloadLink()); exit; }
protected function doClean($values) { if (is_null($values)) { $values = array(); } if (!is_array($values)) { throw new InvalidArgumentException('You must pass an array parameter to the clean() method'); } $errors = array(); $deps = isset($values[$this->getOption('dependencies_field')]) ? $values[$this->getOption('dependencies_field')] : array(); if (!empty($deps)) { foreach ($deps as $i => $dep) { if (!isset($dep['package']) || !$dep['package']) { $errors[] = new sfValidatorError($this, 'no_package'); } else { if (!ForgeToolkit::isUrl($dep['package'])) { if (!isset($dep['version']) || !$dep['version']) { $errors[] = new sfValidatorError($this, 'missing_tag', array('value' => $results[3])); } $plugin = PluginPeer::retrieveBySlug($results[3]); if ($plugin) { if ($tag = $plugin->getGitTagByName($dep['tag'])) { $values[$i]['plugin_tag_id'] = $tag->getId(); $errors[] = new sfValidatorError($this, 'tag_not_found', array('plugin' => $results[3], 'value' => $dep['tag'])); } } else { $errors[] = new sfValidatorError($this, 'plugin_not_found', array('value' => $dep['package'])); } } else { $values[$i]['external'] = true; $values[$i]['url'] = $dep['package']; $values[$i]['title'] = ForgeToolkit::retrieveTitleFromURL($dep['package']); } } } } if (!empty($errors)) { throw new sfValidatorErrorSchema($this, $errors); } return $values; }
/** * Delete a plugin * * @author Guillermo Rauch **/ public function executeDelete(sfWebRequest $request) { $this->plugin = PluginPeer::retrieveBySlug($request->getParameter('slug')); $this->plugin->delete(); $this->redirect('@homepage'); }
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); } } } } }