/** * Returns an array of all possible upgrade files as an array with * the upgrade's key and version * * This first looks for all .php files in the versions directory. * The files should have the format of VERSION_NUMBER (e.g. 1.0.0__1). * The project is then checked to see if */ public function getUpgrades() { if (!$this->_upgrades) { $this->_upgrades = array(); $versions = array(); $dir = dirname(__FILE__) . '/versions'; $files = sfFinder::type('file')->name('*.php')->in($dir); foreach ($files as $file) { $info = pathinfo($file); if (strpos($info['filename'], '__') === false) { throw new sfException(sprintf('Invalid upgrade filename format for file "%s" - must contain a double underscore - VERSION__NUMBER (e.g. 1.0.0__1) ', $info['filename'])); } $e = explode('__', $info['filename']); $version = $e[0]; $number = $e[1]; if ($this->_isVersionNew($info['filename'])) { $versions[] = array('version' => $version, 'number' => $number); $this->_upgrades[] = $version . '__' . $number; } } natcasesort($this->_upgrades); foreach ($this->_upgrades as $key => $version) { $this->_upgrades[$key] = $versions[$key]; } } return $this->_upgrades; }
/** * @see sfGenerator */ public function generate($params = array()) { $this->params = $params; foreach (array('index_class', 'moduleName') as $required) { if (!isset($this->params[$required])) { throw new xfGeneratorException('You must specify "' . $required . '".'); } } if (!class_exists($this->params['index_class'])) { throw new xfGeneratorException('Unable to build interface for nonexistant index "' . $this->params['index_class'] . '"'); } if (null !== ($form = $this->get('simple.form.class', null))) { $reflection = new ReflectionClass($form); if (!$reflection->isSubClassOf(new ReflectionClass('xfForm'))) { throw new xfGeneratorException('Form class must extend xfForm'); } } // check to see if theme exists if (!isset($this->params['theme'])) { $this->params['theme'] = 'default'; } $themeDir = $this->generatorManager->getConfiguration()->getGeneratorTemplate($this->getGeneratorClass(), $this->params['theme'], ''); $this->setGeneratedModuleName('auto' . ucfirst($this->params['moduleName'])); $this->setModuleName($this->params['moduleName']); $this->setTheme($this->params['theme']); $themeFiles = sfFinder::type('file')->relative()->discard('.*')->in($themeDir); $this->generatePhpFiles($this->generatedModuleName, $themeFiles); $data = "require_once(sfConfig::get('sf_module_cache_dir') . '/" . $this->generatedModuleName . "/actions/actions.class.php');"; $data .= "require_once(sfConfig::get('sf_module_cache_dir') . '/" . $this->generatedModuleName . "/actions/components.class.php');"; return $data; }
/** * Generates classes and templates in cache. * * @param array $params The parameters * * @return string The data to put in configuration cache */ public function generate($params = array()) { $this->validateParameters($params); $this->modelClass = $this->params['model_class']; // generated module name $this->setModuleName($this->params['moduleName']); $this->setGeneratedModuleName('auto' . ucfirst($this->params['moduleName'])); // theme exists? $theme = isset($this->params['theme']) ? $this->params['theme'] : 'default'; $this->setTheme($theme); $themeDir = $this->generatorManager->getConfiguration()->getGeneratorTemplate($this->getGeneratorClass(), $theme, ''); if (!is_dir($themeDir)) { throw new sfConfigurationException(sprintf('The theme "%s" does not exist.', $theme)); } // configure the model $this->configure(); $this->configuration = $this->loadConfiguration(); // generate files $this->generatePhpFiles($this->generatedModuleName, sfFinder::type('file')->relative()->in($themeDir)); // move helper file if (file_exists($file = $this->generatorManager->getBasePath() . '/' . $this->getGeneratedModuleName() . '/lib/helper.php')) { @rename($file, $this->generatorManager->getBasePath() . '/' . $this->getGeneratedModuleName() . '/lib/Base' . ucfirst($this->moduleName) . 'GeneratorHelper.class.php'); } return "require_once(sfConfig::get('sf_module_cache_dir').'/" . $this->generatedModuleName . "/actions/actions.class.php');"; }
/** * Clears the super cache by listening to the task.cache.clear event. * * @param sfEvent An sfEvent instance */ public static function clearCache(sfEvent $event) { $config = sfFilterConfigHandler::getConfiguration($event['app']->getConfigPaths('config/filters.yml')); $event->getSubject()->logSection('cache', 'Clearing super cache'); // find super cache configuration $found = false; $cacheDir = 'cache'; foreach ($config as $value) { if ('sfSuperCacheFilter' == $value['class']) { $found = true; if (isset($value['param']['cache_dir'])) { $cacheDir = $value['param']['cache_dir']; } break; } } if ($found) { // clear the cache $cacheDir = sfConfig::get('sf_web_dir') . '/' . $cacheDir; if (is_dir($cacheDir)) { // remove cache files $event->getSubject()->getFilesystem()->remove(sfFinder::type('file')->ignore_version_control()->discard('.sf')->in($cacheDir)); } } }
/** * @see sfI18nExtract */ public function extract() { foreach (sfFinder::type('dir')->maxdepth(0)->relative()->in($this->parameters['path'] . '/modules') as $moduleName) { $this->extractFromPhpFiles(array($this->parameters['path'] . '/modules/' . $moduleName . '/actions', $this->parameters['path'] . '/modules/' . $moduleName . '/lib', $this->parameters['path'] . '/modules/' . $moduleName . '/templates')); } $this->extractFromPhpFiles($this->parameters['path'] . '/lib'); }
/** * * * @param unknown_type $arguments * @param unknown_type $options * @todo run in build task * @todo add lock file */ protected function execute($arguments = array(), $options = array()) { // run only in staging or dev mode if ($options['env'] == "dev") { throw new sfException(sprintf("Don't run the s3sync in the '%s' environment.", $options['env'])); } $lReleaseName = sfConfig::get('app_release_name'); $lBucket = sfConfig::get('app_amazons3_bucket'); $lNewPath = CdnSingleton::getInstance()->getNextHost() . '/' . $lReleaseName; $lCssDirectory = sfConfig::get('sf_web_dir') . "/css"; $lS3Directory = sfConfig::get('sf_web_dir') . "/s3sync"; $this->getFilesystem()->execute("rm -rf " . $lS3Directory . "/css"); $this->getFilesystem()->execute("rsync -aC --exclude .svn " . $lCssDirectory . " " . $lS3Directory); $lFiles = sfFinder::type('file')->follow_link()->relative()->in($lS3Directory . "/css"); foreach ($lFiles as $lFile) { // absolute path $lFile = $lS3Directory . "/css/" . $lFile; $lContent = file_get_contents($lFile); $lContent = str_replace('url("/img/', 'url("' . $lNewPath . "/img/", $lContent); $fp = fopen($lFile, 'w'); fwrite($fp, $lContent); fclose($fp); } $this->getFilesystem()->execute("s3cmd --bucket-location=EU -P -r --exclude='*.svn*' --add-header 'Expires: Sat, 08 May 2015 15:22:28 GMT' sync web/s3sync/css/ s3://{$lBucket}/{$lReleaseName}/css/"); $this->getFilesystem()->execute("s3cmd --bucket-location=EU -P -r --exclude='*.svn*' --add-header 'Expires: Sat, 08 May 2015 15:22:28 GMT' sync web/img/ s3://{$lBucket}/{$lReleaseName}/img/"); $this->getFilesystem()->execute("s3cmd --bucket-location=EU -P -r --exclude='*.svn*' --add-header 'Expires: Sat, 08 May 2015 15:22:28 GMT' sync web/js/100_main/include/ s3://{$lBucket}/{$lReleaseName}/js/100_main/include/"); $this->getFilesystem()->execute("find ./web/js/100_main/include -type f -exec 7z a -tgzip -x\\!\\*.svn -x\\!\\*.gz {}.gz {} \\;"); $this->getFilesystem()->execute("s3cmd --bucket-location=EU -P -r --exclude='*.*' --include '*.gz' --mime-type 'application/javascript' --add-header 'Content-Encoding: gzip' sync web/js/100_main/include/ s3://{$lBucket}/{$lReleaseName}/js/100_main/include/"); $this->getFilesystem()->execute("find ./web/js/100_main/include -name '*.gz' -exec rm {} \\;"); $this->getFilesystem()->execute("find ./web/s3sync/css -type f -exec 7z a -tgzip -x\\!\\*.svn -x\\!\\*.gz {}.gz {} \\;"); $this->getFilesystem()->execute("s3cmd --bucket-location=EU -P -r --exclude='*.*' --include '*.gz' --mime-type 'text/css' --add-header 'Content-Encoding: gzip' sync web/s3sync/css/ s3://{$lBucket}/{$lReleaseName}/css/"); $this->getFilesystem()->execute("find ./web/s3sync/css -name '*.gz' -exec rm {} \\;"); }
/** * Loads all available tasks. * * Looks for tasks in the symfony core, the current project and all project plugins. * * @param sfProjectConfiguration $configuration The project configuration */ protected function loadTasks(sfProjectConfiguration $configuration) { // Symfony core tasks $dirs = array(sfConfig::get('sf_symfony_lib_dir') . '/task'); // Plugin tasks foreach ($configuration->getPluginPaths() as $path) { if (is_dir($taskPath = $path . '/lib/task')) { $dirs[] = $taskPath; } } // project tasks $dirs[] = sfConfig::get('sf_lib_dir') . '/task'; $finder = sfFinder::type('file')->name('*Task.class.php'); foreach ($finder->in($dirs) as $file) { $this->taskFiles[basename($file, '.class.php')] = $file; } // register local autoloader for tasks spl_autoload_register(array($this, 'autoloadTask')); // require tasks foreach ($this->taskFiles as $task => $file) { // forces autoloading of each task class class_exists($task, true); } // unregister local autoloader spl_autoload_unregister(array($this, 'autoloadTask')); }
protected function execute($arguments = array(), $options = array()) { $plugin = $arguments['plugin']; $app = $arguments['application']; $module = $arguments['module']; $pluginsDir = sfConfig::get('sf_plugins_dir') . '/' . $plugin; // Validate the module name if (!preg_match('/^[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*$/', $module)) { throw new sfCommandException(sprintf('The module name "%s" is invalid.', $module)); } $moduleDir = $pluginsDir . '/apps/' . $app . '/modules/' . $module; if (is_dir($moduleDir)) { throw new sfCommandException(sprintf('The module "%s" already exists in the "%s" application.in the "%s" plugin', $moduleDir, $app, $plugin)); } $properties = parse_ini_file(sfConfig::get('sf_config_dir') . '/properties.ini', true); if (is_readable($pluginsDir . '/config/properties.ini')) { $pluginProperties = parse_ini_file($pluginsDir . '/config/properties.ini', true); $properties = array_merge($properties, $pluginProperties); } $constants = array('PROJECT_NAME' => isset($properties['symfony']['name']) ? $properties['symfony']['name'] : 'symfony', 'APP_NAME' => $app, 'MODULE_NAME' => $module, 'AUTHOR_NAME' => isset($properties['symfony']['author']) ? $properties['symfony']['author'] : 'Your name here'); $skeletonDir = dirname(__FILE__) . '/skeleton/module'; // create basic application structure $finder = sfFinder::type('any')->discard('.sf'); $this->getFilesystem()->mirror($skeletonDir . '/module', $moduleDir, $finder); // customize php and yml files $finder = sfFinder::type('file')->name('*.php', '*.yml'); $this->getFilesystem()->replaceTokens($finder->in($moduleDir), '##', '##', $constants); }
public function upgrade() { if (!file_exists($file = sfConfig::get('sf_lib_dir') . '/form/BaseForm.class.php')) { $properties = parse_ini_file(sfConfig::get('sf_config_dir') . '/properties.ini', true); $tokens = array('PROJECT_NAME' => isset($properties['symfony']['name']) ? $properties['symfony']['name'] : 'symfony', 'AUTHOR_NAME' => isset($properties['symfony']['author']) ? $properties['symfony']['author'] : 'Your name here'); $this->getFilesystem()->copy(sfConfig::get('sf_symfony_lib_dir') . '/task/generator/skeleton/project/lib/form/BaseForm.class.php', $file); $this->getFilesystem()->replaceTokens(array($file), '##', '##', $tokens); } $finder = sfFinder::type('file')->name('*.php'); foreach ($finder->in($this->getProjectLibDirectories('/form')) as $file) { $contents = file_get_contents($file); $changed = false; // forms that extend sfForm should now extend BaseForm $contents = preg_replace('/(\\bextends\\s+)sfForm\\b/i', '\\1BaseForm', $contents, -1, $count); $changed = $count || $changed; // change instances of sfWidgetFormInput to sfWidgetFormInputText $contents = preg_replace('/\\bnew\\s+sfWidgetFormInput\\b/i', '\\0Text', $contents, -1, $count); $changed = $count || $changed; // change signature of sfFormDoctrine::processValues() $contents = preg_replace('/public\\s+function\\s+processValues\\s*\\(\\s*\\$\\w+(\\s*=\\s*null\\s*)\\)/ie', "str_replace('\$1', '', '\$0')", $contents, -1, $count); $changed = $count || $changed; if ($changed) { $this->logSection('form', 'Migrating ' . $file); file_put_contents($file, $contents); } } }
public function loadAllFilesInDir($dir) { $files = sfFinder::type('file')->name('*.schema.sql')->follow_link()->in($dir); foreach ($files as $file) { $this->loadFromFile($file); } }
protected function execute($arguments = array(), $options = array()) { $app = $arguments['application']; $override = $options['override']; $testAppDir = sfConfig::get('sf_test_dir').'/features/'.$app; if (is_readable(sfConfig::get('sf_data_dir').'/skeleton/features')) { $skeletonDir = sfConfig::get('sf_data_dir').'/skeleton/features'; } else { $skeletonDir = dirname(__FILE__).'/skeleton/features'; } if (file_exists(sfConfig::get('sf_root_dir') . '/behat.yml')) { $this->getFilesystem()->remove(sfConfig::get('sf_root_dir') . '/behat.yml'); } // create basic application features $finder = sfFinder::type('any')->discard('.sf'); $this->getFilesystem()->mirror($skeletonDir.'/app', $testAppDir, $finder, array( 'override' => $override )); $this->getFilesystem()->mirror($skeletonDir.'/root', sfConfig::get('sf_root_dir'), $finder, array( 'override' => $override )); }
protected function execute($arguments = array(), $options = array()) { $plugins = explode(',', $options['plugins']); foreach (glob(sfConfig::get('sf_plugins_dir') . '/*', GLOB_ONLYDIR) as $plugin_path) { $plugin = basename($plugin_path); if ($options['plugins'] != 'all' && !in_array($plugin, $plugins)) { continue; } if (is_dir(sfConfig::get('sf_plugins_dir') . '/' . $plugin . '/.git')) { $this->logSection($plugin, 'plugin folder already under git management'); continue; } $file = sfConfig::get('sf_plugins_dir') . '/' . $plugin . '/.sw_git_migration'; if (!is_file($file) && $options['plugins'] != 'all') { $this->logSection($plugin, 'no .sw_git_migration file'); continue; } $git_repository = trim(file_get_contents($file)); $this->logSection($plugin, 'starting restore ...'); // remove current directory content $this->getFileSystem()->remove(sfFinder::type('any')->ignore_version_control(false)->in(sprintf('%s/.sw_git_migration_plugin', sfConfig::get('sf_plugins_dir')))); // run the task to deploy a git repository over a svn repo $this->logSection($plugin, 'clone the repository'); $cmd = sprintf('%s clone %s %s/.sw_git_migration_plugin', $options['git'], $git_repository, sfConfig::get('sf_plugins_dir')); $this->exec($cmd); $this->logSection($plugin, 'copy the content into the'); $this->getFileSystem()->mirror(sprintf('%s/.sw_git_migration_plugin', sfConfig::get('sf_plugins_dir')), sfConfig::get('sf_plugins_dir') . '/' . $plugin, sfFinder::type('any')->ignore_version_control(false), array('overwrite' => true)); $this->getFileSystem()->remove(sfFinder::type('any')->ignore_version_control(false)->in(sprintf('%s/.sw_git_migration_plugin', sfConfig::get('sf_plugins_dir')))); } }
/** * Loads map builder classes. * * This method is ORM dependant. * * @throws sfException */ protected function loadMapBuilderClasses() { // we must load all map builder classes to be able to deal with foreign keys (cf. editSuccess.php template) $classes = sfFinder::type('file')->ignore_version_control()->name('*MapBuilder.php')->in(sfLoader::getModelDirs()); foreach ($classes as $class) { $class_map_builder = basename($class, '.php'); $maps[$class_map_builder] = new $class_map_builder(); if (!$maps[$class_map_builder]->isBuilt()) { $maps[$class_map_builder]->doBuild(); } if ($this->className == str_replace('MapBuilder', '', $class_map_builder)) { $this->map = $maps[$class_map_builder]; } } if (!$this->map) { throw new sfException('The model class "'.$this->className.'" does not exist.'); } $this->tableMap = $this->map->getDatabaseMap()->getTable(constant($this->className.'Peer::TABLE_NAME')); }
/** * * Combine files defined in module's view.yml files */ public function combineModuleFiles() { // get the all modules $modules = sfConfig::get('sf_enabled_modules', array()); $app_modules = sfFinder::type('directory')->maxdepth(0)->in(sfConfig::get('sf_app_module_dir')); foreach ($app_modules as $module) { $modules[] = str_replace(sfConfig::get('sf_app_module_dir') . '/', '', $module); } foreach ($modules as $module) { $this->logSection('combine', 'module : ' . $module); $configPath = sprintf('modules/%s/config/view.yml', $module); $files = $this->configuration->getConfigPaths($configPath); $config = swCombineViewConfigHandler::getConfiguration($files); $this->view_handler->setYamlConfig($config); foreach ($config as $view => $params) { $this->logSection('combine', ' > view : ' . $module . '::' . $view); // Generate css module files $stylesheets = $this->view_handler->exposeMergeConfigValue('stylesheets', $view); if (count($stylesheets) > 0) { $assets = $this->view_handler->exposeAddAssets('stylesheet', $stylesheets, false); $this->combineAndOptimize('stylesheet', $assets); } // Generate js module files $javascripts = $this->view_handler->exposeMergeConfigValue('javascripts', $view); if (count($javascripts) > 0) { $assets = $this->view_handler->exposeAddAssets('javascript', $javascripts, false); $this->combineAndOptimize('javascript', $assets); } } } }
/** * Generates classes and templates in cache. * * @param array The parameters * * @return string The data to put in configuration cache */ public function generate($params = array()) { $logger = sfContext::getInstance()->getLogger(); $logger->err("WOW generate enter"); $logger->err(print_r($params, true)); $this->params = $params; // check if all required parameters are present $required_parameters = array('moduleName'); foreach ($required_parameters as $entry) { if (!isset($this->params[$entry])) { throw new sfParseException(sprintf('You must specify a "%s".', $entry)); } } // generated module name $this->setGeneratedModuleName('auto' . ucfirst($this->params['moduleName'])); $this->setModuleName($this->params['moduleName']); // check if the theme exists? $theme = isset($this->params['theme']) ? $this->params['theme'] : 'default'; $themeDir = $this->generatorManager->getConfiguration()->getGeneratorTemplate($this->getGeneratorClass(), $theme, ''); if (!is_dir($themeDir)) { throw new sfConfigurationException(sprintf('The theme "%s" does not exist.', $theme)); } $this->setTheme($theme); $files = sfFinder::type('file')->relative()->in($themeDir); $this->generatePhpFiles($this->generatedModuleName, $files); // require generated action class $data = "require_once(sfConfig::get('sf_module_cache_dir').'/" . $this->generatedModuleName . "/actions/actions.class.php');\n"; $logger->err("WOW generate leave"); return $data; }
/** * @see sfTaskExtraAddon */ public function executeAddon($arguments = array(), $options = array()) { $finder = sfFinder::type('file')->maxdepth(0); foreach ($finder->in($this->pluginConfiguration->getConnectedPluginSubPaths('/lib/model')) as $file) { if (!file_exists($pluginFile = dirname($file) . '/plugin/Plugin' . basename($file)) && preg_match('/(\\w+) extends (\\w+)/', $contents = file_get_contents($file), $match) && 0 !== strpos($match[2], 'Plugin')) { $pluginContents = <<<EOF <?php /** * Plugin model class generated by sfTaskExtraPlugin. */ class Plugin{$match[1]} extends {$match['2']} { } EOF; // create plugin class $this->getFilesystem()->mkdirs(dirname($pluginFile)); $this->getFilesystem()->touch($pluginFile); file_put_contents($pluginFile, $pluginContents); // edit stub class $this->logSection('edit', $file); file_put_contents($file, str_replace('extends ' . $match[2], 'extends Plugin' . $match[1], $contents)); } } }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { // remove lib/symfony and data/symfony directories if (!is_dir('lib/symfony')) { throw new sfCommandException('You can unfreeze only if you froze the symfony libraries before.'); } // change symfony path in ProjectConfiguration.class.php $config = sfConfig::get('sf_config_dir') . '/ProjectConfiguration.class.php'; $content = file_get_contents($config); if (preg_match('/^# FROZEN_SF_LIB_DIR\\: (.+?)$/m', $content, $match)) { $publishAssets = new sfPluginPublishAssetsTask($this->dispatcher, $this->formatter); $publishAssets->setCommandApplication($this->commandApplication); $symfonyLibDir = $match[1]; $content = str_replace("# FROZEN_SF_LIB_DIR: {$match[1]}\n\n", '', $content); // need to escape windows pathes "symfony\1.2" -> "symfony\\1.2" // because preg_replace would then use \1 as group identifier resulting in "symfony.2" $content = preg_replace('#^require_once.+?$#m', sprintf("require_once '%s/autoload/sfCoreAutoload.class.php';", str_replace('\\', '\\\\', $symfonyLibDir)), $content, 1); file_put_contents($config, $content); // re-publish assets $publishAssets->run(array(), array('--symfony-lib-dir=' . $symfonyLibDir)); // remove files $finder = sfFinder::type('any'); $this->getFilesystem()->remove($finder->in(sfConfig::get('sf_lib_dir') . '/symfony')); $this->getFilesystem()->remove(sfConfig::get('sf_lib_dir') . '/symfony'); $this->getFilesystem()->remove($finder->in(sfConfig::get('sf_data_dir') . '/symfony')); $this->getFilesystem()->remove(sfConfig::get('sf_data_dir') . '/symfony'); $this->getFilesystem()->remove($finder->in(sfConfig::get('sf_web_dir') . '/sf')); $this->getFilesystem()->remove(sfConfig::get('sf_web_dir') . '/sf'); } }
/** * Executes index action * * @param sfWebRequest $request A request object */ public function executeIndex(sfWebRequest $request) { $this->task = $request->getParameter('task', null); if (!is_null($this->task)) { $this->form = new opKdtPluginBackendForm(array('task' => $this->task)); if ($request->isMethod(sfRequest::POST)) { $this->form->bind($request->getParameter($this->form->getName())); if ($this->form->isValid()) { $this->form->executeTask(); $this->getUser()->setFlash('notice', 'Execute the tasks.'); $this->redirect('opKdtPlugin/index'); } } return sfView::INPUT; } $finder = sfFinder::type('file')->maxdepth(0)->ignore_version_control(false)->follow_link()->name('opKdt*Task.class.php'); $dir = array(sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'opKdtPlugin'.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'task'); $this->tasks = array(); foreach ($finder->in($dir) as $path) { preg_match('/^opKdt(.*)Task.class.php$/', basename($path), $matches); $this->tasks[] = $matches[1]; } }
public function testFolderCorrelations(lime_test $t) { $t->diag('Verify that each db folder exist in fs'); $errors = 0; foreach ($this->folderTable->findAll() as $f) { if (!is_dir($f->fullPath)) { $t->diag(sprintf('folder %s does not exist in fs', $f)); $errors++; } } $t->is($errors, 0, 'Each db folder exist in fs'); if ($errors > 0) { die; } $t->diag('Verify that each fs folder exist in db'); $errors = 0; foreach (sfFinder::type('dir')->discard(".*")->ignore_version_control()->maxdepth(20)->in($this->folderTable->getTree()->fetchRoot()->fullPath) as $f) { if (strpos($f, '/.')) { continue; } $f = dmOs::normalize($f); $f = str_replace(dmOs::normalize(sfConfig::get('sf_upload_dir')) . '/', '', $f); if (!$this->folderTable->createQuery('f')->where('f.rel_path = ?', $f)->exists()) { $t->diag(sprintf('folder %s does not exist in db', $f)); $errors++; } } $t->is($errors, 0, 'Each fs folder exist in db'); }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { // check that the symfony librairies are not already freeze for this project if (is_readable(sfConfig::get('sf_lib_dir') . '/symfony')) { throw new sfCommandException('You can only freeze when lib/symfony is empty.'); } if (is_readable(sfConfig::get('sf_data_dir') . '/symfony')) { throw new sfCommandException('You can only freeze when data/symfony is empty.'); } if (is_readable(sfConfig::get('sf_web_dir') . '/sf')) { throw new sfCommandException('You can only freeze when web/sf is empty.'); } if (is_link(sfConfig::get('sf_web_dir') . '/sf')) { $this->getFilesystem()->remove(sfConfig::get('sf_web_dir') . '/sf'); } $symfonyLibDir = sfConfig::get('sf_symfony_lib_dir'); $symfonyDataDir = $arguments['symfony_data_dir']; if (!is_readable($symfonyDataDir)) { throw new sfCommandException(sprintf('The symfony data dir does not seem to be located at "%s".', $symfonyDataDir)); } $this->logSection('freeze', sprintf('freezing lib found in "%s', $symfonyLibDir)); $this->logSection('freeze', sprintf('freezing data found in "%s"', $symfonyDataDir)); $this->getFilesystem()->mkdirs('lib' . DIRECTORY_SEPARATOR . 'symfony'); $this->getFilesystem()->mkdirs('data' . DIRECTORY_SEPARATOR . 'symfony'); $finder = sfFinder::type('any')->exec(array($this, 'excludeTests')); $this->getFilesystem()->mirror($symfonyLibDir, sfConfig::get('sf_lib_dir') . '/symfony', $finder); $this->getFilesystem()->mirror($symfonyDataDir, sfConfig::get('sf_data_dir') . '/symfony', $finder); $this->getFilesystem()->rename(sfConfig::get('sf_data_dir') . '/symfony/web/sf', sfConfig::get('sf_web_dir') . '/sf'); // change symfony path in ProjectConfiguration.class.php $config = sfConfig::get('sf_config_dir') . '/ProjectConfiguration.class.php'; $content = file_get_contents($config); $content = str_replace('<?php', "<?php\n\n# FROZEN_SF_LIB_DIR: {$symfonyLibDir}", $content); $content = preg_replace('#(\'|")' . preg_quote($symfonyLibDir, '#') . '#', "dirname(__FILE__).\$1/../lib/symfony", $content); file_put_contents($config, $content); }
/** * Generates classes and templates in cache. * * @param array $params The parameters * * @return string The data to put in configuration cache */ public function generate($params = array()) { $this->params = $params; $required_parameters = array('model_class', 'moduleName'); foreach ($required_parameters as $entry) { if (!isset($this->params[$entry])) { throw new sfParseException(sprintf('You must specify a "%s".', $entry)); } } $modelClass = $this->params['model_class']; if (!class_exists($modelClass)) { throw new sfInitializationException(sprintf('Unable to scaffold nonexistent model "%s".', $modelClass)); } $this->setScaffoldingClassName($modelClass); // generated module name $this->setGeneratedModuleName('auto' . ucfirst($this->params['moduleName'])); $this->setModuleName($this->params['moduleName']); // get some model metadata $this->loadMapBuilderClasses(); // load all primary keys $this->loadPrimaryKeys(); // theme exists? $theme = isset($this->params['theme']) ? $this->params['theme'] : 'default'; $themeDir = $this->generatorManager->getConfiguration()->getGeneratorTemplate($this->getGeneratorClass(), $theme, ''); if (!is_dir($themeDir)) { throw new sfConfigurationException(sprintf('The theme "%s" does not exist.', $theme)); } $this->setTheme($theme); $files = sfFinder::type('file')->relative()->in($themeDir); $this->generatePhpFiles($this->generatedModuleName, $files); // require generated action class $data = "require_once(sfConfig::get('sf_module_cache_dir').'/" . $this->generatedModuleName . "/actions/actions.class.php');\n"; return $data; }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { $app = $arguments['application']; $module = $arguments['module']; // Validate the module name if (!preg_match('/^[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*$/', $app)) { throw new sfCommandException(sprintf('The module name "%s" is invalid.', $app)); } $moduleDir = sfConfig::get('sf_app_module_dir') . '/' . $module; if (is_dir($moduleDir)) { throw new sfCommandException(sprintf('The module "%s" already exists in the "%s" application.', $moduleDir, $app)); } $properties = parse_ini_file(sfConfig::get('sf_config_dir') . '/properties.ini', true); $constants = array('PROJECT_NAME' => isset($properties['symfony']['name']) ? $properties['symfony']['name'] : 'symfony', 'APP_NAME' => $app, 'MODULE_NAME' => $module, 'AUTHOR_NAME' => isset($properties['symfony']['author']) ? $properties['symfony']['author'] : 'Your name here'); if (is_readable(sfConfig::get('sf_data_dir') . '/skeleton/module')) { $skeletonDir = sfConfig::get('sf_data_dir') . '/skeleton/module'; } else { $skeletonDir = dirname(__FILE__) . '/skeleton/module'; } // create basic application structure $finder = sfFinder::type('any')->discard('.sf'); $this->getFilesystem()->mirror($skeletonDir . '/module', $moduleDir, $finder); // create basic test $this->getFilesystem()->copy($skeletonDir . '/test/actionsTest.php', sfConfig::get('sf_test_dir') . '/functional/' . $app . '/' . $module . 'ActionsTest.php'); // customize test file $this->getFilesystem()->replaceTokens(sfConfig::get('sf_test_dir') . '/functional/' . $app . DIRECTORY_SEPARATOR . $module . 'ActionsTest.php', '##', '##', $constants); // customize php and yml files $finder = sfFinder::type('file')->name('*.php', '*.yml'); $this->getFilesystem()->replaceTokens($finder->in($moduleDir), '##', '##', $constants); }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { $app = $arguments['application']; if (count($arguments['controller'])) { $files = array(); foreach ($arguments['controller'] as $controller) { $finder = sfFinder::type('file')->follow_link()->name(basename($controller) . 'Test.php'); $files = array_merge($files, $finder->in(sfConfig::get('sf_test_dir') . '/functional/' . $app . '/' . dirname($controller))); } if ($allFiles = $this->filterTestFiles($files, $arguments, $options)) { foreach ($allFiles as $file) { include $file; } } else { $this->logSection('functional', 'no controller found', null, 'ERROR'); } } else { require_once dirname(__FILE__) . '/sfLimeHarness.class.php'; $h = new sfLimeHarness(array('force_colors' => $options['color'], 'verbose' => $options['trace'])); $h->addPlugins(array_map(array($this->configuration, 'getPluginConfiguration'), $this->configuration->getPlugins())); $h->base_dir = sfConfig::get('sf_test_dir') . '/functional/' . $app; // filter and register functional tests $finder = sfFinder::type('file')->follow_link()->name('*Test.php'); $h->register($this->filterTestFiles($finder->in($h->base_dir), $arguments, $options)); $ret = $h->run() ? 0 : 1; if ($options['xml']) { file_put_contents($options['xml'], $h->to_xml()); } return $ret; } }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { $config = $this->getCliConfig(); $pluginSchemaDirectories = glob(sfConfig::get('sf_plugins_dir') . DIRECTORY_SEPARATOR . '*' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'doctrine'); $pluginSchemas = sfFinder::type('file')->name('*.yml')->in($pluginSchemaDirectories); $tmpPath = sfConfig::get('sf_cache_dir') . DIRECTORY_SEPARATOR . 'tmp'; if (!file_exists($tmpPath)) { Doctrine_Lib::makeDirectories($tmpPath); } foreach ($pluginSchemas as $schema) { $schema = str_replace('/', DIRECTORY_SEPARATOR, $schema); $plugin = str_replace(sfConfig::get('sf_plugins_dir') . DIRECTORY_SEPARATOR, '', $schema); $e = explode(DIRECTORY_SEPARATOR, $plugin); $plugin = $e[0]; $name = basename($schema); $tmpSchemaPath = $tmpPath . DIRECTORY_SEPARATOR . $plugin . '-' . $name; $models = Doctrine_Parser::load($schema, 'yml'); if (!isset($models['package'])) { $models['package'] = $plugin . '.lib.model.doctrine'; } Doctrine_Parser::dump($models, 'yml', $tmpSchemaPath); } $import = new Doctrine_Import_Schema(); $import->setOption('generateBaseClasses', true); $import->setOption('generateTableClasses', true); $import->setOption('packagesPath', sfConfig::get('sf_plugins_dir')); $import->setOption('packagesPrefix', 'Plugin'); $import->setOption('suffix', '.class.php'); $import->setOption('baseClassesDirectory', 'generated'); $import->setOption('baseClassName', 'sfDoctrineRecord'); $import->importSchema(array($tmpPath, $config['yaml_schema_path']), 'yml', $config['models_path']); $this->dispatcher->notify(new sfEvent($this, 'command.log', array($this->formatter->formatSection('doctrine', 'Generated models successfully')))); }
/** * Autoloads symfony * Note: This is not compatible with ->bootstrap() * Code adopted from command/sfSymfonyCommandApplication.class.php */ public function autoload() { if ($this->autoload) { return; } $this->autoload = 'simple'; require_once $this->sf_lib_dir . '/util/sfCore.class.php'; require_once $this->sf_lib_dir . '/config/sfConfig.class.php'; require_once $this->sf_lib_dir . '/util/sfSimpleAutoload.class.php'; require_once $this->sf_lib_dir . '/util/sfToolkit.class.php'; require_once $this->sf_lib_dir . '/util/sfFinder.class.php'; sfConfig::add(array('sf_symfony_lib_dir' => $this->sf_lib_dir, 'sf_symfony_data_dir' => $this->sf_lib_dir)); // directory layout sfCore::initDirectoryLayout($this->sf_lib_dir); // include path set_include_path(sfConfig::get('sf_lib_dir') . PATH_SEPARATOR . sfConfig::get('sf_app_lib_dir') . PATH_SEPARATOR . sfConfig::get('sf_model_dir') . PATH_SEPARATOR . get_include_path()); $cache = sfToolkit::getTmpDir() . DIRECTORY_SEPARATOR . sprintf('limeade_autoload_%s.data', md5(__FILE__)); $autoloader = sfSimpleAutoload::getInstance($cache); $autoloader->register(); $finder = sfFinder::type('file')->ignore_version_control()->prune('test')->prune('vendor')->name('*.php'); $autoloader->addFiles($finder->in(sfConfig::get('sf_symfony_lib_dir'))); $autoloader->addFiles($finder->in($this->project_root)); $autoloader->addDirectory(sfConfig::get('sf_root_dir') . '/plugins'); return $this; }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { $finder = sfFinder::type('dir')->name('base'); $this->addIgnore(array_merge($finder->in('lib/form/doctrine'), $finder->in('lib/filter/doctrine'), $finder->in('lib/model/doctrine'), array('cache', 'data/sql', 'lib/model/om', 'lib/model/map', 'log', 'web/uploads'))); $this->setSubversionProperty('svn:ignore', array('*transformed*', '*generated*'), 'config'); $this->setSubversionProperty('svn:ignore', 'frontend_dev.php', 'web'); }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { if (count($arguments['name'])) { $files = array(); foreach ($arguments['name'] as $name) { $finder = sfFinder::type('file')->follow_link()->name(basename($name) . 'Test.php'); $files = array_merge($files, $finder->in(sfConfig::get('sf_test_dir') . '/unit/' . dirname($name))); } if ($allFiles = $this->filterTestFiles($files, $arguments, $options)) { foreach ($allFiles as $file) { include $file; } } else { $this->logSection('test', 'no tests found', null, 'ERROR'); } } else { require_once __DIR__ . '/sfLimeHarness.class.php'; $h = new sfLimeHarness(array('force_colors' => isset($options['color']) && $options['color'], 'verbose' => isset($options['trace']) && $options['trace'], 'test_path' => sfConfig::get('sf_cache_dir') . '/lime')); $h->addPlugins(array_map(array($this->configuration, 'getPluginConfiguration'), $this->configuration->getPlugins())); $h->base_dir = sfConfig::get('sf_test_dir') . '/unit'; // filter and register unit tests $finder = sfFinder::type('file')->follow_link()->name('*Test.php'); $h->register($this->filterTestFiles($finder->in($h->base_dir), $arguments, $options)); $ret = $h->run() ? 0 : 1; if ($options['xml']) { file_put_contents($options['xml'], $h->to_xml()); } return $ret; } }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { $this->logSection('doctrine', 'generating form classes'); $databaseManager = new sfDatabaseManager($this->configuration); $generatorManager = new sfGeneratorManager($this->configuration); $generatorManager->generate($options['generator-class'], array( 'model_dir_name' => $options['model-dir-name'], 'form_dir_name' => $options['form-dir-name'], )); $properties = parse_ini_file(sfConfig::get('sf_config_dir').DIRECTORY_SEPARATOR.'properties.ini', true); $constants = array( 'PROJECT_NAME' => isset($properties['symfony']['name']) ? $properties['symfony']['name'] : 'symfony', 'AUTHOR_NAME' => isset($properties['symfony']['author']) ? $properties['symfony']['author'] : 'Your name here' ); // customize php and yml files $finder = sfFinder::type('file')->name('*.php'); $this->getFilesystem()->replaceTokens($finder->in(sfConfig::get('sf_lib_dir').'/form/'), '##', '##', $constants); // check for base form class if (!class_exists('BaseForm')) { $file = sfConfig::get('sf_lib_dir').'/'.$options['form-dir-name'].'/BaseForm.class.php'; $this->getFilesystem()->copy(sfConfig::get('sf_symfony_lib_dir').'/task/generator/skeleton/project/lib/form/BaseForm.class.php', $file); $this->getFilesystem()->replaceTokens($file, '##', '##', $constants); } $this->reloadAutoload(); }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { require_once dirname(__FILE__) . '/sfLimeHarness.class.php'; $h = new sfLimeHarness(array('force_colors' => isset($options['color']) && $options['color'], 'verbose' => isset($options['trace']) && $options['trace'])); $h->addPlugins(array_map(array($this->configuration, 'getPluginConfiguration'), $this->configuration->getPlugins())); $h->base_dir = sfConfig::get('sf_test_dir'); $status = false; $statusFile = sfConfig::get('sf_cache_dir') . '/.test_all_status'; if ($options['only-failed']) { if (file_exists($statusFile)) { $status = unserialize(file_get_contents($statusFile)); } } if ($status) { foreach ($status as $file) { $h->register($file); } } else { // filter and register all tests $finder = sfFinder::type('file')->follow_link()->name('*Test.php'); $h->register($this->filterTestFiles($finder->in($h->base_dir), $arguments, $options)); } $ret = $h->run() ? 0 : 1; file_put_contents($statusFile, serialize($h->get_failed_files())); if ($options['xml']) { file_put_contents($options['xml'], $h->to_xml()); } return $ret; }
protected function execute($arguments = array(), $options = array()) { // Remove E_STRICT and E_DEPRECATED from error_reporting error_reporting(error_reporting() & ~(E_STRICT | E_DEPRECATED)); if (sfConfig::get('op_http_proxy')) { $config = $this->getPluginManager()->getEnvironment()->getConfig(); $config->set('http_proxy', sfConfig::get('op_http_proxy'), 'user', 'pear.php.net'); } if ($this->isSelfInstalledPlugins($arguments['name'])) { $str = "\"%s\" is already installed manually, so it will not be reinstalled.\n" . "If you want to manage it automatically, delete it manually and retry this command."; $this->logBlock(sprintf($str, $arguments['name']), 'INFO'); return false; } try { $isExists = $this->isPluginExists($arguments['name']); parent::execute($arguments, $options); if (count(sfFinder::type('file')->name('databases.yml')->in(sfConfig::get('sf_config_dir'))) && !$isExists) { $databaseManager = new sfDatabaseManager($this->configuration); Doctrine::getTable('SnsConfig')->set($arguments['name'] . '_needs_data_load', '1'); } } catch (sfPluginException $e) { $this->logBlock($e->getMessage(), 'ERROR'); return false; } }