Pour le fichier reçu ajout d'une option de routage
This commit is contained in:
parent
1d4a18065b
commit
0271f2e27c
13
README
13
README
@ -109,13 +109,18 @@ Configuration pour les fichiers en entrées
|
||||
),
|
||||
),
|
||||
|
||||
Send Options list
|
||||
-----------------
|
||||
Send Options list (in)
|
||||
----------------------
|
||||
- CopyAddDate - Copy file and add a timestamp to the end of the filename
|
||||
- CopyDeleteAfter - After copying the file delete it in repository
|
||||
- RunWithEndFile - Only execute action when we receive file with extension .fin or .end
|
||||
- Log - Log transfert disable by default
|
||||
- Route - For each Route options (cp, ftp, sftp, mail)
|
||||
cp => realpath of dir
|
||||
ftp
|
||||
sftp
|
||||
mail
|
||||
|
||||
Recv Options list
|
||||
-----------------
|
||||
Recv Options list (out)
|
||||
-----------------------
|
||||
- Log - Log read disable by default
|
56
fileSend.php
56
fileSend.php
@ -4,24 +4,24 @@
|
||||
* Attention le script doit s'executer avec l'utilisateur root
|
||||
*/
|
||||
|
||||
// Define path to application directory
|
||||
// --- Define path to application directory
|
||||
defined('APPLICATION_PATH')
|
||||
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/application'));
|
||||
|
||||
// Define application environment
|
||||
// --- Define application environment
|
||||
defined('APPLICATION_ENV')
|
||||
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
|
||||
|
||||
// Ensure library/ is on include_path
|
||||
// --- Ensure library/ is on include_path
|
||||
set_include_path(implode(PATH_SEPARATOR, array(
|
||||
realpath(APPLICATION_PATH . '/../library'),
|
||||
get_include_path(),
|
||||
)));
|
||||
|
||||
/** Zend_Application */
|
||||
// --- Zend_Application
|
||||
require_once 'Zend/Application.php';
|
||||
|
||||
// Create application, bootstrap, and run
|
||||
// --- Create application, bootstrap, and run
|
||||
$application = new Zend_Application(
|
||||
APPLICATION_ENV,
|
||||
APPLICATION_PATH . '/configs/application.ini'
|
||||
@ -29,7 +29,7 @@ $application = new Zend_Application(
|
||||
|
||||
try {
|
||||
$opts = new Zend_Console_Getopt(
|
||||
//Options
|
||||
// --- Options
|
||||
array(
|
||||
'help|?' => "Displays usage information.",
|
||||
'file|f=s' => "Give the full file path to integrate",
|
||||
@ -43,7 +43,7 @@ try {
|
||||
exit;
|
||||
}
|
||||
|
||||
//Usage
|
||||
// --- Usage
|
||||
if( isset($opts->help) || count($opts->getOptions())==0 )
|
||||
{
|
||||
echo "Execute basic action when a customer send a file.\n";
|
||||
@ -51,20 +51,21 @@ if( isset($opts->help) || count($opts->getOptions())==0 )
|
||||
exit;
|
||||
}
|
||||
|
||||
//Get the file
|
||||
// --- Get the file
|
||||
if ( isset($opts->file) )
|
||||
{
|
||||
$optionsCopyAddDate = false;
|
||||
$optionsCopyDeleteAfter = false;
|
||||
$optionsRunWithEndFile = false;
|
||||
$optionsLog = false;
|
||||
$optionsRoute = array();
|
||||
$repositoryDir = 'send';
|
||||
|
||||
$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);
|
||||
$filenameIn = $pathParts['basename'];
|
||||
$extension = '';
|
||||
@ -74,8 +75,8 @@ if ( isset($opts->file) )
|
||||
}
|
||||
$client = basename(dirname($pathParts['dirname']));
|
||||
|
||||
// Base path, type and repository
|
||||
$startpos = strlen( $c->profil->path->data . DIRECTORY_SEPARATOR );
|
||||
// --- Base path, type and repository
|
||||
$startpos = strlen( $c->profil->path->data . '/' );
|
||||
if ('sftp' == substr($opts->file, $startpos, 4))
|
||||
{
|
||||
$type = 'SFTP';
|
||||
@ -88,7 +89,7 @@ if ( isset($opts->file) )
|
||||
}
|
||||
$fluxRepository = str_replace(array($fluxBasePath.'/', '/'.$filenameIn), array('', ''), $opts->file);
|
||||
|
||||
// Match prestation
|
||||
// --- Match prestation
|
||||
$prestations = include __DIR__ . '/fileConfig.php';
|
||||
$prestation = null;
|
||||
if (array_key_exists($client, $prestations))
|
||||
@ -96,7 +97,7 @@ if ( isset($opts->file) )
|
||||
$clientPrestations = $prestations[$client]['prestations'];
|
||||
foreach ($clientPrestations as $i => $p)
|
||||
{
|
||||
// Not default repository dir
|
||||
// --- Not default repository dir
|
||||
if (array_key_exists('directory', $p) && !empty($p['directory']))
|
||||
{
|
||||
$repositoryDir = $p['directory'];
|
||||
@ -106,7 +107,7 @@ if ( isset($opts->file) )
|
||||
{
|
||||
$prestation = $p['name'];
|
||||
|
||||
// Set option
|
||||
// --- Set option
|
||||
if (array_key_exists('in', $p) && count($p['in']) > 0)
|
||||
{
|
||||
foreach ($p['in'] as $option => $value)
|
||||
@ -127,7 +128,7 @@ if ( isset($opts->file) )
|
||||
|
||||
$fluxBasePath .= '/'.$repositoryDir;
|
||||
|
||||
//Use ".fin" or ".end" files to do something
|
||||
// --- Use ".fin" or ".end" files to do something
|
||||
$runExtensions = array('fin', 'end');
|
||||
if (in_array( $extension, $runExtensions))
|
||||
{
|
||||
@ -156,7 +157,7 @@ if ( isset($opts->file) )
|
||||
}
|
||||
}
|
||||
|
||||
//Get the realname of file IN or exit
|
||||
// --- Get the realname of file IN or exit
|
||||
if ($optionsRunWithEndFile)
|
||||
{
|
||||
if (in_array( $extension, $runExtensions))
|
||||
@ -179,10 +180,10 @@ if ( isset($opts->file) )
|
||||
}
|
||||
$size = filesize($fluxBasePath . '/' . $filenameIn);
|
||||
|
||||
//Define default out filename
|
||||
// --- Define default out filename
|
||||
$filenameOut = $filenameIn;
|
||||
|
||||
//Add date to filename
|
||||
// --- Add date to filename
|
||||
if ($optionsCopyAddDate)
|
||||
{
|
||||
$extensionLength = 0;
|
||||
@ -198,7 +199,7 @@ if ( isset($opts->file) )
|
||||
}
|
||||
}
|
||||
|
||||
//Prepare mail
|
||||
// --- Prepare mail
|
||||
if ($opts->mail || $opts->debug)
|
||||
{
|
||||
$subject = "[Flux] - Réception fichier $client";
|
||||
@ -238,14 +239,27 @@ if ( isset($opts->file) )
|
||||
$mail->setSubject($subject);
|
||||
$mail->send();
|
||||
|
||||
//Stop
|
||||
// --- Stop
|
||||
if ($opts->mail)
|
||||
{
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
// Copy file
|
||||
// --- Before store the file send to another repository
|
||||
if (count($optionsRoute) > 0) {
|
||||
foreach ($optionsRoute as $tr => $value) {
|
||||
switch($tr) {
|
||||
case 'cp':
|
||||
if (copy($fluxBasePath . '/' . $filenameIn, $value. '/' . $filenameOut)) {
|
||||
echo date('Y-m-d H:i:s')." - Copie du fichier $filenameIn dans $value\n";
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- Copy file
|
||||
$destDir = $c->profil->path->storage . '/' . $client . '/' . 'send';
|
||||
|
||||
if (!is_dir($destDir))
|
||||
|
Loading…
Reference in New Issue
Block a user