Files
piratepoet/mailpoet/lib/Cron/Workers/SubscriberLinkTokens.php
Rostislav Wolny 33f4b2d729 Replace usage of WP's current_time without gmt parameter in libs
This commit replaces usages by Carbon::now or in case we need a timestamp it
keeps current_time but adds the gtm parameter as true.
[MAILPOET-6142]
2024-08-19 15:29:42 +02:00

46 lines
1.7 KiB
PHP

<?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing
namespace MailPoet\Cron\Workers;
use MailPoet\DI\ContainerWrapper;
use MailPoet\Entities\ScheduledTaskEntity;
use MailPoet\Entities\SubscriberEntity;
use MailPoet\Subscribers\SubscribersRepository;
use MailPoetVendor\Carbon\Carbon;
use MailPoetVendor\Doctrine\DBAL\ParameterType;
use MailPoetVendor\Doctrine\ORM\EntityManager;
if (!defined('ABSPATH')) exit;
class SubscriberLinkTokens extends SimpleWorker {
const TASK_TYPE = 'subscriber_link_tokens';
const BATCH_SIZE = 10000;
const AUTOMATIC_SCHEDULING = false;
public function processTaskStrategy(ScheduledTaskEntity $task, $timer) {
$entityManager = ContainerWrapper::getInstance()->get(EntityManager::class);
$subscribersRepository = ContainerWrapper::getInstance()->get(SubscribersRepository::class);
$subscribersTable = $entityManager->getClassMetadata(SubscriberEntity::class)->getTableName();
$connection = $entityManager->getConnection();
$count = $subscribersRepository->countBy(['linkToken' => null]);
if ($count) {
$authKey = defined('AUTH_KEY') ? AUTH_KEY : '';
$connection->executeStatement(
"UPDATE {$subscribersTable} SET link_token = SUBSTRING(MD5(CONCAT(:authKey, email)), 1, :tokenLength) WHERE link_token IS NULL LIMIT :limit",
['authKey' => $authKey, 'tokenLength' => SubscriberEntity::OBSOLETE_LINK_TOKEN_LENGTH, 'limit' => self::BATCH_SIZE],
['authKey' => ParameterType::STRING, 'tokenLength' => ParameterType::INTEGER, 'limit' => ParameterType::INTEGER]
);
$this->schedule();
}
return true;
}
public function getNextRunDate() {
return Carbon::now()->millisecond(0);
}
}