diff --git a/mailpoet/lib/Automation/Engine/Migrations/Migrator.php b/mailpoet/lib/Automation/Engine/Migrations/Migrator.php index ef20010fd0..9728c74c83 100644 --- a/mailpoet/lib/Automation/Engine/Migrations/Migrator.php +++ b/mailpoet/lib/Automation/Engine/Migrations/Migrator.php @@ -14,11 +14,13 @@ class Migrator { public function __construct() { global $wpdb; - $this->prefix = $wpdb->prefix . 'mailpoet_automation_'; + $this->prefix = $wpdb->prefix . 'mailpoet_'; $this->wpdb = $wpdb; } public function createSchema(): void { + $this->removeOldSchema(); + $this->runQuery(" CREATE TABLE {$this->prefix}workflows ( id int(11) unsigned NOT NULL AUTO_INCREMENT, @@ -48,6 +50,7 @@ class Migrator { } public function deleteSchema(): void { + $this->removeOldSchema(); $this->runQuery("DROP TABLE IF EXISTS {$this->prefix}workflows"); $this->runQuery("DROP TABLE IF EXISTS {$this->prefix}workflow_runs"); @@ -67,10 +70,16 @@ class Migrator { } public function hasSchema(): bool { - $pattern = $this->wpdb->esc_like($this->prefix) . '%'; + $pattern = $this->wpdb->esc_like("{$this->prefix}workflows") . '%'; return $this->runQuery("SHOW TABLES LIKE '$pattern'") > 0; } + private function removeOldSchema(): void { + $oldPrefix = $this->wpdb->prefix . 'mailpoet_automation_'; + $this->runQuery("DROP TABLE IF EXISTS {$oldPrefix}workflows"); + $this->runQuery("DROP TABLE IF EXISTS {$oldPrefix}workflow_runs"); + } + private function runQuery(string $query): int { $this->wpdb->hide_errors(); // It's a private method and all Queries in this class are safe diff --git a/mailpoet/lib/Automation/Engine/Storage/WorkflowRunStorage.php b/mailpoet/lib/Automation/Engine/Storage/WorkflowRunStorage.php index 082285f226..ba23372273 100644 --- a/mailpoet/lib/Automation/Engine/Storage/WorkflowRunStorage.php +++ b/mailpoet/lib/Automation/Engine/Storage/WorkflowRunStorage.php @@ -22,7 +22,7 @@ class WorkflowRunStorage { SubjectLoader $subjectLoader ) { global $wpdb; - $this->table = $wpdb->prefix . 'mailpoet_automation_workflow_runs'; + $this->table = $wpdb->prefix . 'mailpoet_workflow_runs'; $this->wpdb = $wpdb; $this->subjectLoader = $subjectLoader; } diff --git a/mailpoet/lib/Automation/Engine/Storage/WorkflowStorage.php b/mailpoet/lib/Automation/Engine/Storage/WorkflowStorage.php index fa00bb01eb..2f0863c523 100644 --- a/mailpoet/lib/Automation/Engine/Storage/WorkflowStorage.php +++ b/mailpoet/lib/Automation/Engine/Storage/WorkflowStorage.php @@ -17,7 +17,7 @@ class WorkflowStorage { public function __construct() { global $wpdb; - $this->table = $wpdb->prefix . 'mailpoet_automation_workflows'; + $this->table = $wpdb->prefix . 'mailpoet_workflows'; $this->wpdb = $wpdb; }