| [ Index ] |
|
Code source de Symfony 1.0.0 |
1 <?php 2 3 /* 4 * This file is part of the symfony package. 5 * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com> 6 * 7 * For the full copyright and license information, please view the LICENSE 8 * file that was distributed with this source code. 9 */ 10 11 pake_desc('clear cached information'); 12 pake_task('clear-cache', 'project_exists'); 13 pake_alias('cc', 'clear-cache'); 14 15 pake_desc('clear controllers'); 16 pake_task('clear-controllers', 'project_exists'); 17 18 pake_desc('fix directories permissions'); 19 pake_task('fix-perms', 'project_exists'); 20 21 pake_desc('rotates an applications log files'); 22 pake_task('log-rotate', 'app_exists'); 23 24 pake_desc('purges an applications log files'); 25 pake_task('log-purge', 'project_exists'); 26 27 pake_desc('enables an application in a given environment'); 28 pake_task('enable', 'app_exists'); 29 30 pake_desc('disables an application in a given environment'); 31 pake_task('disable', 'app_exists'); 32 33 /** 34 * fixes permissions in a symfony project 35 * 36 * @example symfony fix-perms 37 * 38 * @param object $task 39 * @param array $args 40 */ 41 function run_fix_perms($task, $args) 42 { 43 $sf_root_dir = sfConfig::get('sf_root_dir'); 44 45 pake_chmod(sfConfig::get('sf_cache_dir_name'), $sf_root_dir, 0777); 46 pake_chmod(sfConfig::get('sf_log_dir_name'), $sf_root_dir, 0777); 47 pake_chmod(sfConfig::get('sf_web_dir_name').DIRECTORY_SEPARATOR.sfConfig::get('sf_upload_dir_name'), $sf_root_dir, 0777); 48 pake_chmod('symfony', $sf_root_dir, 0777); 49 50 $dirs = array(sfConfig::get('sf_cache_dir_name'), sfConfig::get('sf_web_dir_name').DIRECTORY_SEPARATOR.sfConfig::get('sf_upload_dir_name'), sfConfig::get('sf_log_dir_name')); 51 $dir_finder = pakeFinder::type('dir')->ignore_version_control(); 52 $file_finder = pakeFinder::type('file')->ignore_version_control(); 53 foreach ($dirs as $dir) 54 { 55 pake_chmod($dir_finder, $dir, 0777); 56 pake_chmod($file_finder, $dir, 0666); 57 } 58 } 59 60 /** 61 * clears symfony project cache 62 * 63 * @example symfony clear-cache 64 * @example symfony cc 65 * 66 * @param object $task 67 * @param array $args 68 */ 69 function run_clear_cache($task, $args) 70 { 71 if (!file_exists('cache')) 72 { 73 throw new Exception('Cache directory does not exist.'); 74 } 75 76 $cache_dir = sfConfig::get('sf_cache_dir_name'); 77 78 // app 79 $main_app = ''; 80 if (isset($args[0])) 81 { 82 $main_app = $args[0]; 83 } 84 85 // type (template, i18n or config) 86 $main_type = ''; 87 if (isset($args[1])) 88 { 89 $main_type = $args[1]; 90 } 91 92 // declare type that must be cleaned safely (with a lock file during cleaning) 93 $safe_types = array(sfConfig::get('sf_app_config_dir_name'), sfConfig::get('sf_app_i18n_dir_name')); 94 95 // finder to remove all files in a cache directory 96 $finder = pakeFinder::type('file')->ignore_version_control()->discard('.sf'); 97 98 // finder to find directories (1 level) in a directory 99 $dir_finder = pakeFinder::type('dir')->ignore_version_control()->discard('.sf')->maxdepth(0)->relative(); 100 101 // iterate through applications 102 $apps = array(); 103 if ($main_app) 104 { 105 $apps[] = $main_app; 106 } 107 else 108 { 109 $apps = $dir_finder->in($cache_dir); 110 } 111 112 foreach ($apps as $app) 113 { 114 if (!is_dir($cache_dir.'/'.$app)) 115 { 116 continue; 117 } 118 119 // remove cache for all environments 120 foreach ($dir_finder->in($cache_dir.'/'.$app) as $env) 121 { 122 // which types? 123 $types = array(); 124 if ($main_type) 125 { 126 $types[] = $main_type; 127 } 128 else 129 { 130 $types = $dir_finder->in($cache_dir.'/'.$app.'/'.$env); 131 } 132 133 $sf_root_dir = sfConfig::get('sf_root_dir'); 134 foreach ($types as $type) 135 { 136 $sub_dir = $cache_dir.'/'.$app.'/'.$env.'/'.$type; 137 138 if (!is_dir($sub_dir)) 139 { 140 continue; 141 } 142 143 // remove cache files 144 if (in_array($type, $safe_types)) 145 { 146 $lock_name = $app.'_'.$env; 147 _safe_cache_remove($finder, $sub_dir, $lock_name); 148 } 149 else 150 { 151 pake_remove($finder, $sf_root_dir.'/'.$sub_dir); 152 } 153 } 154 } 155 } 156 } 157 158 /** 159 * clears all controllers in your web directory other than one running in a produciton environment 160 * 161 * @example symfony clear-controllers 162 * 163 * @param object $task 164 * @param array $args 165 */ 166 function run_clear_controllers($task, $args) 167 { 168 $web_dir = sfConfig::get('sf_web_dir'); 169 $app_dir = sfConfig::get('sf_app_dir'); 170 171 $apps = count($args) > 1 ? $args : null; 172 173 // get controller 174 $controllers = pakeFinder::type('file')->ignore_version_control()->maxdepth(1)->name('*.php')->in($web_dir); 175 176 foreach ($controllers as $controller) 177 { 178 $contents = file_get_contents($controller); 179 preg_match('/\'SF_APP\',[\s]*\'(.*)\'\)/', $contents, $found_app); 180 preg_match('/\'SF_ENVIRONMENT\',[\s]*\'(.*)\'\)/', $contents, $env); 181 182 // remove file if it has found an application and the environment is not production 183 if (isset($found_app[1]) && isset($env[1]) && $env[1] != 'prod') 184 { 185 pake_remove($controller, ''); 186 } 187 } 188 } 189 190 /** 191 * safely removes directory via pake 192 * 193 * @param object $finder 194 * @param string $sub_dir 195 * @param string $lock_name 196 */ 197 function _safe_cache_remove($finder, $sub_dir, $lock_name) 198 { 199 $sf_root_dir = sfConfig::get('sf_root_dir'); 200 201 // create a lock file 202 pake_touch($sf_root_dir.'/'.$lock_name.'.lck', ''); 203 204 // change mode so the web user can remove it if we die 205 pake_chmod($lock_name.'.lck', $sf_root_dir, 0777); 206 207 // remove cache files 208 pake_remove($finder, $sf_root_dir.'/'.$sub_dir); 209 210 // release lock 211 pake_remove($sf_root_dir.'/'.$lock_name.'.lck', ''); 212 } 213 214 /** 215 * forces rotation of the given log file 216 * 217 * @example symfony log-rotate 218 * 219 * @param object $task 220 * @param array $args 221 */ 222 function run_log_rotate($task, $args) 223 { 224 // handling two required arguments (application and environment) 225 if (count($args) < 2) 226 { 227 throw new Exception('You must provide the environment of the log to rotate'); 228 } 229 $app = $args[0]; 230 $env = $args[1]; 231 232 // define constants 233 define('SF_ROOT_DIR', sfConfig::get('sf_root_dir')); 234 define('SF_APP', $app); 235 define('SF_ENVIRONMENT', $env); 236 define('SF_DEBUG', true); 237 238 // get configuration 239 require_once SF_ROOT_DIR.DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.SF_APP.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php'; 240 241 sfLogManager::rotate($app, $env, sfConfig::get('sf_logging_period'), sfConfig::get('sf_logging_history'), true); 242 } 243 244 /** 245 * purges the application log directory as per settings in logging.yml 246 * 247 * @example symfony log-purge 248 * 249 * @param object $task 250 * @param array $args 251 */ 252 function run_log_purge($task, $args) 253 { 254 $sf_symfony_data_dir = sfConfig::get('sf_symfony_data_dir'); 255 256 $default_logging = sfYaml::load($sf_symfony_data_dir.'/config/logging.yml'); 257 $app_dir = sfConfig::get('sf_app_dir'); 258 $apps = pakeFinder::type('dir')->maxdepth(0)->relative()->ignore_version_control()->in('apps'); 259 $ignore = array('all', 'default'); 260 261 foreach ($apps as $app) 262 { 263 $logging = sfYaml::load($app_dir.'/'.$app.'/config/logging.yml'); 264 $logging = array_merge($default_logging, $logging); 265 266 foreach ($logging as $env => $config) 267 { 268 if (in_array($env, $ignore)) 269 { 270 continue; 271 } 272 $props = array_merge($default_logging['default'], is_array($config) ? $config : array()); 273 $active = isset($props['active']) ? $props['active'] : true; 274 $purge = isset($props['purge']) ? $props['purge'] : true; 275 if ($active && $purge) 276 { 277 $filename = sfConfig::get('sf_log_dir').'/'.$app.'_'.$env.'.log'; 278 if (file_exists($filename)) 279 { 280 pake_remove($filename, ''); 281 } 282 } 283 } 284 } 285 } 286 287 function run_enable($task, $args) 288 { 289 // handling two required arguments (application and environment) 290 if (count($args) < 2) 291 { 292 throw new Exception('You must provide an environment for the application.'); 293 } 294 295 $app = $args[0]; 296 $env = $args[1]; 297 298 $lockFile = $app.'_'.$env.'.clilock'; 299 $locks = pakeFinder::type('file')->prune('.svn')->discard('.svn')->maxdepth(0)->name($lockFile)->relative()->in('./'); 300 301 if (file_exists(sfConfig::get('sf_root_dir').'/'.$lockFile)) 302 { 303 pake_remove($lockFile, ''); 304 run_clear_cache($task, array()); 305 pake_echo_action('enable', "$app [$env] has been ENABLED"); 306 307 return; 308 } 309 310 pake_echo_action('enable', "$app [$env] is currently ENABLED"); 311 } 312 313 function run_disable($task, $args) 314 { 315 // handling two required arguments (application and environment) 316 if (count($args) < 2) 317 { 318 throw new Exception('You must provide an environment for the application.'); 319 } 320 321 $app = $args[0]; 322 $env = $args[1]; 323 324 $lockFile = $app.'_'.$env.'.clilock'; 325 326 if (!file_exists(sfConfig::get('sf_root_dir').'/'.$lockFile)) 327 { 328 pake_touch(sfConfig::get('sf_root_dir').'/'.$lockFile, '777'); 329 330 pake_echo_action('enable', "$app [$env] has been DISABLED"); 331 332 return; 333 } 334 335 pake_echo_action('enable', "$app [$env] is currently DISABLED"); 336 337 return; 338 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Fri Mar 16 22:42:14 2007 | par Balluche grâce à PHPXref 0.7 |