diff --git a/lib/Config/Migrator.php b/lib/Config/Migrator.php index c64857a4cd..94698dc66c 100644 --- a/lib/Config/Migrator.php +++ b/lib/Config/Migrator.php @@ -282,6 +282,7 @@ class Migrator { 'updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,', 'deleted_at timestamp NULL,', 'unsubscribe_token char(15) NULL,', + 'ga_campaign varchar(250) NOT NULL DEFAULT "",', 'PRIMARY KEY (id),', 'UNIQUE KEY unsubscribe_token (unsubscribe_token),', 'KEY type_status (type,status)', diff --git a/lib/Config/Populator.php b/lib/Config/Populator.php index ba526485cc..1ea1cdf26b 100644 --- a/lib/Config/Populator.php +++ b/lib/Config/Populator.php @@ -176,6 +176,7 @@ class Populator { $this->detectReferral(); $this->updateFormsSuccessMessages(); $this->initWooCommerceTransactionalEmails(); + $this->moveGoogleAnalyticsFromPremium(); } private function createMailPoetPage() { @@ -692,6 +693,37 @@ class Populator { $this->settings->set(Worker::SETTINGS_KEY, $settings); } + private function moveGoogleAnalyticsFromPremium() { + global $wpdb; + if (version_compare($this->settings->get('db_version', '3.38.2'), '3.38.1', '>')) { + return; + } + $premium_table_name = $wpdb->prefix . 'mailpoet_premium_newsletter_extra_data'; + $premium_table_exists = (int)$wpdb->get_var( + $wpdb->prepare( + "SELECT COUNT(1) FROM information_schema.tables WHERE table_schema=%s AND table_name=%s;", + $wpdb->dbname, + $premium_table_name + ) + ); + if ($premium_table_exists) { + $query = " + UPDATE + `%s` as n + JOIN %s as ped ON n.id=ped.newsletter_id + SET n.ga_campaign = ped.ga_campaign + "; + $wpdb->query( + sprintf( + $query, + Newsletter::$_table, + $premium_table_name + ) + ); + } + return true; + } + private function detectReferral() { $this->referralDetector->detect(); }