/** * clears symfony project cache * * @example symfony clear-cache * @example symfony cc * * @param object $task * @param array $args */ function run_clear_cache($task, $args) { ini_set("memory_limit", "2048M"); $cache_dir = sfConfig::get('sf_cache_dir_name'); if (!file_exists($cache_dir)) { throw new Exception('Cache directory "' . $cache_dir . '" doesn\'t exist.'); } // app $main_app = ''; /* if (isset($args[0])) { $main_app = $args[0]; }*/ // type (template, i18n or config) $main_type = ''; /* if (isset($args[1])) { $main_type = $args[1]; }*/ // declare type that must be cleaned safely (with a lock file during cleaning) $safe_types = array(sfConfig::get('sf_app_config_dir_name'), sfConfig::get('sf_app_i18n_dir_name')); // finder to remove all files in a cache directory $finder = pakeFinder::type('file')->ignore_version_control()->discard('.sf'); // finder to find directories (1 level) in a directory $dir_finder = pakeFinder::type('dir')->ignore_version_control()->discard('.sf')->maxdepth(0)->relative(); // iterate through applications $apps = array(); if ($main_app) { $apps[] = $main_app; } else { $apps = $dir_finder->in($cache_dir); } echo "sf_cache_objects = " . sfConfig::get('sf_cache_objects') . "\n"; echo "sf_cache_relations = " . sfConfig::get('sf_cache_relations') . "\n"; echo "sf_cache_trees = " . sfConfig::get('sf_cache_trees') . "\n"; echo "\n\n"; // if param setdo not delete objects from cache! if (isset($args[0])) { // don't delete objcache files $objKey = array_search("objcache", $apps); if (is_int($objKey)) { unset($apps[$objKey]); } // deleting TREE files if ($args[0] == "tree") { echo "Removing TREE CACHE files...\n"; foreach ($finder->in($cache_dir . '/backend') as $env) { if (substr($env, -8) == "Tree.php" || substr($env, -9) == "Tree.html") { echo "Removing: " . $env . "\n"; @unlink($env); } } } // deleting REALTIONS cache if (substr($args[0], 0, 3) == "rel") { // finder to remove all files in a cache directory $finderRel = pakeFinder::type('file')->ignore_version_control()->discard('.sf')->maxdepth(1); // delete RELATIONS files echo "Removing RELATIONS CACHE files...\n"; foreach ($finderRel->in($cache_dir) as $env) { if (substr($env, -13) == "Relations.php") { echo "Removing: " . $env . "\n"; @unlink($env); } } } // deleting LIST cache if (substr($args[0], 0, 4) == "list") { // finder to remove all files in a cache directory $finderList = pakeFinder::type('file')->ignore_version_control()->discard('.sf')->maxdepth(1); // delete RELATIONS files echo "Removing LIST CACHE files...\n"; foreach ($finderList->in($cache_dir . '/listscache') as $env) { echo "Removing: " . $env . "\n"; @unlink($env); } } } foreach ($apps as $app) { if (!is_dir($cache_dir . '/' . $app)) { continue; } // remove cache for all environments foreach ($dir_finder->in($cache_dir . '/' . $app) as $env) { // which types? $types = array(); if ($main_type) { $types[] = $main_type; } else { $types = $dir_finder->in($cache_dir . '/' . $app . '/' . $env); } $sf_root_dir = sfConfig::get('sf_root_dir'); foreach ($types as $type) { $sub_dir = $cache_dir . '/' . $app . '/' . $env . '/' . $type; if (!is_dir($sub_dir)) { continue; } // remove cache files if (in_array($type, $safe_types)) { $lock_name = $app . '_' . $env; _safe_cache_remove($finder, $sub_dir, $lock_name); } else { pake_remove($finder, $sf_root_dir . '/' . $sub_dir); } } } } }
/** * clears symfony project cache * * @example symfony clear-cache * @example symfony cc * * @param object $task * @param array $args */ function run_clear_cache($task, $args) { if (!file_exists('cache')) { throw new Exception('Cache directory does not exist.'); } $cache_dir = sfConfig::get('sf_cache_dir_name'); // app $main_app = ''; if (isset($args[0])) { $main_app = $args[0]; } // type (template, i18n or config) $main_type = ''; if (isset($args[1])) { $main_type = $args[1]; } // declare type that must be cleaned safely (with a lock file during cleaning) $safe_types = array(sfConfig::get('sf_app_config_dir_name'), sfConfig::get('sf_app_i18n_dir_name')); // finder to remove all files in a cache directory $finder = pakeFinder::type('file')->ignore_version_control()->discard('.sf'); // finder to find directories (1 level) in a directory $dir_finder = pakeFinder::type('dir')->ignore_version_control()->discard('.sf')->maxdepth(0)->relative(); // iterate through applications $apps = array(); if ($main_app) { $apps[] = $main_app; } else { $apps = $dir_finder->in($cache_dir); } foreach ($apps as $app) { if (!is_dir($cache_dir . '/' . $app)) { continue; } // remove cache for all environments foreach ($dir_finder->in($cache_dir . '/' . $app) as $env) { // which types? $types = array(); if ($main_type) { $types[] = $main_type; } else { $types = $dir_finder->in($cache_dir . '/' . $app . '/' . $env); } $sf_root_dir = sfConfig::get('sf_root_dir'); foreach ($types as $type) { $sub_dir = $cache_dir . '/' . $app . '/' . $env . '/' . $type; if (!is_dir($sub_dir)) { continue; } // remove cache files if (in_array($type, $safe_types)) { $lock_name = $app . '_' . $env; _safe_cache_remove($finder, $sub_dir, $lock_name); } else { pake_remove($finder, $sf_root_dir . '/' . $sub_dir); } } } } }