139 lines
3.6 KiB
PHP
139 lines
3.6 KiB
PHP
<?php
|
|
// Define path to application directory
|
|
defined('APPLICATION_PATH')
|
|
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../../application'));
|
|
|
|
// Define application environment
|
|
defined('APPLICATION_ENV')
|
|
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
|
|
|
|
// Ensure library/ is on include_path
|
|
set_include_path(implode(PATH_SEPARATOR, array(
|
|
realpath(APPLICATION_PATH . '/../library'),
|
|
get_include_path(),
|
|
)));
|
|
|
|
//Use classmap autoloader - useful with opcode and realpath cache
|
|
require_once 'Zend/Loader/AutoloaderFactory.php';
|
|
require_once 'Zend/Loader/ClassMapAutoloader.php';
|
|
Zend_Loader_AutoloaderFactory::factory(array(
|
|
'Zend_Loader_ClassMapAutoloader' => array(
|
|
__DIR__ . '/../../library/autoload_classmap.php',
|
|
),
|
|
'Zend_Loader_StandardAutoloader' => array(
|
|
'prefixes' => array(
|
|
'Zend' => __DIR__ . '/../../library/Zend',
|
|
'Application' => __DIR__ . '/../../library/Application',
|
|
'Scores' => __DIR__ . '/../../library/Scores',
|
|
'Metier' => __DIR__ . '/../../library/Metier',
|
|
),
|
|
'fallback_autoloader' => true
|
|
)
|
|
));
|
|
|
|
// Zend_Application - Use it if you don't have autoloaders
|
|
//require_once 'Zend/Application.php';
|
|
|
|
// Create application, bootstrap, and run
|
|
$application = new Zend_Application(
|
|
APPLICATION_ENV,
|
|
APPLICATION_PATH . '/configs/application.ini'
|
|
);
|
|
|
|
try {
|
|
$opts = new Zend_Console_Getopt(
|
|
//Options
|
|
array(
|
|
'help|?' => "Display help.",
|
|
'options|o' => " all: All files, [directory_name]: Files in this directory",
|
|
)
|
|
);
|
|
$opts->parse();
|
|
} catch (Zend_Console_Getopt_Exception $e) {
|
|
echo $e->getUsageMessage();
|
|
exit;
|
|
}
|
|
|
|
//Usage
|
|
if(count($opts->getOptions())==0 || isset($opts->help))
|
|
{
|
|
echo "Delete temporary files";
|
|
echo "\n\n";
|
|
echo $opts->getUsageMessage();
|
|
echo "\n";
|
|
exit;
|
|
}
|
|
|
|
$c = new Zend_Config($application->getOptions());
|
|
|
|
define('PATH_TEMPFILE', realpath(dirname(__FILE__).'/../cache'));
|
|
|
|
//Liste des Repertoires
|
|
$tempDirs = array(
|
|
'cache' => array(
|
|
'path' => $c->profil->path->cache,
|
|
'files' => array('*.tpl')
|
|
),
|
|
'files' => array(
|
|
'path' => $c->profil->path->files,
|
|
'files' => array('*.pdf', '*.jpeg', '*.jpg', '*.csv', '*.csv.bz2', '*.xls','*.xml')
|
|
),
|
|
'pages' => array(
|
|
'path' => $c->profil->path->pages,
|
|
'files' => array('*.html')
|
|
),
|
|
'imgcache' => array(
|
|
'path' => $c->profil->path->pages . '/imgcache',
|
|
'files' => array('*.png', '*.gif', '*.jpeg', '*.jpg')
|
|
),
|
|
'sessions' => array(
|
|
'path' => $c->profil->path->data . '/sessions',
|
|
'files' => array('sess_*')
|
|
),
|
|
);
|
|
|
|
/**
|
|
* Suppression des fichiers dans un repertoire
|
|
* @param string $path
|
|
* @param string $filePattern
|
|
*/
|
|
function removeFile($path, $filePattern)
|
|
{
|
|
$dir = realpath($path);
|
|
if (is_dir($dir)) {
|
|
if (stristr(PHP_OS, 'WIN')) {
|
|
$cmd = 'del '.$dir.'/'.$filePattern;
|
|
} else {
|
|
/**
|
|
* To avoid too args error from rm command
|
|
*/
|
|
$cmd = 'find '.$dir.'/ -name "'.$filePattern.'" -exec rm {} \;';
|
|
}
|
|
return shell_exec($cmd);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
function removePatternInDir($path, $tabPattern)
|
|
{
|
|
foreach($tabPattern as $pattern) {
|
|
echo "Suppression fichiers ".$path." : ";
|
|
$result = removeFile($path, $pattern);
|
|
if ($result === false){
|
|
echo "Erreur";
|
|
} else {
|
|
echo $result;
|
|
}
|
|
echo "\n";
|
|
}
|
|
}
|
|
|
|
foreach($tempDirs as $dir => $options) {
|
|
if ($opts->options == 'all') {
|
|
removePatternInDir($options['path'], $options['files']);
|
|
} elseif ($opts->options == $dir) {
|
|
removePatternInDir($options['path'], $options['files']);
|
|
break;
|
|
}
|
|
}
|