121 lines
2.8 KiB
PHP
121 lines
2.8 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(),
|
||
|
)));
|
||
|
|
||
|
/** 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(
|
||
|
'path' => 'cache',
|
||
|
'files' => array('*.tpl', '*.xml')
|
||
|
),
|
||
|
'files' => array(
|
||
|
'path' => 'files',
|
||
|
'files' => array('*.pdf', '*.jpeg', '*.jpg', '*.csv', '*.xls','*.xml')
|
||
|
),
|
||
|
'pages' => array(
|
||
|
'path' => 'pages',
|
||
|
'files' => array('*.html')
|
||
|
),
|
||
|
'imgcache' => array(
|
||
|
'path' => 'pages/imgcache',
|
||
|
'files' => array('*.png', '*.gif')
|
||
|
),
|
||
|
'sessions' => array(
|
||
|
'path' => 'sessions',
|
||
|
'files' => array('sess_*')
|
||
|
),
|
||
|
);
|
||
|
|
||
|
/**
|
||
|
* Suppression des fichiers dans un repertoire
|
||
|
* @param string $path
|
||
|
* @param string $filePattern
|
||
|
*/
|
||
|
function removeFile($path, $filePattern)
|
||
|
{
|
||
|
$dir = PATH_TEMPFILE.DIRECTORY_SEPARATOR.$path;
|
||
|
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;
|
||
|
}
|
||
|
}
|