Automations
1 year ago
KeyCheck
1 year ago
SendingQueue
4 days ago
StatsNotifications
2 months ago
AuthorizedSendingEmailsCheck.php
3 years ago
BackfillEngagementData.php
1 year ago
Bounce.php
4 days ago
BounceTaskSubscribersCleanup.php
1 month ago
BulkConfirmationEmailResend.php
2 months ago
ExportFilesCleanup.php
2 months ago
InactiveSubscribersMaintenance.php
2 weeks ago
LogCleanup.php
10 months ago
Mixpanel.php
9 months ago
NewsletterTemplateThumbnails.php
1 year ago
ReEngagementEmailsScheduler.php
1 year ago
Scheduler.php
2 months ago
SendingQueueBodyCleanup.php
2 months ago
SendingTaskSubscribersCleanup.php
2 months ago
SimpleWorker.php
1 year ago
StatisticsExport.php
2 months ago
SubscriberLimitNotificationWorker.php
2 months ago
SubscriberLinkTokens.php
1 year ago
SubscribersCountCacheRecalculation.php
2 weeks ago
SubscribersEngagementScore.php
3 days ago
SubscribersLastEngagement.php
2 months ago
SubscribersSegmentsCountSync.php
2 weeks ago
SubscribersStatsReport.php
1 year ago
Tracks.php
9 months ago
UnconfirmedSubscribersCleanup.php
2 months ago
UnsubscribeTokens.php
1 month ago
WooCommercePastOrders.php
1 year ago
WooCommerceSync.php
3 years ago
WorkersFactory.php
2 weeks ago
index.php
3 years ago
BackfillEngagementData.php
49 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\Cron\Workers; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Entities\ScheduledTaskEntity; |
| 9 | use MailPoet\Subscribers\EngagementDataBackfiller; |
| 10 | |
| 11 | class BackfillEngagementData extends SimpleWorker { |
| 12 | const TASK_TYPE = 'backfill_engagement_data'; |
| 13 | const BATCH_SIZE = 100; |
| 14 | const AUTOMATIC_SCHEDULING = false; |
| 15 | const SUPPORT_MULTIPLE_INSTANCES = false; |
| 16 | |
| 17 | /** @var EngagementDataBackfiller */ |
| 18 | private $engagementDataBackfiller; |
| 19 | |
| 20 | public function __construct( |
| 21 | EngagementDataBackfiller $engagementDataBackfiller |
| 22 | ) { |
| 23 | parent::__construct(); |
| 24 | $this->engagementDataBackfiller = $engagementDataBackfiller; |
| 25 | } |
| 26 | |
| 27 | public function processTaskStrategy(ScheduledTaskEntity $task, $timer) { |
| 28 | $meta = $task->getMeta(); |
| 29 | |
| 30 | $lastSubscriberId = $meta['last_subscriber_id'] ?? 0; |
| 31 | |
| 32 | do { |
| 33 | $this->cronHelper->enforceExecutionLimit($timer); |
| 34 | $batch = $this->engagementDataBackfiller->getBatch($lastSubscriberId, self::BATCH_SIZE); |
| 35 | if (empty($batch)) { |
| 36 | break; |
| 37 | } |
| 38 | $this->engagementDataBackfiller->updateBatch($batch); |
| 39 | $lastSubscriberId = $this->engagementDataBackfiller->getLastProcessedSubscriberId(); |
| 40 | $meta['last_subscriber_id'] = $lastSubscriberId; |
| 41 | $task->setMeta($meta); |
| 42 | $this->scheduledTasksRepository->persist($task); |
| 43 | $this->scheduledTasksRepository->flush(); |
| 44 | } while (count($batch) === self::BATCH_SIZE); |
| 45 | |
| 46 | return true; |
| 47 | } |
| 48 | } |
| 49 |