From e2dd0e8c0e255f26d4cc788294a9fd3a35bf47e5 Mon Sep 17 00:00:00 2001 From: Henri-Damien LAURENT <hdlaurent@afi-sa.fr> Date: Tue, 22 Jun 2021 19:57:43 +0200 Subject: [PATCH] hotline#128960 : Paniers : Correction de la synchronisation des paniers --- VERSIONS_HOTLINE/129860 | 1 + .../Cosmogramme/Integration/PhasePanier.php | 21 ++- .../Integration/PhasePanierTest.php | 144 ++++++++++++++++-- .../PhasePrepareIntegrationsTest.php | 21 ++- 4 files changed, 169 insertions(+), 18 deletions(-) create mode 100644 VERSIONS_HOTLINE/129860 diff --git a/VERSIONS_HOTLINE/129860 b/VERSIONS_HOTLINE/129860 new file mode 100644 index 00000000000..36ef33e3137 --- /dev/null +++ b/VERSIONS_HOTLINE/129860 @@ -0,0 +1 @@ + - ticket #129860 : Intégrations : Les paniers vides non utilisés dans les domaines sont maintenant supprimés lors d'un import total de panier. \ No newline at end of file diff --git a/library/Class/Cosmogramme/Integration/PhasePanier.php b/library/Class/Cosmogramme/Integration/PhasePanier.php index a9b9358f491..983ecc0b0ea 100644 --- a/library/Class/Cosmogramme/Integration/PhasePanier.php +++ b/library/Class/Cosmogramme/Integration/PhasePanier.php @@ -163,12 +163,31 @@ class Class_Cosmogramme_Integration_PhasePanier protected function _clean($integration) { - $baskets = Class_PanierNotice::findAllBy(['integration_hash' => $integration->getHash()]); + $this->_cleanOldCarts($integration); + + $baskets = Class_PanierNotice::findAllBy(['id_int_bib' => $integration->getIdBib()]); foreach($baskets as $basket) $basket->setNotices('')->save(); } + protected function _cleanOldCarts($integration) { + if (0 === count($all_integration = Class_IntBib::findAll())) + return; + + $id_bib = $integration->getIdBib(); + + $id_bibs = array_map(function($integration) + { + return $integration->getIdBib(); + }, $all_integration); + + foreach ( Class_PanierNotice::findAllBy(['id_sigb not' => [null, '', 0], + 'id_int_bib not' => $id_bibs]) as $old_cart) + $old_cart->setIdIntBib($id_bib)->save(); + } + + protected function _shouldIgnoreLine($line, $integration) { return $line->withDataDo([$this, 'isHeader']); } diff --git a/tests/library/Class/Cosmogramme/Integration/PhasePanierTest.php b/tests/library/Class/Cosmogramme/Integration/PhasePanierTest.php index 9ce502309cd..e737b9d05b6 100644 --- a/tests/library/Class/Cosmogramme/Integration/PhasePanierTest.php +++ b/tests/library/Class/Cosmogramme/Integration/PhasePanierTest.php @@ -51,12 +51,11 @@ abstract class PhasePanierTestCase extends Class_Cosmogramme_Integration_PhaseTe 'fichier' => 'baskets.txt', 'nom_fichier' => 'baskets.txt', 'pointeur_reprise' => 0]); - } + } public function setUp() { parent::setUp(); - $this->_phase = $this->_buildPhase('Panier') ->setMemoryCleaner(function() {}) ->setPrinter($this->_printer) @@ -219,8 +218,8 @@ class PhasePanierKohaSameIdOrigineTest extends PhasePanierKohaTestCase { /** @test */ - public function firstBasketRecordsShouldContainsCOKEENSTOCKCASTAFIORELUNE() { - $this->assertEquals('COKEENSTOCK;CASTAFIORE;LUNE', + public function firstBasketRecordsShouldContainsCASTAFIORELUNE() { + $this->assertEquals('CASTAFIORE;LUNE', Class_PanierNotice::find(1)->getNotices()); } } @@ -277,7 +276,7 @@ class PhasePanierFullImportTest extends PhasePanierKohaTestCase { /** @test */ public function numberOfBasketsShouldBeEight() { - $this->assertCount(9, Class_PanierNotice::findAll()); + $this->assertCount(8, Class_PanierNotice::findAll()); } @@ -312,8 +311,8 @@ class PhasePanierFullImportTest extends PhasePanierKohaTestCase { /** @test */ - public function thirdBasketShouldNotBeModified() { - $this->assertEquals(['VOL714'], Class_PanierNotice::find(3)->getClesNotices()); + public function thirdBasketShouldBeDeleted() { + $this->assertNull( Class_PanierNotice::find(3)); } @@ -331,9 +330,8 @@ class PhasePanierFullImportTest extends PhasePanierKohaTestCase { /** @test */ - public function firstBasketRecordsShouldContains3items() { - $this->assertEquals(['COKEENSTOCK', - 'CASTAFIORE', + public function firstBasketRecordsShouldContains2items() { + $this->assertEquals(['CASTAFIORE', 'LUNE'], Class_PanierNotice::find(1)->getClesNotices()); } @@ -542,3 +540,129 @@ class PhasePanierNanookTest extends PhasePanierTestCase { $this->assertEquals(2, $this->_basket->getIdIntBib()); } } + + + + +class PhasePanierWithOldCartAndUserCartInDbTests extends PhasePanierTestCase { + public function _prepareFixtures() { + parent::_prepareFixtures(); + + $this->fixture('Class_Users', + ['id' => 1, + 'login' => 'milou_pro', + 'password' => 'secret', + 'role_level' => ZendAfi_Acl_AdminControllerRoles::MODO_PORTAIL, + 'idabon' => '0006', + 'mail' => 'milou@herge.fr']); + + $this->fixture('Class_PanierNotice', + ['id' => 78, + 'id_sigb' => 898, + 'id_int_bib' => 897, + 'libelle' => 'ciné', + 'notices' => 'COKEENSTOCK']); + + $this->fixture('Class_PanierNotice', + ['id' => 23423423, + 'id_sigb' => null, + 'id_int_bib' => null, + 'libelle' => 'mes préférés', + 'notices' => '']); + + $this->fixture('Class_PanierNotice', + ['id' => 782374, + 'id_sigb' => 0, + 'id_int_bib' => 0, + 'libelle' => 'mes favoris', + 'notices' => '']); + + $this->fixture('Class_PanierNotice', + ['id' => 12131231, + 'id_sigb' => '', + 'id_int_bib' => '', + 'libelle' => 'à lire', + 'notices' => '']); + } + + + /** @test */ + public function cartCinéShouldBeDeleted() { + Class_PanierNotice::clearCache(); + $this->assertNull(Class_PanierNotice::find(78)); + } + + + /** @test */ + public function cartMesPréféresShouldExists() { + $this->assertNotNull(Class_PanierNotice::find(23423423)); + } + + + /** @test */ + public function cartMesfavorisShouldExists() { + $this->assertNotNull(Class_PanierNotice::find(782374)); + } + + + /** @test */ + public function cartAlireShouldExists() { + $this->assertNotNull(Class_PanierNotice::find(12131231)); + } +} + + + + +class PhasePanierWithMultipleIntegrationLibraryAndOldCartAndUserCartInDbTests extends PhasePanierTestCase { + public function _prepareFixtures() { + parent::_prepareFixtures(); + + $this->fixture('Class_IntBib', + ['id' => 3, + 'nom_court' => 'Annexe 3', + 'sigb' => 14]); + + $this->fixture('Class_Users', + ['id' => 1, + 'login' => 'milou_pro', + 'password' => 'secret', + 'role_level' => ZendAfi_Acl_AdminControllerRoles::MODO_PORTAIL, + 'idabon' => '0006', + 'mail' => 'milou@herge.fr']); + + $this->fixture('Class_PanierNotice', + ['id' => 78, + 'id_sigb' => 898, + 'id_int_bib' => 897, + 'libelle' => 'ciné', + 'notices' => 'COKEENSTOCK']); + + $this->fixture('Class_PanierNotice', + ['id' => 23423423, + 'id_sigb' => 123, + 'id_int_bib' => 3, + 'libelle' => 'mes préférés', + 'notices' => '']); + + $this->fixture('Class_PanierNotice', + ['id' => 782374, + 'id_sigb' => 125, + 'id_int_bib' => 2, + 'libelle' => 'mes favoris', + 'notices' => '']); + } + + + /** @test */ + public function cartCinéShouldBeDeleted() { + Class_PanierNotice::clearCache(); + $this->assertNull(Class_PanierNotice::find(78)); + } + + + /** @test */ + public function cartMesPréféresShouldExists() { + $this->assertNotNull(Class_PanierNotice::find(23423423)); + } +} \ No newline at end of file diff --git a/tests/library/Class/Cosmogramme/Integration/PhasePrepareIntegrationsTest.php b/tests/library/Class/Cosmogramme/Integration/PhasePrepareIntegrationsTest.php index d15d2746c3c..1242b7c8319 100644 --- a/tests/library/Class/Cosmogramme/Integration/PhasePrepareIntegrationsTest.php +++ b/tests/library/Class/Cosmogramme/Integration/PhasePrepareIntegrationsTest.php @@ -230,7 +230,7 @@ abstract class PhasePrepareIntegrationsWithOAITestCase 'taille_min_import_total' => 10]); - $this->fixture('Class_Cosmogramme_Integration', + $this->fixture(Class_Cosmogramme_Integration::class, ['id' => 1, 'id_bib' => 2, 'type_operation' => Class_Cosmogramme_Integration::TYPE_OPERATION_TOTAL, @@ -238,6 +238,13 @@ abstract class PhasePrepareIntegrationsWithOAITestCase 'traite' => 'oui', 'fichier' => 'http://oai-repository.fr/oai', 'pointeur_reprise' => 'SCD01@000195008000000979marc21-18]']); + + $this->fixture(Class_Cosmogramme_Integration::class, + ['id' => 2, + 'id_bib' => 2, + 'type_operation' => Class_Cosmogramme_Integration::TYPE_OPERATION_TOTAL, + 'profil' => 113, + 'traite' => 'oui']); } @@ -261,8 +268,8 @@ class PhasePrepareIntegrationsWithOAITest extends PhasePrepareIntegrationsWithOA /** @test */ - public function fiveIntegrationsShouldHaveBeenCreated() { - $this->assertEquals(5, count(Class_Cosmogramme_Integration::findAll())); + public function sixIntegrationsShouldHaveBeenCreated() { + $this->assertEquals(6, count(Class_Cosmogramme_Integration::findAll())); } @@ -275,28 +282,28 @@ class PhasePrepareIntegrationsWithOAITest extends PhasePrepareIntegrationsWithOA /** @test */ public function secondIntegrationShouldBeIncremental() { - $this->assertTrue(Class_Cosmogramme_Integration::find(3)->isIncrement()); + $this->assertTrue(Class_Cosmogramme_Integration::find(4)->isIncrement()); } /** @test */ public function secondIntegrationFileShouldContainsDate() { $this->assertContains('[DATE]', - Class_Cosmogramme_Integration::find(3)->getNomFichier()); + Class_Cosmogramme_Integration::find(4)->getNomFichier()); } /** @test */ public function thirdIntegrationURIShouldBeOAIRepository() { $this->assertEquals('http://oai-repository.fr/oai', - Class_Cosmogramme_Integration::find(5)->getFichier()); + Class_Cosmogramme_Integration::find(6)->getFichier()); } /** @test */ public function thirdIntegrationTransfertDateShouldBeBar() { $this->assertEquals('2015-03-26', - Class_Cosmogramme_Integration::find(4)->getDateTransfert()); + Class_Cosmogramme_Integration::find(5)->getDateTransfert()); } -- GitLab