diff --git a/VERSIONS_HOTLINE/86956 b/VERSIONS_HOTLINE/86956 new file mode 100644 index 0000000000000000000000000000000000000000..c183e4cd01755259ad9997c2d0f46f1860a7d04d --- /dev/null +++ b/VERSIONS_HOTLINE/86956 @@ -0,0 +1,2 @@ + - ticket #86956 : Intégration Cosmogramme : correction de l'import de paniers + \ No newline at end of file diff --git a/library/Class/Cosmogramme/Integration/PhasePanier.php b/library/Class/Cosmogramme/Integration/PhasePanier.php index b70e0cb0bda58d1770daebcd7827a49a423d5c8f..2f2a35b95d3dfb190a69cc978cc190491cc815a7 100644 --- a/library/Class/Cosmogramme/Integration/PhasePanier.php +++ b/library/Class/Cosmogramme/Integration/PhasePanier.php @@ -98,13 +98,7 @@ class Class_Cosmogramme_Integration_PhasePanier extends Class_Cosmogramme_Integr $id_int_bib = $integration->getIdBib(); - if (!$exemplaire = Class_Exemplaire::findFirstBy(['id_origine' => $map['id_notice_sigb'], - 'id_int_bib' => $id_int_bib])) { - $this->_log->error($this->_('L\'exemplaire id_origine : %s / id_int_bib : %s n\'a pas été trouvé.', - $map['id_notice_sigb'], - $id_int_bib)); - $exemplaire = new Class_Entity(); - } + $exemplaire = $this->_getItem($map['id_notice_sigb'], $id_int_bib); $owners = $this->findPossibleOwnersOfBasketRecord($map); if ($owners->isEmpty()) { @@ -134,6 +128,35 @@ class Class_Cosmogramme_Integration_PhasePanier extends Class_Cosmogramme_Integr } + protected function _getItem($id_notice_sigb, $id_int_bib) { + return ($items = Class_Exemplaire::findAllBy(['id_origine' => $id_notice_sigb, + 'id_int_bib' => $id_int_bib])) + ? $this->_findItem($items, $id_notice_sigb, $id_int_bib) + : $this->_noItem($id_notice_sigb, $id_int_bib); + } + + + protected function _findItem($items, $id_notice_sigb, $id_int_bib) { + foreach ($items as $item) { + if (!$record = $item->getNotice()) + continue; + + if ($record->isSigb()) + return $item; + } + + return $this->_noItem($id_notice_sigb, $id_int_bib); + } + + + protected function _noItem($id_notice_sigb, $id_int_bib) { + $this->_log->error($this->_('L\'exemplaire id_origine : %s / id_int_bib : %s n\'a pas été trouvé.', + $id_notice_sigb, + $id_int_bib)); + return new Class_Entity(); + } + + protected function _clean($integration) { $baskets = Class_PanierNotice::findAllBy(['integration_hash' => $integration->getHash()]); foreach($baskets as $basket) diff --git a/tests/library/Class/Cosmogramme/Integration/PhasePanierTest.php b/tests/library/Class/Cosmogramme/Integration/PhasePanierTest.php index 1df36f2cad1bba9849d9923c8dce2210479829d1..e62f284ae2f4d99b4cd206caa37edb02c61d41eb 100644 --- a/tests/library/Class/Cosmogramme/Integration/PhasePanierTest.php +++ b/tests/library/Class/Cosmogramme/Integration/PhasePanierTest.php @@ -128,6 +128,7 @@ abstract class PhasePanierKohaTestCase extends PhasePanierTestCase { $this->fixture('Class_Notice', ['id' => 23, + 'type_doc' => 1, 'clef_alpha' => 'CASTAFIORE', 'exemplaires' => [$this->fixture('Class_Exemplaire', ['id' => 231, @@ -137,19 +138,29 @@ abstract class PhasePanierKohaTestCase extends PhasePanierTestCase { $this->fixture('Class_Notice', ['id' => 45, 'clef_alpha' => 'TIBET', + 'type_doc' => 1, 'exemplaires' => [$this->fixture('Class_Exemplaire', ['id' => 4511, 'id_int_bib' => 2, 'id_origine' => 72490])]]); + $this->fixture('Class_Notice', + ['id' => 289898, + 'clef_alpha' => 'NONO', + 'type_doc' => '121', + 'exemplaires' => [$this->fixture('Class_Exemplaire', + ['id' => 21, + 'id_int_bib' => 2, + 'id_origine' => 58265])]]); + $this->fixture('Class_Notice', ['id' => 24, 'clef_alpha' => 'LUNE', + 'type_doc' => 1, 'exemplaires' => [$this->fixture('Class_Exemplaire', ['id' => 241, 'id_int_bib' => 2, 'id_origine' => 58265])]]); - } } @@ -157,7 +168,7 @@ abstract class PhasePanierKohaTestCase extends PhasePanierTestCase { -class PhasePanierKohaSameIdOrigine extends PhasePanierKohaTestCase { +class PhasePanierKohaSameIdOrigineTest extends PhasePanierKohaTestCase { public function _prepareFixtures() { parent::_prepareFixtures(); @@ -192,6 +203,12 @@ class PhasePanierKohaSameIdOrigine extends PhasePanierKohaTestCase { $this->assertEquals('577f79a2c26968b6f5e1360df0dc17af', Class_PanierNotice::find(1)->getIntegrationHash()); } + + + /** @test */ + public function firstBasketRecordsShouldContainsCOKEENSTOCKCASTAFIORELUNE() { + $this->assertEquals('COKEENSTOCK;CASTAFIORE;LUNE', Class_PanierNotice::find(1)->getNotices()); + } }