Add API for fixing inconsistent data

[MAILPOET-1587]
This commit is contained in:
Rostislav Wolny
2024-08-01 10:11:48 +02:00
committed by Aschepikov
parent b68e6b7639
commit cb5f533e54
3 changed files with 52 additions and 11 deletions

View File

@@ -2,8 +2,14 @@
namespace MailPoet\Util\DataInconsistency;
use MailPoet\UnexpectedValueException;
class DataInconsistencyController {
const ORPHANED_TASKS = 'orphaned_tasks';
const ORPHANED_SENDING_TASKS = 'orphaned_sending_tasks';
const SUPPORTED_INCONSISTENCY_CHECKS = [
self::ORPHANED_SENDING_TASKS,
];
private DataInconsistencyRepository $repository;
@@ -15,9 +21,19 @@ class DataInconsistencyController {
public function getInconsistentDataStatus(): array {
$result = [
self::ORPHANED_TASKS => $this->repository->getOrphanedSendingTasksCount(),
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;
}
}
}