200 lines
6.6 KiB
PHP
200 lines
6.6 KiB
PHP
#!/usr/bin/php -q
|
|
<?php
|
|
// 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/autoload_classmap.php',
|
|
),
|
|
'Zend_Loader_StandardAutoloader' => array(
|
|
'prefixes' => array(
|
|
'Zend' => __DIR__ . '/../../library/Zend',
|
|
'Application' => __DIR__ . '/../../library/Application',
|
|
'Scores' => __DIR__ . '/../../library/Scores',
|
|
'Metier' => __DIR__ . '/../../library/Metier',
|
|
),
|
|
'fallback_autoloader' => true
|
|
)
|
|
));
|
|
|
|
// Zend_Application - Use it if you don't have autoloaders
|
|
//require_once 'Zend/Application.php';
|
|
|
|
// 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|?' => "Affiche l'aide.",
|
|
'reprise' => "Reprise des actes en erreur de moins de 120 heures",
|
|
'rapport' => "Envoi d'un email listant les commandes en erreur à J-1",
|
|
'rapportcomplet' => "Envoi d'un email listant toutes les commandes en erreur",
|
|
));
|
|
$opts->parse();
|
|
} catch (Zend_Console_Getopt_Exception $e) {
|
|
echo $e->getUsageMessage();
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* Usage
|
|
*/
|
|
if(count($opts->getOptions())==0 || isset($opts->help))
|
|
{
|
|
echo "Reprise de commande InfoGreffe par le WebService.";
|
|
echo "\n\n";
|
|
echo $opts->getUsageMessage();
|
|
echo "\n";
|
|
exit;
|
|
}
|
|
|
|
$c = new Zend_Config($application->getOptions());
|
|
Zend_Registry::set('config', $c);
|
|
|
|
define ('PATH_DATA', $c->profil->path->data);
|
|
|
|
/**
|
|
* Connexion à la base de données
|
|
*/
|
|
$db = Zend_Db::factory($c->profil->db->sdv1);
|
|
Zend_Db_Table_Abstract::setDefaultAdapter($db);
|
|
$db->setFetchMode(Zend_Db::FETCH_OBJ);
|
|
|
|
if ( isset($opts->reprise) )
|
|
{
|
|
$timestamp = mktime(0, 0, 0, date("m"), date("d")-5, date("Y"));
|
|
$daybefore = date('Y-m-d', $timestamp);
|
|
$commandesM = new Application_Model_CommandesErreur();
|
|
$sql = $commandesM->select()->where("dateReception='0000-00-00 00:00:00' AND dateCommande > '".$daybefore." 00:00:00'");
|
|
$repErreur = $commandesM->fetchAll($sql);
|
|
|
|
if (count($repErreur)==0) exit;
|
|
|
|
foreach($repErreur as $cmd)
|
|
{
|
|
require_once 'Infogreffe/Infogreffe.php';
|
|
$infogreffe = new Infogreffe();
|
|
switch($cmd->type){
|
|
case 'acte':
|
|
$path = $infogreffe->actePath($cmd->ref);
|
|
$fichier = $infogreffe->acteFilename($cmd->siren, $cmd->ref);
|
|
break;
|
|
case 'bilan':
|
|
$path = $infogreffe->bilanPath('0000_'.$cmd->ref);
|
|
$fichier = $infogreffe->bilanFilename($cmd->siren, '0000_'.$cmd->ref);
|
|
break;
|
|
}
|
|
echo date('Y-m-d\TH:i:s').' - '.$path.$fichier." = ";
|
|
$dl = $infogreffe->dl($path.$fichier, $cmd->url, false);
|
|
echo $dl."\n";
|
|
if( $dl ) {
|
|
$data = array('erreur' => '', 'dateReception' => date('Y-m-d H:i:s'));
|
|
$where = "siren='".$cmd->siren."' AND type='".$cmd->type."' AND ref='".$cmd->ref."' AND dateCommande='".$cmd->dateCommande."'";
|
|
$commandesM->update($data, $where);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
if ( isset($opts->rapport) || isset($opts->rapportcomplet) )
|
|
{
|
|
$commandesM = new Application_Model_CommandesErreur();
|
|
if (isset($opts->rapportcomplet)) {
|
|
$sql = $commandesM->select()->where("erreur!='' AND dateReception='0000-00-00 00:00:00'")
|
|
->order("dateCommande ASC");
|
|
$sujet = "[Commandes Greffe - Erreur WebService] - Rapport Complet";
|
|
} else {
|
|
$timestamp = mktime(0, 0, 0, date("m"), date("d")-1, date("Y"));
|
|
$hier = date('Y-m-d', $timestamp);
|
|
$sujet = "[Commandes Greffe - Erreur WebService] - ".$hier;
|
|
$sql = $commandesM->select()->where("(dateCommande BETWEEN '".$hier." 00:00:00' AND '".$hier." 23:59:59') AND erreur!='' AND dateReception='0000-00-00 00:00:00'")
|
|
->order("dateCommande ASC");;
|
|
}
|
|
$repErreur = $commandesM->fetchAll($sql);
|
|
|
|
$emailTxt = '<b><u>Commandes Greffe - Erreur WebService</u></b>';
|
|
$emailTxt.= '<br/>';
|
|
if (count($repErreur)==0) {
|
|
|
|
$emailtTxt.= "Aucune commande en erreur !";
|
|
|
|
} else {
|
|
$emailTxt.= '<table border="1" style="border:1px solid; margin:5px; border-collapse:collapse;">';
|
|
$emailTxt.= '<thead>';
|
|
$emailTxt.= '<tr>';
|
|
$emailTxt.= '<th>Siren</th>';
|
|
$emailTxt.= '<th>Type</th>';
|
|
$emailTxt.= '<th>Ref</th>';
|
|
$emailTxt.= '<th>Date de commande</th>';
|
|
$emailTxt.= '<th>URL</th>';
|
|
$emailTxt.= '<th>Erreur</th>';
|
|
$emailTxt.= '</tr>';
|
|
$emailTxt.= '</thead>';
|
|
$emailTxt.= '<tbody>';
|
|
foreach($repErreur as $cmd)
|
|
{
|
|
require_once 'Infogreffe/Infogreffe.php';
|
|
$infogreffe = new Infogreffe();
|
|
switch($cmd->type){
|
|
case 'acte':
|
|
$path = $infogreffe->actePath($cmd->ref);
|
|
$fichier = $infogreffe->acteFilename($cmd->siren, $cmd->ref);
|
|
break;
|
|
case 'bilan':
|
|
|
|
$path = $infogreffe->bilanPath($cmd->ref);
|
|
|
|
$fichier = $infogreffe->bilanFilename($cmd->siren, $cmd->ref);
|
|
break;
|
|
}
|
|
//Le fichier existe, alors on a résolu le problème (mauellement ?)
|
|
if( file_exists(PATH_DATA . $path . $fichier) ) {
|
|
$data = array('erreur' => '', 'dateReception' => date('Y-m-d H:i:s'));
|
|
$where = "siren='".$cmd->siren."' AND type='".$cmd->type."' AND ref='".$cmd->ref."' AND dateCommande='".$cmd->dateCommande."'";
|
|
$commandesM->update($data, $where);
|
|
} else {
|
|
//Lister les fichier en erreur
|
|
$emailTxt.= '<tr>';
|
|
$emailTxt.= '<td style="padding:5px">'.$cmd->siren.'</td>';
|
|
$emailTxt.= '<td style="padding:5px">'.$cmd->type.'</a></td>';
|
|
$emailTxt.= '<td style="padding:5px">'.$cmd->ref.'</a></td>';
|
|
$emailTxt.= '<td style="padding:5px">'.$cmd->dateCommande.'</td>';
|
|
$emailTxt.= '<td style="padding:5px">'.$cmd->url.'</td>';
|
|
$emailTxt.= '<td style="padding:5px">'.$cmd->erreur.'</td>';
|
|
$emailTxt.= '</tr>';
|
|
}
|
|
}
|
|
$emailTxt.= '</tbody>';
|
|
$emailTxt.= '</table>';
|
|
$emailTxt.= '<br/>';
|
|
$emailTxt = utf8_encode($emailTxt);
|
|
}
|
|
//Envoi mail
|
|
$mail = new Scores_Mail_Method();
|
|
$mail->setFromKey('production');
|
|
$mail->addTo('support@scores-decisions.com', 'Support');
|
|
$mail->addTo('supportdev@scores-decisions.com', 'Support Dev');
|
|
$mail->setSubject($sujet);
|
|
$mail->setBodyText($emailTxt);
|
|
$mail->execute();
|
|
} |