From 1f89fcf5b2962c4a687d76315bca1928d535ac97 Mon Sep 17 00:00:00 2001 From: gloas <gloas@afi-sa.fr> Date: Wed, 15 Feb 2023 12:17:33 +0100 Subject: [PATCH] hotline #163727 clearCache when asking events with event timing enabled to force use Class_Article::newFromRow --- VERSIONS_HOTLINE/163727 | 1 + library/Class/Article/SelectWithTimings.php | 4 ++ tests/library/Class/ArticleSelectTest.php | 71 +++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 VERSIONS_HOTLINE/163727 create mode 100644 tests/library/Class/ArticleSelectTest.php diff --git a/VERSIONS_HOTLINE/163727 b/VERSIONS_HOTLINE/163727 new file mode 100644 index 00000000000..c9786d5ce7a --- /dev/null +++ b/VERSIONS_HOTLINE/163727 @@ -0,0 +1 @@ + - correctif #169349 : Agenda : Correction du chargement des événements lorsqu'il y a plusieurs boites agenda ou d'articles dans une même page. \ No newline at end of file diff --git a/library/Class/Article/SelectWithTimings.php b/library/Class/Article/SelectWithTimings.php index 4c7f2b42649..3e4d0b603a0 100644 --- a/library/Class/Article/SelectWithTimings.php +++ b/library/Class/Article/SelectWithTimings.php @@ -25,11 +25,15 @@ class Class_Article_SelectWithTimings extends Class_Article_Select { protected function _selectArticles() { parent::_selectArticles(); + + Class_Article::clearCache(); + $this->_select ->joinLeft('cms_article_timings', 'cms_article.id_article=cms_article_timings.article_id', ['min(cms_article_timings.start) as start', 'min(cms_article_timings.end) as end']) ->group('id_article'); + return $this; } diff --git a/tests/library/Class/ArticleSelectTest.php b/tests/library/Class/ArticleSelectTest.php new file mode 100644 index 00000000000..f13ce979ad5 --- /dev/null +++ b/tests/library/Class/ArticleSelectTest.php @@ -0,0 +1,71 @@ +<?php +/** + * Copyright (c) 2012-2022, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class ArticleSelectCacheTest extends ModelTestCase { + + + /** @test */ + public function findAllArticlesWithselectWithTimingShouldClearArticlesCache() { + $this->fixture(Class_Article::class, + ['id' => 1, + 'titre' => 'Atelier de chansons potaches', + 'contenu' => 'L\'actualité parodiée et chantée.']); + + $this->fixture(Class_Article::class, + ['id' => 2, + 'titre' => 'Atelier de chansons potaches', + 'contenu' => 'L\'actualité parodiée et chantée.']); + + + Class_Article::newInstanceWithId(3, + ['titre' => 'Atelier de chansons potaches', + 'contenu' => 'L\'actualité parodiée et chantée.']); + + $params = ['order' => 'DebutPublicationDesc', + 'size' => 30, + 'nb_analyse' => '', + 'id_items' => '1', + 'id_categorie' => '', + 'langue' => '', + 'event_date' => '', + 'event_end_after' => '', + 'event_start_after' => '', + 'id_bib' => '', + 'id_lieu' => '', + 'status' => '', + 'events_only' => '', + 'published' => '', + 'display_mode' => '', + 'custom_fields' => '', + 'place_town' => '', + 'filter_by_workflow' => '', + 'filter_by_local' => '']; + + $loader = Class_Article::getLoader(); + + $articles = + (new Class_Article_SelectWithTimings($loader)) + ->findAll($params); + + $this->assertCount(2, $loader->getLoadedInstances()); + } +} -- GitLab