diff --git a/cosmogramme/php/classes/classe_profil_donnees.php b/cosmogramme/php/classes/classe_profil_donnees.php index fecfec429c9981291584382c1c2f0cb69d1edeee..e2640a6579d35218abfbb9a697708ffa47e740bc 100644 --- a/cosmogramme/php/classes/classe_profil_donnees.php +++ b/cosmogramme/php/classes/classe_profil_donnees.php @@ -24,6 +24,10 @@ class profil_donnees { HOMOGENIZATION_ISBN = -1, HOMOGENIZATION_EAN = -2; + protected static + $_profil_cache = [], + $_type_docs_cache = null; + private $id_profil; // Id sgbd private $libelle; // Libellé du profil private $rejet_periodiques; // Rejet des periodiques dans les imports @@ -33,9 +37,35 @@ class profil_donnees { private $format; // Format du fichier à parser (variable import_format) private $attributs; // Bloc de donnees associe au format + protected $_to_array=[]; //legacy refactoring @see getProfil + + + public static function clearCache() { + static::$_profil_cache = []; + static::$_type_docs_cache = null; + } + + public static function find($id_profil) { + if (isset(static::$_profil_cache[$id_profil])) + return static::$_profil_cache[$id_profil]; + + $profil = new static(); + $profil->lire($id_profil); + + return static::$_profil_cache[$profil->getId()] = $profil; + } + + + public function getId() { + return $this->id_profil; + } + public function lire($id_profil) { - $all_type_docs = Class_TypeDoc::findAll(); + if (!static::$_type_docs_cache) + static::$_type_docs_cache = Class_TypeDoc::findAll(); + + $all_type_docs = static::$_type_docs_cache; // Profils d'homogeneisation : -1= isbn -2=ean if ($id_profil < 0) { @@ -105,9 +135,7 @@ class profil_donnees { return $this->id_profil; } - - public function getProfil($id_profil) { - $this->lire($id_profil); + public function toArray() { $profil["id_profil"]=$this->id_profil; $profil["libelle"]=$this->libelle; $profil["accents"]=$this->accents; @@ -124,6 +152,10 @@ class profil_donnees { return $profil; } + public function getProfil($id_profil) { + return static::find($id_profil)->toArray(); + } + /** * Profils standard réhomogénéisations : -1: panier d'isbn -2:panier d'ean diff --git a/cosmogramme/php/classes/classe_unimarc.php b/cosmogramme/php/classes/classe_unimarc.php index 35f82a9edbb01d13e563f87c6f9317bc7ba18734..7d1d7bc364e0cfc1625abbe9febf79b3ce05c387 100644 --- a/cosmogramme/php/classes/classe_unimarc.php +++ b/cosmogramme/php/classes/classe_unimarc.php @@ -68,12 +68,16 @@ class notice_unimarc extends iso2709_record { $this->sigb = $sigb; $this->id_profil = $id_profil; + if($this->id_profil == 0) { - $this->profil = $this->profil_unimarc->getProfil(1); + $this->profil_unimarc = profil_donnees::find(1); + $this->profil = $this->profil_unimarc->lire(1); $this->profil['accents'] = 0; } - else + else { + $this->profil_unimarc = profil_donnees::find($this->id_profil); $this->profil = $this->profil_unimarc->getProfil($this->id_profil); + } if (!$decode_string) { $this->profil['accents'] = 0; diff --git a/cosmogramme/tests/php/classes/NoticeIntegrationTest.php b/cosmogramme/tests/php/classes/NoticeIntegrationTest.php index ec65b9b556dfe2d8821ab75070a2f7ce3f905f00..e0d2510f376e5171cc3bf84509a44afcc8829f71 100644 --- a/cosmogramme/tests/php/classes/NoticeIntegrationTest.php +++ b/cosmogramme/tests/php/classes/NoticeIntegrationTest.php @@ -65,6 +65,7 @@ abstract class NoticeIntegrationTestCase extends ModelTestCase { global $sql; $sql = $this->_mock_sql = Storm_Test_ObjectWrapper::mock(); + profil_donnees::clearCache(); $this->_mock_sql ->whenCalled('execute')->answers(true)