Automations
1 year ago
KeyCheck
1 year ago
SendingQueue
5 days ago
StatsNotifications
2 months ago
AuthorizedSendingEmailsCheck.php
3 years ago
BackfillEngagementData.php
1 year ago
Bounce.php
5 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
4 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
UnconfirmedSubscribersCleanup.php
71 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\Cron\Workers; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Cron\CronHelper; |
| 9 | use MailPoet\Entities\ScheduledTaskEntity; |
| 10 | use MailPoet\Settings\SettingsController; |
| 11 | use MailPoet\Subscribers\SubscribersRepository; |
| 12 | use MailPoetVendor\Carbon\Carbon; |
| 13 | |
| 14 | class UnconfirmedSubscribersCleanup extends SimpleWorker { |
| 15 | const TASK_TYPE = 'unconfirmed_subscribers_cleanup'; |
| 16 | const RETENTION_DAYS = 30; |
| 17 | const BATCH_SIZE = 1000; |
| 18 | const SUPPORT_MULTIPLE_INSTANCES = false; |
| 19 | |
| 20 | /** @var SettingsController */ |
| 21 | private $settings; |
| 22 | |
| 23 | /** @var SubscribersRepository */ |
| 24 | private $subscribersRepository; |
| 25 | |
| 26 | public function __construct( |
| 27 | SettingsController $settings, |
| 28 | SubscribersRepository $subscribersRepository |
| 29 | ) { |
| 30 | $this->settings = $settings; |
| 31 | $this->subscribersRepository = $subscribersRepository; |
| 32 | parent::__construct(); |
| 33 | } |
| 34 | |
| 35 | public function processTaskStrategy(ScheduledTaskEntity $task, $timer) { |
| 36 | if ($this->settings->get('delete_unconfirmed_subscribers_after_days') !== (string)self::RETENTION_DAYS) { |
| 37 | $this->schedule(); |
| 38 | return true; |
| 39 | } |
| 40 | |
| 41 | $cutoff = Carbon::now()->millisecond(0)->subDays(self::RETENTION_DAYS); |
| 42 | |
| 43 | do { |
| 44 | if ($this->settings->fetch('delete_unconfirmed_subscribers_after_days') !== (string)self::RETENTION_DAYS) { |
| 45 | break; |
| 46 | } |
| 47 | |
| 48 | $deletedIds = $this->subscribersRepository->deleteUnconfirmedSubscribersForCleanup($cutoff, self::BATCH_SIZE); |
| 49 | if (empty($deletedIds)) { |
| 50 | break; |
| 51 | } |
| 52 | |
| 53 | try { |
| 54 | $this->cronHelper->enforceExecutionLimit($timer); |
| 55 | } catch (\Exception $e) { |
| 56 | if ($e->getCode() === CronHelper::DAEMON_EXECUTION_LIMIT_REACHED) { |
| 57 | $this->cronWorkerScheduler->schedule(static::TASK_TYPE, Carbon::now()->millisecond(0)->addMinutes(5)); |
| 58 | } |
| 59 | throw $e; |
| 60 | } |
| 61 | } while (true); |
| 62 | |
| 63 | $this->schedule(); |
| 64 | return true; |
| 65 | } |
| 66 | |
| 67 | public function getNextRunDate() { |
| 68 | return Carbon::now()->millisecond(0)->addDay(); |
| 69 | } |
| 70 | } |
| 71 |