From 5b45068a87276197336808e57f4ac8a077bec18c Mon Sep 17 00:00:00 2001 From: Arthur Suzuki <arthur.suzuki@biblibre.com> Date: Tue, 6 Sep 2022 08:57:33 +0200 Subject: [PATCH] hotline#155528 : fix image cache generation for authors widget --- VERSIONS_HOTLINE/155528 | 1 + library/Class/Catalogue/Loader.php | 18 +++-- library/Class/CodifAuteur.php | 9 ++- .../Library/Widget/Carousel/Author/View.php | 6 ++ .../controllers/CatalogueControllerTest.php | 4 +- tests/library/Class/CatalogueTest.php | 12 +-- .../scenarios/AuthorPage/AuthorWidgetTest.php | 73 ++++++++++++------- 7 files changed, 83 insertions(+), 40 deletions(-) create mode 100644 VERSIONS_HOTLINE/155528 diff --git a/VERSIONS_HOTLINE/155528 b/VERSIONS_HOTLINE/155528 new file mode 100644 index 00000000000..152cbd8bc9a --- /dev/null +++ b/VERSIONS_HOTLINE/155528 @@ -0,0 +1 @@ + - correctif #155528 : Boite auteurs : correctif pour constitution du cache des images \ No newline at end of file diff --git a/library/Class/Catalogue/Loader.php b/library/Class/Catalogue/Loader.php index aa947e2171a..9693c9812f2 100644 --- a/library/Class/Catalogue/Loader.php +++ b/library/Class/Catalogue/Loader.php @@ -662,18 +662,18 @@ class Class_Catalogue_Loader extends Storm_Model_Loader { if ( !$valeurs = array_filter(explode(';', $valeurs))) return false; - $cond = ''; + $cond = []; foreach ($valeurs as $valeur) { if (!$valeur) continue; if (!$descendants) { - $cond .= $type . $valeur . ' '; + $cond [] = $type . $valeur; continue; } if ('M' != $type) { - $cond .= $type . $valeur . '* '; + $cond [] = $type . $valeur . '*'; continue; } @@ -682,12 +682,18 @@ class Class_Catalogue_Loader extends Storm_Model_Loader { if ('' != ($sous_vedettes = trim($matiere->getSousVedettes()))) $valeur .= str_replace(' ', ' M', ' ' . $sous_vedettes); - $cond .= $type . $valeur . ' '; + $cond [] = $type . $valeur; } - $cond = trim($cond); + $is_first_cond_multiple = count(explode(' ', reset($cond))) > 1; - return ($signe) ? ' +(' . $cond . ')' : ' ' . $cond; + $multiple_cond = count($cond) > 1 || $is_first_cond_multiple + ? ' +(%s)' + : '%s'; + + $cond = implode(' ', $cond); + + return ($signe) ? sprintf($multiple_cond, $cond) : ' ' . $cond; } diff --git a/library/Class/CodifAuteur.php b/library/Class/CodifAuteur.php index 4816039f584..a0c95c4227f 100644 --- a/library/Class/CodifAuteur.php +++ b/library/Class/CodifAuteur.php @@ -218,7 +218,7 @@ class CodifAuteurLoader extends Storm_Model_Loader { && isset($preferences['responsibilities'])) return Class_CodifAuteur::findAllIdsByResponsibilitiesIdsFromRecords($records, array_filter(explode(';', $preferences['responsibilities']))); - return Class_CodifAuteur::findAllIdsFromRecords($records); + return Class_CodifAuteur::findAllIdsFromRecords($records); } @@ -311,6 +311,13 @@ class CodifAuteurLoader extends Storm_Model_Loader { }) ->suggest($value, $mode, $limit); } + + + public function refreshThumbnails(array $preferences) : array { + $preferences['nb_notices'] = static::RECORDS_LOAD_LIMIT; + $authors_ids = Class_CodifAuteur::findAllIdsFromRecords(Class_Notice::getNoticesFromPreferences($preferences)); + return Class_CodifAuteur::fetchBiographies(Class_CodifAuteur::findAllBy(['id_auteur' => $authors_ids])); + } } diff --git a/library/templates/Intonation/Library/Widget/Carousel/Author/View.php b/library/templates/Intonation/Library/Widget/Carousel/Author/View.php index 7a8108c05ea..d33bae32d9a 100644 --- a/library/templates/Intonation/Library/Widget/Carousel/Author/View.php +++ b/library/templates/Intonation/Library/Widget/Carousel/Author/View.php @@ -28,6 +28,12 @@ class Intonation_Library_Widget_Carousel_Author_View extends Intonation_Library_ } + public function performAction($action) { + if ($action === 'refresh') + Class_CodifAuteur::refreshThumbnails($this->_settings->getPreferences()); + } + + protected function _getRSSUrl() { return ''; } diff --git a/tests/application/modules/admin/controllers/CatalogueControllerTest.php b/tests/application/modules/admin/controllers/CatalogueControllerTest.php index 44fc658f526..bb9635a6365 100644 --- a/tests/application/modules/admin/controllers/CatalogueControllerTest.php +++ b/tests/application/modules/admin/controllers/CatalogueControllerTest.php @@ -1875,7 +1875,7 @@ class CatalogueControllerActionTesterWithResultsPageTwoTest extends CatalogueCon Storm_Cache::beVolatile(); - $clauses = 'from notices Where (MATCH(facettes) AGAINST(\' +(B1) +( D78308*)\' IN BOOLEAN MODE) and notices.type_doc IN (\'1\', \'3\') and annee >= \'2012\' and annee <= \'2012\') and type=1'; + $clauses = 'from notices Where (MATCH(facettes) AGAINST(\'B1 +( D78308*)\' IN BOOLEAN MODE) and notices.type_doc IN (\'1\', \'3\') and annee >= \'2012\' and annee <= \'2012\') and type=1'; $this->_mock_sql ->whenCalled('fetchAllByColumn') @@ -1990,7 +1990,7 @@ class CatalogueControllerSystemeControllerMakeCacheActionTesterWithResultsTest 'auteur_principal' => 'miles', 'url_vignette' => '']); - $this->_sql_query = 'select notices.id_notice from notices Where (MATCH(facettes) AGAINST(\' +(B1) +( D78308*)\' IN BOOLEAN MODE) and notices.type_doc IN (\'1\', \'3\') and annee >= \'2012\' and annee <= \'2012\' and url_vignette=\'\') and type=1 order by alpha_titre LIMIT 0,5000'; + $this->_sql_query = 'select notices.id_notice from notices Where (MATCH(facettes) AGAINST(\'B1 +( D78308*)\' IN BOOLEAN MODE) and notices.type_doc IN (\'1\', \'3\') and annee >= \'2012\' and annee <= \'2012\' and url_vignette=\'\') and type=1 order by alpha_titre LIMIT 0,5000'; $this->_mock_sql ->whenCalled('fetchAllByColumn') diff --git a/tests/library/Class/CatalogueTest.php b/tests/library/Class/CatalogueTest.php index eef1976cce0..53e7eacf444 100644 --- a/tests/library/Class/CatalogueTest.php +++ b/tests/library/Class/CatalogueTest.php @@ -305,7 +305,7 @@ class CatalogueGetPagedNoticesTest extends ModelTestCase { /** @test */ public function withBibliothequeShouldQueryNoticeWithFacet() { $lambda = function($catalogue) {$catalogue->setBibliotheque('23;88');}; - $this->_prepareAndLoadForFacet($lambda, 'B23 B88'); + $this->_prepareAndLoadForFacet($lambda, ' +(B23 B88)'); } @@ -340,7 +340,7 @@ class CatalogueGetPagedNoticesTest extends ModelTestCase { /** @test */ public function withTagShouldQueryNoticeWithFacet() { $lambda = function($catalogue) {$catalogue->setTags('12;14');}; - $this->_prepareAndLoadForFacet($lambda, ' Z12 Z14'); + $this->_prepareAndLoadForFacet($lambda, ' +( Z12 Z14)'); } @@ -465,7 +465,7 @@ class CatalogueGetPagedNoticesTest extends ModelTestCase { protected function _facetsClauseWith($clauses) { - return sprintf('MATCH(facettes) AGAINST(\' +(%s)\' IN BOOLEAN MODE)', $clauses); + return sprintf('MATCH(facettes) AGAINST(\'%s\' IN BOOLEAN MODE)', $clauses); } } @@ -1047,7 +1047,7 @@ class CatalogueGetAllNoticesIdsForDomaineTest extends ModelTestCase { public function queryWithNb5Page10() { $this->mock_sql ->whenCalled('fetchAll') - ->with('select id_notice from notices Where (MATCH(facettes) AGAINST(\' +(T1)\' IN BOOLEAN MODE)) and type=1 order by alpha_titre limit 50,5') + ->with('select id_notice from notices Where (MATCH(facettes) AGAINST(\'T1\' IN BOOLEAN MODE)) and type=1 order by alpha_titre limit 50,5') ->answers([ ['id_notice' => 23, 'titre' => 'POTTER'], ['id_notice' => 45, 'titre' => 'POTTER2'], ]) @@ -1061,7 +1061,7 @@ class CatalogueGetAllNoticesIdsForDomaineTest extends ModelTestCase { public function queryWithNb1Page2() { $this->mock_sql ->whenCalled('fetchAll') - ->with('select id_notice from notices Where (MATCH(facettes) AGAINST(\' +(T1)\' IN BOOLEAN MODE)) and type=1 order by alpha_titre limit 2,1') + ->with('select id_notice from notices Where (MATCH(facettes) AGAINST(\'T1\' IN BOOLEAN MODE)) and type=1 order by alpha_titre limit 2,1') ->answers([]) ->beStrict(); @@ -1262,7 +1262,7 @@ class CatalogueEmptyFacetTestCase extends ModelTestCase { /** @test */ public function facetsClausesForWithEmptyFacetsShouldAnswerEmptyString() { $catalogue = Class_Catalogue::find(23); - $this->assertEquals('MATCH(facettes) AGAINST(\' +(S4)\' IN BOOLEAN MODE)', + $this->assertEquals('MATCH(facettes) AGAINST(\'S4\' IN BOOLEAN MODE)', Class_Catalogue::facetsClauseFor($catalogue)); } } diff --git a/tests/scenarios/AuthorPage/AuthorWidgetTest.php b/tests/scenarios/AuthorPage/AuthorWidgetTest.php index 2b3196e031c..538088d8c99 100644 --- a/tests/scenarios/AuthorPage/AuthorWidgetTest.php +++ b/tests/scenarios/AuthorPage/AuthorWidgetTest.php @@ -21,26 +21,16 @@ abstract class AuthorWidgetOnPageTestCase extends Admin_AbstractControllerTestCase { - protected - $_storm_default_to_volatile = true; + public function setUp() { parent::setUp(); Class_AdminVar::set('AUTHOR_PAGE', 1); - $cfg_accueil = ['modules' => ['1' => ['division' => '2', - 'type_module' => 'AUTHORS', - 'preferences' => ['titre' => 'Mes auteurs', - 'id_panier' => 3]]]]; + $this->_setupProfile(); - $this->fixture('Class_Profil', - ['id' => 2, - 'libelle' => 'auteurs', - 'cfg_accueil' => $cfg_accueil]) - ->beCurrentProfil(); - - $this->fixture('Class_Notice', + $this->fixture(Class_Notice::class, ['id' => 8, 'type_doc' => Class_TypeDoc::LIVRE, 'clef_alpha'=>'GAVROCHE_HUGO', @@ -48,7 +38,7 @@ abstract class AuthorWidgetOnPageTestCase extends Admin_AbstractControllerTestCa 'facettes' => 'A2408 A3 A666 G4 M6', 'url_vignette' => 'gavroche.jpg']); - $this->fixture('Class_Notice', + $this->fixture(Class_Notice::class, ['id' => 9, 'type_doc' => Class_TypeDoc::LIVRE, 'clef_alpha'=>'MISERABLES_HUGO', @@ -58,7 +48,7 @@ abstract class AuthorWidgetOnPageTestCase extends Admin_AbstractControllerTestCa 'url_vignette' => 'miserables.jpg', 'url_image' => 'miserables.jpg']); - $this->fixture('Class_Notice', + $this->fixture(Class_Notice::class, ['id' => 10, 'type_doc' => Class_TypeDoc::DVD, 'clef_alpha'=>'DAMEPARIS_HUGO', @@ -67,34 +57,50 @@ abstract class AuthorWidgetOnPageTestCase extends Admin_AbstractControllerTestCa 'facettes' => 'A2408 A3', 'url_vignette' => 'paris.jpg']); - $this->fixture('Class_CodifAuteur', + $this->fixture(Class_CodifAuteur::class, ['id' => 2408, 'libelle' => 'Victor Hugo', 'thumbnail_url' => 'http://wp/hugo.jpg']); - $this->fixture('Class_CodifAuteur', + $this->fixture(Class_CodifAuteur::class, ['id' => 3, 'libelle' => 'Robert Hossein', 'thumbnail_url' => 'http://wp/hossein.jpg']); - $this->fixture('Class_CodifAuteur', + $this->fixture(Class_CodifAuteur::class, ['id' => 4, 'libelle' => 'Marcus %s \Mill', 'thumbnail_url' => 'http://wp&f=Defaut.svg']); - $this->fixture('Class_CodifAuteur', + $this->fixture(Class_CodifAuteur::class, ['id' => 5, 'libelle' => 'Delannoy Jean', 'thumbnail_url' => 'http://wp/delannoy.jpg']); - $this->fixture('Class_CodifAuteurFonction', + $this->fixture(Class_CodifAuteurFonction::class, ['id' => 635, 'libelle' => 'Programmeur informatique']); - $this->fixture('Class_CodifAuteurFonction', + $this->fixture(Class_CodifAuteurFonction::class, ['id' => '370', 'libelle' => 'Réalisateur']); } + + + protected function _setupProfile() : self { + $cfg_accueil = ['modules' => ['1' => ['division' => '2', + 'type_module' => 'AUTHORS', + 'preferences' => ['titre' => 'Mes auteurs', + 'id_panier' => 3]]]]; + + $this->fixture(Class_Profil::class, + ['id' => 2, + 'libelle' => 'auteurs', + 'cfg_accueil' => $cfg_accueil]) + ->beCurrentProfil(); + + return $this; + } } @@ -210,8 +216,7 @@ class AuthorWidgetOnPageTest extends AuthorWidgetOnPageTestCase { /** @test */ public function numberOfAuthorsShouldBeTwo() { $this->assertXPathCount('//div[@class="boite authors"]//div[@class="author"]', - 2, - $this->_response->getBody()); + 2); } @@ -377,8 +382,7 @@ class AuthorWidgetConfigurationTest extends AuthorWidgetOnPageTestCase { /** @test */ public function formShouldContainsInputForTitre() { - $this->assertXPath('//input[@name="titre"][@value="Mes auteurs"]', - $this->_response->getBody()); + $this->assertXPath('//input[@name="titre"][@value="Mes auteurs"]'); } @@ -502,3 +506,22 @@ class AuthorWidgetResponsibilitiesInputSuggestTest extends AuthorWidgetOnPageTes $this->_response->getBody()); } } + + + + +class AuthorWidgetActionRefreshThumbnailsInTemplateTest + extends AuthorWidgetActionRefreshThumbnailsTest { + + protected function _setupProfile() : self { + $cfg_accueil = ['modules' => ['1' => ['division' => '2', + 'type_module' => 'AUTHORS', + 'preferences' => ['titre' => 'Mes auteurs', + 'id_panier' => 3]]]]; + + $this->_buildTemplateProfil(['id' => 2, + 'libelle' => 'auteurs', + 'cfg_accueil' => $cfg_accueil]); + return $this; + } +} \ No newline at end of file -- GitLab