Shorten automation table names
[MAILPOET-4465]
This commit is contained in:
@ -14,11 +14,13 @@ class Migrator {
|
|||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
$this->prefix = $wpdb->prefix . 'mailpoet_automation_';
|
$this->prefix = $wpdb->prefix . 'mailpoet_';
|
||||||
$this->wpdb = $wpdb;
|
$this->wpdb = $wpdb;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createSchema(): void {
|
public function createSchema(): void {
|
||||||
|
$this->removeOldSchema();
|
||||||
|
|
||||||
$this->runQuery("
|
$this->runQuery("
|
||||||
CREATE TABLE {$this->prefix}workflows (
|
CREATE TABLE {$this->prefix}workflows (
|
||||||
id int(11) unsigned NOT NULL AUTO_INCREMENT,
|
id int(11) unsigned NOT NULL AUTO_INCREMENT,
|
||||||
@ -48,6 +50,7 @@ class Migrator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function deleteSchema(): void {
|
public function deleteSchema(): void {
|
||||||
|
$this->removeOldSchema();
|
||||||
$this->runQuery("DROP TABLE IF EXISTS {$this->prefix}workflows");
|
$this->runQuery("DROP TABLE IF EXISTS {$this->prefix}workflows");
|
||||||
$this->runQuery("DROP TABLE IF EXISTS {$this->prefix}workflow_runs");
|
$this->runQuery("DROP TABLE IF EXISTS {$this->prefix}workflow_runs");
|
||||||
|
|
||||||
@ -67,10 +70,16 @@ class Migrator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function hasSchema(): bool {
|
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;
|
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 {
|
private function runQuery(string $query): int {
|
||||||
$this->wpdb->hide_errors();
|
$this->wpdb->hide_errors();
|
||||||
// It's a private method and all Queries in this class are safe
|
// It's a private method and all Queries in this class are safe
|
||||||
|
@ -22,7 +22,7 @@ class WorkflowRunStorage {
|
|||||||
SubjectLoader $subjectLoader
|
SubjectLoader $subjectLoader
|
||||||
) {
|
) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
$this->table = $wpdb->prefix . 'mailpoet_automation_workflow_runs';
|
$this->table = $wpdb->prefix . 'mailpoet_workflow_runs';
|
||||||
$this->wpdb = $wpdb;
|
$this->wpdb = $wpdb;
|
||||||
$this->subjectLoader = $subjectLoader;
|
$this->subjectLoader = $subjectLoader;
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ class WorkflowStorage {
|
|||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
$this->table = $wpdb->prefix . 'mailpoet_automation_workflows';
|
$this->table = $wpdb->prefix . 'mailpoet_workflows';
|
||||||
$this->wpdb = $wpdb;
|
$this->wpdb = $wpdb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user