extranet/batch/removeTempFile.php
2011-08-29 15:56:11 +00:00

122 lines
2.5 KiB
PHP

#!/usr/bin/php
<?php
define('PATH_TEMPFILE', realpath(dirname(__FILE__).'/../cache'));
//Liste des Repertoires
$tempDirs = array(
'avis' => array(
'path' => 'avis',
'files' => array('*.pdf')
),
'bdf' => array(
'path' => 'bdf',
'files' => array('*.pdf')
),
'consommation' => array(
'path' => 'consommation',
'files' => array('*.pdf')
),
'creditsafe' => array(
'path' => 'creditsafe',
'files' => array('*.pdf')
),
'graydon' => array(
'path' => 'graydon',
'files' => array('*.pdf')
),
'infogreffe' => array(
'path' => 'infogreffe',
'files' => array('*.xml', '*.xml.query')
),
'kbis' => array(
'path' => 'kbis',
'files' => array('*.pdf')
),
'liasse' => array(
'path' => 'liasse',
'files' => array('*.xls')
),
'pages' => array(
'path' => 'pages',
'files' => array('*.tpl', '*.xml', '*.csv', '*.pdf')
),
'imgcache' => array(
'path' => 'pages/imgcache',
'files' => array('*.png', '*.gif')
),
'portefeuille' => array(
'path' => 'portefeuille',
'files' => array('*.pdf')
),
'surveillance' => array(
'path' => 'surveillance',
'files' => array('*.pdf')
),
'survliste' => array(
'path' => 'survliste',
'files' => array('*.pdf')
),
);
// Paramètres
if ( $argc<2 || in_array($argv[1], array('--help', '-help', '-h', '-?')) ) {
?>
Supprime les fichiers temporaires
Avec les options --help, -help, -h, et -?, vous obtiendrez cette aide.
Utilisation :
<?php echo $argv[0]; ?> OPTIONS
OPTIONS :
all : Tous les fichiers définit (cron)
Liste des options pour utilisation manuelle :
<?php
foreach($tempDirs as $dir => $options) {
echo $dir."\n";
}
exit;
}
/**
* 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')) {
$exe = 'del';
} else {
$exe = 'rm';
}
$cmd = $exe.' '.$dir.DIRECTORY_SEPARATOR.$filePattern;
return shell_exec($cmd);
}
return false;
}
function removePatternInDir($path, $tabPattern)
{
foreach($tabPattern as $pattern) {
$result = removeFile($path, $pattern);
echo "Suppression fichiers ".$dir." : ";
if ($result === false){
echo "Erreur";
} else {
echo $result;
}
echo "\n";
}
}
foreach($tempDirs as $dir => $options) {
if ($argv[1] == 'all') {
removePatternInDir($options['path'], $options['files']);
} elseif ($argv[1] == $dir) {
removePatternInDir($options['path'], $options['files']);
break;
}
}