Files
piratepoet/mailpoet/lib/Util/DataInconsistency/DataInconsistencyController.php
Rostislav Wolny cb5f533e54 Add API for fixing inconsistent data
[MAILPOET-1587]
2024-08-08 15:37:32 +02:00

40 lines
1.1 KiB
PHP

<?php declare(strict_types = 1);
namespace MailPoet\Util\DataInconsistency;
use MailPoet\UnexpectedValueException;
class DataInconsistencyController {
const ORPHANED_SENDING_TASKS = 'orphaned_sending_tasks';
const SUPPORTED_INCONSISTENCY_CHECKS = [
self::ORPHANED_SENDING_TASKS,
];
private DataInconsistencyRepository $repository;
public function __construct(
DataInconsistencyRepository $repository
) {
$this->repository = $repository;
}
public function getInconsistentDataStatus(): array {
$result = [
self::ORPHANED_SENDING_TASKS => $this->repository->getOrphanedSendingTasksCount(),
];
$result['total'] = array_sum($result);
return $result;
}
public function fixInconsistentData(string $inconsistency): void {
if (!in_array($inconsistency, self::SUPPORTED_INCONSISTENCY_CHECKS, true)) {
throw new UnexpectedValueException(__('Unsupported data inconsistency check.', 'mailpoet'));
}
if ($inconsistency === self::ORPHANED_SENDING_TASKS) {
$this->repository->cleanupOrphanedSendingTasks();
return;
}
}
}