Traitement avec les fichiers .fin ou .end
This commit is contained in:
parent
805d6b6eaa
commit
fbbd02e749
94
fileSend.php
94
fileSend.php
@ -56,29 +56,29 @@ if ( isset($opts->file) )
|
|||||||
{
|
{
|
||||||
$c = new Zend_Config($application->getOptions());
|
$c = new Zend_Config($application->getOptions());
|
||||||
|
|
||||||
|
$dateFile = date('YmdHis', filectime($opts->file));
|
||||||
|
|
||||||
//Get the main directory name in FTP and SFTP
|
//Get the main directory name in FTP and SFTP
|
||||||
$pathParts = pathinfo($opts->file);
|
$pathParts = pathinfo($opts->file);
|
||||||
|
$filenameIn = $pathParts['basename'];
|
||||||
$filename = $pathParts['basename'];
|
|
||||||
$extension = '';
|
$extension = '';
|
||||||
if (array_key_exists('extension', $pathParts) ){
|
if (array_key_exists('extension', $pathParts) ){
|
||||||
$extension = $pathParts['extension'];
|
$extension = $pathParts['extension'];
|
||||||
}
|
}
|
||||||
$client = basename(dirname($pathParts['dirname']));
|
$client = basename(dirname($pathParts['dirname']));
|
||||||
$dateFile = date('YmdHis', filectime($opts->file));
|
|
||||||
|
|
||||||
$startpos = strlen( $c->profil->path->data . DIRECTORY_SEPARATOR );
|
$startpos = strlen( $c->profil->path->data . DIRECTORY_SEPARATOR );
|
||||||
if ( 'sftp' == substr($opts->file, $startpos, 4) ) {
|
if ( 'sftp' == substr($opts->file, $startpos, 4) ) {
|
||||||
$type = 'SFTP';
|
$type = 'SFTP';
|
||||||
|
$fluxBasePath = $c->profil->path->sftp . '/' . $client;
|
||||||
} elseif ( 'ftp' == substr($opts->file, $startpos, 3) ) {
|
} elseif ( 'ftp' == substr($opts->file, $startpos, 3) ) {
|
||||||
$type = 'FTP';
|
$type = 'FTP';
|
||||||
|
$fluxBasePath = $c->profil->path->ftp . '/' . $client;
|
||||||
}
|
}
|
||||||
|
|
||||||
$lines = file($opts->file);
|
$OptionsCopyAddDate = false;
|
||||||
$nbLines = count($lines);
|
$OptionsCopyDeleteAfter = false;
|
||||||
|
$OptionsRunWithEndFile = false;
|
||||||
$copyOptionsAddDate = false;
|
|
||||||
$copyOptionsDeleteAfter = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @todo : links to prestation table and file rules
|
* @todo : links to prestation table and file rules
|
||||||
@ -92,20 +92,48 @@ if ( isset($opts->file) )
|
|||||||
break;
|
break;
|
||||||
case 'gefacto':
|
case 'gefacto':
|
||||||
$prestation = 'GEFACTO';
|
$prestation = 'GEFACTO';
|
||||||
$copyOptionsAddDate = true;
|
$OptionsCopyAddDate = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($copyOptionsAddDate) {
|
//Use ".fin" or ".end" files to do something
|
||||||
|
$runExtensions = array('fin', 'end');
|
||||||
|
if ( in_array( $extension, $runExtensions) ) {
|
||||||
|
if ( $OptionsRunWithEndFile ) {
|
||||||
|
$extToDelete = $extension;
|
||||||
|
if (file_exists($fluxBasePath . '/' . $filenameIn)) {
|
||||||
|
$pathParts = pathinfo($fluxBasePath . '/' . $filenameIn);
|
||||||
|
$filenameIn = $pathParts['basename'];
|
||||||
|
$extension = '';
|
||||||
|
if (array_key_exists('extension', $pathParts) ){
|
||||||
|
$extension = $pathParts['extension'];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echo "Fichier inexistant $filenameIn\n";
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $OptionsRunWithEndFile && !in_array( $extension, $runExtensions) ) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$lines = file($fluxBasePath . '/' . $filenameIn);
|
||||||
|
$nbLines = count($lines);
|
||||||
|
|
||||||
|
//Add date to filename
|
||||||
|
if ( $OptionsCopyAddDate ) {
|
||||||
$extensionLength = 0;
|
$extensionLength = 0;
|
||||||
if ( $extension != '' ) {
|
if ( $extension != '' ) {
|
||||||
$extensionLength = strlen($extension)+1;
|
$extensionLength = strlen($extension)+1;
|
||||||
$filename = substr($filename, 0, strlen($filename)-$extensionLength);
|
$filenameOut = substr($filenameIn, 0, strlen($filenameIn)-$extensionLength);
|
||||||
$filename = $filename . '_' . date('YmdHis') . '.' . $extension;
|
$filenameOut = $filenameOut . '_' . date('YmdHis') . '.' . $extension;
|
||||||
} else {
|
} else {
|
||||||
$filename = $filename . '_' . date('YmdHis');
|
$filenameOut = $filenameIn . '_' . date('YmdHis');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Prepare mail
|
//Prepare mail
|
||||||
@ -115,7 +143,7 @@ if ( isset($opts->file) )
|
|||||||
$txt = "Réception d'un fichier pour traitement\n";
|
$txt = "Réception d'un fichier pour traitement\n";
|
||||||
$txt.= "Client : $client\n";
|
$txt.= "Client : $client\n";
|
||||||
$txt.= "Mode de transmission : $type\n";
|
$txt.= "Mode de transmission : $type\n";
|
||||||
$txt.= "Fichier : ".$opts->file."\n";
|
$txt.= "Fichier : ".$filenameIn."\n";
|
||||||
$txt.= "Nombre de Lignes : $nbLines\n";
|
$txt.= "Nombre de Lignes : $nbLines\n";
|
||||||
|
|
||||||
$mail = new Zend_Mail('UTF-8');
|
$mail = new Zend_Mail('UTF-8');
|
||||||
@ -134,6 +162,16 @@ if ( isset($opts->file) )
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Copie du fichier
|
||||||
|
$destDir = $c->profil->path->storage . '/' . $client . '/' . 'send';
|
||||||
|
|
||||||
|
if ( !is_dir($destDir) ) {
|
||||||
|
mkdir($destDir, 0755, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( copy($fluxBasePath . '/' . $filenameIn, $destDir. '/' . $filenameOut) ) {
|
||||||
|
echo date('Y-m-d H:i:s')." - Copie du fichier $filenameIn dans $destDir\n";
|
||||||
|
|
||||||
//Execute
|
//Execute
|
||||||
$db = Zend_Db::factory($c->profil->db->metier);
|
$db = Zend_Db::factory($c->profil->db->metier);
|
||||||
Zend_Db_Table::setDefaultAdapter($db);
|
Zend_Db_Table::setDefaultAdapter($db);
|
||||||
@ -144,33 +182,27 @@ if ( isset($opts->file) )
|
|||||||
'name' => $prestation,
|
'name' => $prestation,
|
||||||
'depotType' => $type,
|
'depotType' => $type,
|
||||||
'depotDate' => $dateFile,
|
'depotDate' => $dateFile,
|
||||||
'depotFile' => $filename,
|
'depotFile' => $filenameOut,
|
||||||
'nbLines' => $nbLines,
|
'nbLines' => $nbLines,
|
||||||
'dateInsert' => date('YmdHis'),
|
'dateInsert' => date('YmdHis'),
|
||||||
'dateExecute' => '0000-00-00 00:00:00',
|
'dateExecute' => '0000-00-00 00:00:00',
|
||||||
));
|
));
|
||||||
echo date('Y-m-d H:i:s')." - Enregistrement client:$client fichier:$filename\n";
|
echo date('Y-m-d H:i:s')." - Enregistrement client:$client fichier:$filenameOut\n";
|
||||||
} catch (Zend_Db_Exception $e) {
|
} catch (Zend_Db_Exception $e) {
|
||||||
echo date('Y-m-d H:i:s')." - ERREUR Enregistrement client:$client fichier:$filename\n";
|
echo date('Y-m-d H:i:s')." - ERREUR Enregistrement client:$client fichier:$filenameOut\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
//Copie du fichier
|
//Suppression des fichiers
|
||||||
$destDir = $c->profil->path->storage .
|
if ( $OptionsCopyDeleteAfter ) {
|
||||||
DIRECTORY_SEPARATOR . $client .
|
unlink( $fluxBasePath . '/' . $filenameIn );
|
||||||
DIRECTORY_SEPARATOR . 'send';
|
|
||||||
|
|
||||||
if ( !is_dir($destDir) ) {
|
if ( $OptionsRunWithEndFile ) {
|
||||||
mkdir($destDir, 0755, true);
|
unlink( $fluxBasePath . '/' . $filenameIn . '.' . $extToDelete );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( copy($opts->file, $destDir. DIRECTORY_SEPARATOR . $filename) ) {
|
|
||||||
echo date('Y-m-d H:i:s')." - Copie du fichier $filename dans $destDir\n";
|
|
||||||
|
|
||||||
if ($copyOptionsDeleteAfter) {
|
|
||||||
unlink($opts->file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
echo date('Y-m-d H:i:s')." - ERREUR Copie du fichier $filename dans $destDir\n";
|
echo date('Y-m-d H:i:s')." - ERREUR Copie du fichier $filenameIn dans $destDir\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user