2012-11-16 09:34:42 +00:00
|
|
|
<?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(),
|
|
|
|
)));
|
|
|
|
|
|
|
|
/** Zend_Application */
|
|
|
|
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(
|
2012-11-16 15:31:42 +00:00
|
|
|
'path' => $c->profil->path->cache,
|
|
|
|
'files' => array('*.tpl')
|
2012-11-16 09:34:42 +00:00
|
|
|
),
|
|
|
|
'files' => array(
|
2012-11-16 15:31:42 +00:00
|
|
|
'path' => $c->profil->path->files,
|
2012-11-16 09:34:42 +00:00
|
|
|
'files' => array('*.pdf', '*.jpeg', '*.jpg', '*.csv', '*.xls','*.xml')
|
|
|
|
),
|
|
|
|
'pages' => array(
|
2012-11-16 15:31:42 +00:00
|
|
|
'path' => $c->profil->path->pages,
|
2012-11-16 09:34:42 +00:00
|
|
|
'files' => array('*.html')
|
|
|
|
),
|
|
|
|
'imgcache' => array(
|
2012-11-16 15:31:42 +00:00
|
|
|
'path' => $c->profil->path->pages . '/imgcache',
|
|
|
|
'files' => array('*.png', '*.gif', '*.jpeg', '*.jpg')
|
2012-11-16 09:34:42 +00:00
|
|
|
),
|
|
|
|
'sessions' => array(
|
2012-11-16 15:31:42 +00:00
|
|
|
'path' => $c->profil->path->data . '/sessions',
|
2012-11-16 09:34:42 +00:00
|
|
|
'files' => array('sess_*')
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Suppression des fichiers dans un repertoire
|
|
|
|
* @param string $path
|
|
|
|
* @param string $filePattern
|
|
|
|
*/
|
|
|
|
function removeFile($path, $filePattern)
|
|
|
|
{
|
2012-11-16 15:31:42 +00:00
|
|
|
$dir = realpath($path);
|
2012-11-16 09:34:42 +00:00
|
|
|
if (is_dir($dir)) {
|
|
|
|
if (stristr(PHP_OS, 'WIN')) {
|
|
|
|
$cmd = 'del '.$dir.DIRECTORY_SEPARATOR.$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;
|
|
|
|
}
|
|
|
|
}
|