ksRepository */ private $scheduledTasksRepository; /** @var Scheduler */ private $scheduler; public function __construct( SubscribersRepository $subscribersRepository, SegmentsRepository $segmentsRepository, NewslettersRepository $newslettersRepository, ScheduledTasksRepository $scheduledTasksRepository, Scheduler $scheduler ) { $this->subscribersRepository = $subscribersRepository; $this->segmentsRepository = $segmentsRepository; $this->newslettersRepository = $newslettersRepository; $this->scheduledTasksRepository = $scheduledTasksRepository; $this->scheduler = $scheduler; } public function scheduleSubscriberWelcomeNotification($subscriberId, $segments) { $newsletters = $this->newslettersRepository->findActiveByTypes([NewsletterEntity::TYPE_WELCOME]); if (empty($newsletters)) return false; $result = []; foreach ($newsletters as $newsletter) { if ( $newsletter->getOptionValue(NewsletterOptionFieldEntity::NAME_EVENT) === 'segment' && in_array($newsletter->getOptionValue(NewsletterOptionFieldEntity::NAME_SEGMENT), $segments) ) { $sendingTask = $this->createWelcomeNotificationSendingTask($newsletter, $subscriberId); if ($sendingTask) { $result[] = $sendingTask; } } } return $result ?: false; } public function scheduleWPUserWelcomeNotification( $subscriberId, $wpUser, $oldUserData = false ) { $newsletters = $this->newslettersRepository->findActiveByTypes([NewsletterEntity::TYPE_WELCOME]); if (empty($newsletters)) return false; foreach ($newsletters as $newsletter) { if ($newsletter->getOptionValue(NewsletterOptionFieldEntity::NAME_EVENT) !== 'user') { continue; } $newsletterRole = $newsletter->getOptionValue(NewsletterOptionFieldEntity::NAME_ROLE); if (!empty($oldUserData['roles'])) { // do not schedule welcome newsletter if roles have not changed $oldRole = $oldUserData['roles']; $newRole = $wpUser['roles']; if ( $newsletterRole === self::WORDPRESS_ALL_ROLES || !array_diff($newRole, $oldRole) ) { continue; } } if ( $newsletterRole === self::WORDPRESS_ALL_ROLES || in_array($newsletterRole, $wpUser['roles']) ) { $this->createWelcomeNotificationSendingTask($newsletter, $subscriberId); } } } public function createWelcomeNotificationSendingTask(NewsletterEntity $newsletter, $subscriberId) { $subscriber = $this->subscribersRepository->findOneById($subscriberId); if (!($subscriber instanceof SubscriberEntity) || $subscriber->getDeletedAt() !== null) { return; } if ($newsletter->getOptionValue(NewsletterOptionFieldEntity::NAME_EVENT) === 'segment') { $segment = $this->segmentsRepository->findOneById((int)$newsletter->getOptionValue(NewsletterOptionFieldEntity::NAME_SEGMENT)); if ((!$segment instanceof SegmentEntity) || $segment->getDeletedAt() !== null) { return; } } if ($newsletter->getOptionValue(NewsletterOptionFieldEntity::NAME_EVENT) === 'user') { $segment = $this->segmentsRepository->getWPUsersSegment(); if ((!$segment instanceof SegmentEntity) || $segment->getDeletedAt() !== null) { return; } } $previouslyScheduledNotification = $this->scheduledTasksRepository->findByNewsletterAndSubscriberId($newsletter, $subscriberId); if (!empty($previouslyScheduledNotification)) { return; } $sendingTask = SendingTask::create(); $sendingTask->newsletterId = $newsletter->getId(); $sendingTask->setSubscribers([$subscriberId]); $sendingTask->status = SendingQueueEntity::STATUS_SCHEDULED; $sendingTask->priority = SendingQueueEntity::PRIORITY_HIGH; $sendingTask->scheduledAt = $this->scheduler->getScheduledTimeWithDelay( $newsletter->getOptionValue(NewsletterOptionFieldEntity::NAME_AFTER_TIME_TYPE), $newsletter->getOptionValue(NewsletterOptionFieldEntity::NAME_AFTER_TIME_NUMBER) ); return $sendingTask->save(); } }
Fatal error: Uncaught Error: Class "MailPoet\Newsletter\Scheduler\WelcomeScheduler" not found in /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php:3447 Stack trace: #0 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(4114): MailPoetGenerated\FreeCachedContainer->getWelcomeSchedulerService() #1 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(2309): MailPoetGenerated\FreeCachedContainer->getWPService() #2 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(2214): MailPoetGenerated\FreeCachedContainer->getPopulatorService() #3 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(2276): 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(206): require_once('/htdocs/wp-cont...') #9 /htdocs/wp-settings.php(462): include_once('/htdocs/wp-cont...') #10 /htdocs/wp-config.php(96): 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 3447