From ffa552e71e8044ceb3096aa6deec9a5ba1d828c6 Mon Sep 17 00:00:00 2001 From: llaffont <llaffont@afi-sa.fr> Date: Fri, 13 Jun 2014 15:04:13 +0200 Subject: [PATCH] hotline #13866 sites index real time --- .../admin/controllers/SitoController.php | 2 + library/Class/CodifThesaurus.php | 7 +-- library/Class/Indexation/PseudoNotice.php | 2 +- .../PseudoNotice/FacettesVisitor.php | 1 - library/Class/Sitotheque.php | 10 ++++ .../controllers/SitothequeControllerTest.php | 48 ++++++++++++++++++- 6 files changed, 64 insertions(+), 6 deletions(-) diff --git a/application/modules/admin/controllers/SitoController.php b/application/modules/admin/controllers/SitoController.php index d06e0cd4afd..0cd675a52c8 100644 --- a/application/modules/admin/controllers/SitoController.php +++ b/application/modules/admin/controllers/SitoController.php @@ -288,6 +288,8 @@ class Admin_SitoController extends Zend_Controller_Action { if ($site ->updateAttributes($post) ->save()) { + $site->index(); + (new Storm_Cache())->clean(); $this->_helper->notify($this->_('Le site "%s" a été sauvegardé', $site->getTitre())); $this->_redirect('/admin/sito/sitoedit/id/'.$site->getId()); return; diff --git a/library/Class/CodifThesaurus.php b/library/Class/CodifThesaurus.php index 8a3e53661e5..09e856c75f4 100644 --- a/library/Class/CodifThesaurus.php +++ b/library/Class/CodifThesaurus.php @@ -21,8 +21,8 @@ class Class_CodifThesaurusLoader extends Storm_Model_Loader { public function findThesaurusForCatalogue($catalogue_id) { - return Class_CodifThesaurus::findFirstBy(['id_origine'=> $catalogue_id, - 'CODE' => 'Catalogue']); + return Class_CodifThesaurus::getLoader()->findFirstBy(['id_origine'=> $catalogue_id, + 'code' => Class_CodifThesaurus::CODE_CATALOGUE]); } @@ -151,6 +151,7 @@ class Class_CodifThesaurusLoader extends Storm_Model_Loader { class Class_CodifThesaurus extends Storm_Model_Abstract { const CODE_FACETTE = 'H'; + const CODE_CATALOGUE = 'Catalogue'; const MODE_HIERARCHY_CONTAINS = 1; const MODE_LABEL_STARTS_WITH = 2; const MODE_LABEL_CONTAINS = 3; @@ -212,4 +213,4 @@ class Class_CodifThesaurus extends Storm_Model_Abstract { } } -?> +?> \ No newline at end of file diff --git a/library/Class/Indexation/PseudoNotice.php b/library/Class/Indexation/PseudoNotice.php index cfe8fef44be..7e8b5dc2bec 100644 --- a/library/Class/Indexation/PseudoNotice.php +++ b/library/Class/Indexation/PseudoNotice.php @@ -450,7 +450,7 @@ class Class_Indexation_PseudoNotice_Rss extends Class_Indexation_PseudoNotice{ class Class_Indexation_PseudoNotice_Sito extends Class_Indexation_PseudoNotice{ protected $_model_name = 'Class_Sitotheque'; - protected $_id = 'ID_SITO'; + protected $_id = 'id_sito'; protected $_label='m3'; } diff --git a/library/Class/Indexation/PseudoNotice/FacettesVisitor.php b/library/Class/Indexation/PseudoNotice/FacettesVisitor.php index 3a9ae1e4282..ab10b77c79b 100644 --- a/library/Class/Indexation/PseudoNotice/FacettesVisitor.php +++ b/library/Class/Indexation/PseudoNotice/FacettesVisitor.php @@ -121,7 +121,6 @@ class Class_Indexation_PseudoNotice_FacettesVisitor extends Class_Indexation_Pse } public function visitDomaine($domaine_ids) { - foreach(explode(';', $domaine_ids) as $domaine) { if (!$thesaurus = Class_CodifThesaurus::findThesaurusForCatalogue($domaine)) continue; diff --git a/library/Class/Sitotheque.php b/library/Class/Sitotheque.php index e8f10d93619..4aa33592f53 100644 --- a/library/Class/Sitotheque.php +++ b/library/Class/Sitotheque.php @@ -146,6 +146,16 @@ class Class_Sitotheque extends Storm_Model_Abstract { } + public function index() { + return Class_Indexation_PseudoNotice::index($this); + } + + + public function getTypeDocId() { + return Class_TypeDoc::SITE; + } + + //------------------------------------------------------------------------------------------------------ // Get site //------------------------------------------------------------------------------------------------------ diff --git a/tests/application/modules/admin/controllers/SitothequeControllerTest.php b/tests/application/modules/admin/controllers/SitothequeControllerTest.php index 84ec9bbe4e9..d7b675e01df 100644 --- a/tests/application/modules/admin/controllers/SitothequeControllerTest.php +++ b/tests/application/modules/admin/controllers/SitothequeControllerTest.php @@ -27,6 +27,10 @@ abstract class SitothequeControllerTestCase extends Admin_AbstractControllerTest parent::setUp(); $this->setupDomaines(); + + Class_Notice::beVolatile(); + Class_CodifThesaurus::beVolatile(); + $categorie_informations = $this->fixture('Class_SitothequeCategorie', ['id' => 2, 'libelle' => 'Informations', @@ -64,6 +68,20 @@ abstract class SitothequeControllerTestCase extends Admin_AbstractControllerTest $this->fixture('Class_Catalogue', ['id' => 66, 'libelle' => 'Informations', 'sous_domaines' => []]); + + $this->fixture('Class_CodifThesaurus', + ['id' => 1, + 'id_thesaurus' => 'C0001', + 'id_origine' => 10, + 'libelle' => 'Histoire', + 'code' => 'Catalogue']); + + $this->fixture('Class_CodifThesaurus', + ['id' => 2, + 'id_thesaurus' => 'C0002', + 'id_origine' => 66, + 'libelle' => 'Informations', + 'code' => 'Catalogue']); } } @@ -215,10 +233,14 @@ class SitothequeControllerPostAddActionTest extends SitothequeControllerTestCase public function setUp() { parent::setUp(); + $this->cache = Storm_Test_ObjectWrapper::mock()->whenCalled('clean')->answers(true); + Storm_Cache::setDefaultZendCache($this->cache); + $this->postDispatch('/admin/sito/sitoadd/id_cat/2', ['titre' => 'google', 'url' => 'http://www.google.fr', - 'id_items' => '23-23'], + 'id_items' => '23-23', + 'domaine_ids' => 10], true); } @@ -233,6 +255,30 @@ class SitothequeControllerPostAddActionTest extends SitothequeControllerTestCase public function sitoShouldNotHaveIdItems() { $this->assertTrue(Class_Sitotheque::find(24)->isAttributeEmpty('id_items')); } + + + + /** @test */ + public function pseudoNoticeShouldBeCreated() { + $this->assertNotEmpty(Class_Notice::find(1)); + } + + + /** @test */ + public function pseudoNoticeTitleShouldBeGoogle() { + $this->assertEquals('google', Class_Notice::find(1)->getTitrePrincipal()); + } + + + /** @test */ + public function pseudoNoticeShouldHaveIndexForTypeDocAndDomaineHistoire() { + $this->assertEquals('T10 HC0001', Class_Notice::find(1)->getFacettes()); + } + + /** @test */ + public function cacheShouldHaveBeenCleaned() { + $this->assertTrue($this->cache->methodHasBeenCalled('clean')); + } } -- GitLab