/** * clears xml files in the cache * * @example symfony fb-clear-xml-cache * @example symfony cx * * @param object $task * @param array $args */ function run_fb_clear_xml_cache($task, $args) { if (!file_exists('cache')) { throw new Exception('Cache directory does not exist.'); } $xml_cache_dir = sfConfig::get('sf_root_cache_dir') . "/atti"; // finder to remove all files in a cache directory $finder = pakeFinder::type('file')->ignore_version_control()->discard('.sf'); foreach ($args as $id) { $finder = $finder->name($id . ".xml"); } // actually do remove the files under xml_cache_dir pake_remove($finder, $xml_cache_dir); }
function run_unfreeze($task, $args) { // remove lib/symfony and data/symfony directories if (!is_dir('lib/symfony')) { throw new Exception('You can unfreeze only if you froze the symfony libraries before.'); } $dirs = explode('#', file_get_contents('config/config.php.bak')); _change_symfony_dirs('\'' . $dirs[0] . '\'', '\'' . $dirs[1] . '\''); $finder = pakeFinder::type('any')->ignore_version_control(); pake_remove($finder, sfConfig::get('sf_lib_dir') . '/symfony'); pake_remove(sfConfig::get('sf_lib_dir') . '/symfony', ''); pake_remove($finder, sfConfig::get('sf_data_dir') . '/symfony'); pake_remove(sfConfig::get('sf_data_dir') . '/symfony', ''); pake_remove('symfony.php', ''); pake_remove($finder, sfConfig::get('sf_web_dir') . '/sf'); pake_remove(sfConfig::get('sf_web_dir') . '/sf', ''); }
function run_propel_generate_crud($task, $args) { if (count($args) < 2) { throw new Exception('You must provide your module name.'); } if (count($args) < 3) { throw new Exception('You must provide your model class name.'); } $theme = isset($args[3]) ? $args[3] : 'default'; $app = $args[0]; $module = $args[1]; $model_class = $args[2]; $sf_root_dir = sfConfig::get('sf_root_dir'); // generate module $tmp_dir = $sf_root_dir . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . md5(uniqid(rand(), true)); sfConfig::set('sf_module_cache_dir', $tmp_dir); $generator_manager = new sfGeneratorManager(); $generator_manager->initialize(); $generator_manager->generate('sfPropelCrudGenerator', array('model_class' => $model_class, 'moduleName' => $module, 'theme' => $theme)); $moduleDir = $sf_root_dir . '/' . sfConfig::get('sf_apps_dir_name') . '/' . $app . '/' . sfConfig::get('sf_app_module_dir_name') . '/' . $module; // copy our generated module $finder = pakeFinder::type('any'); pake_mirror($finder, $tmp_dir . '/auto' . ucfirst($module), $moduleDir); // change module name pake_replace_tokens($moduleDir . '/actions/actions.class.php', getcwd(), '', '', array('auto' . ucfirst($module) => $module)); try { $author_name = $task->get_property('author', 'symfony'); } catch (pakeException $e) { $author_name = 'Your name here'; } $constants = array('PROJECT_NAME' => $task->get_property('name', 'symfony'), 'APP_NAME' => $app, 'MODULE_NAME' => $module, 'MODEL_CLASS' => $model_class, 'AUTHOR_NAME' => $author_name); // customize php and yml files $finder = pakeFinder::type('file')->name('*.php', '*.yml'); pake_replace_tokens($finder, $moduleDir, '##', '##', $constants); // create basic test pake_copy(sfConfig::get('sf_symfony_data_dir') . '/skeleton/module/test/actionsTest.php', $sf_root_dir . '/test/functional/' . $app . '/' . $module . 'ActionsTest.php'); // customize test file pake_replace_tokens($module . 'ActionsTest.php', $sf_root_dir . '/test/functional/' . $app, '##', '##', $constants); // delete temp files $finder = pakeFinder::type('any'); pake_remove($finder, $tmp_dir); }
function killWorker($id) { $pid = (int) trim(file_get_contents(RUNTIME_PATH . getWorkerPidFile($id))); @exec("kill -9 {$pid}"); $rule = pakeFinder::type('file')->name(getWorkerPidFile($id)); pake_remove($rule, RUNTIME_PATH); }
function _uninstall_web_content($plugin_name) { $web_dir = sfConfig::get('sf_plugins_dir') . DIRECTORY_SEPARATOR . $plugin_name . DIRECTORY_SEPARATOR . 'web'; $target_dir = sfConfig::get('sf_web_dir') . DIRECTORY_SEPARATOR . $plugin_name; if (is_dir($web_dir) && is_dir($target_dir)) { pake_echo_action('plugin', 'uninstalling web data for plugin'); if (is_link($target_dir)) { pake_remove($target_dir, ''); } else { pake_remove(pakeFinder::type('any'), $target_dir); pake_remove($target_dir, ''); } } }
function run_clean_dist() { pake_remove_dir(Builder::distDir()); $finder = pakeFinder::type('file')->name(Builder::distFiles()); pake_remove($finder, Builder::buildDir()); }
// unit tests $h->register_glob($h->base_dir . '/unit/*/*Test.php'); // functional tests $h->register_glob($h->base_dir . '/functional/*Test.php'); $h->register_glob($h->base_dir . '/functional/*/*Test.php'); $ret = $h->run(); if (!$ret) { throw new Exception('Some tests failed. Release process aborted!'); } if (is_file('package.xml')) { pake_remove('package.xml', getcwd()); } pake_copy(getcwd() . '/package.xml.tmpl', getcwd() . '/package.xml'); // add class files $finder = pakeFinder::type('file')->ignore_version_control()->relative(); $xml_classes = ''; $dirs = array('lib' => 'php', 'data' => 'data'); foreach ($dirs as $dir => $role) { $class_files = $finder->in($dir); foreach ($class_files as $file) { $xml_classes .= '<file role="' . $role . '" baseinstalldir="symfony" install-as="' . $file . '" name="' . $dir . '/' . $file . '" />' . "\n"; } } // replace tokens pake_replace_tokens('package.xml', getcwd(), '##', '##', array('SYMFONY_VERSION' => $version, 'CURRENT_DATE' => date('Y-m-d'), 'CLASS_FILES' => $xml_classes, 'STABILITY' => $stability)); $results = pake_sh('pear package'); echo $results; pake_remove('package.xml', getcwd()); // copy .tgz as symfony-latest.tgz pake_copy(getcwd() . '/symfony-' . $version . '.tgz', getcwd() . '/symfony-latest.tgz'); exit(0);
function run_create_pear_package() { run_create_package_xml(); $_root = dirname(__FILE__); $options = pakeYaml::loadFile($_root . '/options.yaml'); $version = $options['version']; pake_replace_tokens('lib/pake/pakeApp.class.php', $_root, 'const VERSION = \'', '\';', array('1.1.DEV' => "const VERSION = '{$version}';")); // run packager try { pakePearTask::package_pear_package($_root . '/package.xml', $_root . '/target'); } catch (pakeException $e) { } // cleanup pake_remove('package.xml', $_root); pake_replace_tokens('lib/pake/pakeApp.class.php', $_root, "const VERSION = '", "';", array($version => "const VERSION = '1.1.DEV';")); if (isset($e)) { throw $e; } }
function _propel_copy_xml_schema_from_plugins($prefix = '') { $schemas = pakeFinder::type('file')->name('*schema.xml')->in(glob(sfConfig::get('sf_root_dir') . '/plugins/*/config')); foreach ($schemas as $schema) { // reset local prefix $localprefix = ''; // change prefix for plugins if (preg_match('#plugins[/\\\\]([^/\\\\]+)[/\\\\]#', $schema, $match)) { // if the plugin name is not in the schema filename, add it if (!strstr(basename($schema), $match[1])) { $localprefix = $match[1] . '-'; } } // if the prefix is not in the schema filename, add it if (!strstr(basename($schema), $prefix)) { $localprefix = $prefix . $localprefix; } pake_copy($schema, 'config' . DIRECTORY_SEPARATOR . $localprefix . basename($schema)); if ('' === $localprefix) { pake_remove($schema, ''); } } }
function run_propel_build_schema($task, $args) { _call_phing($task, 'creole', false); // fix database name if (file_exists('config/schema.xml')) { $schema = file_get_contents('config/schema.xml'); $schema = preg_replace('/<database\\s+name="[^"]+"/s', '<database name="propel"', $schema); file_put_contents('config/schema.xml', $schema); } if (!isset($args[0]) || $args[0] != 'xml') { _propel_convert_xml_schema(false, ''); $finder = pakeFinder::type('file')->name('schema.xml'); pake_remove($finder, 'config'); } }
function pake_remove_dir($path) { // remove contents $finder = pakeFinder::type('any'); pake_remove($finder, $path); // remove folder $finder = pakeFinder::type('dir')->name(basename($path))->maxdepth(0); pake_remove($finder, dirname($path)); }
/** * Removes directory and all it's contents * * @param $path string */ function pake_remove_dir($path) { if (!file_exists($path)) { // nothing to do return; } if (!is_dir($path)) { throw new pakeException('"' . $path . '" is not a directory'); } // remove contents $finder = pakeFinder::type('any'); pake_remove($finder, $path); // remove folder pake_unlink($path); }
function run_upgrade_1_0($task, $args) { // check we have a project if (!file_exists('symfony') && !file_exists('SYMFONY')) { throw new Exception('You must be in a symfony project directory'); } // upgrade propel.ini _upgrade_1_0_propel_ini(); // upgrade i18n support _upgrade_1_0_i18n(); // upgrade model classes _upgrade_1_0_propel_model(); // migrate activate to enabled _upgrade_1_0_activate(); // find all applications for this project $apps = pakeFinder::type('directory')->name(sfConfig::get('sf_app_module_dir_name'))->mindepth(1)->maxdepth(1)->relative()->in(sfConfig::get('sf_apps_dir_name')); // install symfony CLI if (file_exists(sfConfig::get('sf_root_dir') . '/SYMFONY')) { pake_remove(sfConfig::get('sf_root_dir') . '/SYMFONY', ''); } pake_copy(sfConfig::get('sf_symfony_data_dir') . '/skeleton/project/symfony', sfConfig::get('sf_root_dir') . '/symfony'); pake_chmod('symfony', sfConfig::get('sf_root_dir'), 0777); // update schemas _upgrade_1_0_schemas(); // add bootstrap files for tests _add_1_0_test_bootstraps(); // upgrade main config.php _upgrade_1_0_main_config_php(); // upgrade all applications foreach ($apps as $app_module_dir) { $app = str_replace(DIRECTORY_SEPARATOR . sfConfig::get('sf_app_module_dir_name'), '', $app_module_dir); pake_echo_action('upgrade 1.0', pakeColor::colorize(sprintf('upgrading application "%s"', $app), array('fg' => 'cyan'))); $app_dir = sfConfig::get('sf_apps_dir_name') . '/' . $app; // upgrade config.php _upgrade_1_0_config_php($app_dir); // upgrade filters.yml _upgrade_1_0_filters_yml($app_dir); // upgrade all modules $dir = $app_dir . '/' . sfConfig::get('sf_app_module_dir_name'); if ($dir) { // template dirs $template_dirs = pakeFinder::type('directory')->name('templates')->mindepth(1)->maxdepth(1)->in($dir); $template_dirs[] = $app_dir . '/' . sfConfig::get('sf_app_template_dir_name'); _upgrade_1_0_deprecated_for_templates($template_dirs); _upgrade_1_0_date_form_helpers($template_dirs); _upgrade_1_0_deprecated_for_generator($app_dir); _upgrade_1_0_cache_yml($app_dir); // actions dirs $action_dirs = pakeFinder::type('directory')->name('actions')->mindepth(1)->maxdepth(1)->in($dir); _upgrade_1_0_deprecated_for_actions($action_dirs); // view.yml _upgrade_1_0_view_yml($app_dir); _upgrade_1_0_php_files($app_dir); } } pake_echo_action('upgrade 1.0', 'done'); pake_mkdirs(sfConfig::get('sf_root_dir') . '/plugins'); if (is_dir(sfConfig::get('sf_lib_dir') . '/plugins')) { pake_echo_comment('WARNING: you must re-install all your plugins'); } pake_echo_comment('Now, you must:'); pake_echo_comment(' - rebuild your model classes: symfony propel-build-model'); pake_echo_comment(' - clear the cache: symfony cc'); }
public static function createPharArchive($arg, $origin_dir, $archive_file, $stub = null, $web_stub = null, $overwrite = false) { if (!extension_loaded('phar')) { throw new pakeException(__CLASS__ . ' module requires "phar" extension'); } if (false === $overwrite and file_exists($archive_file)) { return true; } if (!self::endsWith($archive_file, '.phar')) { throw new pakeException("Archive must have .phar extension"); } $files = pakeFinder::get_files_from_argument($arg, $origin_dir, true); pake_echo_action('file+', $archive_file); try { $arc = new Phar($archive_file); foreach ($files as $file) { $full_path = $origin_dir . '/' . $file; pake_echo_action('phar', '-> ' . $file); if (is_dir($full_path)) { $arc->addEmptyDir($file); } else { $arc->addFile($full_path, $file); } } if (null !== $stub) { pake_echo_action('phar', '[stub] ' . $stub . (null === $web_stub ? '' : ', ' . $web_stub)); $arc->setStub($arc->createDefaultStub($stub, $web_stub)); } } catch (PharException $e) { unset($arc); pake_remove($archive_file); throw $e; } }
function run_enable($task, $args) { ini_set("memory_limit", "2048M"); // handling two required arguments (application and environment) if (count($args) < 2) { throw new Exception('You must provide an environment for the application.'); } $app = $args[0]; $env = $args[1]; $lockFile = $app . '_' . $env . '.clilock'; $locks = pakeFinder::type('file')->prune('.svn')->discard('.svn')->maxdepth(0)->name($lockFile)->relative()->in('./'); if (file_exists(sfConfig::get('sf_root_dir') . '/' . $lockFile)) { pake_remove($lockFile, ''); run_clear_cache($task, array()); pake_echo_action('enable', "{$app} [{$env}] has been ENABLED"); return; } pake_echo_action('enable', "{$app} [{$env}] is currently ENABLED"); }
/** * Generates the documentation of the extension, if created in RST format in the doc/ folder, plus optionally * API docs via doxygen; options: --doxygen=/path/to/doxygen * * Builds an html file of all doc/*.rst files, and removes the source, then, if * configured in the options file, uses doxygen to create html documentation of * php source code in doc/api. The location of the doxygen binary can be specified * via a configuration option * * @todo allow config file to specify doc dir * @todo use local doxygen file if found, instead of std one * @todo create api doc from php files using phpdoc too * example cli cmd: ${phpdocinstall}phpdoc -t ${phpdocdir}/html -ti 'eZ Publish' -pp -s -d lib/ezdb/classes,lib/ezdbschema/classes,lib/ezdiff/classes,lib/ezfile/classes,lib/ezi18n/classes,lib/ezimage/classes,lib/ezlocale/classes,lib/ezmath/classes,lib/ezpdf/classes,lib/ezsession/classes,lib/ezsoap/classes,lib/eztemplate/classes,lib/ezutils/classes,lib/ezxml/classes,kernel/classes,kernel/private/classes,kernel/common,cronjobs,update/common/scripts > ${phpdocdir}/generate.log */ static function run_generate_documentation($task = null, $args = array(), $cliopts = array()) { $opts = self::getOpts(@$args[0], @$args[1], $cliopts); if (!SharedLock::acquire($opts['extension']['name'], LOCK_EX, $opts)) { throw new PakeException("Source code locked by another process"); } $destdir = self::getBuildDir($opts) . '/' . $opts['extension']['name']; $docdir = $destdir . '/doc'; $files = pakeFinder::type('file')->name('*.rst')->in($docdir); foreach ($files as $i => $file) { $dst = substr($file, 0, -3) . 'html'; $document = new ezcDocumentRst(); $document->loadFile($file); $docbook = $document->getAsXhtml(); file_put_contents($dst, $docbook->save()); pake_echo_action('file+', $dst); pake_remove($file, ''); } /* * A few extension have Makefiles to generate documentation * We remove them as well as the original .rst files * NB: this is not done anymore since version 0.1. Use files.to_exclude option instead */ //pake_remove( pakeFinder::type( 'file' )->name( 'Makefile' )->in( $destdir ), '' ); // doxygen if ($opts['create']['doxygen_doc']) { pake_mkdirs($docdir . '/api'); $doxygen = self::getTool('doxygen', $opts); $doxyfile = $destdir . '/doxyfile'; pake_copy(self::getResourceDir() . '/doxyfile_master', $doxyfile, array('override' => true)); file_put_contents($doxyfile, "\nPROJECT_NAME = " . $opts['extension']['name'] . "\nPROJECT_NUMBER = " . $opts['version']['alias'] . $opts['releasenr']['separator'] . $opts['version']['release'] . "\nOUTPUT_DIRECTORY = " . $docdir . '/api' . "\nINPUT = " . $destdir . "\nEXCLUDE = " . $destdir . '/settings' . "\nSTRIP_FROM_PATH = " . $destdir, FILE_APPEND); $out = pake_sh($doxygen . ' ' . escapeshellarg($doxyfile)); pake_remove($doxyfile, ''); // cleanup leftover files, just in case dot tool is not found $files = pakeFinder::type('file')->name(array('*.dot', '*.md5', '*.map', 'installdox'))->in($docdir . '/api'); pake_remove($files, ''); } SharedLock::release($opts['extension']['name'], LOCK_EX, $opts); }
public static function run__clean_config() { $dir = dirname(pakeApp::get_instance()->getPakefilePath()); $cfg_file = $dir . '/' . __CLASS__ . '.yaml'; if (file_exists($cfg_file)) { pake_remove($cfg_file, ''); } }
function run_doctrine_generate_crud($task, $args) { if (count($args) < 2) { throw new Exception('You must provide your module name.'); } if (count($args) < 3) { throw new Exception('You must provide your model class name.'); } $app = $args[0]; $module = $args[1]; $model_class = $args[2]; $theme = isset($args[3]) ? $args[3] : 'crud'; // function variables $doctrineModelDir = sfConfig::get('sf_lib_dir') . DIRECTORY_SEPARATOR . 'model' . DIRECTORY_SEPARATOR . 'doctrine' . DIRECTORY_SEPARATOR; $sf_root_dir = sfConfig::get('sf_root_dir'); $sf_symfony_lib_dir = sfConfig::get('sf_symfony_lib_dir'); $pluginDir = realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..'); $doctrineLibDir = $pluginDir . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'doctrine' . DIRECTORY_SEPARATOR . 'Doctrine' . DIRECTORY_SEPARATOR; $tmp_dir = $sf_root_dir . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . md5(uniqid(rand(), true)); sfConfig::set('sf_module_cache_dir', $tmp_dir); sfConfig::set('sf_app_dir', $tmp_dir); // add classes to autoload function pake_echo_action('PluginDir', $pluginDir); simpleAutoloader::registerCallable(array('Doctrine', 'autoload')); // generate module $generator_manager = new sfGeneratorManager(); $generator_manager->initialize(); $generator_manager->generate('sfDoctrineAdminGenerator', array('model_class' => $model_class, 'moduleName' => $module, 'theme' => $theme)); $moduleDir = $sf_root_dir . '/' . sfConfig::get('sf_apps_dir_name') . '/' . $app . '/' . sfConfig::get('sf_app_module_dir_name') . '/' . $module; // copy our generated module $finder = pakeFinder::type('any'); pake_mirror($finder, $tmp_dir . '/auto' . ucfirst($module), $moduleDir); // change module name pake_replace_tokens($moduleDir . '/actions/actions.class.php', getcwd(), '', '', array('auto' . ucfirst($module) => $module)); try { $author_name = $task->get_property('author', 'symfony'); } catch (pakeException $e) { $author_name = 'Your name here'; } $constants = array('PROJECT_NAME' => $task->get_property('name', 'symfony'), 'APP_NAME' => $app, 'MODULE_NAME' => $module, 'MODEL_CLASS' => $model_class, 'AUTHOR_NAME' => $author_name); // customize php files $finder = pakeFinder::type('file')->name('*.php'); pake_replace_tokens($finder, $moduleDir, '##', '##', $constants); // delete temp files $finder = pakeFinder::type('any'); pake_remove($finder, $tmp_dir); // for some reason the above does not remove the tmp dir as it should. // delete temp dir @rmdir($tmp_dir); // delete cache/tmp @rmdir(sfConfig::get('sf_cache_dir') . 'tmp'); }