From fc6c215a0898c2c1ccceb291dc419f8f4a8d1237 Mon Sep 17 00:00:00 2001 From: Laurent Laffont <llaffont@afi-sa.fr> Date: Fri, 28 Apr 2017 11:57:11 +0200 Subject: [PATCH] hotline #55142 more debug logs + fix cosmo path --- .../cosmo/controllers/LogsController.php | 2 + .../cosmo/views/scripts/logs/debug.phtml | 1 + .../views/scripts/logs/integration.phtml | 1 + cosmogramme/php/classes/classe_cosmopaths.php | 4 + cosmogramme/php/classes/classe_log.php | 117 +++++++++--------- .../tests/php/classes/CosmoPathsTest.php | 29 +++++ .../WebService/BibNumerique/AbstractOAI.php | 18 ++- public/admin/css/global.css | 5 + public/admin/skins/bokeh74/global.css | 5 + 9 files changed, 120 insertions(+), 62 deletions(-) diff --git a/cosmogramme/cosmozend/application/modules/cosmo/controllers/LogsController.php b/cosmogramme/cosmozend/application/modules/cosmo/controllers/LogsController.php index 1ebd3d4d49c..c76e029af4c 100644 --- a/cosmogramme/cosmozend/application/modules/cosmo/controllers/LogsController.php +++ b/cosmogramme/cosmozend/application/modules/cosmo/controllers/LogsController.php @@ -29,11 +29,13 @@ class Cosmo_LogsController extends ZendAfi_Controller_Action { public function integrationAction() { + $this->view->titre = $this->_('Journal des intégrations du %s', $this->_getParam('day')); $this->view->contents = $this->getFileSystem()->fileGetContents($this->_logPath('integration')); } public function debugAction() { + $this->view->titre = $this->_('Journal technique du %s', $this->_getParam('day')); $this->view->contents = $this->getFileSystem()->fileGetContents($this->_logPath('debug')); } diff --git a/cosmogramme/cosmozend/application/modules/cosmo/views/scripts/logs/debug.phtml b/cosmogramme/cosmozend/application/modules/cosmo/views/scripts/logs/debug.phtml index 2e53089704e..a73db3cef17 100644 --- a/cosmogramme/cosmozend/application/modules/cosmo/views/scripts/logs/debug.phtml +++ b/cosmogramme/cosmozend/application/modules/cosmo/views/scripts/logs/debug.phtml @@ -1,3 +1,4 @@ +<h1><?php echo $this->titre ?></h1> <div> <?php echo nl2br($this->contents); diff --git a/cosmogramme/cosmozend/application/modules/cosmo/views/scripts/logs/integration.phtml b/cosmogramme/cosmozend/application/modules/cosmo/views/scripts/logs/integration.phtml index fe2696eea78..8395921351c 100644 --- a/cosmogramme/cosmozend/application/modules/cosmo/views/scripts/logs/integration.phtml +++ b/cosmogramme/cosmozend/application/modules/cosmo/views/scripts/logs/integration.phtml @@ -1,3 +1,4 @@ +<h1><?php echo $this->titre ?></h1> <div> <?php echo $this->contents; diff --git a/cosmogramme/php/classes/classe_cosmopaths.php b/cosmogramme/php/classes/classe_cosmopaths.php index c5b932b1f24..4eaac8a7c82 100644 --- a/cosmogramme/php/classes/classe_cosmopaths.php +++ b/cosmogramme/php/classes/classe_cosmopaths.php @@ -35,6 +35,10 @@ class CosmoPaths { while ((count($parts)>0) && (end($parts) !== static::$_dir_name)) array_pop($parts); array_pop($parts); + + if (empty($parts)) + return './'; + return ($this->isWindowsPath() ? '' : '/') . implode('/', $parts) . '/'; } diff --git a/cosmogramme/php/classes/classe_log.php b/cosmogramme/php/classes/classe_log.php index 2883eca86e2..a70e7bb30ad 100644 --- a/cosmogramme/php/classes/classe_log.php +++ b/cosmogramme/php/classes/classe_log.php @@ -22,49 +22,50 @@ // LOGS //////////////////////////////////////////////////////////////////////// -class Class_log -{ - private $path; // Chemin pour les logs - private $fic; // Handle du fichier - private $typeLog; // Type de fichier log (préfixe du nom de fichier) - private $maxLog; // Nombre maxi de fichiers pour 1 type de log - private $afficher; // Afficher à l'écran ou pas - private $entete; // Entetes pour les logs de type tableau +class Class_log { + use Trait_Translator; + + private $path; // Chemin pour les logs + private $fic; // Handle du fichier + private $typeLog; // Type de fichier log (préfixe du nom de fichier) + private $maxLog; // Nombre maxi de fichiers pour 1 type de log + private $afficher; // Afficher à l'écran ou pas + private $entete; // Entetes pour les logs de type tableau // ---------------------------------------------------------------- // Contructeur // ---------------------------------------------------------------- - function __construct($typeLog,$afficher=true) - { - $this->typeLog = $typeLog; - $this->afficher=$afficher; - $this->path=getVariable("log_path"); - if(!$this->path) afficherErreur("La variable : log_path n'est pas définie."); - if( strRight($this->path,1) != "/" ) $this->path .="/"; - $this->maxLog=getVariable("log_max"); - if(!$this->maxLog) $this->maxLog=100; - - // Entetes - if($typeLog=="erreur") $this->entete=array("n°","Bibliothèque","Type d'opération","Erreur"); - elseif($typeLog=="warning") $this->entete=array("n°","Bibliothèque","Type d'opération","Alerte","Valeur"); - } + function __construct($typeLog,$afficher=true) + { + $this->typeLog = $typeLog; + $this->afficher=$afficher; + $this->path = getVariable("log_path"); + if(!$this->path) afficherErreur("La variable : log_path n'est pas définie."); + if( strRight($this->path,1) != "/" ) $this->path .="/"; + $this->maxLog=getVariable("log_max"); + if(!$this->maxLog) $this->maxLog=100; + + // Entetes + if($typeLog=="erreur") $this->entete=array("n°","Bibliothèque","Type d'opération","Erreur"); + elseif($typeLog=="warning") $this->entete=array("n°","Bibliothèque","Type d'opération","Alerte","Valeur"); + } // ---------------------------------------------------------------- // Ouverture fichier // ---------------------------------------------------------------- - public function open($append=0) { - // Controle de l'historique - if($append==0) { + public function open($append=0) { + // Controle de l'historique + if($append==0) { $this->_removeOldLogs(); } - // Ouverture du nouveau log - $nom = $this->path . $this->typeLog . "_" . dateDuJour(0) .".log"; - //if($append == true )$mode="a"; else $mode="w"; - $mode='a'; // test en mode append systematique - umask(0002); - $this->fic =fopen($nom, $mode); - } + // Ouverture du nouveau log + $nom = $this->path . $this->typeLog . "_" . dateDuJour(0) .".log"; + $mode='a'; // test en mode append systematique + umask(0002); + if (!$this->fic = fopen($nom, $mode)) + throw new RuntimeException($this->_('Impossible de créer le fichier de log: %s', $nom)); + } protected function _removeOldLogs() { @@ -89,52 +90,52 @@ class Class_log // ---------------------------------------------------------------- // Ecrire // ---------------------------------------------------------------- - public function log($texte) { - global $mode_cron; - fwrite($this->fic, $texte ."\n"); - if($this->afficher == false) return false; + public function log($texte) { + global $mode_cron; + fwrite($this->fic, $texte ."\n"); + if($this->afficher == false) return false; - if($mode_cron) { + if($mode_cron) { $texte=strip_tags($texte); if(trim($texte)) print($texte ."\n"); } - else + else print($texte); - flush(); - } + flush(); + } // ---------------------------------------------------------------- // Taille des logs // ---------------------------------------------------------------- - public function getTailleLogs() - { - // Parse directory - @$dir = opendir( $this->path) or AfficherErreur("Impossible d'ouvrir le dossier des logs : " .$this->path); - $taille=0; - $nb_fic=0; - while (($file = readdir($dir)) !== false) + public function getTailleLogs() + { + // Parse directory + @$dir = opendir( $this->path) or AfficherErreur("Impossible d'ouvrir le dossier des logs : " .$this->path); + $taille=0; + $nb_fic=0; + while (($file = readdir($dir)) !== false) { $fic=$this->path.$file; if(!is_file($fic)) continue; $nb_fic++; $taille+=filesize($fic); } - $ret["nb_fic"]=$nb_fic; - $ret["taille"]=(int)($taille / 1024); - $ret["taille"]=number_format($ret["taille"], 0, ',', ' ')." ko"; - return $ret; - } + $ret["nb_fic"]=$nb_fic; + $ret["taille"]=(int)($taille / 1024); + $ret["taille"]=number_format($ret["taille"], 0, ',', ' ')." ko"; + return $ret; + } - public function close() { - fclose($this->fic); - } + public function close() { + fclose($this->fic); + } - public function error($message) { - $this->log('<br><span class="rouge">'.$message.'</span><br>'); - } + public function error($message) { + $this->log('<br><span class="rouge">'.$message.'</span><br>'); + } public function success($message) { diff --git a/cosmogramme/tests/php/classes/CosmoPathsTest.php b/cosmogramme/tests/php/classes/CosmoPathsTest.php index 962902accea..41b4ace6588 100644 --- a/cosmogramme/tests/php/classes/CosmoPathsTest.php +++ b/cosmogramme/tests/php/classes/CosmoPathsTest.php @@ -244,4 +244,33 @@ class CosmoPathsFromGitlabCiRunnerTest extends PHPUnit_Framework_TestCase { } + + +class CosmoPathsFromCommandLineAtRootTest extends PHPUnit_Framework_TestCase { + protected $_cosmo_paths; + + public function setUp() { + parent::setUp(); + unset($_SERVER); + $_SERVER = ['SCRIPT_NAME' => 'cosmogramme/php/integre_traite_main.php', + 'SCRIPT_FILENAME' => 'cosmogramme/php/integre_traite_main.php']; + $this->_cosmo_paths = new CosmoPaths(); + $this->_cosmo_paths->setFileSystem(Storm_Test_ObjectWrapper::mock() + ->whenCalled('getcwd') + ->answers('/srv/http/bokeh.fr')); + } + + /** @test */ + public function configPathShouldBeCosmogrammeConfigDotPhp() { + $this->assertEquals('./cosmogramme/config.php', $this->_cosmo_paths->getConfigPath()); + } + + + /** @test */ + public function configIniPathShouldBeConfigIni() { + $this->assertEquals('./config.ini', $this->_cosmo_paths->getBokehConfigPath()); + } + +} + ?> \ No newline at end of file diff --git a/library/Class/WebService/BibNumerique/AbstractOAI.php b/library/Class/WebService/BibNumerique/AbstractOAI.php index 1a4cc0809e4..bea20e00742 100644 --- a/library/Class/WebService/BibNumerique/AbstractOAI.php +++ b/library/Class/WebService/BibNumerique/AbstractOAI.php @@ -23,11 +23,17 @@ abstract class Class_WebService_BibNumerique_AbstractOAI extends Class_WebService_BibNumerique_Abstract { use Trait_Translator; - protected $_harvested_ids = [], $_oaiws; + protected + $_harvested_ids = [], + $_oaiws; public function harvest() { - while($this->getOaiWS()->hasRecordsToHarvest()) - $this->addHarvestedIds($this->_importRessources($this->loadPage())); + $page = 0; + + while($this->getOaiWS()->hasRecordsToHarvest()) { + $page = $page + 1; + $this->addHarvestedIds($this->_importRessources($this->loadPage($page))); + } return $this->_logRun(); } @@ -41,7 +47,11 @@ abstract class Class_WebService_BibNumerique_AbstractOAI extends Class_WebServic protected function loadPage($page_number = 1) { - $this->getLogger()->log($this->_('Traitement de la page %d', $page_number), '*'); + $this->getLogger()->log($this->_('Traitement de la page %d (nombre d\'enregistrements: %d)', + $page_number, + $this->getOaiWS()->getTotalNumberOfRecords()), + 'debug'); + return $this->getOaiWS() ->getRecordsResourcesNumerique($this->_addFromTo([])); } diff --git a/public/admin/css/global.css b/public/admin/css/global.css index 4add6a93cb7..3cbe5b1cc85 100644 --- a/public/admin/css/global.css +++ b/public/admin/css/global.css @@ -1520,3 +1520,8 @@ div.ColorPickerDivSample { [class*=edit-multiple] .modules form tr:hover { background-color: rgba(0, 0 , 0 , 0.15); } + + +table#logs img { + vertical-align: middle; +} \ No newline at end of file diff --git a/public/admin/skins/bokeh74/global.css b/public/admin/skins/bokeh74/global.css index 3f9e3332506..10ba904efb4 100755 --- a/public/admin/skins/bokeh74/global.css +++ b/public/admin/skins/bokeh74/global.css @@ -863,3 +863,8 @@ form .droite { .modules .bokeh-days > a:hover { color: #6AA5FF; } + + +table#logs img { + vertical-align: middle; +} \ No newline at end of file -- GitLab