which we need to newly subscribe. $newlySubscribedSegments = array_diff($segmentIds, $existingSegmentIds); if (!$newlySubscribedSegments && !$unsubscribedSegments) { return; } // The segments we need to unsubscribe. $unsubscribe = array_filter( $existingSegments, function(SegmentEntity $segment) use ($unsubscribedSegments): bool { return in_array($segment->getId(), $unsubscribedSegments); } ); // The segments we need to newly subscribe. $subscribe = array_filter( $segments, function(SegmentEntity $segment) use ($newlySubscribedSegments): bool { return in_array($segment->getId(), $newlySubscribedSegments); } ); if ($unsubscribe) { $this->unsubscribeFromSegments($subscriber, $unsubscribe); } if ($subscribe) { $this->subscribeToSegments($subscriber, $subscribe); } } /** * @param SegmentEntity[] $segments */ public function subscribeToSegments(SubscriberEntity $subscriber, array $segments, bool $skipHooks = false): void { foreach ($segments as $segment) { $this->createOrUpdate($subscriber, $segment, SubscriberEntity::STATUS_SUBSCRIBED, $skipHooks); } } public function createOrUpdate( SubscriberEntity $subscriber, SegmentEntity $segment, string $status, bool $skipHooks = false ): SubscriberSegmentEntity { $subscriberSegment = $this->findOneBy(['segment' => $segment, 'subscriber' => $subscriber]); $oldStatus = null; if ($subscriberSegment instanceof SubscriberSegmentEntity) { $oldStatus = $subscriberSegment->getStatus(); $subscriberSegment->setStatus($status); } else { $subscriberSegment = new SubscriberSegmentEntity($segment, $subscriber, $status); $subscriber->getSubscriberSegments()->add($subscriberSegment); $this->entityManager->persist($subscriberSegment); } $this->entityManager->flush(); // fire subscribed hook for new subscriptions if ( !$skipHooks && $subscriber->getStatus() === SubscriberEntity::STATUS_SUBSCRIBED && $subscriberSegment->getStatus() === SubscriberEntity::STATUS_SUBSCRIBED && $oldStatus !== SubscriberEntity::STATUS_SUBSCRIBED ) { $this->wp->doAction('mailpoet_segment_subscribed', $subscriberSegment); } return $subscriberSegment; } }
Fatal error: Uncaught Error: Class "MailPoet\Subscribers\SubscriberSegmentRepository" not found in /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php:5258 Stack trace: #0 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(4808): MailPoetGenerated\FreeCachedContainer->getSubscriberSegmentRepositoryService() #1 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(2673): MailPoetGenerated\FreeCachedContainer->getWPService() #2 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(2578): MailPoetGenerated\FreeCachedContainer->getPopulatorService() #3 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(2640): MailPoetGenerated\FreeCachedContainer->getActivatorService() #4 /htdocs/wp-content/plugins/mailpoet/vendor-prefixed/symfony/dependency-injection/Container.php(122): MailPoetGenerated\FreeCachedContainer->getInitializerService() #5 /htdocs/wp-content/plugins/mailpoet/vendor-prefixed/symfony/dependency-injection/Container.php(110): MailPoetVendor\Symfony\Component\DependencyInjection\Container->make('MailPoet\\Config...', 1) #6 /htdocs/wp-content/plugins/mailpoet/lib/DI/ContainerWrapper.php(39): MailPoetVendor\Symfony\Component\DependencyInjection\Container->get('MailPoet\\Config...') #7 /htdocs/wp-content/plugins/mailpoet/mailpoet_initializer.php(89): MailPoet\DI\ContainerWrapper->get('MailPoet\\Config...') #8 /htdocs/wp-content/plugins/mailpoet/mailpoet.php(194): require_once('/htdocs/wp-cont...') #9 /htdocs/wp-settings.php(526): include_once('/htdocs/wp-cont...') #10 /htdocs/wp-config.php(85): require_once('/htdocs/wp-sett...') #11 /htdocs/wp-load.php(50): require_once('/htdocs/wp-conf...') #12 /htdocs/wp-blog-header.php(13): require_once('/htdocs/wp-load...') #13 /htdocs/index.php(17): require('/htdocs/wp-blog...') #14 {main} thrown in /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php on line 5258