Add backend classes for fetching inconsistent data
[MAILPOET-1587]
This commit is contained in:
committed by
Aschepikov
parent
22ee156dcd
commit
54c21df3a6
@@ -617,6 +617,8 @@ class ContainerConfigurator implements IContainerConfigurator {
|
|||||||
$container->autowire(\MailPoet\NewsletterTemplates\ThumbnailSaver::class)->setPublic(true);
|
$container->autowire(\MailPoet\NewsletterTemplates\ThumbnailSaver::class)->setPublic(true);
|
||||||
$container->autowire(\MailPoet\NewsletterTemplates\BrandStyles::class)->setPublic(true);
|
$container->autowire(\MailPoet\NewsletterTemplates\BrandStyles::class)->setPublic(true);
|
||||||
// Util
|
// Util
|
||||||
|
$container->autowire(\MailPoet\Util\DataInconsistency\DataInconsistencyController::class)->setPublic(true);
|
||||||
|
$container->autowire(\MailPoet\Util\DataInconsistency\DataInconsistencyRepository::class)->setPublic(true);
|
||||||
$container->autowire(\MailPoet\Util\Cookies::class)->setPublic(true);
|
$container->autowire(\MailPoet\Util\Cookies::class)->setPublic(true);
|
||||||
$container->autowire(\MailPoet\Util\DBCollationChecker::class);
|
$container->autowire(\MailPoet\Util\DBCollationChecker::class);
|
||||||
$container->autowire(\MailPoet\Util\FreeDomains::class);
|
$container->autowire(\MailPoet\Util\FreeDomains::class);
|
||||||
|
@@ -0,0 +1,23 @@
|
|||||||
|
<?php declare(strict_types = 1);
|
||||||
|
|
||||||
|
namespace MailPoet\Util\DataInconsistency;
|
||||||
|
|
||||||
|
class DataInconsistencyController {
|
||||||
|
const ORPHANED_TASKS = 'orphaned_tasks';
|
||||||
|
|
||||||
|
private DataInconsistencyRepository $repository;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
DataInconsistencyRepository $repository
|
||||||
|
) {
|
||||||
|
$this->repository = $repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getInconsistentDataStatus(): array {
|
||||||
|
$result = [
|
||||||
|
self::ORPHANED_TASKS => $this->repository->getOrphanedSendingTasksCount(),
|
||||||
|
];
|
||||||
|
$result['total'] = array_sum($result);
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,29 @@
|
|||||||
|
<?php declare(strict_types = 1);
|
||||||
|
|
||||||
|
namespace MailPoet\Util\DataInconsistency;
|
||||||
|
|
||||||
|
use MailPoet\Cron\Workers\SendingQueue\SendingQueue;
|
||||||
|
use MailPoet\Entities\ScheduledTaskEntity;
|
||||||
|
use MailPoetVendor\Doctrine\ORM\EntityManager;
|
||||||
|
|
||||||
|
class DataInconsistencyRepository {
|
||||||
|
private EntityManager $entityManager;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
EntityManager $entityManager
|
||||||
|
) {
|
||||||
|
$this->entityManager = $entityManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getOrphanedSendingTasksCount(): int {
|
||||||
|
return (int)$this->entityManager->createQueryBuilder()
|
||||||
|
->select('count(st.id)')
|
||||||
|
->from(ScheduledTaskEntity::class, 'st')
|
||||||
|
->leftJoin('st.sendingQueue', 'sq')
|
||||||
|
->where('sq.id IS NULL')
|
||||||
|
->andWhere('st.type = :type')
|
||||||
|
->setParameter('type', SendingQueue::TASK_TYPE)
|
||||||
|
->getQuery()
|
||||||
|
->getSingleScalarResult();
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,33 @@
|
|||||||
|
<?php declare(strict_types = 1);
|
||||||
|
|
||||||
|
namespace MailPoet\Util\DataInconsistency;
|
||||||
|
|
||||||
|
use MailPoet\Cron\Workers\SendingQueue\SendingQueue as SendingQueueWorker;
|
||||||
|
use MailPoet\Entities\ScheduledTaskEntity;
|
||||||
|
use MailPoet\Test\DataFactories\ScheduledTask;
|
||||||
|
use MailPoet\Test\DataFactories\SendingQueue;
|
||||||
|
|
||||||
|
class DataInconsistencyRepositoryTest extends \MailPoetTest {
|
||||||
|
private DataInconsistencyRepository $repository;
|
||||||
|
|
||||||
|
public function _before() {
|
||||||
|
$this->repository = $this->diContainer->get(DataInconsistencyRepository::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testItFetchesOrphanedSendingTasksCount() {
|
||||||
|
$orphanedSendingTasksCount = $this->repository->getOrphanedSendingTasksCount();
|
||||||
|
verify($orphanedSendingTasksCount)->equals(0);
|
||||||
|
|
||||||
|
// Add non orphaned sending task
|
||||||
|
$okTask = (new ScheduledTask())->create(SendingQueueWorker::TASK_TYPE, ScheduledTaskEntity::STATUS_SCHEDULED);
|
||||||
|
(new SendingQueue())->create($okTask);
|
||||||
|
$orphanedSendingTasksCount = $this->repository->getOrphanedSendingTasksCount();
|
||||||
|
verify($orphanedSendingTasksCount)->equals(0);
|
||||||
|
|
||||||
|
// Add orphaned sending tasks
|
||||||
|
(new ScheduledTask())->create(SendingQueueWorker::TASK_TYPE, ScheduledTaskEntity::STATUS_SCHEDULED);
|
||||||
|
(new ScheduledTask())->create(SendingQueueWorker::TASK_TYPE, null);
|
||||||
|
$orphanedSendingTasksCount = $this->repository->getOrphanedSendingTasksCount();
|
||||||
|
verify($orphanedSendingTasksCount)->equals(2);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user