Interrupt automation run creation if a run already exists and only_once setting is set
[MAILPOET-4966]
This commit is contained in:
@@ -4,6 +4,7 @@ namespace MailPoet\Automation\Engine\Storage;
|
||||
|
||||
use MailPoet\Automation\Engine\Data\Automation;
|
||||
use MailPoet\Automation\Engine\Data\AutomationRun;
|
||||
use MailPoet\Automation\Engine\Data\Subject;
|
||||
use MailPoet\Automation\Engine\Exceptions;
|
||||
use wpdb;
|
||||
|
||||
@@ -108,6 +109,26 @@ class AutomationRunStorage {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Automation $automation
|
||||
* @return int
|
||||
*/
|
||||
public function countRunsForAutomationAndSubject(Automation $automation, Subject $subject): int {
|
||||
$table = esc_sql($this->table);
|
||||
$subjectTable = esc_sql($this->subjectTable);
|
||||
|
||||
$sql = "SELECT count(runs.id) as count from $table as runs
|
||||
JOIN $subjectTable as subjects on runs.id = subjects.automation_run_id
|
||||
WHERE runs.automation_id = %d
|
||||
AND subjects.hash = %s";
|
||||
|
||||
$result = $this->wpdb->get_col(
|
||||
(string)$this->wpdb->prepare($sql, $automation->getId(), $subject->hash())
|
||||
);
|
||||
|
||||
return $result ? (int)current($result) : 0;
|
||||
}
|
||||
|
||||
public function getCountForAutomation(Automation $automation, string ...$status): int {
|
||||
if (!count($status)) {
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user