Ajout decompression du fichier et archivage
This commit is contained in:
parent
cdd699a9e3
commit
dc85785668
@ -24,6 +24,25 @@
|
||||
*/
|
||||
require ("../../master.inc.php");
|
||||
|
||||
$nbdays = 1;
|
||||
|
||||
for ($i = 1 ; $i < sizeof($argv) ; $i++)
|
||||
{
|
||||
if ($argv[$i] == "-n")
|
||||
{
|
||||
$nbdays = $argv[$i+1];
|
||||
}
|
||||
if ($argv[$i] == "-v")
|
||||
{
|
||||
$verbose = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (! is_numeric($nbdays))
|
||||
{
|
||||
die("Bad argument $nbdays\n");
|
||||
}
|
||||
|
||||
$ftp_server = GETCDR_FTP_SERVER;
|
||||
$ftp_user_name = GETCDR_FTP_USER;
|
||||
$ftp_user_pass = GETCDR_FTP_PASS;
|
||||
@ -50,17 +69,23 @@ if (!$login_result)
|
||||
exit;
|
||||
}
|
||||
|
||||
$date = time() - (24 * 3600);
|
||||
if (!file_exists(DOL_DATA_ROOT.'/telephonie/CDR/temp/'))
|
||||
{
|
||||
create_dir(DOL_DATA_ROOT.'/telephonie/CDR/temp/');
|
||||
}
|
||||
|
||||
$date = time() - (24 * 3600 * $nbdays);
|
||||
|
||||
$file = "daily_report_".strftime("%Y%m%d", $date).".zip";
|
||||
|
||||
$remote_file = 'cdr/'.$file;
|
||||
$local_file = DOL_DATA_ROOT.'/telephonie/CDR/atraiter/'.$file;
|
||||
$local_file = DOL_DATA_ROOT.'/telephonie/CDR/temp/'.$file;
|
||||
$handle = fopen($local_file, 'w');
|
||||
|
||||
if (ftp_fget($conn_id, $handle, $remote_file, FTP_ASCII, 0))
|
||||
{
|
||||
//echo "Le chargement a réussi dans ".$local_file."\n";
|
||||
if ($verbose)
|
||||
echo "Le chargement a réussi dans ".$local_file."\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -69,4 +94,71 @@ else
|
||||
|
||||
// Fermeture du flux FTP
|
||||
ftp_close($conn_id);
|
||||
|
||||
// Dezippage du fichier
|
||||
|
||||
$zip = zip_open($local_file);
|
||||
|
||||
if ($zip) {
|
||||
|
||||
while ($zip_entry = zip_read($zip))
|
||||
{
|
||||
if ($verbose)
|
||||
{
|
||||
echo "Nom du fichier : " . zip_entry_name($zip_entry) . "\n";
|
||||
echo "Taille réelle : " . zip_entry_filesize($zip_entry) . "\n";
|
||||
echo "Taille compressée : " . zip_entry_compressedsize($zip_entry) . "\n";
|
||||
echo "Méthode : " . zip_entry_compressionmethod($zip_entry) . "\n";
|
||||
}
|
||||
|
||||
if (zip_entry_open($zip, $zip_entry, "r"))
|
||||
{
|
||||
if ($verbose)
|
||||
echo "Decompression dans ".DOL_DATA_ROOT.'/telephonie/CDR/atraiter/'.zip_entry_name($zip_entry)."\n";
|
||||
|
||||
$fp = fopen(DOL_DATA_ROOT.'/telephonie/CDR/atraiter/'.zip_entry_name($zip_entry),"w");
|
||||
|
||||
if ($fp)
|
||||
{
|
||||
$buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
|
||||
|
||||
if (fwrite($fp, $buf) === FALSE)
|
||||
{
|
||||
echo "Erreur d'ecriture\n";
|
||||
}
|
||||
fclose($fp);
|
||||
}
|
||||
zip_entry_close($zip_entry);
|
||||
}
|
||||
}
|
||||
zip_close($zip);
|
||||
}
|
||||
|
||||
// Archivage du fichier
|
||||
|
||||
if (!file_exists(DOL_DATA_ROOT.'/telephonie/CDR/archive/'))
|
||||
{
|
||||
create_dir(DOL_DATA_ROOT.'/telephonie/CDR/archive/');
|
||||
}
|
||||
|
||||
$dir = DOL_DATA_ROOT.'/telephonie/CDR/archive/'.strftime("%Y", $date);
|
||||
if (!file_exists($dir))
|
||||
create_dir($dir);
|
||||
|
||||
$dir = DOL_DATA_ROOT.'/telephonie/CDR/archive/'.strftime("%Y", $date).'/'.strftime("%m", $date);
|
||||
if (!file_exists($dir))
|
||||
create_dir($dir);
|
||||
|
||||
function create_dir($dir)
|
||||
{
|
||||
if (! file_exists($dir))
|
||||
{
|
||||
umask(0);
|
||||
if (! @mkdir($dir, 0755))
|
||||
{
|
||||
die ("Erreur: Le répertoire ".$dir." n'existe pas et Dolibarr n'a pu le créer.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user