From 996694e5ee9b83c682cf5099b35d5820677dca07 Mon Sep 17 00:00:00 2001 From: Leo Feyer Date: Wed, 9 Dec 2020 10:36:10 +0100 Subject: [PATCH] Add tagging for the missing modules --- .../src/Resources/contao/classes/Events.php | 3 ++- .../contao/modules/ModuleCalendar.php | 13 +++++++------ .../contao/modules/ModuleEventReader.php | 13 +++++++------ .../contao/modules/ModuleEventlist.php | 3 ++- .../src/Resources/contao/classes/Comments.php | 4 +--- .../contao/classes/FrontendTemplate.php | 4 +--- .../contao/elements/ContentElement.php | 4 +--- .../contao/elements/ContentModule.php | 5 +---- .../src/Resources/contao/modules/Module.php | 4 +--- .../Resources/contao/modules/ModuleArticle.php | 5 +---- .../Resources/contao/modules/ModuleFaqList.php | 17 +++++++++++++++++ .../Resources/contao/modules/ModuleFaqPage.php | 17 +++++++++++++++++ .../contao/modules/ModuleFaqReader.php | 7 +++++++ .../Resources/contao/modules/ModuleNews.php | 3 ++- .../contao/modules/ModuleNewsArchive.php | 3 ++- .../contao/modules/ModuleNewsList.php | 3 ++- .../contao/modules/ModuleNewsletterList.php | 18 ++++++++++++++++++ .../contao/modules/ModuleNewsletterReader.php | 7 +++++++ 18 files changed, 96 insertions(+), 37 deletions(-) diff --git a/calendar-bundle/src/Resources/contao/classes/Events.php b/calendar-bundle/src/Resources/contao/classes/Events.php index 26901c8d3bb..3cefcfcfc80 100644 --- a/calendar-bundle/src/Resources/contao/classes/Events.php +++ b/calendar-bundle/src/Resources/contao/classes/Events.php @@ -284,7 +284,8 @@ protected function addEvent($objEvents, $intStart, $intEnd, $intBegin, $intLimit // Tag the event (see #2137) if (System::getContainer()->has('fos_http_cache.http.symfony_response_tagger')) { - System::getContainer()->get('fos_http_cache.http.symfony_response_tagger')->addTags(array('contao.db.tl_calendar_events.' . $objEvents->id)); + $responseTagger = System::getContainer()->get('fos_http_cache.http.symfony_response_tagger'); + $responseTagger->addTags(array('contao.db.tl_calendar_events.' . $objEvents->id)); } // Store raw data diff --git a/calendar-bundle/src/Resources/contao/modules/ModuleCalendar.php b/calendar-bundle/src/Resources/contao/modules/ModuleCalendar.php index 8046fc8656b..141745777a6 100644 --- a/calendar-bundle/src/Resources/contao/modules/ModuleCalendar.php +++ b/calendar-bundle/src/Resources/contao/modules/ModuleCalendar.php @@ -71,12 +71,6 @@ public function generate() return ''; } - // Tag the calendars (see #2137) - if (System::getContainer()->has('fos_http_cache.http.symfony_response_tagger')) - { - System::getContainer()->get('fos_http_cache.http.symfony_response_tagger')->addTags(array_map(static function ($id) { return 'contao.db.tl_calendar.' . $id; }, $this->cal_calendar)); - } - $this->strUrl = preg_replace('/\?.*$/', '', Environment::get('request')); $this->strLink = $this->strUrl; @@ -86,6 +80,13 @@ public function generate() $this->strLink = $objTarget->getFrontendUrl(); } + // Tag the calendars (see #2137) + if (System::getContainer()->has('fos_http_cache.http.symfony_response_tagger')) + { + $responseTagger = System::getContainer()->get('fos_http_cache.http.symfony_response_tagger'); + $responseTagger->addTags(array_map(static function ($id) { return 'contao.db.tl_calendar.' . $id; }, $this->cal_calendar)); + } + return parent::generate(); } diff --git a/calendar-bundle/src/Resources/contao/modules/ModuleEventReader.php b/calendar-bundle/src/Resources/contao/modules/ModuleEventReader.php index 0805b130d5b..057d727d541 100644 --- a/calendar-bundle/src/Resources/contao/modules/ModuleEventReader.php +++ b/calendar-bundle/src/Resources/contao/modules/ModuleEventReader.php @@ -237,12 +237,6 @@ protected function compile() $objTemplate->hasDetails = false; $objTemplate->hasTeaser = false; - // Tag the event (see #2137) - if (System::getContainer()->has('fos_http_cache.http.symfony_response_tagger')) - { - System::getContainer()->get('fos_http_cache.http.symfony_response_tagger')->addTags(array('contao.db.tl_calendar_events.' . $objEvent->id)); - } - // Clean the RTE output if ($objEvent->teaser) { @@ -398,6 +392,13 @@ protected function compile() $this->Template->event = $objTemplate->parse(); + // Tag the event (see #2137) + if (System::getContainer()->has('fos_http_cache.http.symfony_response_tagger')) + { + $responseTagger = System::getContainer()->get('fos_http_cache.http.symfony_response_tagger'); + $responseTagger->addTags(array('contao.db.tl_calendar_events.' . $objEvent->id)); + } + $bundles = System::getContainer()->getParameter('kernel.bundles'); // HOOK: comments extension required diff --git a/calendar-bundle/src/Resources/contao/modules/ModuleEventlist.php b/calendar-bundle/src/Resources/contao/modules/ModuleEventlist.php index d41be29b8b3..2a3195fadb4 100644 --- a/calendar-bundle/src/Resources/contao/modules/ModuleEventlist.php +++ b/calendar-bundle/src/Resources/contao/modules/ModuleEventlist.php @@ -80,7 +80,8 @@ public function generate() // Tag the calendars (see #2137) if (System::getContainer()->has('fos_http_cache.http.symfony_response_tagger')) { - System::getContainer()->get('fos_http_cache.http.symfony_response_tagger')->addTags(array_map(static function ($id) { return 'contao.db.tl_calendar.' . $id; }, $this->cal_calendar)); + $responseTagger = System::getContainer()->get('fos_http_cache.http.symfony_response_tagger'); + $responseTagger->addTags(array_map(static function ($id) { return 'contao.db.tl_calendar.' . $id; }, $this->cal_calendar)); } return parent::generate(); diff --git a/comments-bundle/src/Resources/contao/classes/Comments.php b/comments-bundle/src/Resources/contao/classes/Comments.php index 5201ca1a176..548900ced8a 100644 --- a/comments-bundle/src/Resources/contao/classes/Comments.php +++ b/comments-bundle/src/Resources/contao/classes/Comments.php @@ -12,7 +12,6 @@ use Contao\CoreBundle\Exception\PageNotFoundException; use Contao\CoreBundle\OptIn\OptIn; -use FOS\HttpCache\ResponseTagger; /** * Class Comments @@ -43,10 +42,9 @@ public function addCommentsToTemplate(FrontendTemplate $objTemplate, \stdClass $ $objTemplate->comments = array(); // see #4064 - // Tag the response + // Tag the comment (see #2137) if (System::getContainer()->has('fos_http_cache.http.symfony_response_tagger')) { - /** @var ResponseTagger $responseTagger */ $responseTagger = System::getContainer()->get('fos_http_cache.http.symfony_response_tagger'); $responseTagger->addTags(array(sprintf('contao.comments.%s.%s', $strSource, $intParent))); } diff --git a/core-bundle/src/Resources/contao/classes/FrontendTemplate.php b/core-bundle/src/Resources/contao/classes/FrontendTemplate.php index 24fa2430235..95688ca73a3 100644 --- a/core-bundle/src/Resources/contao/classes/FrontendTemplate.php +++ b/core-bundle/src/Resources/contao/classes/FrontendTemplate.php @@ -10,7 +10,6 @@ namespace Contao; -use FOS\HttpCache\ResponseTagger; use Symfony\Component\HttpFoundation\Response; /** @@ -403,10 +402,9 @@ private function setCacheHeaders(Response $response) $response->setVary(array('Cookie')); } - // Tag the response with cache tags für the shared cache only + // Tag the page (see #2137) if (System::getContainer()->has('fos_http_cache.http.symfony_response_tagger')) { - /** @var ResponseTagger $responseTagger */ $responseTagger = System::getContainer()->get('fos_http_cache.http.symfony_response_tagger'); $responseTagger->addTags(array('contao.db.tl_page.' . $objPage->id)); } diff --git a/core-bundle/src/Resources/contao/elements/ContentElement.php b/core-bundle/src/Resources/contao/elements/ContentElement.php index 15b4ebd9cc7..1bb88f1d996 100644 --- a/core-bundle/src/Resources/contao/elements/ContentElement.php +++ b/core-bundle/src/Resources/contao/elements/ContentElement.php @@ -11,7 +11,6 @@ namespace Contao; use Contao\Model\Collection; -use FOS\HttpCache\ResponseTagger; /** * Parent class for content elements. @@ -274,10 +273,9 @@ public function generate() $this->Template->class .= ' ' . implode(' ', $this->objModel->classes); } - // Tag the response + // Tag the content element (see #2137) if (System::getContainer()->has('fos_http_cache.http.symfony_response_tagger')) { - /** @var ResponseTagger $responseTagger */ $responseTagger = System::getContainer()->get('fos_http_cache.http.symfony_response_tagger'); $responseTagger->addTags(array('contao.db.tl_content.' . $this->id)); } diff --git a/core-bundle/src/Resources/contao/elements/ContentModule.php b/core-bundle/src/Resources/contao/elements/ContentModule.php index 7803177f24a..a1314761336 100644 --- a/core-bundle/src/Resources/contao/elements/ContentModule.php +++ b/core-bundle/src/Resources/contao/elements/ContentModule.php @@ -10,8 +10,6 @@ namespace Contao; -use FOS\HttpCache\ResponseTagger; - /** * Front end content element "module". * @@ -67,10 +65,9 @@ public function generate() /** @var Module $objModule */ $objModule = new $strClass($objModel, $this->strColumn); - // Tag the response + // Tag the content element (see #2137) if (System::getContainer()->has('fos_http_cache.http.symfony_response_tagger')) { - /** @var ResponseTagger $responseTagger */ $responseTagger = System::getContainer()->get('fos_http_cache.http.symfony_response_tagger'); $responseTagger->addTags(array('contao.db.tl_content.' . $this->id)); } diff --git a/core-bundle/src/Resources/contao/modules/Module.php b/core-bundle/src/Resources/contao/modules/Module.php index 050b1dbc270..b5dc2e10b68 100644 --- a/core-bundle/src/Resources/contao/modules/Module.php +++ b/core-bundle/src/Resources/contao/modules/Module.php @@ -11,7 +11,6 @@ namespace Contao; use Contao\Model\Collection; -use FOS\HttpCache\ResponseTagger; /** * Parent class for front end modules. @@ -236,10 +235,9 @@ public function generate() $this->Template->class .= ' ' . implode(' ', $this->objModel->classes); } - // Tag the response + // Tag the module (see #2137) if (System::getContainer()->has('fos_http_cache.http.symfony_response_tagger')) { - /** @var ResponseTagger $responseTagger */ $responseTagger = System::getContainer()->get('fos_http_cache.http.symfony_response_tagger'); $responseTagger->addTags(array('contao.db.tl_module.' . $this->id)); } diff --git a/core-bundle/src/Resources/contao/modules/ModuleArticle.php b/core-bundle/src/Resources/contao/modules/ModuleArticle.php index 2a8966cf4c9..bb5b71848b6 100644 --- a/core-bundle/src/Resources/contao/modules/ModuleArticle.php +++ b/core-bundle/src/Resources/contao/modules/ModuleArticle.php @@ -10,8 +10,6 @@ namespace Contao; -use FOS\HttpCache\ResponseTagger; - /** * Provides methodes to handle articles. * @@ -63,10 +61,9 @@ public function generate($blnNoMarkup=false) $this->type = 'article'; $this->blnNoMarkup = $blnNoMarkup; - // Tag response + // Tag the article (see #2137) if (System::getContainer()->has('fos_http_cache.http.symfony_response_tagger')) { - /** @var ResponseTagger $responseTagger */ $responseTagger = System::getContainer()->get('fos_http_cache.http.symfony_response_tagger'); $responseTagger->addTags(array('contao.db.tl_article.' . $this->id)); } diff --git a/faq-bundle/src/Resources/contao/modules/ModuleFaqList.php b/faq-bundle/src/Resources/contao/modules/ModuleFaqList.php index 377cb677faa..ebada4bb4d0 100644 --- a/faq-bundle/src/Resources/contao/modules/ModuleFaqList.php +++ b/faq-bundle/src/Resources/contao/modules/ModuleFaqList.php @@ -69,6 +69,13 @@ public function generate() return $this->getFrontendModule($this->faq_readerModule, $this->strColumn); } + // Tag the FAQ categories (see #2137) + if (System::getContainer()->has('fos_http_cache.http.symfony_response_tagger')) + { + $responseTagger = System::getContainer()->get('fos_http_cache.http.symfony_response_tagger'); + $responseTagger->addTags(array_map(static function ($id) { return 'contao.db.tl_faq_category.' . $id; }, $this->faq_categories)); + } + return parent::generate(); } @@ -86,6 +93,7 @@ protected function compile() return; } + $tags = array(); $arrFaq = array_fill_keys($this->faq_categories, array()); // Add FAQs @@ -101,6 +109,15 @@ protected function compile() $arrFaq[$objFaq->pid]['items'][] = $arrTemp; $arrFaq[$objFaq->pid]['headline'] = $objPid->headline; $arrFaq[$objFaq->pid]['title'] = $objPid->title; + + $tags[] = 'contao.db.tl_faq.' . $objFaq->id; + } + + // Tag the FAQs (see #2137) + if (System::getContainer()->has('fos_http_cache.http.symfony_response_tagger')) + { + $responseTagger = System::getContainer()->get('fos_http_cache.http.symfony_response_tagger'); + $responseTagger->addTags($tags); } $arrFaq = array_values(array_filter($arrFaq)); diff --git a/faq-bundle/src/Resources/contao/modules/ModuleFaqPage.php b/faq-bundle/src/Resources/contao/modules/ModuleFaqPage.php index 1aa176d2902..691cfaeb621 100644 --- a/faq-bundle/src/Resources/contao/modules/ModuleFaqPage.php +++ b/faq-bundle/src/Resources/contao/modules/ModuleFaqPage.php @@ -56,6 +56,13 @@ public function generate() return ''; } + // Tag the FAQ categories (see #2137) + if (System::getContainer()->has('fos_http_cache.http.symfony_response_tagger')) + { + $responseTagger = System::getContainer()->get('fos_http_cache.http.symfony_response_tagger'); + $responseTagger->addTags(array_map(static function ($id) { return 'contao.db.tl_faq_category.' . $id; }, $this->faq_categories)); + } + return parent::generate(); } @@ -76,6 +83,7 @@ protected function compile() /** @var PageModel $objPage */ global $objPage; + $tags = array(); $arrFaqs = array_fill_keys($this->faq_categories, array()); $projectDir = System::getContainer()->getParameter('kernel.project_dir'); @@ -126,6 +134,15 @@ protected function compile() $arrFaqs[$objFaq->pid]['items'][] = $objTemp; $arrFaqs[$objFaq->pid]['headline'] = $objPid->headline; $arrFaqs[$objFaq->pid]['title'] = $objPid->title; + + $tags[] = 'contao.db.tl_faq.' . $objFaq->id; + } + + // Tag the FAQs (see #2137) + if (System::getContainer()->has('fos_http_cache.http.symfony_response_tagger')) + { + $responseTagger = System::getContainer()->get('fos_http_cache.http.symfony_response_tagger'); + $responseTagger->addTags($tags); } $arrFaqs = array_values(array_filter($arrFaqs)); diff --git a/faq-bundle/src/Resources/contao/modules/ModuleFaqReader.php b/faq-bundle/src/Resources/contao/modules/ModuleFaqReader.php index d591c599ce6..a30a9d211c9 100644 --- a/faq-bundle/src/Resources/contao/modules/ModuleFaqReader.php +++ b/faq-bundle/src/Resources/contao/modules/ModuleFaqReader.php @@ -155,6 +155,13 @@ protected function compile() $this->Template->info = sprintf($GLOBALS['TL_LANG']['MSC']['faqCreatedBy'], Date::parse($objPage->dateFormat, $objFaq->tstamp), $strAuthor); + // Tag the FAQ (see #2137) + if (System::getContainer()->has('fos_http_cache.http.symfony_response_tagger')) + { + $responseTagger = System::getContainer()->get('fos_http_cache.http.symfony_response_tagger'); + $responseTagger->addTags(array('contao.db.tl_faq.' . $objFaq->id)); + } + $bundles = System::getContainer()->getParameter('kernel.bundles'); // HOOK: comments extension required diff --git a/news-bundle/src/Resources/contao/modules/ModuleNews.php b/news-bundle/src/Resources/contao/modules/ModuleNews.php index 4d034578eeb..4183061c7c8 100644 --- a/news-bundle/src/Resources/contao/modules/ModuleNews.php +++ b/news-bundle/src/Resources/contao/modules/ModuleNews.php @@ -225,7 +225,8 @@ protected function parseArticle($objArticle, $blnAddArchive=false, $strClass='', // Tag the news (see #2137) if (System::getContainer()->has('fos_http_cache.http.symfony_response_tagger')) { - System::getContainer()->get('fos_http_cache.http.symfony_response_tagger')->addTags(array('contao.db.tl_news.' . $objArticle->id)); + $responseTagger = System::getContainer()->get('fos_http_cache.http.symfony_response_tagger'); + $responseTagger->addTags(array('contao.db.tl_news.' . $objArticle->id)); } return $objTemplate->parse(); diff --git a/news-bundle/src/Resources/contao/modules/ModuleNewsArchive.php b/news-bundle/src/Resources/contao/modules/ModuleNewsArchive.php index 7f1c4067af2..1cb401ea943 100644 --- a/news-bundle/src/Resources/contao/modules/ModuleNewsArchive.php +++ b/news-bundle/src/Resources/contao/modules/ModuleNewsArchive.php @@ -76,7 +76,8 @@ public function generate() // Tag the news archives (see #2137) if (System::getContainer()->has('fos_http_cache.http.symfony_response_tagger')) { - System::getContainer()->get('fos_http_cache.http.symfony_response_tagger')->addTags(array_map(static function ($id) { return 'contao.db.tl_news_archive.' . $id; }, $this->news_archives)); + $responseTagger = System::getContainer()->get('fos_http_cache.http.symfony_response_tagger'); + $responseTagger->addTags(array_map(static function ($id) { return 'contao.db.tl_news_archive.' . $id; }, $this->news_archives)); } return parent::generate(); diff --git a/news-bundle/src/Resources/contao/modules/ModuleNewsList.php b/news-bundle/src/Resources/contao/modules/ModuleNewsList.php index 5a5271027dd..008722b066a 100644 --- a/news-bundle/src/Resources/contao/modules/ModuleNewsList.php +++ b/news-bundle/src/Resources/contao/modules/ModuleNewsList.php @@ -69,7 +69,8 @@ public function generate() // Tag the news archives (see #2137) if (System::getContainer()->has('fos_http_cache.http.symfony_response_tagger')) { - System::getContainer()->get('fos_http_cache.http.symfony_response_tagger')->addTags(array_map(static function ($id) { return 'contao.db.tl_news_archive.' . $id; }, $this->news_archives)); + $responseTagger = System::getContainer()->get('fos_http_cache.http.symfony_response_tagger'); + $responseTagger->addTags(array_map(static function ($id) { return 'contao.db.tl_news_archive.' . $id; }, $this->news_archives)); } return parent::generate(); diff --git a/newsletter-bundle/src/Resources/contao/modules/ModuleNewsletterList.php b/newsletter-bundle/src/Resources/contao/modules/ModuleNewsletterList.php index a1d75b0189b..0e8eac7d9b9 100644 --- a/newsletter-bundle/src/Resources/contao/modules/ModuleNewsletterList.php +++ b/newsletter-bundle/src/Resources/contao/modules/ModuleNewsletterList.php @@ -56,6 +56,13 @@ public function generate() return ''; } + // Tag the channels (see #2137) + if (System::getContainer()->has('fos_http_cache.http.symfony_response_tagger')) + { + $responseTagger = System::getContainer()->get('fos_http_cache.http.symfony_response_tagger'); + $responseTagger->addTags(array_map(static function ($id) { return 'contao.db.tl_newsletter_channel.' . $id; }, $this->nl_channels)); + } + return parent::generate(); } @@ -75,6 +82,8 @@ protected function compile() if ($objNewsletter !== null) { + $tags = array(); + while ($objNewsletter->next()) { /** @var NewsletterChannelModel $objTarget */ @@ -119,6 +128,15 @@ protected function compile() 'time' => Date::parse($objPage->timeFormat, $objNewsletter->date), 'channel' => $objNewsletter->pid ); + + $tags[] = 'contao.db.tl_newsletter.' . $objNewsletter->id; + } + + // Tag the newsletters (see #2137) + if (System::getContainer()->has('fos_http_cache.http.symfony_response_tagger')) + { + $responseTagger = System::getContainer()->get('fos_http_cache.http.symfony_response_tagger'); + $responseTagger->addTags($tags); } } diff --git a/newsletter-bundle/src/Resources/contao/modules/ModuleNewsletterReader.php b/newsletter-bundle/src/Resources/contao/modules/ModuleNewsletterReader.php index 5ed8b1d7454..8400626ff7c 100644 --- a/newsletter-bundle/src/Resources/contao/modules/ModuleNewsletterReader.php +++ b/newsletter-bundle/src/Resources/contao/modules/ModuleNewsletterReader.php @@ -134,6 +134,13 @@ protected function compile() $this->Template->content = $strContent; $this->Template->subject = $objNewsletter->subject; + + // Tag the newsletter (see #2137) + if (System::getContainer()->has('fos_http_cache.http.symfony_response_tagger')) + { + $responseTagger = System::getContainer()->get('fos_http_cache.http.symfony_response_tagger'); + $responseTagger->addTags(array('contao.db.tl_newsletter.' . $objNewsletter->id)); + } } }