Maj de fileSend après création de fallback
This commit is contained in:
parent
a81fe86d6f
commit
e0987c8e85
102
fileSend.php
102
fileSend.php
@ -55,14 +55,11 @@ if ( isset($opts->file) )
|
||||
|
||||
$c = new Zend_Config($application->getOptions());
|
||||
|
||||
$dateFile = date('YmdHis', filectime($opts->file));
|
||||
|
||||
// --- Get the main directory name in FTP and SFTP
|
||||
$pathParts = pathinfo($opts->file);
|
||||
$filenameIn = $pathParts['basename'];
|
||||
$extension = '';
|
||||
if (array_key_exists('extension', $pathParts))
|
||||
{
|
||||
if (array_key_exists('extension', $pathParts)) {
|
||||
$extension = $pathParts['extension'];
|
||||
}
|
||||
// --- Don't play with *.tck files
|
||||
@ -74,13 +71,11 @@ if ( isset($opts->file) )
|
||||
|
||||
// --- Base path, type and repository
|
||||
$startpos = strlen( $c->profil->path->data . '/' );
|
||||
if ('sftp' == substr($opts->file, $startpos, 4))
|
||||
{
|
||||
if ('sftp' == substr($opts->file, $startpos, 4)) {
|
||||
$type = 'SFTP';
|
||||
$fluxBasePath = $c->profil->path->sftp . '/' . $client;
|
||||
}
|
||||
elseif ('ftp' == substr($opts->file, $startpos, 3))
|
||||
{
|
||||
elseif ('ftp' == substr($opts->file, $startpos, 3)) {
|
||||
$type = 'FTP';
|
||||
$fluxBasePath = $c->profil->path->ftp . '/' . $client;
|
||||
}
|
||||
@ -89,27 +84,21 @@ if ( isset($opts->file) )
|
||||
// --- Match prestation
|
||||
$prestations = include __DIR__ . '/fileConfig.php';
|
||||
$prestation = null;
|
||||
if (array_key_exists($client, $prestations))
|
||||
{
|
||||
if (array_key_exists($client, $prestations)) {
|
||||
$clientPrestations = $prestations[$client]['prestations'];
|
||||
foreach ($clientPrestations as $i => $p)
|
||||
{
|
||||
foreach ($clientPrestations as $i => $p) {
|
||||
// --- Not default repository dir
|
||||
if (array_key_exists('directory', $p) && !empty($p['directory']))
|
||||
{
|
||||
if (array_key_exists('directory', $p) && !empty($p['directory'])) {
|
||||
$repositoryDir = $p['directory'];
|
||||
}
|
||||
|
||||
// --- Match prestation
|
||||
if ($type == $p['type'] && $fluxRepository == $repositoryDir)
|
||||
{
|
||||
if ($type == $p['type'] && $fluxRepository == $repositoryDir) {
|
||||
$prestation = $p['name'];
|
||||
|
||||
// --- Set options
|
||||
if (array_key_exists('in', $p) && count($p['in']) > 0)
|
||||
{
|
||||
foreach ($p['in'] as $option => $value)
|
||||
{
|
||||
if (array_key_exists('in', $p) && count($p['in']) > 0) {
|
||||
foreach ($p['in'] as $option => $value) {
|
||||
${'options'.$option} = $value;
|
||||
}
|
||||
}
|
||||
@ -131,8 +120,7 @@ if ( isset($opts->file) )
|
||||
}
|
||||
}
|
||||
|
||||
if ($prestation === null)
|
||||
{
|
||||
if ($prestation === null) {
|
||||
echo date('Y-m-d H:i:s')." - Prestation not found !\n";
|
||||
}
|
||||
|
||||
@ -140,44 +128,31 @@ if ( isset($opts->file) )
|
||||
|
||||
// --- Use ".fin" or ".end" files to do something
|
||||
$runExtensions = array('fin', 'end');
|
||||
if (in_array( $extension, $runExtensions))
|
||||
{
|
||||
if ( $optionsRunWithEndFile )
|
||||
{
|
||||
if (in_array($extension, $runExtensions)) {
|
||||
if ($optionsRunWithEndFile) {
|
||||
$extToDelete = $extension;
|
||||
if (file_exists($fluxBasePath . '/' . $filenameIn))
|
||||
{
|
||||
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";
|
||||
else {
|
||||
echo "Fichier fin inexistant $filenameIn\n";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
// --- Get the realname of file IN or exit
|
||||
if ($optionsRunWithEndFile)
|
||||
{
|
||||
if (in_array( $extension, $runExtensions))
|
||||
{
|
||||
if ($optionsRunWithEndFile) {
|
||||
if (in_array($extension, $runExtensions)) {
|
||||
$extensionLength = strlen($extension)+1;
|
||||
$filenameIn = substr($filenameIn, 0, strlen($filenameIn) - $extensionLength);
|
||||
$extension = '';
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
exit;
|
||||
}
|
||||
}
|
||||
@ -191,29 +166,26 @@ if ( isset($opts->file) )
|
||||
$nbLines = count($lines);
|
||||
}
|
||||
$size = filesize($fluxBasePath . '/' . $filenameIn);
|
||||
$dateFile = date('YmdHis', filectime($fluxBasePath . '/' . $filenameIn));
|
||||
|
||||
// --- Define default out filename
|
||||
$filenameOut = $filenameIn;
|
||||
|
||||
// --- Add date to filename
|
||||
if ($optionsCopyAddDate)
|
||||
{
|
||||
if ($optionsCopyAddDate) {
|
||||
$extensionLength = 0;
|
||||
if ($extension != '')
|
||||
{
|
||||
if ($extension != '') {
|
||||
$extensionLength = strlen($extension)+1;
|
||||
$filenameOut = substr($filenameIn, 0, strlen($filenameIn) - $extensionLength);
|
||||
$filenameOut = $filenameOut . '_' . date('YmdHis') . '.' . $extension;
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
$filenameOut = $filenameIn . '_' . date('YmdHis');
|
||||
}
|
||||
}
|
||||
|
||||
// --- Prepare mail
|
||||
if ($opts->mail || $opts->debug)
|
||||
{
|
||||
if ($opts->mail || $opts->debug) {
|
||||
$subject = "[Flux] - Réception fichier $client";
|
||||
$txt = "Réception d'un fichier pour traitement\n";
|
||||
$txt.= "Client : $client\n";
|
||||
@ -252,8 +224,7 @@ if ( isset($opts->file) )
|
||||
$mail->send();
|
||||
|
||||
// --- Stop
|
||||
if ($opts->mail)
|
||||
{
|
||||
if ($opts->mail) {
|
||||
exit;
|
||||
}
|
||||
}
|
||||
@ -274,18 +245,15 @@ if ( isset($opts->file) )
|
||||
// --- Copy file
|
||||
$destDir = $c->profil->path->storage . '/' . $client . '/' . 'send';
|
||||
|
||||
if (!is_dir($destDir))
|
||||
{
|
||||
if (!is_dir($destDir)) {
|
||||
mkdir($destDir, 0755, true);
|
||||
}
|
||||
|
||||
if (copy($fluxBasePath . '/' . $filenameIn, $destDir. '/' . $filenameOut))
|
||||
{
|
||||
if (copy($fluxBasePath . '/' . $filenameIn, $destDir. '/' . $filenameOut)) {
|
||||
echo date('Y-m-d H:i:s')." - Copie du fichier $filenameIn dans $destDir\n";
|
||||
|
||||
// --- Execute
|
||||
if ($optionsLog === true)
|
||||
{
|
||||
if ($optionsLog === true) {
|
||||
$db = Zend_Db::factory($c->profil->db->metier);
|
||||
Zend_Db_Table::setDefaultAdapter($db);
|
||||
try {
|
||||
@ -302,27 +270,21 @@ if ( isset($opts->file) )
|
||||
'dateExecute' => '0000-00-00 00:00:00', // @todo : dateExecute
|
||||
));
|
||||
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:$filenameOut\n";
|
||||
}
|
||||
}
|
||||
|
||||
// --- Suppression des fichiers
|
||||
if ($optionsCopyDeleteAfter)
|
||||
{
|
||||
if ($optionsCopyDeleteAfter) {
|
||||
unlink( $fluxBasePath . '/' . $filenameIn );
|
||||
|
||||
if ($optionsRunWithEndFile)
|
||||
{
|
||||
if ($optionsRunWithEndFile) {
|
||||
unlink( $fluxBasePath . '/' . $filenameIn . '.' . $extToDelete );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
echo date('Y-m-d H:i:s')." - ERREUR Copie du fichier $filenameIn dans $destDir\n";
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user