2011-12-09 08:01:53 +00:00
#!/usr/bin/php -q
< ? php
// Define path to application directory
defined ( 'APPLICATION_PATH' )
2012-11-16 09:34:42 +00:00
|| define ( 'APPLICATION_PATH' , realpath ( dirname ( __FILE__ ) . '/../../application' ));
2011-12-09 08:01:53 +00:00
// Define application environment
defined ( 'APPLICATION_ENV' )
2012-11-16 09:34:42 +00:00
|| define ( 'APPLICATION_ENV' , ( getenv ( 'APPLICATION_ENV' ) ? getenv ( 'APPLICATION_ENV' ) : 'production' ));
2011-12-09 08:01:53 +00:00
// Ensure library/ is on include_path
set_include_path ( implode ( PATH_SEPARATOR , array (
2012-11-16 09:34:42 +00:00
realpath ( APPLICATION_PATH . '/../library' ),
get_include_path (),
2011-12-09 08:01:53 +00:00
)));
/** Zend_Application */
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 ();
2012-11-02 20:26:44 +00:00
} catch ( Zend_Console_Getopt_Exception $e ) {
2011-12-09 08:01:53 +00:00
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 ;
}
2012-11-16 09:34:42 +00:00
$c = new Zend_Config ( $application -> getOptions ());
Zend_Registry :: set ( 'config' , $c );
2012-11-16 14:12:03 +00:00
define ( 'PATH_DATA' , $c -> profil -> path -> data );
2011-12-09 08:01:53 +00:00
/**
* Connexion à la base de données
*/
2012-11-16 14:12:03 +00:00
$db = Zend_Db :: factory ( $c -> profil -> db -> sdv1 );
2011-12-09 08:01:53 +00:00
Zend_Db_Table_Abstract :: setDefaultAdapter ( $db );
2012-01-30 09:19:07 +00:00
$db -> setFetchMode ( Zend_Db :: FETCH_OBJ );
2011-12-09 08:01:53 +00:00
2012-11-02 20:26:44 +00:00
if ( isset ( $opts -> reprise ) )
2011-12-09 08:01:53 +00:00
{
2013-01-30 09:58:51 +00:00
$timestamp = mktime ( 0 , 0 , 0 , date ( " m " ), date ( " d " ) - 5 , date ( " Y " ));
$daybefore = date ( 'Y-m-d' , $timestamp );
$commandesM = new Application_Model_CommandesErreur ();
2013-02-04 12:41:29 +00:00
$sql = $commandesM -> select () -> where ( " dateReception='0000-00-00 00:00:00' AND dateCommande > ' " . $daybefore . " 00:00:00' " );
2011-12-09 08:01:53 +00:00
$repErreur = $commandesM -> fetchAll ( $sql );
2013-01-30 08:49:20 +00:00
2011-12-09 08:01:53 +00:00
if ( count ( $repErreur ) == 0 ) exit ;
2013-01-30 08:49:20 +00:00
2011-12-09 08:01:53 +00:00
foreach ( $repErreur as $cmd )
{
2012-11-02 21:45:08 +00:00
require_once 'Infogreffe/Infogreffe.php' ;
2011-12-09 08:01:53 +00:00
$infogreffe = new Infogreffe ();
switch ( $cmd -> type ){
case 'acte' :
2013-04-02 14:02:21 +00:00
$path = $infogreffe -> actePath ( $cmd -> ref );
2012-11-16 09:34:42 +00:00
$fichier = $infogreffe -> acteFilename ( $cmd -> siren , $cmd -> ref );
2011-12-09 08:01:53 +00:00
break ;
case 'bilan' :
2013-05-14 15:46:35 +00:00
$path = $infogreffe -> bilanPath ( '0000_' . $cmd -> ref );
2013-01-30 09:43:38 +00:00
$fichier = $infogreffe -> bilanFilename ( $cmd -> siren , '0000_' . $cmd -> ref );
2011-12-09 08:01:53 +00:00
break ;
}
2013-04-19 10:15:34 +00:00
echo date ( 'Y-m-d\TH:i:s' ) . ' - ' . $path . $fichier . " = " ;
2013-02-12 17:51:26 +00:00
$dl = $infogreffe -> dl ( $path . $fichier , $cmd -> url , false );
2013-01-30 09:25:36 +00:00
echo $dl . " \n " ;
2011-12-09 08:01:53 +00:00
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 );
}
}
2013-01-30 08:49:20 +00:00
2011-12-09 08:01:53 +00:00
}
2012-11-02 20:26:44 +00:00
if ( isset ( $opts -> rapport ) || isset ( $opts -> rapportcomplet ) )
2011-12-09 08:01:53 +00:00
{
$commandesM = new Application_Model_CommandesErreur ();
if ( isset ( $opts -> rapportcomplet )) {
2013-01-30 08:49:20 +00:00
$sql = $commandesM -> select () -> where ( " erreur!='' AND dateReception='0000-00-00 00:00:00' " )
-> order ( " dateCommande ASC " );
2011-12-09 08:01:53 +00:00
$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 ;
2013-01-30 08:49:20 +00:00
$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 " );;
2011-12-09 08:01:53 +00:00
}
$repErreur = $commandesM -> fetchAll ( $sql );
2013-01-30 08:49:20 +00:00
2011-12-09 08:01:53 +00:00
$emailTxt = '<b><u>Commandes Greffe - Erreur WebService</u></b>' ;
$emailTxt .= '<br/>' ;
if ( count ( $repErreur ) == 0 ) {
2013-01-30 08:49:20 +00:00
2011-12-09 08:01:53 +00:00
$emailtTxt .= " Aucune commande en erreur ! " ;
2013-01-30 08:49:20 +00:00
2011-12-09 08:01:53 +00:00
} 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 )
{
2012-11-02 21:45:08 +00:00
require_once 'Infogreffe/Infogreffe.php' ;
2011-12-09 08:01:53 +00:00
$infogreffe = new Infogreffe ();
switch ( $cmd -> type ){
case 'acte' :
2013-04-02 14:02:21 +00:00
$path = $infogreffe -> actePath ( $cmd -> ref );
2011-12-09 08:01:53 +00:00
$fichier = $infogreffe -> acteFilename ( $cmd -> siren , $cmd -> ref );
break ;
case 'bilan' :
2013-05-14 15:46:35 +00:00
2013-04-02 14:02:21 +00:00
$path = $infogreffe -> bilanPath ( $cmd -> ref );
2013-05-14 15:46:35 +00:00
$fichier = $infogreffe -> bilanFilename ( $cmd -> siren , $cmd -> ref );
2011-12-09 08:01:53 +00:00
break ;
}
//Le fichier existe, alors on a résolu le problème (mauellement ?)
2013-04-02 14:03:55 +00:00
if ( file_exists ( PATH_DATA . $path . $fichier ) ) {
2011-12-09 08:01:53 +00:00
$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
require_once 'Scores/Mail.php' ;
$mail = new Mail ();
$mail -> setFrom ( 'production' );
2012-11-16 09:34:42 +00:00
$mail -> addTo ( 'support@scores-decisions.com' , 'Support' );
$mail -> addTo ( 'supportdev@scores-decisions.com' , 'Support Dev' );
2011-12-09 08:01:53 +00:00
$mail -> setSubject ( $sujet );
$mail -> setBodyTexte ( $emailTxt );
$mail -> send ();
}