268 lines
10 KiB
PHP
268 lines
10 KiB
PHP
<?php
|
|
/**
|
|
* Livraison des fichiers pour orone
|
|
*
|
|
* Toutes les 10 minutes
|
|
* Lire les fichiers dans le repertoire clients/jalpdfsed/send
|
|
* Intégrer les informations dans la table octde.jalpdfsed
|
|
* Copier le fichier dans clients/orone/recv
|
|
* Integrer les informations dans flux_fileout pour livraison
|
|
* Mettre à jour la date de livraison
|
|
* Déplacer le fichier dans clients/jalpdfsed/send/done
|
|
*/
|
|
|
|
//error_reporting(E_ALL & ~E_STRICT & ~E_NOTICE & ~E_WARNING & ~E_DEPRECATED);
|
|
error_reporting(E_ALL & ~E_STRICT & ~E_NOTICE & ~E_WARNING & ~E_DEPRECATED);
|
|
|
|
// Define path to application directory
|
|
defined('APPLICATION_PATH')
|
|
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../../application'));
|
|
|
|
// Define application environment
|
|
defined('APPLICATION_ENV')
|
|
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
|
|
|
|
// Ensure library/ is on include_path
|
|
set_include_path(implode(PATH_SEPARATOR, array(
|
|
realpath(APPLICATION_PATH . '/../library'),
|
|
get_include_path(),
|
|
)));
|
|
|
|
//Use classmap autoloader - useful with opcode and realpath cache
|
|
require_once 'Zend/Loader/AutoloaderFactory.php';
|
|
require_once 'Zend/Loader/ClassMapAutoloader.php';
|
|
Zend_Loader_AutoloaderFactory::factory(array(
|
|
'Zend_Loader_ClassMapAutoloader' => array(
|
|
__DIR__ . '/../../library/Zend/autoload_classmap.php',
|
|
__DIR__ . '/../../library/Application/autoload_classmap.php',
|
|
__DIR__ . '/../../library/Scores/autoload_classmap.php',
|
|
__DIR__ . '/../../application/autoload_classmap.php',
|
|
),
|
|
'Zend_Loader_StandardAutoloader' => array(
|
|
'prefixes' => array(
|
|
'Zend' => __DIR__ . '/../../library/Zend',
|
|
'Application' => __DIR__ . '/../../library/Application',
|
|
'Scores' => __DIR__ . '/../../library/Scores',
|
|
'SdMetier' => __DIR__ . '/../../library/SdMetier',
|
|
'Metier' => __DIR__ . '/../../library/Metier',
|
|
),
|
|
'fallback_autoloader' => true
|
|
)
|
|
));
|
|
|
|
// Create application, bootstrap, and run
|
|
$application = new Zend_Application(
|
|
APPLICATION_ENV,
|
|
APPLICATION_PATH . '/configs/application.ini'
|
|
);
|
|
|
|
try {
|
|
$opts = new Zend_Console_Getopt(
|
|
//Options
|
|
array(
|
|
'help|?' => "Displays usage information.",
|
|
'parsefile' => "Parcours les fichiers",
|
|
'deliver' => "Relivrer les fichiers depuis (from)",
|
|
'from=s' => "db, date au format AAAAMMJJ",
|
|
'verbose' => "mode verbeux",
|
|
'cron' => "Mandatory option for launch the cli in cron",
|
|
)
|
|
);
|
|
$opts->parse();
|
|
} catch (Zend_Console_Getopt_Exception $e) {
|
|
echo $e->getUsageMessage();
|
|
exit;
|
|
}
|
|
|
|
//Usage
|
|
if( isset($opts->help) || count($opts->getOptions())==0 )
|
|
{
|
|
echo "Prestation RRG Surveillance.\n";
|
|
echo $opts->getUsageMessage();
|
|
exit;
|
|
}
|
|
|
|
$c = new Zend_Config($application->getOptions());
|
|
Zend_Registry::set('config', $c);
|
|
|
|
$db = Zend_Db::factory($c->profil->db->metier);
|
|
Zend_Db_Table_Abstract::setDefaultAdapter($db);
|
|
|
|
|
|
if ($opts->cron) {
|
|
|
|
echo date('Y-m-d H:i:s')." - Récupération des fichiers jalpdfsed.\n";
|
|
|
|
// --- Lire les fichiers dans sdv1.flux_filein (jalpdfsed/PDF) avec dateExecute = 0
|
|
try {
|
|
$fileinM = new Application_Model_Sdv1FluxFileIn();
|
|
$sql = $fileinM->select()
|
|
->where('client=?','jalpdfsed')
|
|
->where('name=?', 'PDF')
|
|
->where('dateExecute=?','0000-00-00 00:00:00');
|
|
$fileResult = $fileinM->fetchAll($sql);
|
|
} catch (Zend_Db_Exception $e) {
|
|
echo date('Y-m-d H:i:s')." - ".$e->getMessage()."\n"; exit;
|
|
}
|
|
|
|
if ( $fileResult === null ) {
|
|
echo date('Y-m-d H:i:s')." - Aucun fichier à traiter\n";
|
|
} else {
|
|
foreach( $fileResult as $item) {
|
|
|
|
$fileName = $item->depotFile;
|
|
$filePath = $c->profil->path->storage . '/clients/jalpdfsed/send/' . $fileName;
|
|
|
|
echo date('Y-m-d H:i:s')." - Fichier $fileName\n";
|
|
|
|
if ( false !== ( $file = file_get_contents($filePath) ) ) {
|
|
if (preg_match('/^([0-9]{1,})_([0-9]{8})\.pdf$/', $fileName, $t)) {
|
|
$idJalEd = $t[1];
|
|
$dateJalEd = $t[2];
|
|
|
|
//Version
|
|
preg_match( "/^\%PDF\-(.*)\s/U", $file, $matches );
|
|
$fileVersion = $matches[1];
|
|
//Number of page
|
|
$filePage = preg_match_all( "/\/Page\W/", $file, $matches );
|
|
//Pdf size
|
|
$fileSize = filesize($filePath);
|
|
//Date de création
|
|
$fileDate = date('Ymd', filectime($filePath));
|
|
|
|
$isInsert = false;
|
|
$jalM = new Application_Model_OctdeJalpdfsed();
|
|
$sql = $jalM->select()->where('pdfName=?', $fileName);
|
|
$exist = $jalM->fetchRow($sql);
|
|
if ( $exist === null ) {
|
|
$data = array(
|
|
'pdfName' => $fileName,
|
|
'idJalEd' => $idJalEd,
|
|
'dateJalEd' => $dateJalEd,
|
|
'pdfSize' => $fileSize,
|
|
'pdfPage' => $filePage,
|
|
'pdfVer' => $fileVersion,
|
|
'pdfDate' => $fileDate,
|
|
'pdfText' => 0,
|
|
'dateInsert' => date('YmdHis'),
|
|
);
|
|
|
|
// --- Renseigner octde.jalpdfsed
|
|
try {
|
|
$isInsert = $jalM->insert($data);
|
|
} catch (Zend_Db_Exception $e) {
|
|
echo date('Y-m-d H:i:s')." - ".$e->getMessage()."\n";
|
|
continue;
|
|
}
|
|
} else {
|
|
// --- Vérification de la taille des fichiers
|
|
if ($fileSize != $exist->pdfSize) {
|
|
// --- Renseigner octde.jalpdfsed
|
|
try {
|
|
$isInsert = $jalM->update(array(
|
|
'pdfSize' => $fileSize,
|
|
'pdfPage' => $filePage,
|
|
'pdfVer' => $fileVersion,
|
|
'pdfDate' => $fileDate,
|
|
'dateDeliver' => '0000-00-00 00:00:00',
|
|
), "id=".$exist->id);
|
|
} catch (Zend_Db_Exception $e) {
|
|
echo date('Y-m-d H:i:s')." - ".$e->getMessage()."\n";
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($isInsert) {
|
|
// --- Copier le fichier dans le dossier de stockage orone/recv
|
|
if (copy($filePath, $c->profil->path->storage . '/clients/orone/recv/' . $fileName)) {
|
|
// --- Definir sdv1.flux_filein dateExecute
|
|
try {
|
|
$fileinM->update(array('dateExecute' => date('YmdHis')), 'id='.$item->id);
|
|
} catch (Zend_Db_Exception $e) {
|
|
echo date('Y-m-d H:i:s')." - ".$e->getMessage()."\n";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
echo date('Y-m-d H:i:s')." - Fin Récupération des fichiers jalpdfsed.\n";
|
|
}
|
|
|
|
if ($opts->deliver || $opts->cron) {
|
|
|
|
echo date('Y-m-d H:i:s')." - Livraison des fichiers.\n";
|
|
|
|
$fileList = array();
|
|
|
|
$from = 'db';
|
|
if (isset($opts->from) && $opts->from != 'db') {
|
|
$from = $opts->from;
|
|
}
|
|
|
|
// --- Lire tous les fichiers avec dateDeliver = 0
|
|
if ($from == 'db') {
|
|
try {
|
|
$jalM = new Application_Model_OctdeJalpdfsed();
|
|
$sql = $jalM->select()->where('dateDeliver=?', '0000-00-00 00:00:00');
|
|
$fileList = $jalM->fetchAll($sql);
|
|
} catch(Zend_Db_Exception $e) {
|
|
echo date('Y-m-d H:i:s')." - ".$e->getMessage()."\n";
|
|
}
|
|
}
|
|
// --- Renvoyer tous les fichiers en date du AAAAMMJJ
|
|
else {
|
|
exit;
|
|
}
|
|
|
|
if ($fileList === null) {
|
|
echo date('Y-m-d H:i:s')." - Aucun nouveau fichier pour orone\n";
|
|
} else {
|
|
// --- Envoyer les fichiers pour orone, simplement marquer dans teletransmission
|
|
foreach ($fileList as $item) {
|
|
echo date('Y-m-d H:i:s')." - Fichier $item->pdfName\n";
|
|
$filePath = $c->profil->path->storage . '/clients/orone/recv/' . $item->pdfName;
|
|
if ( file_exists($filePath) ) {
|
|
$isInsert = false;
|
|
$size = filesize($filePath);
|
|
try {
|
|
$fileoutM = new Application_Model_Sdv1FluxFileOut();
|
|
$isInsert = $fileoutM->insert(array(
|
|
'client' => 'orone',
|
|
'name' => 'PDF',
|
|
'nbLines' => 0,
|
|
'dateBegin' => date('YmdHis'),
|
|
'dateEnd' => date('YmdHis'),
|
|
'fileOut' => $item->pdfName,
|
|
'depotFileSize' => $size,
|
|
'depotType' => 'FTP',
|
|
'depotDate' => '0000-00-00 00:00:00',
|
|
));
|
|
} catch (Zend_Db_Exception $e) {
|
|
echo date('Y-m-d H:i:s')." - ".$e->getMessage()."\n";
|
|
continue;
|
|
}
|
|
|
|
// --- Definir octde.jalpdfsed dateDeliver
|
|
if ($isInsert) {
|
|
try {
|
|
$jalM->update(array('dateDeliver' => date('YmdHis')), 'id='.$item->id);
|
|
} catch(Zend_Db_Exception $e) {
|
|
echo date('Y-m-d H:i:s')." - ".$e->getMessage()."\n";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
echo date('Y-m-d H:i:s')." - Fin Livraison des fichiers.\n";
|
|
}
|
|
|
|
if ($opts->parsefile) {
|
|
// --- Lire les fichiers dans clients/jalpdfsed/send
|
|
// --- Vérifier la présence en base
|
|
}
|
|
|