mations,wpUserId,isWoocommerceUser,engagementScore,lastSubscribedAt}"); } protected function applyFromClause(QueryBuilder $queryBuilder) { $queryBuilder->from(SubscriberEntity::class, 's'); } protected function applyGroup(QueryBuilder $queryBuilder, string $group) { // include/exclude deleted if ($group === 'trash') { $queryBuilder->andWhere('s.deletedAt IS NOT NULL'); } else { $queryBuilder->andWhere('s.deletedAt IS NULL'); } if (!in_array($group, self::$supportedStatuses)) { return; } if (!in_array($group, [SubscriberEntity::STATUS_SUBSCRIBED, SubscriberEntity::STATUS_UNSUBSCRIBED])) { $queryBuilder ->andWhere('s.status = :status') ->setParameter('status', $group); return; } $segment = $this->definition && array_key_exists('segment', $this->definition->getFilters()) ? $this->entityManager->find(SegmentEntity::class, (int)$this->definition->getFilters()['segment']) : null; if (!$segment instanceof SegmentEntity || !$segment->isStatic()) { $queryBuilder ->andWhere('s.status = :status') ->setParameter('status', $group); return; } $operator = $group === SubscriberEntity::STATUS_SUBSCRIBED ? 'AND' : 'OR'; $queryBuilder ->andWhere('(s.status = :status ' . $operator . ' ss.status = :status)') ->setParameter('status', $group); } protected function applySearch(QueryBuilder $queryBuilder, string $search, array $parameters = []) { $search = Helpers::escapeSearch($search); $queryBuilder ->andWhere('s.email LIKE :search or s.firstName LIKE :search or s.lastName LIKE :search') ->setParameter('search', "%$search%"); } protected function applyFilters(QueryBuilder $queryBuilder, array $filters) { if (isset($filters['segment'])) { if ($filters['segment'] === self::FILTER_WITHOUT_LIST) { $this->segmentSubscribersRepository->addConstraintsForSubscribersWithoutSegment($queryBuilder); } else { $segment = $this->entityManager->find(SegmentEntity::class, (int)$filters['segment']); if ($segment instanceof SegmentEntity && $segment->isStatic()) { $queryBuilder->join('s.subscriberSegments', 'ss', Join::WITH, 'ss.segment = :ssSegment') ->setParameter('ssSegment', $segment->getId()); } } } // filtering by minimal updated at if (isset($filters['minUpdatedAt']) && $filters['minUpdatedAt'] instanceof \DateTimeInterface) { $queryBuilder->andWhere('s.updatedAt >= :updatedAt') ->setParameter('updatedAt', $filters['minUpdatedAt']); } if (isset($filters['tag'])) { $tag = $this->entityManager->find(TagEntity::class, (int)$filters['tag']); if ($tag) { $queryBuilder->join('s.subscriberTags', 'st', Join::WITH, 'st.tag = :stTag') ->setParameter('stTag', $tag); } } } protected function applyParameters(QueryBuilder $queryBuilder, array $parameters) { // nothing to do here } protected function applySorting(QueryBuilder $queryBuilder, string $sortBy, string $sortOrder) { if (!$sortBy) { $sortBy = self::DEFAULT_SORT_BY; } $queryBuilder->addOrderBy("s.$sortBy", $sortOrder); } public function getGroups(ListingDefinition $definition): array { $queryBuilder = clone $this->queryBuilder; $this->applyFromClause($queryBuilder); $groupCounts = [ SubscriberEntity::STATUS_SUBSCRIBED => 0, SubscriberEntity::STATUS_UNCONFIRMED => 0, SubscriberEntity::STATUS_UNSUBSCRIBED => 0, SubscriberEntity::STATUS_INACTIVE => 0, SubscriberEntity::STATUS_BOUNCED => 0, 'trash' => 0, ]; foreach (array_keys($groupCounts) as $group) { $groupDefinition = $group === $definition->getGroup() ? $definition : new ListingDefinition( $group, $definition->getFilters(), $definition->getSearch(), $definition->getParameters(), $definition->getSortBy(), $definition->getSortOrder(), $definition->getOffset(), $definition->getLimit(), $definition->getSelection() ); $groupCounts[$group] = $this->getCount($groupDefinition); } $trashedCount = $groupCounts['trash']; unset($groupCounts['trash']); $totalCount = (int)array_sum($groupCounts); return [ [ 'name' => 'all', 'label' => __('All', 'mailpoet'), 'count' => $totalCount, ], [ 'name' => SubscriberEntity::STATUS_SUBSCRIBED, 'label' => __('Subscribed', 'mailpoet'), 'count' => $groupCounts[SubscriberEntity::STATUS_SUBSCRIBED], ], [ 'name' => SubscriberEntity::STATUS_UNCONFIRMED, 'label' => __('Unconfirmed', 'mailpoet'), 'count' => $groupCounts[SubscriberEntity::STATUS_UNCONFIRMED], ], [ 'name' => SubscriberEntity::STATUS_UNSUBSCRIBED, 'label' => __('Unsubscribed', 'mailpoet'), 'count' => $groupCounts[SubscriberEntity::STATUS_UNSUBSCRIBED], ], [ 'name' => SubscriberEntity::STATUS_INACTIVE, 'label' => __('Inactive', 'mailpoet'), 'count' => $groupCounts[SubscriberEntity::STATUS_INACTIVE], ], [ 'name' => SubscriberEntity::STATUS_BOUNCED, 'label' => __('Bounced', 'mailpoet'), 'count' => $groupCounts[SubscriberEntity::STATUS_BOUNCED], ], [ 'name' => 'trash', 'label' => __('Trash', 'mailpoet'), 'count' => $trashedCount, ], ]; } public function getFilters(ListingDefinition $definition): array { return [ 'segment' => $this->getSegmentFilter($definition), 'tag' => $this->getTagsFilter($definition), ]; } /** * @return array */ private function getSegmentFilter(ListingDefinition $definition): array { $group = $definition->getGroup(); $subscribersWithoutSegmentStats = $this->subscribersCountsController->getSubscribersWithoutSegmentStatisticsCount(); $key = $group ?: 'all'; $subscribersWithoutSegmentCount = $subscribersWithoutSegmentStats[$key]; $subscribersWithoutSegmentLabel = sprintf( // translators: %s is the number of subscribers without a list. __('Subscribers without a list (%s)', 'mailpoet'), number_format((float)$subscribersWithoutSegmentCount) ); $queryBuilder = clone $this->queryBuilder; $queryBuilder ->select('s') ->from(SegmentEntity::class, 's'); if ($group !== 'trash') { $queryBuilder->andWhere('s.deletedAt IS NULL'); } // format segment list $allSubscribersList = [ 'label' => __('All Lists', 'mailpoet'), 'value' => '', ]; $withoutSegmentList = [ 'label' => $subscribersWithoutSegmentLabel, 'value' => self::FILTER_WITHOUT_LIST, ]; $segmentList = []; foreach ($queryBuilder->getQuery()->getResult() as $segment) { $key = $group ?: 'all'; $count = $this->subscribersCountsController->getSegmentStatisticsCount($segment); $subscribersCount = (float)$count[$key]; // filter segments without subscribers if (!$subscribersCount) { continue; } $segmentList[] = [ 'label' => sprintf('%s (%s)', $segment->getName(), number_format($subscribersCount)), 'value' => $segment->getId(), ]; } usort($segmentList, function($a, $b) { return strcasecmp($a['label'], $b['label']); }); array_unshift($segmentList, $allSubscribersList, $withoutSegmentList); return $segmentList; } /** * @return array */ private function getTagsFilter(ListingDefinition $definition): array { $group = $definition->getGroup(); $allTagsList = [ 'label' => __('All Tags', 'mailpoet'), 'value' => '', ]; $status = in_array($group, ['all', 'trash']) ? null : $group; $isDeleted = $group === 'trash'; $tagsStatistics = $this->subscribersCountsController->getTagsStatisticsCount($status, $isDeleted); $tagsList = []; foreach ($tagsStatistics as $tagStatistics) { $tagsList[] = [ 'label' => sprintf('%s (%s)', $tagStatistics['name'], number_format((float)$tagStatistics['subscribersCount'])), 'value' => $tagStatistics['id'], ]; } array_unshift($tagsList, $allTagsList); return $tagsList; } private function getDataForDynamicSegment(ListingDefinition $definition, SegmentEntity $segment) { $queryBuilder = clone $this->queryBuilder; $sortBy = Helpers::underscoreToCamelCase($definition->getSortBy()) ?: self::DEFAULT_SORT_BY; $this->applySelectClause($queryBuilder); $this->applyFromClause($queryBuilder); $subscribersTable = $this->entityManager->getClassMetadata(SubscriberEntity::class)->getTableName(); $subscribersIdsQuery = $this->entityManager ->getConnection() ->createQueryBuilder() ->select("DISTINCT $subscribersTable.id") ->from($subscribersTable); $subscribersIdsQuery = $this->applyConstraintsForDynamicSegment($subscribersIdsQuery, $definition, $segment); $subscribersIdsQuery->orderBy("$subscribersTable." . Helpers::camelCaseToUnderscore($sortBy), $definition->getSortOrder()); $subscribersIdsQuery->setFirstResult($definition->getOffset()); $subscribersIdsQuery->setMaxResults($definition->getLimit()); $idsStatement = $subscribersIdsQuery->executeQuery(); $result = $idsStatement->fetchAll(); $ids = array_column($result, 'id'); if (count($ids)) { $queryBuilder->andWhere('s.id IN (:subscriberIds)') ->setParameter('subscriberIds', $ids); } else { $queryBuilder->andWhere('0 = 1'); // Don't return any subscribers if no ids found } $this->applySorting($queryBuilder, $sortBy, $definition->getSortOrder()); return $queryBuilder->getQuery()->getResult(); } private function applyConstraintsForDynamicSegment( DBALQueryBuilder $subscribersQuery, ListingDefinition $definition, SegmentEntity $segment ) { // Apply dynamic segments filters $subscribersQuery = $this->dynamicSegmentsFilter->apply($subscribersQuery, $segment); // Apply group, search to fetch only necessary ids $subscribersTable = $this->entityManager->getClassMetadata(SubscriberEntity::class)->getTableName(); if ($definition->getSearch()) { $search = Helpers::escapeSearch((string)$definition->getSearch()); $subscribersQuery ->andWhere("$subscribersTable.email LIKE :search or $subscribersTable.first_name LIKE :search or $subscribersTable.last_name LIKE :search") ->setParameter('search', "%$search%"); } if ($definition->getGroup()) { if ($definition->getGroup() === 'trash') { $subscribersQuery->andWhere("$subscribersTable.deleted_at IS NOT NULL"); } else { $subscribersQuery->andWhere("$subscribersTable.deleted_at IS NULL"); } if (in_array($definition->getGroup(), self::$supportedStatuses)) { $subscribersQuery ->andWhere("$subscribersTable.status = :status") ->setParameter('status', $definition->getGroup()); } } return $subscribersQuery; } private function getDynamicSegmentFromFilters(ListingDefinition $definition): ?SegmentEntity { $filters = $definition->getFilters(); if (!$filters || !isset($filters['segment'])) { return null; } if ($filters['segment'] === self::FILTER_WITHOUT_LIST) { return null; } $segment = $this->entityManager->find(SegmentEntity::class, (int)$filters['segment']); if (!$segment instanceof SegmentEntity) { return null; } return $segment->isStatic() ? null : $segment; } }
Fatal error: Uncaught Error: Class "MailPoet\Subscribers\SubscriberListingRepository" not found in /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php:5228 Stack trace: #0 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(1321): MailPoetGenerated\FreeCachedContainer->getSubscriberListingRepositoryService() #1 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(1311): MailPoetGenerated\FreeCachedContainer->getReporterService() #2 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(916): MailPoetGenerated\FreeCachedContainer->getAnalytics2Service() #3 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(5592): MailPoetGenerated\FreeCachedContainer->getServicesService() #4 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(2612): MailPoetGenerated\FreeCachedContainer->getDotcomLicenseProvisionerService() #5 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(2640): MailPoetGenerated\FreeCachedContainer->getHooks2Service() #6 /htdocs/wp-content/plugins/mailpoet/vendor-prefixed/symfony/dependency-injection/Container.php(122): MailPoetGenerated\FreeCachedContainer->getInitializerService() #7 /htdocs/wp-content/plugins/mailpoet/vendor-prefixed/symfony/dependency-injection/Container.php(110): MailPoetVendor\Symfony\Component\DependencyInjection\Container->make('MailPoet\\Config...', 1) #8 /htdocs/wp-content/plugins/mailpoet/lib/DI/ContainerWrapper.php(39): MailPoetVendor\Symfony\Component\DependencyInjection\Container->get('MailPoet\\Config...') #9 /htdocs/wp-content/plugins/mailpoet/mailpoet_initializer.php(89): MailPoet\DI\ContainerWrapper->get('MailPoet\\Config...') #10 /htdocs/wp-content/plugins/mailpoet/mailpoet.php(194): require_once('/htdocs/wp-cont...') #11 /htdocs/wp-settings.php(526): include_once('/htdocs/wp-cont...') #12 /htdocs/wp-config.php(85): require_once('/htdocs/wp-sett...') #13 /htdocs/wp-load.php(50): require_once('/htdocs/wp-conf...') #14 /htdocs/wp-blog-header.php(13): require_once('/htdocs/wp-load...') #15 /htdocs/index.php(17): require('/htdocs/wp-blog...') #16 {main} thrown in /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php on line 5228