From ae275d08246f5e8a8cbd3eb509c048d13f488961 Mon Sep 17 00:00:00 2001 From: Oluwaseun Olorunsola Date: Thu, 13 Jun 2024 15:35:14 +0100 Subject: [PATCH] Fix post-notification history subject search We previously were looking for search term on the Newsletter table subject column. Unfortunately, post-notification and its history items sometimes contain both static text and dynamic text i.e., MailPoet shortcodes. This prevented the search from returning any useful results. The RenderedSubject on the Sending queues table includes both the static text and dynamic text, so we can look for the search term on it MAILPOET-6072 --- mailpoet/lib/Listing/ListingRepository.php | 5 +++-- .../Listing/NewsletterListingRepository.php | 18 ++++++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/mailpoet/lib/Listing/ListingRepository.php b/mailpoet/lib/Listing/ListingRepository.php index 3389d119c9..603bc8addc 100644 --- a/mailpoet/lib/Listing/ListingRepository.php +++ b/mailpoet/lib/Listing/ListingRepository.php @@ -69,8 +69,10 @@ abstract class ListingRepository { } $search = $definition->getSearch(); + $parameters = $definition->getParameters(); + if ($search && strlen(trim($search)) > 0) { - $this->applySearch($queryBuilder, $search); + $this->applySearch($queryBuilder, $search, $parameters ?: []); } $filters = $definition->getFilters(); @@ -78,7 +80,6 @@ abstract class ListingRepository { $this->applyFilters($queryBuilder, $filters); } - $parameters = $definition->getParameters(); if ($parameters) { $this->applyParameters($queryBuilder, $parameters); } diff --git a/mailpoet/lib/Newsletter/Listing/NewsletterListingRepository.php b/mailpoet/lib/Newsletter/Listing/NewsletterListingRepository.php index f8b7afafa4..761aac48ba 100644 --- a/mailpoet/lib/Newsletter/Listing/NewsletterListingRepository.php +++ b/mailpoet/lib/Newsletter/Listing/NewsletterListingRepository.php @@ -204,11 +204,21 @@ class NewsletterListingRepository extends ListingRepository { ->setParameter('status', $group); } - protected function applySearch(QueryBuilder $queryBuilder, string $search) { + protected function applySearch(QueryBuilder $queryBuilder, string $search, array $parameters = []) { $search = Helpers::escapeSearch($search); - $queryBuilder - ->andWhere('n.subject LIKE :search') - ->setParameter('search', "%$search%"); + + $type = $parameters['type'] ?? null; + + if ($type && $type === NewsletterEntity::TYPE_NOTIFICATION_HISTORY) { + $queryBuilder + ->join('n.queues', 'sq') + ->andWhere('sq.newsletterRenderedSubject LIKE :search') + ->setParameter('search', "%$search%"); + } else { + $queryBuilder + ->andWhere('n.subject LIKE :search') + ->setParameter('search', "%$search%"); + } } protected function applyFilters(QueryBuilder $queryBuilder, array $filters) {