Automations
1 year ago
KeyCheck
1 year ago
SendingQueue
6 days ago
StatsNotifications
2 months ago
AuthorizedSendingEmailsCheck.php
3 years ago
BackfillEngagementData.php
1 year ago
Bounce.php
6 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
SubscriberLinkTokens.php
49 lines
| 1 | <?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing |
| 2 | |
| 3 | namespace MailPoet\Cron\Workers; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\DI\ContainerWrapper; |
| 9 | use MailPoet\Entities\ScheduledTaskEntity; |
| 10 | use MailPoet\Entities\SubscriberEntity; |
| 11 | use MailPoet\Subscribers\SubscribersRepository; |
| 12 | use MailPoetVendor\Carbon\Carbon; |
| 13 | use MailPoetVendor\Doctrine\DBAL\ParameterType; |
| 14 | use MailPoetVendor\Doctrine\ORM\EntityManager; |
| 15 | |
| 16 | if (!defined('ABSPATH')) exit; |
| 17 | |
| 18 | class SubscriberLinkTokens extends SimpleWorker { |
| 19 | const TASK_TYPE = 'subscriber_link_tokens'; |
| 20 | const BATCH_SIZE = 10000; |
| 21 | const AUTOMATIC_SCHEDULING = false; |
| 22 | |
| 23 | public function processTaskStrategy(ScheduledTaskEntity $task, $timer) { |
| 24 | $entityManager = ContainerWrapper::getInstance()->get(EntityManager::class); |
| 25 | $subscribersRepository = ContainerWrapper::getInstance()->get(SubscribersRepository::class); |
| 26 | $subscribersTable = $entityManager->getClassMetadata(SubscriberEntity::class)->getTableName(); |
| 27 | $connection = $entityManager->getConnection(); |
| 28 | |
| 29 | $count = $subscribersRepository->countBy(['linkToken' => null]); |
| 30 | |
| 31 | if ($count) { |
| 32 | $authKey = defined('AUTH_KEY') ? AUTH_KEY : ''; |
| 33 | |
| 34 | $connection->executeStatement( |
| 35 | "UPDATE {$subscribersTable} SET link_token = SUBSTRING(MD5(CONCAT(:authKey, email)), 1, :tokenLength) WHERE link_token IS NULL LIMIT :limit", |
| 36 | ['authKey' => $authKey, 'tokenLength' => SubscriberEntity::OBSOLETE_LINK_TOKEN_LENGTH, 'limit' => self::BATCH_SIZE], |
| 37 | ['authKey' => ParameterType::STRING, 'tokenLength' => ParameterType::INTEGER, 'limit' => ParameterType::INTEGER] |
| 38 | ); |
| 39 | |
| 40 | $this->schedule(); |
| 41 | } |
| 42 | return true; |
| 43 | } |
| 44 | |
| 45 | public function getNextRunDate() { |
| 46 | return Carbon::now()->millisecond(0); |
| 47 | } |
| 48 | } |
| 49 |