diff --git a/application/modules/admin/controllers/SitoController.php b/application/modules/admin/controllers/SitoController.php index d06e0cd4afddb3136f85338243d25f1dfb9d4576..0cd675a52c8cf6ae7205ecad1d6b8df75a03f209 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/cosmogramme/php/integre_traite_main.php b/cosmogramme/php/integre_traite_main.php index ca77f6d96ef92d6443cee2a0e5ee78b8da04922e..12272f1e7fd71a682ca180125d660ba40822d33c 100644 --- a/cosmogramme/php/integre_traite_main.php +++ b/cosmogramme/php/integre_traite_main.php @@ -275,8 +275,7 @@ if ($phase == "0") $phase = "0.1"; // ---------------------------------------------------------------- // PSEUDO-NOTICES - cms rss sitotheque et albums (phase 0.1 a 0.6) // ---------------------------------------------------------------- -if ($phase > 0 and $phase < 1) -{ +if ($phase > 0 and $phase < 1) { include("integration/pseudo_notices.php"); $phase = 1; } diff --git a/library/Class/Catalogue.php b/library/Class/Catalogue.php index 20adf9e55a393ce1feca7fe96ea3e62aa58ea0f9..afe53bb4d2f1b525637e2e3108f608df84d896b6 100644 --- a/library/Class/Catalogue.php +++ b/library/Class/Catalogue.php @@ -382,8 +382,16 @@ class Class_Catalogue extends Storm_Model_Abstract { public function deleteThesaurusInFacette($id_thesaurus) { - $sql = Zend_Registry::get('sql'); - $sql->query('update notices set facettes = clean_spaces(replace(facettes,"H'.$id_thesaurus.'","")) where match(facettes) against("+H'.$id_thesaurus.'" in boolean mode)'); + /* + * Sites, articles and RSS records are first destroyed and then get their own selection of domains. + * So therauri facettes must not be deleted. By the way, need to find a nicer implementation ... + */ + $query = + 'update notices set facettes = clean_spaces(replace(facettes,"H'.$id_thesaurus.'","")) '. + 'where type_doc not in ('.implode(',', [Class_TypeDoc::ARTICLE, Class_TypeDoc::RSS, Class_TypeDoc::SITE]).') '. + 'and match(facettes) against("+H'.$id_thesaurus.'" in boolean mode)'; + + Zend_Registry::get('sql')->query($query); } diff --git a/library/Class/CodifThesaurus.php b/library/Class/CodifThesaurus.php index 8a3e53661e51b9a150197e74cb93f6c368c0de13..09e856c75f42d05e7fe6b347bed61939c8896b23 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 cfe8fef44be3c07ecb1984b2dd2c860a107c5061..280045bf2f580ef4804e6b008ca1c1ea062bdc31 100644 --- a/library/Class/Indexation/PseudoNotice.php +++ b/library/Class/Indexation/PseudoNotice.php @@ -63,8 +63,9 @@ class Class_Indexation_PseudoNotice { public function __construct($type_doc, $datas) { $this->_type_doc = (int)$type_doc; $this->_indexation = new Class_Indexation(); - $this->_datas = $datas; - $this->_model = call_user_func_array([$this->_model_name, 'find'], [$datas[$this->_id]]); + $this->_datas = array_change_key_case($datas, CASE_LOWER); + $this->_model = call_user_func_array([$this->_model_name, 'find'], + [$this->_datas[$this->_id]]); } public function getId() { @@ -431,7 +432,7 @@ class Class_Indexation_PseudoNotice_Album extends Class_Indexation_PseudoNotice{ class Class_Indexation_PseudoNotice_Cms extends Class_Indexation_PseudoNotice{ protected $_model_name = 'Class_Article'; - protected $_id = 'ID_ARTICLE'; + protected $_id = 'id_article'; protected $_label='m1'; protected function _prepare() { @@ -443,14 +444,14 @@ class Class_Indexation_PseudoNotice_Cms extends Class_Indexation_PseudoNotice{ class Class_Indexation_PseudoNotice_Rss extends Class_Indexation_PseudoNotice{ protected $_model_name = 'Class_Rss'; - protected $_id = 'ID_RSS'; + protected $_id = 'id_rss'; protected $_label='m2'; } 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 3a9ae1e4282c9c2cfe2d025f0a6ac39ac7ed6614..ab10b77c79b6db3e5242cdf7076e08bdc455222b 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 e8f10d9361957da7c5ae6d738f06242b34b80a55..4aa33592f53c477176041c634b3e920da18da1f0 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 e38c8e9b860bfaf03a358ba6275eaadab37ab4b1..d7b675e01df3c43b9297e9584cd35064c5b4b1fe 100644 --- a/tests/application/modules/admin/controllers/SitothequeControllerTest.php +++ b/tests/application/modules/admin/controllers/SitothequeControllerTest.php @@ -27,67 +27,61 @@ abstract class SitothequeControllerTestCase extends Admin_AbstractControllerTest parent::setUp(); $this->setupDomaines(); - $categorie_informations = Class_SitothequeCategorie::newInstanceWithId(2, - ['libelle' => 'Informations', - 'id_site' => 3]) - ->setSousCategories([]) - ->setSitotheques([Class_Sitotheque::newInstanceWithId(22, - ['titre' => 'Le Canard', - 'url' => 'http://www.canard.fr', - 'description' => 'indépendant', - 'domaine_ids' => [10]]), - $this->_le_monde = Class_Sitotheque::newInstanceWithId(23, - ['titre' => 'Le Monde', - 'url' => 'http://www.monde.fr'])]); - - - $bib_annecy = Class_Bib::newInstanceWithId(3, ['libelle' => 'Annecy']) - ->setSitothequeCategories([$categorie_informations]); - - Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Bib') - ->whenCalled('findAllBy') - ->with(['order' => 'libelle']) - ->answers([$bib_annecy]) - - ->whenCalled('findAll') - ->answers([$bib_annecy]); + Class_Notice::beVolatile(); + Class_CodifThesaurus::beVolatile(); + + $categorie_informations = $this->fixture('Class_SitothequeCategorie', + ['id' => 2, + 'libelle' => 'Informations', + 'id_site' => 3, + 'sous_categories' => [], + 'sitotheques' => [ + $this->fixture('Class_Sitotheque', + ['id' => 22, + 'titre' => 'Le Canard', + 'url' => 'http://www.canard.fr', + 'description' => 'indépendant', + 'domaine_ids' => [10]]), + + $this->_le_monde = $this->fixture('Class_Sitotheque', + ['id' => 23, + 'titre' => 'Le Monde', + 'url' => 'http://www.monde.fr'])] + ]); + + + $bib_annecy = $this->fixture('Class_Bib', + ['id' => 3, + 'libelle' => 'Annecy', + 'sitotheque_categories' => [$categorie_informations]]); Class_Bib::getPortail()->setSitothequeCategories([]); - - - Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Sitotheque') - ->whenCalled('save')->answers(true) - ->whenCalled('delete')->answers(true); - - Storm_Test_ObjectWrapper::onLoaderOfModel('Class_SitothequeCategorie') - ->whenCalled('save')->answers(true) - ->whenCalled('delete')->answers(true) - - ->whenCalled('findAllBy') - ->with(['id_site' => 3, - 'order' => 'libelle']) - ->answers([$categorie_informations]); } public function setupDomaines() { - $domaine_histoire = Class_Catalogue::newInstanceWithId(10, - ['libelle' => 'Histoire', - 'sous_domaines' => []]); - - $domaine_informations = Class_Catalogue::newInstanceWithId(66, - ['libelle' => 'Informations', - 'sous_domaines' => []]); - - Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Catalogue') - ->whenCalled('findAllBy') - ->answers([$domaine_histoire]) - - ->whenCalled('findFirstBy') - ->with(['parent_id' => null, - 'libelle' => 'Informations']) - ->answers($domaine_informations); + $this->fixture('Class_Catalogue', ['id' => 10, + 'libelle' => 'Histoire', + 'sous_domaines' => []]); + + $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']); } } @@ -239,25 +233,51 @@ class SitothequeControllerPostAddActionTest extends SitothequeControllerTestCase public function setUp() { parent::setUp(); - Class_Sitotheque::whenCalled('save')->willDo(function($site) {$site->setId(25);}); + $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); } /** @test */ - public function anwersShouldRedirectToSitoEdit25() { - $this->assertRedirectTo('/admin/sito/sitoedit/id/25'); + public function anwersShouldRedirectToSitoEdit24() { + $this->assertRedirectTo('/admin/sito/sitoedit/id/24'); } /** @test */ public function sitoShouldNotHaveIdItems() { - $new_site = Class_Sitotheque::getFirstAttributeForLastCallOn('save'); - $this->assertTrue($new_site->isAttributeEmpty('id_items')); + $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')); } } @@ -285,6 +305,8 @@ class SitothequeControllerSitoPostEditLeMondeTest extends SitothequeControllerTe $this->postDispatch('/admin/sito/sitoedit/id/23', ['titre' => 'Times'], true); + Class_Sitotheque::clearCache(); + $this->_le_monde = Class_Sitotheque::find(23); } @@ -294,12 +316,6 @@ class SitothequeControllerSitoPostEditLeMondeTest extends SitothequeControllerTe } - /** @test */ - public function siteShouldHaveBeenSaved() { - $this->assertTrue(Class_Sitotheque::methodHasBeenCalled('save')); - } - - /** @test */ public function anwersShouldRedirectToSitoEdit23() { $this->assertRedirectTo('/admin/sito/sitoedit/id/23'); @@ -318,7 +334,7 @@ class SitothequeControllerSitoDeleteLeMondeTest extends SitothequeControllerTest /** @test */ public function siteShouldHaveBeenDeleted() { - $this->assertTrue(Class_Sitotheque::methodHasBeenCalled('delete')); + $this->assertEmpty(Class_Sitotheque::find(23)); } @@ -383,6 +399,7 @@ class SitothequeControllerPostEditCategorieInformationsTest extends SitothequeCo $this->postDispatch('/admin/sito/catedit/id/2', ['libelle' => 'News'], true); + Class_SitothequeCategorie::clearCache(); } @@ -390,12 +407,6 @@ class SitothequeControllerPostEditCategorieInformationsTest extends SitothequeCo public function libelleShouldBeNews() { $this->assertEquals('News', Class_SitothequeCategorie::find(2)->getLibelle()); } - - - /** @test */ - public function categorieShouldHaveBeenSaved() { - $this->assertTrue(Class_SitothequeCategorie::methodHasBeenCalled('save')); - } } @@ -448,18 +459,11 @@ class SitothequeControllerPostAddCategorieNationalesTest extends SitothequeContr public function setUp() { parent::setUp(); - Class_SitothequeCategorie::whenCalled('save') - ->willDo( - function($cat) { - $cat->setId(5)->cache(); - return true; - }); - $this->postDispatch('/admin/sito/catadd/id/2', ['libelle' => 'Nationales'], true); - $this->_new_cat = Class_SitothequeCategorie::find(5); + $this->_new_cat = Class_SitothequeCategorie::find(3); } @@ -467,12 +471,6 @@ class SitothequeControllerPostAddCategorieNationalesTest extends SitothequeContr public function libelleShouldBeNationales() { $this->assertEquals('Nationales', $this->_new_cat->getLibelle()); } - - - /** @test */ - public function categorieShouldHaveBeenSaved() { - $this->assertTrue(Class_SitothequeCategorie::methodHasBeenCalled('save')); - } } @@ -484,18 +482,11 @@ class SitothequeControllerPostAddCategorieInBibTest extends SitothequeController public function setUp() { parent::setUp(); - Class_SitothequeCategorie::whenCalled('save') - ->willDo( - function($cat) { - $cat->setId(5)->cache(); - return true; - }); - $this->postDispatch('/admin/sito/catadd/id_bib/5', ['libelle' => 'Dans la bib'], true); - $this->_new_cat = Class_SitothequeCategorie::find(5); + $this->_new_cat = Class_SitothequeCategorie::find(3); } @@ -523,7 +514,7 @@ class SitothequeControllerDeleteCategorieInformationsTest extends SitothequeCont /** @test */ public function categorieShouldHaveBeenDeleted() { - $this->assertTrue(Class_SitothequeCategorie::methodHasBeenCalled('delete')); + $this->assertEmpty(Class_SitothequeCategorie::find(2)); } } diff --git a/tests/library/Class/Indexation/PseudoNoticeTest.php b/tests/library/Class/Indexation/PseudoNoticeTest.php index 99ed09366fd2d6b5a6405163f0d3cab7c2630816..955ee80e51b748f0f921547cd905743b2454f9f9 100644 --- a/tests/library/Class/Indexation/PseudoNoticeTest.php +++ b/tests/library/Class/Indexation/PseudoNoticeTest.php @@ -69,6 +69,39 @@ class Class_Indexation_PseudoNoticeAlbumTest extends Class_Indexation_PseudoNoti +class Class_Indexation_PseudoNoticeSitothequeFromRawSQLTest extends Class_Indexation_PseudoNoticeTestCase { + protected $_sito; + protected $_notice; + + + public function setUp() { + parent::setUp(); + $this->fixture('Class_Sitotheque', ['id' => 12, + 'titre' => 'Thot cursus', + 'url' => 'http://cursus.edu/', + 'description' => 'Top notch site', + 'tags' => 'VOD']); + + /** as done in Cosmogramme */ + Class_Indexation_PseudoNotice::newWith(Class_Indexation_PseudoNotice::TYPE_SITO, + ['ID_SITO' => 12, + 'TITRE' => 'Thot cursus', + 'URL' => 'http://cursus.edu/', + 'DESCRIPTION' => 'Top notch site', + 'TAGS' => 'VOD'])->save(); + + $this->_notice = Class_Notice::find(1); + } + + /** @test */ + public function titleShouldBeIndexed() { + $this->assertEquals('Thot cursus', $this->_notice->getTitrePrincipal()); + } +} + + + + class Class_Indexation_PseudoNoticeSitothequeTest extends Class_Indexation_PseudoNoticeTestCase { protected $_sito; protected $_notice;