diff --git a/VERSIONS_HOTLINE/#29082 b/VERSIONS_HOTLINE/#29082 new file mode 100644 index 0000000000000000000000000000000000000000..fc21cdc8e137debd1608ff68ca43cff1264a279f --- /dev/null +++ b/VERSIONS_HOTLINE/#29082 @@ -0,0 +1 @@ + - ticket #29082 : correction de l'indexation des articles et des sitothèques dans les domaines \ No newline at end of file diff --git a/library/Class/Catalogue.php b/library/Class/Catalogue.php index 98082e25cfc8ec8015a32afaf22680835eb5970a..79f20e0e498f47c0ec89add004c3d1527de13262 100644 --- a/library/Class/Catalogue.php +++ b/library/Class/Catalogue.php @@ -537,6 +537,13 @@ class CatalogueLoader extends Storm_Model_Loader { return $thesaurus; } + + + public function getIds($domains) { + return (new Storm_Model_Collection($domains)) + ->collect('id') + ->getArrayCopy(); + } } diff --git a/library/Class/Notice.php b/library/Class/Notice.php index 2dc8bdc49513831dc7ec1bab3f82d50da1687286..75f92e8c4d15f8caa88b23f7389916ac84e54760 100644 --- a/library/Class/Notice.php +++ b/library/Class/Notice.php @@ -143,10 +143,7 @@ class Class_Notice extends Storm_Model_Abstract { protected $_notice_unimarc; protected $_has_many = ['exemplaires' => ['model' => 'Class_Exemplaire', 'role' => 'notice', - 'dependents' => 'delete'], - 'notice_domain' => ['model' => 'Class_NoticeDomain', - 'role' => 'domain', - 'dependents' => 'delete']]; + 'dependents' => 'delete']]; protected $_titre_principal, diff --git a/library/Class/NoticeDomain.php b/library/Class/NoticeDomain.php index 383b1976bd8541879ff617d9103a158513cf3d05..5d2f5bffa138311af7e40258ae791f075cb7d4b8 100644 --- a/library/Class/NoticeDomain.php +++ b/library/Class/NoticeDomain.php @@ -29,13 +29,9 @@ class NoticeDomainLoader extends Storm_Model_Loader { } $all_domain_ids = array_filter(array_unique($all_domain_ids)); - - $domains = []; - foreach ($all_domain_ids as $id) { - $domains[] = Class_Catalogue::find($id); - } - return $domains; - + return $all_domain_ids + ? Class_Catalogue::findAllBy(['id_catalogue' => $all_domain_ids]) + : []; } public function getClesNoticesForDomain($domain_id) { diff --git a/library/Trait/HasManyDomaines.php b/library/Trait/HasManyDomaines.php index 1d74ef8edee3fa1f06022700c18afa52aba245fa..879feab62ce5204b78a6d5058e0399b2bfe0a84e 100644 --- a/library/Trait/HasManyDomaines.php +++ b/library/Trait/HasManyDomaines.php @@ -31,17 +31,14 @@ trait Trait_HasManyDomaines { public function getDomaineIdsAsArray() { $domaines = $this->_get('domaine_ids') ; - return array_filter(explode(';',$domaines)); + return array_filter(explode(';', $domaines)); } public function getDomaines() { - $ids = $this->getDomaineIdsAsArray(); - $domaines = []; - foreach ($ids as $id) { - $domaines[] = Class_Catalogue::find($id); - } - return $domaines; + return empty($domains = $this->getDomaineIdsAsArray()) + ? [] + : Class_Catalogue::findAllBy(['id_catalogue' => $domains]); } diff --git a/library/Trait/Indexable.php b/library/Trait/Indexable.php index 5d35e0f6b8724b50f24c618c230f52e8c7a3e997..9c82a8644040bfd8a03829e4e48e0be6c19aa9af 100644 --- a/library/Trait/Indexable.php +++ b/library/Trait/Indexable.php @@ -30,15 +30,19 @@ trait Trait_Indexable { protected function indexIntoDomain() { - if(!$domains_ids = $this->getDomaineIdsAsArray()) - return $this; - if(!$alpha_key = $this->getAlphaKey()) { return $this; } + $domains_ids = Class_Catalogue::getIds($this->getDomaines()); + $existing = Class_NoticeDomain::findAllBy(['record_alpha_key' => $alpha_key]); - $existing_ids = array_map(function ($item) { return $item->getDomainId();}, $existing); + + $existing_domains = array_filter(array_map(function ($item) { + return $item->getDomain(); + }, $existing)); + + $existing_ids = array_map(function ($item) { return $item->getId();}, $existing_domains); if ($to_delete = array_diff($existing_ids, $domains_ids)) Class_NoticeDomain::deleteBy(['record_alpha_key' => $alpha_key, @@ -56,6 +60,8 @@ trait Trait_Indexable { foreach(Class_NoticeDomain::findAllBy(['record_alpha_key' => $alpha_key]) as $notice_domain) $notice_domain->updateFacette(); + $this->setDomaineIds($domains_ids)->save(); + return $this; } @@ -68,16 +74,16 @@ trait Trait_Indexable { public function unindex() { $alpha_key = $this->getAlphaKey(); - $domains = $this->getDomaines(); - if (empty($domains)) { + $domains_ids = Class_Catalogue::getIds($this->getDomaines()); + if (empty($domains_ids)) { Class_NoticeDomain::deleteBy(['record_alpha_key' => $alpha_key, 'panier_id' => 0]); } - $domains_in_db = Class_NoticeDomain::getDomainsForRecordAlphaKey($alpha_key); + $domains_in_db_ids = Class_Catalogue::getIds(Class_NoticeDomain::getDomainsForRecordAlphaKey($alpha_key)); - foreach(array_diff($domains_in_db, $domains) as $domain) - Class_NoticeDomain::deleteBy(['domain_id' => $domain->getId()]); + if ($to_delete = array_diff($domains_in_db_ids, $domains_ids)) + Class_NoticeDomain::deleteBy(['domain_id' => $to_delete]); } diff --git a/library/storm b/library/storm index 08c073b2bfde86b0d4d4f4ed3ef8503543fa4506..e8b3587ac7dd17e67ce4d968cc7d3e1c1b9a1d5d 160000 --- a/library/storm +++ b/library/storm @@ -1 +1 @@ -Subproject commit 08c073b2bfde86b0d4d4f4ed3ef8503543fa4506 +Subproject commit e8b3587ac7dd17e67ce4d968cc7d3e1c1b9a1d5d diff --git a/tests/application/modules/admin/controllers/AdminAvisModerationControllerTest.php b/tests/application/modules/admin/controllers/AdminAvisModerationControllerTest.php index 9a77e0098ca1bb33042855e4dd53cbddfdb19d26..2f9324112698c367aac768888c8e5b30a2f3ca2e 100644 --- a/tests/application/modules/admin/controllers/AdminAvisModerationControllerTest.php +++ b/tests/application/modules/admin/controllers/AdminAvisModerationControllerTest.php @@ -362,7 +362,7 @@ class AdminAvisModerationControllerCmsWithAvisTest extends AdminAvisModerationCo /** @test */ public function pageShouldContainsLinkToArticle() { $this->assertXPathContentContains('//a[contains(@href, "/admin/cms/viewcms/id/9")]', - "Tintin à Annecy", + "Tintin à Annecy", $this->_response->getBody()); } diff --git a/tests/library/Class/AgendaSQYImportTest.php b/tests/library/Class/AgendaSQYImportTest.php index 7da00334b869cdebc35bcd9b0a94a3299e6dbac9..f8eafbd9ddc8708dd574772d15524dd4abba595c 100644 --- a/tests/library/Class/AgendaSQYImportTest.php +++ b/tests/library/Class/AgendaSQYImportTest.php @@ -78,7 +78,7 @@ class AgendaSQYImportTest extends Storm_Test_ModelTestCase { Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Catalogue') ->whenCalled('save')->answers(true) - ->whenCalled('findAllBy')->answers(null) + ->whenCalled('findAllBy')->answers([]) ->whenCalled('findAllBy')->with(['where' => 'parent_id is null', 'order' => 'libelle'])->answers([$domaine_musique]); @@ -96,7 +96,7 @@ class AgendaSQYImportTest extends Storm_Test_ModelTestCase { Storm_Test_ObjectWrapper::onLoaderOfModel('Class_ArticleCategorie') ->whenCalled('save')->answers(true) - ->whenCalled('findAllBy')->answers(null) + ->whenCalled('findAllBy')->answers([]) ->whenCalled('findAllBy')->with(['id_cat_mere' => 0])->answers([$categorie_musique]); @@ -379,8 +379,8 @@ class AgendaSQYImportTest extends Storm_Test_ModelTestCase { } - /** - * @test + /** + * @test * @depends lieuFermeBelEbatShouldHavePhone0130483344 */ public function lieuFermeBelEbatMailShouldBeSet($ferme) { @@ -388,16 +388,16 @@ class AgendaSQYImportTest extends Storm_Test_ModelTestCase { } - /** - * @test + /** + * @test * @depends lieuFermeBelEbatShouldHavePhone0130483344 */ public function lieuFermeBelEbatLatitueShouldBe48_7($ferme) { $this->assertEquals('48.770757', $ferme->getLatitude()); } - /** - * @test + /** + * @test * @depends lieuFermeBelEbatShouldHavePhone0130483344 */ public function lieuFermeBelEbatLongitudeShouldBe2($ferme) { @@ -405,8 +405,8 @@ class AgendaSQYImportTest extends Storm_Test_ModelTestCase { } - /** - * @test + /** + * @test * @depends lieuFermeBelEbatShouldHavePhone0130483344 */ public function lieuFermeBelEbatUrlShouldBeLaFermeDeBelEbatDotFr($ferme) { diff --git a/tests/library/Class/Import/Typo3Test.php b/tests/library/Class/Import/Typo3Test.php index f26b41ce45ea811f9c4ee98aa1888955d27f1135..38efa977bfc335bb6322fe04589c0fb3b39e8d2c 100644 --- a/tests/library/Class/Import/Typo3Test.php +++ b/tests/library/Class/Import/Typo3Test.php @@ -271,7 +271,7 @@ class Import_Typo3ArticleTest extends Import_Typo3TestCase { /** @test */ public function articleABordDuBateauPirateShouldBeInDomainAutres() { - $this->assertEquals(['Divers', 'NOS TOPS 5', 'Autres'], + $this->assertEquals(['Divers', 'Autres', 'NOS TOPS 5'], $this->bateau_pirate->getDomaineLibelles()); } @@ -601,7 +601,7 @@ class Import_Typo3SitothequeTest extends Import_Typo3TestCase { /** @test */ public function museoParcShouldBeInDomainAutres() { - $this->assertEquals(['Divers', 'NOS TOPS 5', 'Autres'], + $this->assertEquals(['Divers', 'Autres', 'NOS TOPS 5'], $this->sito->getDomaineLibelles()); } diff --git a/tests/library/Class/SitothequeTest.php b/tests/library/Class/SitothequeTest.php index 5711941b9cb4a106fd0d73fbc740000a4e6066ba..5d8250a6f4b8ecc132c3bf2d193cc4f84b7437cf 100644 --- a/tests/library/Class/SitothequeTest.php +++ b/tests/library/Class/SitothequeTest.php @@ -71,7 +71,6 @@ class SitothequeIndexAllTest extends Storm_Test_ModelTestCase { 'domaine_ids' => '1']); Class_Sitotheque::indexAll(); - Class_Sitotheque::find(3)->setDomaineIds('1')->save(); } @@ -97,9 +96,18 @@ class SitothequeIndexAllTest extends Storm_Test_ModelTestCase { public function domainShouldHaveMySito2Record() { $this->assertNotNull(Class_NoticeDomain::findFirstBy(['record_alpha_key' => 'MYSITO2------10'])); } + + + /** @test */ + public function removingMyDomainShouldRemoveFacetInMySito() { + Class_Catalogue::find(1)->delete(); + Class_Sitotheque::indexAll(); + $this->assertNotContains('1', Class_Sitotheque::find(2)->getDomaineIdsAsArray()); + } } + class SitothequeUnindexTest extends Storm_Test_ModelTestCase { public function setUp() { parent::setUp();