Ajout option filtre par nom

This commit is contained in:
Michael RICOIS 2015-06-30 09:32:45 +00:00
parent 7751aa504a
commit 7d3f435f2a
2 changed files with 36 additions and 18 deletions

4
README
View File

@ -120,7 +120,9 @@ Send Options list (in)
ftp ftp
sftp sftp
mail mail
- FilterName - Filtre par nom de prestation (true) ou par nom défini
Recv Options list (out) Recv Options list (out)
----------------------- -----------------------
- Log - Log read disable by default - Log - Log read disable by default

View File

@ -23,18 +23,18 @@ require_once 'Zend/Application.php';
// --- Create application, bootstrap, and run // --- Create application, bootstrap, and run
$application = new Zend_Application( $application = new Zend_Application(
APPLICATION_ENV, APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini' APPLICATION_PATH . '/configs/application.ini'
); );
try { try {
$opts = new Zend_Console_Getopt( $opts = new Zend_Console_Getopt(
// --- Options // --- Options
array( array(
'help|?' => "Displays usage information.", 'help|?' => "Displays usage information.",
'file|f=s' => "Give the full file path to integrate", 'file|f=s' => "Give the full file path to integrate",
'mail' => "Only send a mail when a file is write", 'mail' => "Only send a mail when a file is write",
'debug' => "Send a mail for debug", 'debug' => "Send a mail for debug",
) )
); );
$opts->parse(); $opts->parse();
@ -59,6 +59,7 @@ if ( isset($opts->file) )
$optionsRunWithEndFile = false; $optionsRunWithEndFile = false;
$optionsLog = false; $optionsLog = false;
$optionsRoute = array(); $optionsRoute = array();
$optionsFilterName = false;
$repositoryDir = 'send'; $repositoryDir = 'send';
$c = new Zend_Config($application->getOptions()); $c = new Zend_Config($application->getOptions());
@ -103,11 +104,12 @@ if ( isset($opts->file) )
$repositoryDir = $p['directory']; $repositoryDir = $p['directory'];
} }
// --- Match prestation
if ($type == $p['type'] && $fluxRepository == $repositoryDir) if ($type == $p['type'] && $fluxRepository == $repositoryDir)
{ {
$prestation = $p['name']; $prestation = $p['name'];
// --- Set option // --- Set options
if (array_key_exists('in', $p) && count($p['in']) > 0) if (array_key_exists('in', $p) && count($p['in']) > 0)
{ {
foreach ($p['in'] as $option => $value) foreach ($p['in'] as $option => $value)
@ -116,6 +118,18 @@ if ( isset($opts->file) )
} }
} }
// --- Filters
if ($optionsFilterName === true) {
if ( strpos($filenameIn, $prestation) === false ) {
exit;
}
}
if (is_string($optionsFilterName) && strlen($optionsFilterName) > 0) {
if (strpos($filenameIn, $optionsFilterName) === false) {
exit;
}
}
break; break;
} }
} }
@ -172,6 +186,8 @@ if ( isset($opts->file) )
} }
} }
// ---
// --- Detail du fichier // --- Detail du fichier
$nbLines = 0; $nbLines = 0;
if ( strtolower(substr($filenameIn, -3)) == 'csv' ) { if ( strtolower(substr($filenameIn, -3)) == 'csv' ) {
@ -251,7 +267,7 @@ if ( isset($opts->file) )
foreach ($optionsRoute as $tr => $value) { foreach ($optionsRoute as $tr => $value) {
switch($tr) { switch($tr) {
case 'cp': case 'cp':
if (copy($fluxBasePath . '/' . $filenameIn, $value. '/' . $filenameOut)) { if (copy($fluxBasePath . '/' . $filenameIn, $value . '/' . $filenameOut)) {
echo date('Y-m-d H:i:s')." - Copie du fichier $filenameIn dans $value\n"; echo date('Y-m-d H:i:s')." - Copie du fichier $filenameIn dans $value\n";
} }
break; break;
@ -279,15 +295,15 @@ if ( isset($opts->file) )
try { try {
$fluxM = new Application_Model_Sdv1FluxFileIn(); $fluxM = new Application_Model_Sdv1FluxFileIn();
$fluxM->insert(array( $fluxM->insert(array(
'client' => $client, 'client' => $client,
'name' => $prestation, 'name' => $prestation,
'depotType' => $type, 'depotType' => $type,
'depotDate' => $dateFile, 'depotDate' => $dateFile,
'depotFile' => $filenameOut, 'depotFile' => $filenameOut,
'nbLines' => $nbLines, 'nbLines' => $nbLines,
'depotFileSize' => $size, 'depotFileSize' => $size,
'dateInsert' => date('YmdHis'), 'dateInsert' => date('YmdHis'),
'dateExecute' => '0000-00-00 00:00:00', // @todo : dateExecute 'dateExecute' => '0000-00-00 00:00:00', // @todo : dateExecute
)); ));
echo date('Y-m-d H:i:s')." - Enregistrement client:$client fichier:$filenameOut\n"; echo date('Y-m-d H:i:s')." - Enregistrement client:$client fichier:$filenameOut\n";
} }