From 5e4734fef411d929a80d8fbeabde84a1115f39f6 Mon Sep 17 00:00:00 2001 From: Laurent Laffont <llaffont@afi-sa.fr> Date: Tue, 23 Oct 2018 15:35:17 +0200 Subject: [PATCH] hotline #80953 refactoring --- VERSIONS_HOTLINE/80953 | 1 + library/Class/Cosmogramme/Generator.php | 332 +----------------- .../Cosmogramme/Generator/AbstractTask.php | 24 +- .../Cosmogramme/Generator/BranchesTask.php | 12 +- .../Class/Cosmogramme/Generator/KindsTask.php | 2 +- .../Cosmogramme/Generator/LibrariesTask.php | 118 +++++++ .../Generator/PlannedIntegrationsTask.php | 247 +++++++++++++ 7 files changed, 396 insertions(+), 340 deletions(-) create mode 100644 VERSIONS_HOTLINE/80953 create mode 100644 library/Class/Cosmogramme/Generator/LibrariesTask.php create mode 100644 library/Class/Cosmogramme/Generator/PlannedIntegrationsTask.php diff --git a/VERSIONS_HOTLINE/80953 b/VERSIONS_HOTLINE/80953 new file mode 100644 index 00000000000..bc311295e4e --- /dev/null +++ b/VERSIONS_HOTLINE/80953 @@ -0,0 +1 @@ + - ticket #80953 : [Story] Nanook 4.1 CARACTERES ACCENTUES étalon \ No newline at end of file diff --git a/library/Class/Cosmogramme/Generator.php b/library/Class/Cosmogramme/Generator.php index d66e45e75a0..39e8774e8ea 100644 --- a/library/Class/Cosmogramme/Generator.php +++ b/library/Class/Cosmogramme/Generator.php @@ -97,110 +97,16 @@ class Class_Cosmogramme_Generator { protected function _generateLibraries() { - if (!$libraries = $this->getLandingDirectory()->getLibrariesOf($this->_params['path_ftp'])) { - $this->logError($this->_('Étalon des bibliothèques vide')); - return false; - } + $libraries = $this->getLandingDirectory()->getLibrariesOf($this->_params['path_ftp']); - $this->_disableDeletedLibraries($libraries); - $this->_generateLibrariesEntities($libraries); + (new Class_Cosmogramme_Generator_LibrariesTask($this, $this->_params))->run($libraries); $this->_generateLibrariesBranches($libraries); - $this->_generatePlannedIntegrations($libraries); + (new Class_Cosmogramme_Generator_PlannedIntegrationsTask($this, $this->_params))->run($libraries); return true; } - protected function _disableDeletedLibraries($libraries) { - if ((!$ids = $this->_librariesIdsFrom($libraries)) - || !$libs = Class_IntBib::findAllBy(['id_bib not' => $ids])) - return; - - foreach($libs as $lib) - $this->_disableDeletedLibrary($lib); - } - - - protected function _disableDeletedLibrary($library) { - $library->beDisconnected()->save(); - Class_IntMajAuto::deleteBy(['id_bib' => $library->getId()]); - } - - - protected function _librariesIdsFrom($datas) { - if (!$datas) - return []; - - $ids = []; - foreach($datas as $data) - if ($elem = $this->_extractLibraryData($data)) - $ids[] = $elem[0]; - - return $ids; - } - - - protected function _generateLibrariesEntities($libraries) { - $this->logTitle($this->_('1 - Création des bibliothèques')); - - $html = ''; - foreach ($libraries as $data) - $html .= $this->_generateLibrary($data); - - $this->log('<div class="liste"><table class="blank">' . $html . '</table></div>'); - } - - - protected function _generateLibrary($data) { - if (!$elem = $this->_extractLibraryData($data)) - return ''; - - if (!$bib = Class_Cosmogramme_Generator_FixedIdBib::findFirstBy(['id_site' => $elem[0]])) - $bib = Class_Cosmogramme_Generator_FixedIdBib::newInstance(['ville' => $this->_params['path_ftp']]); - - $bib->updateAttributes(['id_site' => $elem[0], - 'libelle' => trim($elem[1]), - 'id_zone' => 1, - 'visibilite' => Class_Bib::V_DATA]); - - if (!$int_bib = Class_IntBib::findFirstBy(['id_bib' => $bib->getIdSite()])) - $int_bib = Class_IntBib::newInstance(['id_bib' => $bib->getIdSite(), - 'qualite' => 5, - 'sigb' => $this->_params['type_sigb'], - 'planif_mode' => 'r', - 'planif_jours' => '1111111']); - - $int_bib->updateAttributes(['nom' => $bib->getLibelle(), - 'nom_court' => $bib->getLibelle()]); - - $this->_generateNewLibrary($int_bib); - - $int_bib->save(); - // bib after save auto create int_bib and we need Storm::isNew - $bib->save(); - - return '<tr><td class="blank">Site n° '. $bib->getIdSite() . '</td><td class="blank">'. $bib->getLibelle() . '</td></tr>'; - } - - - protected function _generateNewLibrary($int_bib) - { - if (!$int_bib->isNew()) - return $int_bib; - - if ($int_bib->isNanook()) - return $int_bib - ->setCommSigb(Class_IntBib::COM_NANOOK) - ->setCommParams(serialize(['url_serveur' => $this->_params['service_nanook']])); - - return $int_bib - ->setCommSigb(Class_IntBib::COM_PERGAME) - ->setCommParams(serialize(['Autoriser_docs_disponibles' => '0', - 'Max_par_carte' => '3', - 'Max_par_document' => '3'])); - } - - protected function _generateLibrariesBranches($libraries) { if ('1' != $this->_params['creer_annexes']) { $this->logTitle($this->_('2 - Création des annexes')); @@ -208,53 +114,25 @@ class Class_Cosmogramme_Generator { return; } - return (new Class_Cosmogramme_Generator_BranchesTask($this))->run($libraries); - } - - - protected function _generatePlannedIntegrations($libraries) { - $this->logTitle($this->_('3 - Programmation des intégrations')); - - $html = ''; - foreach ($libraries as $data) - $html .= $this->_generatePlannedIntegration($data); - - $this->log('<div class="liste"><table class="blank">' . $html . '</table></div>'); - } - - - protected function _generatePlannedIntegration($data) { - if (!$elem = $this->_extractLibraryData($data)) - return ''; - - $id_bib = $elem[0]; - Class_IntMajAuto::deleteBy(['id_bib' => $id_bib]); - return $this->getPlannedGenerator()->plan($id_bib, $this->_params['path_ftp']); - } - - - protected function getPlannedGenerator() { - return $this->isNanook() - ? new Class_Cosmogramme_GeneratorPlannedNanook() - : new Class_Cosmogramme_GeneratorPlannedPergame(); + return (new Class_Cosmogramme_Generator_BranchesTask($this, $this->_params))->run($libraries); } protected function _generateSections() { $sections = $this->getLandingDirectory()->getSectionsOf($this->_params['path_ftp']); - return (new Class_Cosmogramme_Generator_SectionsTask($this))->run($sections); + return (new Class_Cosmogramme_Generator_SectionsTask($this, $this->_params))->run($sections); } protected function _generateLocations() { $locations = $this->getLandingDirectory()->getLocationsOf($this->_params['path_ftp']); - return (new Class_Cosmogramme_Generator_LocationsTask($this))->run($locations); + return (new Class_Cosmogramme_Generator_LocationsTask($this, $this->_params))->run($locations); } protected function _generateKinds() { $kinds = $this->getLandingDirectory()->getKindsOf($this->_params['path_ftp']); - return (new Class_Cosmogramme_Generator_KindsTask($this))->run($kinds); + return (new Class_Cosmogramme_Generator_KindsTask($this, $this->_params))->run($kinds); } @@ -340,14 +218,6 @@ class Class_Cosmogramme_Generator { public function getLastError() { return $this->_last_error; } - - - protected function _extractLibraryData($data) { - $data = utf8_encode($data); - $elem = explode('|', $data); - - return ($elem[0] == 'BIB_SPS_UTT') ? [] : $elem; - } } @@ -404,190 +274,4 @@ class Class_Cosmogramme_GeneratorProfilesPergameValidator [102, 'Prêts Pergame', Class_IntProfilDonnees::FT_LOANS], [103, 'Réservations Pergame', Class_IntProfilDonnees::FT_HOLDS]]; } -} - - - -class Class_Cosmogramme_GeneratorPlannedAbstract { - use Trait_Translator, Trait_Loggable; - - protected - $_id_bib, - $_id_prog, - $_base_path, - $_html = '', - $_records_profile, - $_users_profile, - $_loans_profile = 102, - $_holds_profile = 103, - $_item_delete = false, - $_holds = false, - $_baskets = false; - - public function plan($id_bib, $base_path) { - $this->_id_bib = $id_bib; - $this->_id_prog = $id_bib * 100; - $this->_base_path = $base_path . DIRECTORY_SEPARATOR . 'site' . $id_bib . DIRECTORY_SEPARATOR; - - $this - ->itemDeletion() - ->recordsTotal() - ->recordsPartial() - ->users() - ->loans() - ->holds() - ->basketsTotal() - ->basketsPartial(); - - return $this->_html; - } - - - protected function itemDeletion() { - if (!$this->_item_delete) - return $this; - - $profile = $this->_getBarCodeProfile(); - - return $this->planWith('Notices - suppression d\'exemplaires', - $profile->getId(), - Class_IntMajAuto::OP_ITEMS_DELETION, - 'suppressions.txt'); - } - - - protected function recordsTotal() { - return $this->planWith('Notices - import total', - $this->_records_profile, - Class_IntMajAuto::OP_FULL_IMPORT, - 'notices_total.txt'); - } - - - protected function recordsPartial() { - return $this->planWith('Notices - import incrémentiel', - $this->_records_profile, - Class_IntMajAuto::OP_PARTIAL_IMPORT, - 'notices.txt'); - } - - - protected function users() { - return $this->planWith('Abonnés', - $this->_users_profile, - Class_IntMajAuto::OP_FULL_IMPORT, - 'abonnes.txt'); - } - - - protected function loans() { - return $this->planWith('Prêts', - $this->_loans_profile, - Class_IntMajAuto::OP_FULL_IMPORT, - 'prets.txt'); - } - - - protected function holds() { - return $this->_holds - ? $this->planWith('Réservations', $this->_holds_profile, - Class_IntMajAuto::OP_FULL_IMPORT, 'reservations.txt') - : $this; - } - - - protected function basketsTotal() { - if (!$this->_baskets) - return $this; - - $profile = $this->_getBasketProfile(); - - return $this->planWith('Paniers - import total', - $profile->getId(), - Class_IntMajAuto::OP_FULL_IMPORT, - 'paniers_total.txt'); - } - - - protected function basketsPartial() { - if (!$this->_baskets) - return $this; - - $profile = $this->_getBasketProfile(); - - return $this->planWith('Paniers - import incrémentiel', - $profile->getId(), - Class_IntMajAuto::OP_PARTIAL_IMPORT, - 'paniers.txt'); - } - - - protected function planWith($name, $profile, $type, $file) { - $this->_html .= '<tr><td class="blank">Site n° '. $this->_id_bib . '</td><td class="blank">' . $name . '</td></tr>'; - $this->_id_prog++; - Class_IntMajAuto::newInstance(['id_bib' => $this->_id_bib, - 'libelle' => $name, - 'profil' => $profile, - 'type_operation' => $type, - 'nom_fichier' => $this->_base_path . $file, - 'rang' => $this->_id_prog]) - ->save(); - - return $this; - } - - - protected function _getBarCodeProfile() { - $label = 'Liste de codes-barres'; - if ($profile = Class_IntProfilDonnees::findFirstBy(['libelle' => $label])) - return $profile; - - - $attributs = 'a:6:{i:0;a:7:{s:8:"type_doc";a:11:{i:0;a:3:{s:4:"code";s:1:"0";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:1;a:3:{s:4:"code";s:1:"1";s:5:"label";s:5:"am;na";s:8:"zone_995";s:0:"";}i:2;a:3:{s:4:"code";s:1:"2";s:5:"label";s:2:"as";s:8:"zone_995";s:0:"";}i:3;a:3:{s:4:"code";s:1:"3";s:5:"label";s:3:"i;j";s:8:"zone_995";s:0:"";}i:4;a:3:{s:4:"code";s:1:"4";s:5:"label";s:1:"g";s:8:"zone_995";s:0:"";}i:5;a:3:{s:4:"code";s:1:"5";s:5:"label";s:3:"l;m";s:8:"zone_995";s:0:"";}i:6;a:3:{s:4:"code";s:1:"8";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:7;a:3:{s:4:"code";s:1:"9";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:8;a:3:{s:4:"code";s:2:"10";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:9;a:3:{s:4:"code";s:3:"100";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:10;a:3:{s:4:"code";s:2:"10";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}}s:17:"champ_code_barres";s:1:"f";s:10:"champ_cote";s:1:"k";s:11:"champ_genre";s:0:"";s:13:"champ_section";s:1:"q";s:17:"champ_emplacement";s:1:"u";s:12:"champ_annexe";s:1:"a";}i:1;a:1:{s:6:"champs";s:11:"code_barres";}i:2;a:1:{s:6:"champs";s:11:"code_barres";}i:3;a:1:{s:6:"champs";s:11:"code_barres";}i:5;a:3:{s:6:"champs";s:11:"code_barres";s:17:"xml_balise_abonne";s:0:"";s:17:"xml_champs_abonne";a:10:{s:6:"IDABON";s:0:"";s:9:"ORDREABON";s:0:"";s:3:"NOM";s:0:"";s:6:"PRENOM";s:0:"";s:9:"NAISSANCE";s:0:"";s:8:"PASSWORD";s:0:"";s:4:"MAIL";s:0:"";s:10:"DATE_DEBUT";s:0:"";s:8:"DATE_FIN";s:0:"";s:7:"ID_SIGB";s:0:"";}}i:4;a:5:{s:4:"zone";s:0:"";s:5:"champ";s:0:"";s:6:"format";s:0:"";s:5:"jours";s:0:"";s:7:"valeurs";s:0:"";}}'; - - $profile = Class_IntProfilDonnees::newInstance(['libelle' => $label, - 'accents' => Class_IntProfilDonnees::ENCODING_UTF8, - 'type_fichier' => Class_IntProfilDonnees::FT_RECORDS, - 'format' => Class_IntProfilDonnees::FORMAT_TABBED_ASCII, - 'attributs' => $attributs]); - $profile->save(); - return $profile; - } - - - protected function _getBasketProfile() { - if ($profile = Class_IntProfilDonnees::findFirstBy(['accents' => Class_IntProfilDonnees::ENCODING_UTF8, - 'type_fichier' => Class_IntProfilDonnees::FT_BASKETS, - 'format' => Class_IntProfilDonnees::FORMAT_PIPED_ASCII])) - return $profile; - - $profile = Class_IntProfilDonnees::newInstance(['libelle' => 'Paniers Nanook', - 'accents' => Class_IntProfilDonnees::ENCODING_UTF8, - 'rejet_periodiques' => 0, - 'id_article_periodique' => 4, - 'type_fichier' => Class_IntProfilDonnees::FT_BASKETS, - 'format' => Class_IntProfilDonnees::FORMAT_PIPED_ASCII, - 'attributs' => 'a:7:{i:0;a:9:{s:8:"type_doc";a:35:{i:0;a:3:{s:4:"code";s:1:"0";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:1;a:3:{s:4:"code";s:1:"1";s:5:"label";s:8:"am;na;mn";s:8:"zone_995";s:9:"LIV;MS;uu";}i:2;a:3:{s:4:"code";s:1:"2";s:5:"label";s:2:"as";s:8:"zone_995";s:3:"PER";}i:3;a:3:{s:4:"code";s:1:"3";s:5:"label";s:3:"i;j";s:8:"zone_995";s:17:"CD;LIVCD;LIVK7;K7";}i:4;a:3:{s:4:"code";s:1:"4";s:5:"label";s:1:"g";s:8:"zone_995";s:20:"DIAPO;DVD;VHS;VHD;VD";}i:5;a:3:{s:4:"code";s:1:"5";s:5:"label";s:6:"l;m;mm";s:8:"zone_995";s:3:"CDR";}i:6;a:3:{s:4:"code";s:1:"8";s:5:"label";s:0:"";s:8:"zone_995";s:1:"D";}i:7;a:3:{s:4:"code";s:1:"9";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:8;a:3:{s:4:"code";s:1:"8";s:5:"label";s:0:"";s:8:"zone_995";s:3:"DOS";}i:9;a:3:{s:4:"code";s:1:"9";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:10;a:3:{s:4:"code";s:2:"10";s:5:"label";s:0:"";s:8:"zone_995";s:6:"WEB;MF";}i:11;a:3:{s:4:"code";s:3:"102";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:12;a:3:{s:4:"code";s:3:"103";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:13;a:3:{s:4:"code";s:3:"104";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:14;a:3:{s:4:"code";s:3:"105";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:15;a:3:{s:4:"code";s:3:"106";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:16;a:3:{s:4:"code";s:3:"107";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:17;a:3:{s:4:"code";s:3:"108";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:18;a:3:{s:4:"code";s:3:"100";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:19;a:3:{s:4:"code";s:3:"101";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:20;a:3:{s:4:"code";s:3:"102";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:21;a:3:{s:4:"code";s:3:"103";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:22;a:3:{s:4:"code";s:3:"104";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:23;a:3:{s:4:"code";s:3:"105";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:24;a:3:{s:4:"code";s:3:"106";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:25;a:3:{s:4:"code";s:3:"107";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:26;a:3:{s:4:"code";s:3:"108";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:27;a:3:{s:4:"code";s:3:"109";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:28;a:3:{s:4:"code";s:3:"111";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:29;a:3:{s:4:"code";s:3:"110";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:30;a:3:{s:4:"code";s:3:"112";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:31;a:3:{s:4:"code";s:3:"114";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:32;a:3:{s:4:"code";s:3:"113";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:33;a:3:{s:4:"code";s:3:"115";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:34;a:3:{s:4:"code";s:3:"116";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}}s:17:"champ_code_barres";s:1:"a";s:10:"champ_cote";s:1:"f";s:14:"champ_type_doc";s:0:"";s:11:"champ_genre";s:1:"#";s:13:"champ_section";s:1:"w";s:17:"champ_emplacement";s:1:"x";s:12:"champ_annexe";s:1:"h";s:9:"champ_url";a:2:{s:4:"zone";s:0:"";s:5:"champ";s:0:"";}}i:1;a:1:{s:6:"champs";s:47:"ID_SIGB;LIBELLE;IDABON;MAIL;ROLE;ID_NOTICE_SIGB";}i:2;a:1:{s:6:"champs";s:47:"ID_SIGB;LIBELLE;IDABON;MAIL;ROLE;ID_NOTICE_SIGB";}i:3;a:1:{s:6:"champs";s:47:"ID_SIGB;LIBELLE;IDABON;MAIL;ROLE;ID_NOTICE_SIGB";}i:5;a:3:{s:6:"champs";s:47:"ID_SIGB;LIBELLE;IDABON;MAIL;ROLE;ID_NOTICE_SIGB";s:17:"xml_balise_abonne";s:0:"";s:17:"xml_champs_abonne";a:11:{s:6:"IDABON";s:0:"";s:9:"ORDREABON";s:0:"";s:3:"NOM";s:0:"";s:6:"PRENOM";s:0:"";s:9:"NAISSANCE";s:0:"";s:8:"PASSWORD";s:0:"";s:4:"MAIL";s:0:"";s:10:"DATE_DEBUT";s:0:"";s:8:"DATE_FIN";s:0:"";s:7:"ID_SIGB";s:0:"";s:9:"NUM_CARTE";s:0:"";}}i:4;a:5:{s:4:"zone";s:3:"995";s:5:"champ";s:1:"5";s:6:"format";s:1:"3";s:5:"jours";s:0:"";s:7:"valeurs";s:1:"1";}i:6;a:2:{s:4:"zone";s:0:"";s:5:"champ";s:0:"";}}']); - $profile->save(); - return $profile; - } -} - - - -class Class_Cosmogramme_GeneratorPlannedNanook extends Class_Cosmogramme_GeneratorPlannedAbstract{ - protected - $_records_profile = 104, - $_users_profile = 105, - $_item_delete = true, - $_baskets = true; -} - - - -class Class_Cosmogramme_GeneratorPlannedPergame extends Class_Cosmogramme_GeneratorPlannedAbstract{ - protected - $_records_profile = 100, - $_users_profile = 101, - $_holds = true; -} +} \ No newline at end of file diff --git a/library/Class/Cosmogramme/Generator/AbstractTask.php b/library/Class/Cosmogramme/Generator/AbstractTask.php index 8453a77b453..79fd9f58aa7 100644 --- a/library/Class/Cosmogramme/Generator/AbstractTask.php +++ b/library/Class/Cosmogramme/Generator/AbstractTask.php @@ -41,8 +41,9 @@ abstract class Class_Cosmogramme_Generator_AbstractTask { } - public function __construct($generator) { + public function __construct($generator, $params) { $this->_generator = $generator; + $this->_params = $params; } @@ -69,17 +70,20 @@ abstract class Class_Cosmogramme_Generator_AbstractTask { protected function _runOne($data) { - $data = utf8_encode($data); - $elems = explode('|', $data); - + $elems = $this->_extract($data); if ($this->_isExcluded($elems)) return ''; $model = $this->_getOrCreate($elems); - $model->setDateMaj($this->_date) - ->save(); + $model->save(); + + return $this->renderOne($elems, $model); + } + - return $this->renderOne($elems); + protected function _extract($data) { + $data = utf8_encode($data); + return explode('|', $data); } @@ -91,7 +95,9 @@ abstract class Class_Cosmogramme_Generator_AbstractTask { if (!$model = $model_class::findFirstBy(['libelle' => $label])) $model = $model_class::newInstance(['libelle' => $label]); - return $model->setRegles($this->_createOrConcatRules($code, $model)); + return + $model->setDateMaj($this->_date) + ->setRegles($this->_createOrConcatRules($code, $model)); } @@ -168,7 +174,7 @@ abstract class Class_Cosmogramme_Generator_AbstractTask { } - protected function renderOne($elems) { + protected function renderOne($elems, $model) { return '<tr><td class="blank">' . $this->getCode($elems) . '</td><td class="blank">' . $this->getLabel($elems) . '</td></tr>'; } diff --git a/library/Class/Cosmogramme/Generator/BranchesTask.php b/library/Class/Cosmogramme/Generator/BranchesTask.php index 9f7fc36f351..44863ef2d57 100644 --- a/library/Class/Cosmogramme/Generator/BranchesTask.php +++ b/library/Class/Cosmogramme/Generator/BranchesTask.php @@ -30,12 +30,12 @@ class Class_Cosmogramme_Generator_BranchesTask $_model_class = 'Class_CodifAnnexe'; protected function _getOrCreate($elems) { - return ($model = Class_CodifAnnexe::findFirstBy(['id_origine' => $elems[0]])) - ? $model - : Class_CodifAnnexe::newInstance(['id_bib' => $elems[0], - 'id_origine' => $elems[0], - 'libelle' => trim($elems[1]), - 'invisible' => 0]); + if (!$model = Class_CodifAnnexe::findFirstBy(['id_origine' => $elems[0]])) + $model = Class_CodifAnnexe::newInstance(['id_bib' => $elems[0], + 'id_origine' => $elems[0], + 'libelle' => trim($elems[1]), + 'invisible' => 0]); + return $model->setDateMaj($this->_date); } diff --git a/library/Class/Cosmogramme/Generator/KindsTask.php b/library/Class/Cosmogramme/Generator/KindsTask.php index 4c4e40b4ba6..416ddd21d3d 100644 --- a/library/Class/Cosmogramme/Generator/KindsTask.php +++ b/library/Class/Cosmogramme/Generator/KindsTask.php @@ -67,7 +67,7 @@ class Class_Cosmogramme_Generator_KindsTask extends Class_Cosmogramme_Generator_ ->setDateMaj($this->_date) ->save(); - return $this->renderOne([$codes, $label]); + return $this->renderOne([$codes, $label], $model); } diff --git a/library/Class/Cosmogramme/Generator/LibrariesTask.php b/library/Class/Cosmogramme/Generator/LibrariesTask.php new file mode 100644 index 00000000000..bc1f6523f04 --- /dev/null +++ b/library/Class/Cosmogramme/Generator/LibrariesTask.php @@ -0,0 +1,118 @@ +<?php +/** + * Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +class Class_Cosmogramme_Generator_LibrariesTask extends Class_Cosmogramme_Generator_AbstractTask { + protected + $_index = 1, + $_name = 'bibliothèques'; + + + protected function _isExcluded($elems) { + return 'BIB_SPS_UTT' == $elems[0] || !trim($elems[0]); + } + + + protected function _prepare($libraries) { + $this->_disableDeletedLibraries($libraries); + return $libraries; + } + + + protected function _disableDeletedLibraries($libraries) { + if ((!$ids = $this->_librariesIdsFrom($libraries)) + || !$libs = Class_IntBib::findAllBy(['id_bib not' => $ids])) + return; + + foreach($libs as $lib) + $this->_disableDeletedLibrary($lib); + } + + + protected function _getOrCreate($elems) { + if (!$bib = Class_Cosmogramme_Generator_FixedIdBib::findFirstBy(['id_site' => $elems[0]])) + $bib = Class_Cosmogramme_Generator_FixedIdBib::newInstance(['ville' => $this->_params['path_ftp']]); + + $bib->updateAttributes(['id_site' => $elems[0], + 'libelle' => trim($elems[1]), + 'id_zone' => 1, + 'visibilite' => Class_Bib::V_DATA]); + + if (!$int_bib = Class_IntBib::findFirstBy(['id_bib' => $bib->getIdSite()])) + $int_bib = Class_IntBib::newInstance(['id_bib' => $bib->getIdSite(), + 'qualite' => 5, + 'sigb' => $this->_params['type_sigb'], + 'planif_mode' => 'r', + 'planif_jours' => '1111111']); + + $int_bib->updateAttributes(['nom' => $bib->getLibelle(), + 'nom_court' => $bib->getLibelle()]); + + $this->_generateNewLibrary($int_bib); + + $int_bib->save(); + return $bib; + } + + + protected function _generateNewLibrary($int_bib) { + if (!$int_bib->isNew()) + return $int_bib; + + if ($int_bib->isNanook()) + return $int_bib + ->setCommSigb(Class_IntBib::COM_NANOOK) + ->setCommParams(serialize(['url_serveur' => $this->_params['service_nanook']])); + + return $int_bib + ->setCommSigb(Class_IntBib::COM_PERGAME) + ->setCommParams(serialize(['Autoriser_docs_disponibles' => '0', + 'Max_par_carte' => '3', + 'Max_par_document' => '3'])); + } + + + protected function renderOne($elems, $bib) { + return '<tr><td class="blank">Site n° '. $bib->getIdSite() . '</td><td class="blank">'. $bib->getLibelle() . '</td></tr>'; + } + + + protected function _disableDeletedLibrary($library) { + $library->beDisconnected()->save(); + Class_IntMajAuto::deleteBy(['id_bib' => $library->getId()]); + } + + + protected function _librariesIdsFrom($datas) { + if (!$datas) + return []; + + $ids = []; + foreach($datas as $data) + if ($elem = $this->_extract($data)) + $ids[] = $elem[0]; + + return $ids; + } + + + protected function _removeDeleted() { + } +} \ No newline at end of file diff --git a/library/Class/Cosmogramme/Generator/PlannedIntegrationsTask.php b/library/Class/Cosmogramme/Generator/PlannedIntegrationsTask.php new file mode 100644 index 00000000000..e700d9567c7 --- /dev/null +++ b/library/Class/Cosmogramme/Generator/PlannedIntegrationsTask.php @@ -0,0 +1,247 @@ +<?php +/** + * Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class Class_Cosmogramme_Generator_PlannedIntegrationsTask + extends Class_Cosmogramme_Generator_AbstractTask { + + protected + $_index = 3, + $_name = 'intégrations programmées', + $_html = ''; + + + protected function _isExcluded($elems) { + return 'BIB_SPS_UTT' == $elems[0] || !trim($elems[0]); + } + + + protected function _getOrCreate($elems) { + $id_bib = $elems[0]; + Class_IntMajAuto::deleteBy(['id_bib' => $id_bib]); + + $this->_html = $this->getPlannedGenerator()->plan($id_bib, $this->_params['path_ftp']); + + return (new Class_Entity())->whenCalledDo('save', function() { return true; } ); + } + + + protected function renderOne($elems, $bib) { + return $this->_html; + } + + + protected function getPlannedGenerator() { + return $this->_generator->isNanook() + ? new Class_Cosmogramme_GeneratorPlannedNanook() + : new Class_Cosmogramme_GeneratorPlannedPergame(); + } + + + protected function _removeDeleted() { + } +} + + + +class Class_Cosmogramme_GeneratorPlannedAbstract { + use Trait_Translator, Trait_Loggable; + + protected + $_id_bib, + $_id_prog, + $_base_path, + $_html = '', + $_records_profile, + $_users_profile, + $_loans_profile = 102, + $_holds_profile = 103, + $_item_delete = false, + $_holds = false, + $_baskets = false; + + public function plan($id_bib, $base_path) { + $this->_id_bib = $id_bib; + $this->_id_prog = $id_bib * 100; + $this->_base_path = $base_path . DIRECTORY_SEPARATOR . 'site' . $id_bib . DIRECTORY_SEPARATOR; + + $this + ->itemDeletion() + ->recordsTotal() + ->recordsPartial() + ->users() + ->loans() + ->holds() + ->basketsTotal() + ->basketsPartial(); + + return $this->_html; + } + + + protected function itemDeletion() { + if (!$this->_item_delete) + return $this; + + $profile = $this->_getBarCodeProfile(); + + return $this->planWith('Notices - suppression d\'exemplaires', + $profile->getId(), + Class_IntMajAuto::OP_ITEMS_DELETION, + 'suppressions.txt'); + } + + + protected function recordsTotal() { + return $this->planWith('Notices - import total', + $this->_records_profile, + Class_IntMajAuto::OP_FULL_IMPORT, + 'notices_total.txt'); + } + + + protected function recordsPartial() { + return $this->planWith('Notices - import incrémentiel', + $this->_records_profile, + Class_IntMajAuto::OP_PARTIAL_IMPORT, + 'notices.txt'); + } + + + protected function users() { + return $this->planWith('Abonnés', + $this->_users_profile, + Class_IntMajAuto::OP_FULL_IMPORT, + 'abonnes.txt'); + } + + + protected function loans() { + return $this->planWith('Prêts', + $this->_loans_profile, + Class_IntMajAuto::OP_FULL_IMPORT, + 'prets.txt'); + } + + + protected function holds() { + return $this->_holds + ? $this->planWith('Réservations', $this->_holds_profile, + Class_IntMajAuto::OP_FULL_IMPORT, 'reservations.txt') + : $this; + } + + + protected function basketsTotal() { + if (!$this->_baskets) + return $this; + + $profile = $this->_getBasketProfile(); + + return $this->planWith('Paniers - import total', + $profile->getId(), + Class_IntMajAuto::OP_FULL_IMPORT, + 'paniers_total.txt'); + } + + + protected function basketsPartial() { + if (!$this->_baskets) + return $this; + + $profile = $this->_getBasketProfile(); + + return $this->planWith('Paniers - import incrémentiel', + $profile->getId(), + Class_IntMajAuto::OP_PARTIAL_IMPORT, + 'paniers.txt'); + } + + + protected function planWith($name, $profile, $type, $file) { + $this->_html .= '<tr><td class="blank">Site n° '. $this->_id_bib . '</td><td class="blank">' . $name . '</td></tr>'; + $this->_id_prog++; + Class_IntMajAuto::newInstance(['id_bib' => $this->_id_bib, + 'libelle' => $name, + 'profil' => $profile, + 'type_operation' => $type, + 'nom_fichier' => $this->_base_path . $file, + 'rang' => $this->_id_prog]) + ->save(); + + return $this; + } + + + protected function _getBarCodeProfile() { + $label = 'Liste de codes-barres'; + if ($profile = Class_IntProfilDonnees::findFirstBy(['libelle' => $label])) + return $profile; + + + $attributs = 'a:6:{i:0;a:7:{s:8:"type_doc";a:11:{i:0;a:3:{s:4:"code";s:1:"0";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:1;a:3:{s:4:"code";s:1:"1";s:5:"label";s:5:"am;na";s:8:"zone_995";s:0:"";}i:2;a:3:{s:4:"code";s:1:"2";s:5:"label";s:2:"as";s:8:"zone_995";s:0:"";}i:3;a:3:{s:4:"code";s:1:"3";s:5:"label";s:3:"i;j";s:8:"zone_995";s:0:"";}i:4;a:3:{s:4:"code";s:1:"4";s:5:"label";s:1:"g";s:8:"zone_995";s:0:"";}i:5;a:3:{s:4:"code";s:1:"5";s:5:"label";s:3:"l;m";s:8:"zone_995";s:0:"";}i:6;a:3:{s:4:"code";s:1:"8";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:7;a:3:{s:4:"code";s:1:"9";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:8;a:3:{s:4:"code";s:2:"10";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:9;a:3:{s:4:"code";s:3:"100";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:10;a:3:{s:4:"code";s:2:"10";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}}s:17:"champ_code_barres";s:1:"f";s:10:"champ_cote";s:1:"k";s:11:"champ_genre";s:0:"";s:13:"champ_section";s:1:"q";s:17:"champ_emplacement";s:1:"u";s:12:"champ_annexe";s:1:"a";}i:1;a:1:{s:6:"champs";s:11:"code_barres";}i:2;a:1:{s:6:"champs";s:11:"code_barres";}i:3;a:1:{s:6:"champs";s:11:"code_barres";}i:5;a:3:{s:6:"champs";s:11:"code_barres";s:17:"xml_balise_abonne";s:0:"";s:17:"xml_champs_abonne";a:10:{s:6:"IDABON";s:0:"";s:9:"ORDREABON";s:0:"";s:3:"NOM";s:0:"";s:6:"PRENOM";s:0:"";s:9:"NAISSANCE";s:0:"";s:8:"PASSWORD";s:0:"";s:4:"MAIL";s:0:"";s:10:"DATE_DEBUT";s:0:"";s:8:"DATE_FIN";s:0:"";s:7:"ID_SIGB";s:0:"";}}i:4;a:5:{s:4:"zone";s:0:"";s:5:"champ";s:0:"";s:6:"format";s:0:"";s:5:"jours";s:0:"";s:7:"valeurs";s:0:"";}}'; + + $profile = Class_IntProfilDonnees::newInstance(['libelle' => $label, + 'accents' => Class_IntProfilDonnees::ENCODING_UTF8, + 'type_fichier' => Class_IntProfilDonnees::FT_RECORDS, + 'format' => Class_IntProfilDonnees::FORMAT_TABBED_ASCII, + 'attributs' => $attributs]); + $profile->save(); + return $profile; + } + + + protected function _getBasketProfile() { + if ($profile = Class_IntProfilDonnees::findFirstBy(['accents' => Class_IntProfilDonnees::ENCODING_UTF8, + 'type_fichier' => Class_IntProfilDonnees::FT_BASKETS, + 'format' => Class_IntProfilDonnees::FORMAT_PIPED_ASCII])) + return $profile; + + $profile = Class_IntProfilDonnees::newInstance(['libelle' => 'Paniers Nanook', + 'accents' => Class_IntProfilDonnees::ENCODING_UTF8, + 'rejet_periodiques' => 0, + 'id_article_periodique' => 4, + 'type_fichier' => Class_IntProfilDonnees::FT_BASKETS, + 'format' => Class_IntProfilDonnees::FORMAT_PIPED_ASCII, + 'attributs' => 'a:7:{i:0;a:9:{s:8:"type_doc";a:35:{i:0;a:3:{s:4:"code";s:1:"0";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:1;a:3:{s:4:"code";s:1:"1";s:5:"label";s:8:"am;na;mn";s:8:"zone_995";s:9:"LIV;MS;uu";}i:2;a:3:{s:4:"code";s:1:"2";s:5:"label";s:2:"as";s:8:"zone_995";s:3:"PER";}i:3;a:3:{s:4:"code";s:1:"3";s:5:"label";s:3:"i;j";s:8:"zone_995";s:17:"CD;LIVCD;LIVK7;K7";}i:4;a:3:{s:4:"code";s:1:"4";s:5:"label";s:1:"g";s:8:"zone_995";s:20:"DIAPO;DVD;VHS;VHD;VD";}i:5;a:3:{s:4:"code";s:1:"5";s:5:"label";s:6:"l;m;mm";s:8:"zone_995";s:3:"CDR";}i:6;a:3:{s:4:"code";s:1:"8";s:5:"label";s:0:"";s:8:"zone_995";s:1:"D";}i:7;a:3:{s:4:"code";s:1:"9";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:8;a:3:{s:4:"code";s:1:"8";s:5:"label";s:0:"";s:8:"zone_995";s:3:"DOS";}i:9;a:3:{s:4:"code";s:1:"9";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:10;a:3:{s:4:"code";s:2:"10";s:5:"label";s:0:"";s:8:"zone_995";s:6:"WEB;MF";}i:11;a:3:{s:4:"code";s:3:"102";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:12;a:3:{s:4:"code";s:3:"103";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:13;a:3:{s:4:"code";s:3:"104";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:14;a:3:{s:4:"code";s:3:"105";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:15;a:3:{s:4:"code";s:3:"106";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:16;a:3:{s:4:"code";s:3:"107";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:17;a:3:{s:4:"code";s:3:"108";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:18;a:3:{s:4:"code";s:3:"100";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:19;a:3:{s:4:"code";s:3:"101";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:20;a:3:{s:4:"code";s:3:"102";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:21;a:3:{s:4:"code";s:3:"103";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:22;a:3:{s:4:"code";s:3:"104";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:23;a:3:{s:4:"code";s:3:"105";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:24;a:3:{s:4:"code";s:3:"106";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:25;a:3:{s:4:"code";s:3:"107";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:26;a:3:{s:4:"code";s:3:"108";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:27;a:3:{s:4:"code";s:3:"109";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:28;a:3:{s:4:"code";s:3:"111";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:29;a:3:{s:4:"code";s:3:"110";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:30;a:3:{s:4:"code";s:3:"112";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:31;a:3:{s:4:"code";s:3:"114";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:32;a:3:{s:4:"code";s:3:"113";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:33;a:3:{s:4:"code";s:3:"115";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:34;a:3:{s:4:"code";s:3:"116";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}}s:17:"champ_code_barres";s:1:"a";s:10:"champ_cote";s:1:"f";s:14:"champ_type_doc";s:0:"";s:11:"champ_genre";s:1:"#";s:13:"champ_section";s:1:"w";s:17:"champ_emplacement";s:1:"x";s:12:"champ_annexe";s:1:"h";s:9:"champ_url";a:2:{s:4:"zone";s:0:"";s:5:"champ";s:0:"";}}i:1;a:1:{s:6:"champs";s:47:"ID_SIGB;LIBELLE;IDABON;MAIL;ROLE;ID_NOTICE_SIGB";}i:2;a:1:{s:6:"champs";s:47:"ID_SIGB;LIBELLE;IDABON;MAIL;ROLE;ID_NOTICE_SIGB";}i:3;a:1:{s:6:"champs";s:47:"ID_SIGB;LIBELLE;IDABON;MAIL;ROLE;ID_NOTICE_SIGB";}i:5;a:3:{s:6:"champs";s:47:"ID_SIGB;LIBELLE;IDABON;MAIL;ROLE;ID_NOTICE_SIGB";s:17:"xml_balise_abonne";s:0:"";s:17:"xml_champs_abonne";a:11:{s:6:"IDABON";s:0:"";s:9:"ORDREABON";s:0:"";s:3:"NOM";s:0:"";s:6:"PRENOM";s:0:"";s:9:"NAISSANCE";s:0:"";s:8:"PASSWORD";s:0:"";s:4:"MAIL";s:0:"";s:10:"DATE_DEBUT";s:0:"";s:8:"DATE_FIN";s:0:"";s:7:"ID_SIGB";s:0:"";s:9:"NUM_CARTE";s:0:"";}}i:4;a:5:{s:4:"zone";s:3:"995";s:5:"champ";s:1:"5";s:6:"format";s:1:"3";s:5:"jours";s:0:"";s:7:"valeurs";s:1:"1";}i:6;a:2:{s:4:"zone";s:0:"";s:5:"champ";s:0:"";}}']); + $profile->save(); + return $profile; + } +} + + + +class Class_Cosmogramme_GeneratorPlannedNanook extends Class_Cosmogramme_GeneratorPlannedAbstract{ + protected + $_records_profile = 104, + $_users_profile = 105, + $_item_delete = true, + $_baskets = true; +} + + + +class Class_Cosmogramme_GeneratorPlannedPergame extends Class_Cosmogramme_GeneratorPlannedAbstract{ + protected + $_records_profile = 100, + $_users_profile = 101, + $_holds = true; +} \ No newline at end of file -- GitLab