From b9ecac91d49b929a1bd623bb39d74ba73113f96b Mon Sep 17 00:00:00 2001 From: David Remer Date: Thu, 7 Sep 2023 10:03:26 +0300 Subject: [PATCH] Query all runs when no status has been added [MAILPOET-5514] --- .../Engine/Storage/AutomationRunStorage.php | 11 +++++++++-- mailpoet/tasks/phpstan/phpstan.neon | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/mailpoet/lib/Automation/Engine/Storage/AutomationRunStorage.php b/mailpoet/lib/Automation/Engine/Storage/AutomationRunStorage.php index 4bded8ca09..b7185b2603 100644 --- a/mailpoet/lib/Automation/Engine/Storage/AutomationRunStorage.php +++ b/mailpoet/lib/Automation/Engine/Storage/AutomationRunStorage.php @@ -134,11 +134,18 @@ class AutomationRunStorage { } public function getCountForAutomation(Automation $automation, string ...$status): int { + $table = esc_sql($this->table); + if (!count($status)) { - return 0; + $query = (string)$this->wpdb->prepare(" + SELECT COUNT(id) as count + FROM $table + WHERE automation_id = %d + ", $automation->getId()); + $result = $this->wpdb->get_col($query); + return $result ? (int)current($result) : 0; } - $table = esc_sql($this->table); $statusSql = (string)$this->wpdb->prepare(implode(',', array_fill(0, count($status), '%s')), ...$status); $query = (string)$this->wpdb->prepare(" SELECT COUNT(id) as count diff --git a/mailpoet/tasks/phpstan/phpstan.neon b/mailpoet/tasks/phpstan/phpstan.neon index fb3c18d23c..b1f330baef 100644 --- a/mailpoet/tasks/phpstan/phpstan.neon +++ b/mailpoet/tasks/phpstan/phpstan.neon @@ -44,7 +44,7 @@ parameters: - '/Call to method getName\(\) on an unknown class _generated\\([a-zA-Z])*Cookie/' # codeception generate incorrect return type in ../../tests/_support/_generated - message: "#^Cannot cast string|void to string\\.$#" - count: 10 + count: 11 path: ../../lib/Automation/Engine/Storage/AutomationRunStorage.php - message: "#^Cannot cast string|void to string\\.$#"