From abd03f95dfaf2d28f5797db026415dea96d485cf Mon Sep 17 00:00:00 2001 From: Michael RICOIS Date: Sat, 3 Nov 2012 14:08:33 +0000 Subject: [PATCH] issue #0001090 : Integrate all changes from branch 2.3 --- .../controllers/DashboardController.php | 2 +- application/controllers/FichierController.php | 2 +- application/controllers/PiecesController.php | 12 ++--- batch/getActes.php | 2 +- batch/greffeCmdTelechargement.php | 4 +- library/Infogreffe/Infogreffe.php | 44 ++++++++++++++++--- 6 files changed, 48 insertions(+), 18 deletions(-) diff --git a/application/controllers/DashboardController.php b/application/controllers/DashboardController.php index 23d362465..d6710f31a 100644 --- a/application/controllers/DashboardController.php +++ b/application/controllers/DashboardController.php @@ -391,7 +391,7 @@ class DashboardController extends Zend_Controller_Action $document = 'Bilan de '.$matches[1]; - require_once 'Scores/Infogreffe.php'; + require_once 'Infogreffe/Infogreffe.php'; $infogreffe = new Infogreffe(); $path = $infogreffe->bilanPath($listCommandes[$i]->refDocument); $fichier = $infogreffe->bilanFilename($listCommandes[$i]->siren, $listCommandes[$i]->refDocument); diff --git a/application/controllers/FichierController.php b/application/controllers/FichierController.php index 8a13764b7..59443215e 100644 --- a/application/controllers/FichierController.php +++ b/application/controllers/FichierController.php @@ -99,7 +99,7 @@ class FichierController extends Zend_Controller_Action $file = $this->getRequest()->getParam('fichier'); $configuration = Zend_Registry::get('configuration'); //bilan - if (preg_match('/^bilan-(consolide|sociaux)-([0-9]{8})/', $file, $matches)) { + if (preg_match('/^bilan-[0-9]{9}-(consolides|sociaux)-([0-9]{8})/', $file, $matches)) { $directory = realpath($configuration->path->data). '/'.'greffes/bilans/'.$matches[1].'/'.substr($matches[2],0,4); } diff --git a/application/controllers/PiecesController.php b/application/controllers/PiecesController.php index 855b75ae8..ef0c3d06a 100644 --- a/application/controllers/PiecesController.php +++ b/application/controllers/PiecesController.php @@ -772,12 +772,12 @@ class PiecesController extends Zend_Controller_Action $ws->setLog('greffe_bilans', $siren, 0, $ref); $info = unserialize($info); - require_once 'Scores/Infogreffe.php'; + require_once 'Infogreffe/Infogreffe.php'; $infogreffe = new Infogreffe(); $path = $infogreffe->bilanPath($ref); $file = $infogreffe->bilanFilename($siren, $ref); - $href = '/fichier/'.$path.$file; + $href = '/fichier/pdf/'.$file; echo '
Ouvrir le bilan millésime '.$info['type'].''; break; @@ -830,12 +830,12 @@ class PiecesController extends Zend_Controller_Action $repErreur = $erreur->fetchAll($sql)->toArray(); if (count($repErreur)>0){ //Téléchagement - require_once 'Scores/Infogreffe.php'; + require_once 'Infogreffe/Infogreffe.php'; $infogreffe = new Infogreffe(); $path = $infogreffe->bilanPath($ref); $fichier = $infogreffe->bilanFilename($siren, $ref); - if (infogreffe_dl($fichier, $repErreur[0]['url'], false)) { + if ($infogreffe->dl($fichier, $repErreur[0]['url'], false)) { $erreur->update(array('erreur'=>''), "siren='$siren' AND type='bilan' AND ref='$ref'"); $ws->setLog('greffe_bilans', $siren, 0, $ref); echo '
Ouvrir le fichier '.$info['type_lib'].' '; @@ -845,7 +845,7 @@ class PiecesController extends Zend_Controller_Action } else { - require_once 'Scores/Infogreffe.php'; + require_once 'Infogreffe/Infogreffe.php'; $infogreffe = new Infogreffe(); $reponse = $infogreffe->getGreffeBilans($siren, $vecteur, $ref); @@ -865,7 +865,7 @@ class PiecesController extends Zend_Controller_Action if($item['url_acces']!==false) { $ws->setLog('greffe_bilans', $siren, 0, $ref); $path = $infogreffe->bilanPath($ref); - $href = '/fichier/'.$path.$item['url_acces']; + $href = '/fichier/pdf/'.$item['url_acces']; echo '
Ouvrir le bilan millésime '.$item['millesime'].''; } else { $ws->setLog('greffe_bilans', $siren, 0, 'Erreur telechargement '.$ref); diff --git a/batch/getActes.php b/batch/getActes.php index e9d9095cf..1a0ad7c46 100644 --- a/batch/getActes.php +++ b/batch/getActes.php @@ -205,7 +205,7 @@ foreach ($tabCommandes as $ref => $commande){ $sirenC = $commande['siren']; $refC = $commande['refDocument']; - require_once 'Scores/Infogreffe.php'; + require_once 'Infogreffe/Infogreffe.php'; $infogreffe = new Infogreffe(); if (preg_match('/^([0-9]{4}_).*?$/', $refC, $matches)){ $path = $infogreffe->bilanPath($refC); diff --git a/batch/greffeCmdTelechargement.php b/batch/greffeCmdTelechargement.php index 9ca7fb3c2..042ab3984 100644 --- a/batch/greffeCmdTelechargement.php +++ b/batch/greffeCmdTelechargement.php @@ -70,7 +70,7 @@ if ( isset($opts->reprise) ) foreach($repErreur as $cmd) { - require_once 'Scores/Infogreffe.php'; + require_once 'Infogreffe/Infogreffe.php'; $infogreffe = new Infogreffe(); switch($cmd->type){ case 'acte': @@ -127,7 +127,7 @@ if ( isset($opts->rapport) || isset($opts->rapportcomplet) ) $emailTxt.= ''; foreach($repErreur as $cmd) { - require_once 'Scores/Infogreffe.php'; + require_once 'Infogreffe/Infogreffe.php'; $infogreffe = new Infogreffe(); switch($cmd->type){ case 'acte': diff --git a/library/Infogreffe/Infogreffe.php b/library/Infogreffe/Infogreffe.php index 632a31834..67a10b2b9 100644 --- a/library/Infogreffe/Infogreffe.php +++ b/library/Infogreffe/Infogreffe.php @@ -605,11 +605,26 @@ class Infogreffe $siren = $depot['num_siren']; } $fichier = $this->pathData.$this->actePath($ref).$this->acteFilename($siren,$ref); + Zend_Registry::get('firebug')->info($fichier); if( file_exists($fichier) && filesize($fichier)>0 ) { $mode = 'fichier'; $file_exist = true; } + + //As type_acte change, try to detect file by a pattern + //acte-388048308-ACSSPRH-20090630-9201-00-B-01374-30975-02.pdf + $filePattern = $this->acteFilename($siren,$ref); + $posBegin = 15; + $posEnd = strpos($filePattern, '-', $posBegin); + $filePattern = substr_replace($filePattern, '*', $posBegin, $posEnd-$posBegin); + Zend_Registry::get('firebug')->info($filePattern); + $detectedFiles = glob($this->pathData.$this->actePath($ref).$filePattern); + if ($detectedFiles!==false && count($detectedFiles)>0) { + $ref = str_replace('.pdf', '',substr(basename($detectedFiles[0]),15)); + $mode = 'fichier'; + $file_exist = true; + } //Génération date (date_acte peut être vide) if(!empty($acte['date_acte'])){ $date = WDate::dateT('Y-m-d', 'Ymd', $acte['date_acte']); } @@ -711,9 +726,10 @@ class Infogreffe } else { $siren = $bilan['num_siren']; } - + //Cas de fichier correspondant à la référence $fichier = $this->pathData.$this->bilanPath($ref).$this->bilanFilename($siren,$ref); + Zend_Registry::get('firebug')->info('Fichier : '.$fichier); if( file_exists($fichier) && filesize($fichier)>0 ) { $mode = 'fichier'; @@ -1157,7 +1173,10 @@ class Infogreffe preg_match('/^([0-9]{4})_([a-z]{0,})-([0-9]{8})/', $ref, $matches); $type = $matches[2]; $dateCloture = $matches[3]; - return 'bilan-'.$siren.'-'.type.'-'.$dateCloture.'.pdf'; + if ($type=='') { + $type = 'sociaux'; + } + return 'bilan-'.$siren.'-'.$type.'-'.$dateCloture.'.pdf'; } function bilanPath($ref) @@ -1165,6 +1184,9 @@ class Infogreffe preg_match('/^([0-9]{4})_([a-z]{0,})-([0-9]{8})/', $ref, $matches); $type = $matches[2]; $dateCloture = $matches[3]; + if ($type=='') { + $type = 'sociaux'; + } return '/greffes/bilans/'.$type.'/'.substr($dateCloture,0,4).'/'; } @@ -1183,6 +1205,9 @@ class Infogreffe if ( !is_dir($path.$wholePath) ) { mkdir($path.$wholePath, 0777, true); } + + Zend_Registry::get('firebug')->info($fichier); + Zend_Registry::get('firebug')->info($url); if(!file_exists($path.$fichier) || !filesize($path.$fichier)>2000) { @@ -1197,13 +1222,18 @@ class Infogreffe } if( ($page['code']!=408 || $page['code']!=400) && substr($body,0,4)=='%PDF') { //Ecriture du fichier sur le serveur en local - file_put_contents($path.$fichier, $body); - $return = $fichier; - $erreurDL = ''; + Zend_Registry::get('firebug')->info($path.$fichier); + if ( file_put_contents($path.$fichier, $body) ) { + $return = basename($fichier); + $erreurDL = ''; + } else { + $return = false; + $erreurDL = "Erreur lors de l'ecriture du fichier"; + } } if ($trace) { $erreur = new Application_Model_CommandesErreur(); - preg_match('/^(acte|bilan)-([0-9]{9})-(.*)\.pdf$/', $fichier, $ref); + preg_match('/(acte|bilan)-([0-9]{9})-(.*)\.pdf$/', $fichier, $ref); $data = array( 'siren' => $ref[2], 'type' => $ref[1], @@ -1215,7 +1245,7 @@ class Infogreffe $erreur->insert($data); } } else { - $return = $fichier; + $return = basename($fichier); } return $return; }