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/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..48e4947df090866a8a320788c5dd4af20871616e 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; } 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/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();