diff --git a/VERSIONS_HOTLINE/163609 b/VERSIONS_HOTLINE/163609 new file mode 100644 index 0000000000000000000000000000000000000000..06e3102e951fe51f63bddedcd0a1beefe0a3d807 --- /dev/null +++ b/VERSIONS_HOTLINE/163609 @@ -0,0 +1 @@ + - ticket#16309 : Cosmogramme : Correction de la phase d'import des paniers \ No newline at end of file diff --git a/library/Class/Batch/PanierNotice.php b/library/Class/Batch/PanierNotice.php index e5f1edff1016d8bfb86c06b593ed1c3b48610fd6..3f92c6fc7e01d55479acaf3990a3e1a9886ce6cb 100644 --- a/library/Class/Batch/PanierNotice.php +++ b/library/Class/Batch/PanierNotice.php @@ -28,7 +28,7 @@ class Class_Batch_PanierNotice extends Class_Batch_Abstract { } public function run() { - return (new Class_PanierNotice())->fixLostClesNoticesForAll(); + return Class_PanierNotice::fixLostClesNoticesForAll(); } } -?> \ No newline at end of file +?> diff --git a/library/Class/Cosmogramme/Integration/PhasePanier.php b/library/Class/Cosmogramme/Integration/PhasePanier.php index 6dc2c424403ac0613bea76f54f23e7825e785ce7..8ffdadbc7c641d8a312979e80c3dc8b0368dee71 100644 --- a/library/Class/Cosmogramme/Integration/PhasePanier.php +++ b/library/Class/Cosmogramme/Integration/PhasePanier.php @@ -99,11 +99,11 @@ class Class_Cosmogramme_Integration_PhasePanier return $this->_log->error($this->_('Pas de donnée trouvée avec le profil de données sélectionné')); if (!$map['libelle']) - return $this->_log->error($this->_('Ligne non traitée car le libellé n\'a pas pu être lu')); + return $this->_log->log($this->_('Ligne non traitée car le libellé n\'a pas pu être lu')); $id_int_bib = $integration->getIdBib(); - $exemplaire = $this->_getItem($map['id_notice_sigb'], $id_int_bib); + $exemplaire = $this->_getItem($map['id_notice_sigb'], (int) $id_int_bib); $owners = $this->findPossibleOwnersOfBasketRecord($map); if ($owners->isEmpty()) { @@ -134,32 +134,47 @@ class Class_Cosmogramme_Integration_PhasePanier } - 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])) + protected function _getItem(string $id_notice_sigb, int $id_int_bib) : Class_Exemplaire { + return ($items = Class_Exemplaire::findAllBy(['id_origine' => $id_notice_sigb])) ? $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) { + protected function _findItem(array $items, int $id_notice_sigb, int $id_int_bib) : Class_Exemplaire { + $count_items = count($items); + $count = 1; foreach ($items as $item) { if (!$record = $item->getNotice()) continue; - if ($record->isSigb()) + if ($record->isSigb() + && ($id_int_bib == ($item_id_int_bib = $item->getIdIntBib()) )) return $item; + + if (($count == $count_items) + && $record->isSigb() ){ + $this->_log->log($this->_('Un exemplaire id_origine : %s / id_int_bib : %s a été trouvé. alors que nous cherchions id_int_bib %s\n', + $id_notice_sigb, + $item_id_int_bib, + $id_int_bib)); + return $item; + } + + $count++; } return $this->_noItem($id_notice_sigb, $id_int_bib); } - protected function _noItem($id_notice_sigb, $id_int_bib) { + protected function _noItem($id_notice_sigb, $id_int_bib) : Class_Exemplaire { $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(); + return (new Class_Exemplaire_Null) + ->setIdOrigine($id_notice_sigb) + ->setIdIntBib($id_int_bib); } diff --git a/library/Class/Exemplaire/Null.php b/library/Class/Exemplaire/Null.php new file mode 100644 index 0000000000000000000000000000000000000000..8eec340864a40dbf9c72fa83bee5d204f1ffb543 --- /dev/null +++ b/library/Class/Exemplaire/Null.php @@ -0,0 +1,27 @@ +<?php +/** + * Copyright (c) 2012-2022, 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_Exemplaire_Null extends Class_Exemplaire { + public function getNotice() { + return null; + } +} diff --git a/tests/library/Class/Cosmogramme/Integration/PhasePanierTest.php b/tests/library/Class/Cosmogramme/Integration/PhasePanierTest.php index 3e31a42eb36d8e6ab3fbf54c2bbc90102d9e1e25..be4eba5ca1438f3a8c784bf54cbba0850c809b40 100644 --- a/tests/library/Class/Cosmogramme/Integration/PhasePanierTest.php +++ b/tests/library/Class/Cosmogramme/Integration/PhasePanierTest.php @@ -459,8 +459,7 @@ class PhasePanierPartialImportTest extends PhasePanierKohaTestCase { -/** @see http://forge.afi-sa.fr/issues/33712 */ -class PhasePanierNanookTest extends PhasePanierTestCase { +abstract class PhasePanierNanookTestCase extends PhasePanierTestCase { protected $_basket; protected function _prepareFixtures() { @@ -488,6 +487,18 @@ class PhasePanierNanookTest extends PhasePanierTestCase { 'role_level' => ZendAfi_Acl_AdminControllerRoles::SUPER_ADMIN, 'idabon' => '', 'mail' => '']); + } +} + + + + +/** @see http://forge.afi-sa.fr/issues/33712 */ +class PhasePanierNanookTest extends PhasePanierNanookTestCase { + protected $_basket; + + protected function _prepareFixtures() { + parent::_prepareFixtures(); $this->fixture(Class_Notice::class, ['id' => 23, @@ -535,3 +546,55 @@ class PhasePanierNanookTest extends PhasePanierTestCase { $this->assertEquals(['CASTAFIORE'], $this->_basket->getClesNotices()); } } + + + + +/** @see http://forge.afi-sa.fr/issues/163609 */ +class PhasePanierNanookWithGhostItemsTest extends PhasePanierNanookTestCase { + protected $_basket; + + protected function _prepareFixtures() { + parent::_prepareFixtures(); + + $this->fixture(Class_IntBib::class, + ['id' => 3, + 'nom_court' => 'Annexe 3', + 'sigb' => 13]); + + $this->fixture(Class_Notice::class, + ['id' => 230, + 'type_doc' => Class_TypeDoc::LIVRE, + 'clef_alpha' => 'CASTAFIORE', + 'exemplaires' => [$this->fixture(Class_Exemplaire::class, + ['id' => 231, + 'id_int_bib' => 3, + 'id_origine' => 45633])]]); + $this->fixture(Class_Notice::class, + ['id' => 234, + 'type_doc' => Class_TypeDoc::LIVRE, + 'clef_alpha' => 'BOB MORANE AVENTURIER', + 'exemplaires' => [$this->fixture(Class_Exemplaire::class, + ['id' => 235, + 'id_int_bib' => 2, + 'id_origine' => 189699])]]); + } + + + /** @test */ + public function panierNoticesLogShouldContainsCastafiore() { + $this->assertLogContains('Un exemplaire id_origine : 45633 / id_int_bib : 3 a été trouvé. alors que nous cherchions id_int_bib 2'); + } + + + /** @test */ + public function panierNoticesShouldContainsCastafiore() { + $this->assertContains('CASTAFIORE',Class_PanierNotice::findFirstBy(['id_sigb' => 509])->getNotices()); + } + + + /** @test */ + public function panierNoticesShouldBeCastafioreAndBobMorane() { + $this->assertContains('BOB MORANE AVENTURIER',Class_PanierNotice::findFirstBy(['id_sigb' => 509])->getNotices()); + } +}