diff --git a/VERSIONS_HOTLINE/50880 b/VERSIONS_HOTLINE/50880 new file mode 100644 index 0000000000000000000000000000000000000000..00a694ed9d17f4b22b6b52ffbc3f3262092dcfef --- /dev/null +++ b/VERSIONS_HOTLINE/50880 @@ -0,0 +1 @@ + - ticket #50880 : Intégration cosmogramme : correction de la phase d'import des paniers. \ No newline at end of file diff --git a/library/Class/Cosmogramme/Integration/PhasePanier.php b/library/Class/Cosmogramme/Integration/PhasePanier.php index e1a732bf71bb825b2b87a1a64d75b38d4341f61f..600af5daea6ab3665a34d51386e2f4950cee8317 100644 --- a/library/Class/Cosmogramme/Integration/PhasePanier.php +++ b/library/Class/Cosmogramme/Integration/PhasePanier.php @@ -72,10 +72,12 @@ class Class_Cosmogramme_Integration_PhasePanier extends Class_Cosmogramme_Integr protected function mapRecordColumns($integration, $datas) { - $fields = $this->getFields($integration->getProfilDonnees()); + if(!$fields = $this->getFields($integration->getProfilDonnees())) + return []; + $map = []; foreach($fields as $k => $name) - $map[strtolower($name)] = $datas[$k]; + $map[strtolower($name)] = isset($datas[$k]) ? $datas[$k] : ''; return $map; } @@ -88,21 +90,28 @@ class Class_Cosmogramme_Integration_PhasePanier extends Class_Cosmogramme_Integr protected function importBasketRecord($datas, $integration) { - if (sizeof($datas) != sizeof($this->getFields($integration->getProfilDonnees()))) - return; + if(!$map = $this->mapRecordColumns($integration, $datas)) + return $this->_log->addError($this->_('Pas de donnée trouvée avec le profil de données sélectionné')); - $map = $this->mapRecordColumns($integration, $datas); + if(!$map['libelle']) + return $this->_log->addError($this->_('Ligne non traitée car le libellé n\'a pas pu être lu')); if (!$exemplaire = Class_Exemplaire::findFirstBy(['id_origine' => $map['id_notice_sigb'], - 'id_int_bib' => $integration->getId()])) - return; + 'id_int_bib' => $integration->getIdBib()])) { + $this->_log->addError($this->_('L\'exemplaire id_origine : %s / id_int_bib : %s n\'a pas été trouvé.', + $map['id_notice_sigb'], + $integration->getIdBib())); + $exemplaire = new Class_Entity(); + } $owners = $this->findPossibleOwnersOfBasketRecord($map); - if ($owners->isEmpty() && $integration->isPergame()) - $owners->addAll([Class_Users::find(1)]); - - if ($owners->isEmpty()) - return $this->_log->addError('Panier orphelin: ' . $map['libelle']); + if ($owners->isEmpty()) { + $user = Class_Users::find(1); + $this->_log->addError($this->_('Le panier "%s" est orphelin. Il sera rattaché à l\'utilisateur "%s"', + $map['libelle'], + $user->getLogin())); + $owners->addAll([$user]); + } $owner = $owners->first(); diff --git a/library/Class/PanierNotice.php b/library/Class/PanierNotice.php index 2ad77b19e99d02362e4069e13baab07a8e47f848..209ebc2ab3e81bc4876538e7f5423acf300f7771 100644 --- a/library/Class/PanierNotice.php +++ b/library/Class/PanierNotice.php @@ -327,6 +327,9 @@ class Class_PanierNotice extends Storm_Model_Abstract { * @return Class_PanierNotice */ public function addNotice($notice) { + if(!$notice) + return $this; + return $this->setClesNotices(array_merge($this->getClesNotices(), [$notice->getClefAlpha()])) ->setDateMaj(date('Y-m-d')); } diff --git a/tests/library/Class/Cosmogramme/Integration/PhasePanierTest.php b/tests/library/Class/Cosmogramme/Integration/PhasePanierTest.php index d76d74fa56f30748c266d9760e7629f7ccd9ebd1..d2741effe13d8001a48cf798de0ee14384f4ab6f 100644 --- a/tests/library/Class/Cosmogramme/Integration/PhasePanierTest.php +++ b/tests/library/Class/Cosmogramme/Integration/PhasePanierTest.php @@ -20,6 +20,8 @@ */ abstract class PhasePanierTestCase extends Class_Cosmogramme_Integration_PhaseTestCase { + protected $_storm_default_to_volatile = true; + protected function _getPreviousPhase() { return (new Class_Cosmogramme_Integration_Phase(14)) ->beCron(); @@ -95,7 +97,7 @@ abstract class PhasePanierKohaTestCase extends PhasePanierTestCase { $this->fixture('Class_PanierNotice', ['id' => 1, 'id_sigb' => 1, - 'id_int_bib' => 999, + 'id_int_bib' => 2, 'libelle' => 'ciné', 'notices' => 'COKEENSTOCK']); @@ -110,7 +112,7 @@ abstract class PhasePanierKohaTestCase extends PhasePanierTestCase { ['id' => 3, 'id_user' => 4, 'id_sigb' => 1, - 'id_int_bib' => 98, + 'id_int_bib' => 2, 'libelle' => 'mon autre panier', 'notices' => 'VOL714']); @@ -118,7 +120,7 @@ abstract class PhasePanierKohaTestCase extends PhasePanierTestCase { ['id' => 4, 'id_user' => 3, 'id_sigb' => 1, - 'id_int_bib' => 999, + 'id_int_bib' => 2, 'libelle' => 'will be killed', 'notices' => 'VOL714']); @@ -127,7 +129,7 @@ abstract class PhasePanierKohaTestCase extends PhasePanierTestCase { 'clef_alpha' => 'CASTAFIORE', 'exemplaires' => [$this->fixture('Class_Exemplaire', ['id' => 231, - 'id_int_bib' => 999, + 'id_int_bib' => 2, 'id_origine' => 39925])]]); $this->fixture('Class_Notice', @@ -135,7 +137,7 @@ abstract class PhasePanierKohaTestCase extends PhasePanierTestCase { 'clef_alpha' => 'TIBET', 'exemplaires' => [$this->fixture('Class_Exemplaire', ['id' => 4511, - 'id_int_bib' => 999, + 'id_int_bib' => 2, 'id_origine' => 72490])]]); $this->fixture('Class_Notice', @@ -143,7 +145,7 @@ abstract class PhasePanierKohaTestCase extends PhasePanierTestCase { 'clef_alpha' => 'LUNE', 'exemplaires' => [$this->fixture('Class_Exemplaire', ['id' => 241, - 'id_int_bib' => 999, + 'id_int_bib' => 2, 'id_origine' => 58265])]]); } @@ -153,27 +155,28 @@ abstract class PhasePanierKohaTestCase extends PhasePanierTestCase { - class PhasePanierKohaSameIdOrigine extends PhasePanierKohaTestCase { public function _prepareFixtures() { parent::_prepareFixtures(); - Class_Notice::find(45)->addExemplaire($this->fixture('Class_Exemplaire', - ['id' => 22, - 'id_origine' => 58265, - 'id_int_bib' => 98 - ]))->save(); + } + - Class_Notice::find(24)->setExemplaires([$this->fixture('Class_Exemplaire', - ['id' => 243, - 'id_origine' => 58265, - 'id_int_bib' => 999])])->save(); + public function tearDown() { + Class_Notice::deleteby([]); + Class_PanierNotice::deleteBy([]); + Class_Exemplaire::deleteBy([]); + Class_IntProfilDonnees::deleteBy([]); + Class_Cosmogramme_Integration::deleteBy([]); + parent:: tearDown(); } /** @test */ public function firstBasketRecordsShouldContainNoticeLune() { - $this->assertEquals([ 'CASTAFIORE', 'LUNE'], + $this->assertEquals(['COKEENSTOCK', + 'CASTAFIORE', + 'LUNE'], Class_PanierNotice::find(1)->getClesNotices()); } @@ -202,8 +205,8 @@ class PhasePanierFullImportTest extends PhasePanierKohaTestCase { /** @test */ - public function numberOfBasketsShouldBeSeven() { - $this->assertCount(7, Class_PanierNotice::findAll()); + public function numberOfBasketsShouldBeTen() { + $this->assertCount(10, Class_PanierNotice::findAll()); } @@ -214,11 +217,8 @@ class PhasePanierFullImportTest extends PhasePanierKohaTestCase { /** @test */ - public function basketFiveLibelleShouldBeFroidLitterature() { - $libelle = ($panier = Class_PanierNotice::find(5)) - ? $panier->getLibelle() - : ''; - $this->assertEquals('froid litterature', $libelle); + public function basketTrouNoirShouldHaveBeenCreated() { + $this->assertNotNull(Class_PanierNotice::findFirstBy(['libelle' => 'trou noir'])); } @@ -247,17 +247,14 @@ class PhasePanierFullImportTest extends PhasePanierKohaTestCase { /** @test */ - public function basketAtFiveShouldBeOwnedByTintin() { - $login = ($panier = Class_PanierNotice::find(5)) - ? $panier->getUserLogin() - : ''; - $this->assertEquals('tintin', $login); + public function basketFroidLitteratureShouldBeOwnedByTintin() { + $this->assertEquals('tintin', Class_PanierNotice::findFirstBy(['libelle' => 'froid litterature'])->getUserLogin()); } /** @test */ - public function fourthBasketShouldBeDeleted() { - $this->assertNull(Class_PanierNotice::find(4)); + public function basketTitiShouldBeEmpty() { + $this->assertEmpty(Class_PanierNotice::findFirstBy(['id_sigb' => '7'])->getClesNotices()); } @@ -269,7 +266,9 @@ class PhasePanierFullImportTest extends PhasePanierKohaTestCase { /** @test */ public function firstBasketRecordsShouldContains3items() { - $this->assertEquals([ 'CASTAFIORE', 'LUNE'], + $this->assertEquals(['COKEENSTOCK', + 'CASTAFIORE', + 'LUNE'], Class_PanierNotice::find(1)->getClesNotices()); } @@ -283,13 +282,13 @@ class PhasePanierFullImportTest extends PhasePanierKohaTestCase { /** @test */ public function logShouldContainsPanierOrphelinTrouNoir() { - $this->assertLogContains('Panier orphelin: trou noir'); + $this->assertLogContains('Le panier "trou noir" est orphelin. Il sera rattaché à l\'utilisateur "milou_pro"'); } /** @test */ public function logShouldContainsPanierOrphelinVideSideral() { - $this->assertLogContains('Panier orphelin: vide sideral'); + $this->assertLogContains('Le panier "vide sideral" est orphelin. Il sera rattaché à l\'utilisateur "milou_pro"'); } @@ -431,7 +430,7 @@ class PhasePanierNanookTest extends PhasePanierTestCase { 'clef_alpha' => 'CASTAFIORE', 'exemplaires' => [$this->fixture('Class_Exemplaire', ['id' => 231, - 'id_int_bib' => 999, + 'id_int_bib' => 2, 'id_origine' => 45633])]]); } diff --git a/tests/library/Class/Cosmogramme/Integration/baskets-piped.txt b/tests/library/Class/Cosmogramme/Integration/baskets-piped.txt index b5e6c772de9f023e5b1fe71fedc2fd386c95ab82..ea42d794c046983146539346370e9ae412b4a8cb 100644 --- a/tests/library/Class/Cosmogramme/Integration/baskets-piped.txt +++ b/tests/library/Class/Cosmogramme/Integration/baskets-piped.txt @@ -6,7 +6,7 @@ 6|"froid litterature"|1234|tintin@herge.fr|1|72490 6|"froid litterature"|1234|tintin@herge.fr|1|67220 6|"froid litterature"|1234|tintin@herge.fr|1| -7|"titi"||tintin@herge.fr|1|72490 +7|"titi"||tintin@herge.fr|1| 9|bd,texte||tintin@herge.fr|1|72490 10|"vide sideral"|||1|72490 |"cine"|0006||0|39925 diff --git a/tests/library/Class/Cosmogramme/Integration/baskets-semicolon.txt b/tests/library/Class/Cosmogramme/Integration/baskets-semicolon.txt index 9da53d8dbd99b38ddfe1c60c8c5e47ea12fba9fe..0a67b237976ce3b39031295b0d0ba8e40e39e20e 100644 --- a/tests/library/Class/Cosmogramme/Integration/baskets-semicolon.txt +++ b/tests/library/Class/Cosmogramme/Integration/baskets-semicolon.txt @@ -6,7 +6,7 @@ 6;"froid litterature";1234;tintin@herge.fr;1;72490 6;"froid litterature";1234;tintin@herge.fr;1;67220 6;"froid litterature";1234;tintin@herge.fr;1; -7;"titi";;tintin@herge.fr;1;72490 +7;"titi";;tintin@herge.fr;1;0 9;"bd,texte";;tintin@herge.fr;1;72490 10;"vide sideral";;;1;72490 ;"cine";0006;;0;39925 diff --git a/tests/library/Class/Cosmogramme/Integration/baskets.txt b/tests/library/Class/Cosmogramme/Integration/baskets.txt index 4ec9c4d8ea0b8dc3825d95486145275194393630..e586e240f60ae1fb3eedd36a523c38c9c6ef3978 100644 --- a/tests/library/Class/Cosmogramme/Integration/baskets.txt +++ b/tests/library/Class/Cosmogramme/Integration/baskets.txt @@ -5,7 +5,7 @@ 6,"froid litterature",1234,tintin@herge.fr,1,72490 6,"froid litterature",1234,tintin@herge.fr,1,67220 6,"froid litterature",1234,tintin@herge.fr,1, -7,"titi",,tintin@herge.fr,1,72490 +7,"titi",,tintin@herge.fr,1,789789798 9,"bd,texte",,tintin@herge.fr,1,72490 10,"vide sideral",,,1,72490 ,"cine",0006,,0,39925