diff --git a/mailpoet/lib/Automation/Engine/Data/Subject.php b/mailpoet/lib/Automation/Engine/Data/Subject.php index d327d5377f..77256d1328 100644 --- a/mailpoet/lib/Automation/Engine/Data/Subject.php +++ b/mailpoet/lib/Automation/Engine/Data/Subject.php @@ -27,10 +27,15 @@ class Subject { return $this->args; } + public function hash(): string { + return md5($this->getKey() . Json::encode($this->getArgs())); + } + public function toArray(): array { return [ 'key' => $this->getKey(), 'args' => Json::encode($this->getArgs()), + 'hash' => $this->hash(), ]; } diff --git a/mailpoet/lib/Automation/Engine/Storage/AutomationRunStorage.php b/mailpoet/lib/Automation/Engine/Storage/AutomationRunStorage.php index bc7f5b4f45..f2323e6931 100644 --- a/mailpoet/lib/Automation/Engine/Storage/AutomationRunStorage.php +++ b/mailpoet/lib/Automation/Engine/Storage/AutomationRunStorage.php @@ -39,10 +39,10 @@ class AutomationRunStorage { return $automationRunId; } - $sql = 'insert into ' . esc_sql($this->subjectTable) . ' (`automation_run_id`, `key`, `args`) values %s'; + $sql = 'insert into ' . esc_sql($this->subjectTable) . ' (`automation_run_id`, `key`, `args`, `hash`) values %s'; $values = []; foreach ($subjectTableData as $entry) { - $values[] = (string)$this->wpdb->prepare("(%d,%s,%s)", $automationRunId, $entry['key'], $entry['args']); + $values[] = (string)$this->wpdb->prepare("(%d,%s,%s,%s)", $automationRunId, $entry['key'], $entry['args'], $entry['hash']); } $sql = sprintf($sql, implode(',', $values)); $result = $this->wpdb->query($sql); diff --git a/mailpoet/lib/Migrations/Migration_20230215_050813.php b/mailpoet/lib/Migrations/Migration_20230215_050813.php index 5d69ec7f1c..caff1a1681 100644 --- a/mailpoet/lib/Migrations/Migration_20230215_050813.php +++ b/mailpoet/lib/Migrations/Migration_20230215_050813.php @@ -25,7 +25,9 @@ class Migration_20230215_050813 extends Migration { '`automation_run_id` int(11) unsigned NOT NULL', '`key` varchar(191)', '`args` longtext', + '`hash` varchar(191)', 'index (automation_run_id)', + 'index (hash)', ]); $this->moveSubjectData(); $this->dropSubjectColumn();