From 66106fcd18426c66b89b12c7eedd1beae84c58ea Mon Sep 17 00:00:00 2001 From: Alex Tselegidis Date: Fri, 20 May 2022 18:27:57 +0200 Subject: [PATCH] Perform setting related migration improvements --- .../002_add_google_analytics_setting.php | 16 +++++++++++----- .../003_add_customer_notifications_setting.php | 16 +++++++++++----- .../migrations/004_add_date_format_setting.php | 16 +++++++++++----- .../005_add_require_captcha_setting.php | 16 +++++++++++----- 4 files changed, 44 insertions(+), 20 deletions(-) diff --git a/application/migrations/002_add_google_analytics_setting.php b/application/migrations/002_add_google_analytics_setting.php index e8f69b97..8cc462cb 100644 --- a/application/migrations/002_add_google_analytics_setting.php +++ b/application/migrations/002_add_google_analytics_setting.php @@ -19,10 +19,13 @@ class Migration_Add_google_analytics_setting extends EA_Migration { */ public function up() { - $this->db->insert('settings', [ - 'name' => 'google_analytics_code', - 'value' => '' - ]); + if ( ! $this->db->get_where('settings', ['name' => 'google_analytics_code'])->num_rows()) + { + $this->db->insert('settings', [ + 'name' => 'google_analytics_code', + 'value' => '' + ]); + } } /** @@ -32,6 +35,9 @@ class Migration_Add_google_analytics_setting extends EA_Migration { */ public function down() { - $this->db->delete('settings', ['name' => 'google_analytics_code']); + if ($this->db->get_where('settings', ['name' => 'google_analytics_code'])->num_rows()) + { + $this->db->delete('settings', ['name' => 'google_analytics_code']); + } } } diff --git a/application/migrations/003_add_customer_notifications_setting.php b/application/migrations/003_add_customer_notifications_setting.php index 729dfb98..19e2f5e1 100644 --- a/application/migrations/003_add_customer_notifications_setting.php +++ b/application/migrations/003_add_customer_notifications_setting.php @@ -19,10 +19,13 @@ class Migration_Add_customer_notifications_setting extends EA_Migration { */ public function up() { - $this->db->insert('settings', [ - 'name' => 'customer_notifications', - 'value' => '1' - ]); + if ( ! $this->db->get_where('settings', ['name' => 'customer_notifications'])->num_rows()) + { + $this->db->insert('settings', [ + 'name' => 'customer_notifications', + 'value' => '1' + ]); + } } /** @@ -32,6 +35,9 @@ class Migration_Add_customer_notifications_setting extends EA_Migration { */ public function down() { - $this->db->delete('settings', ['name' => 'customer_notifications']); + if ($this->db->get_where('settings', ['name' => 'customer_notifications'])->num_rows()) + { + $this->db->delete('settings', ['name' => 'customer_notifications']); + } } } diff --git a/application/migrations/004_add_date_format_setting.php b/application/migrations/004_add_date_format_setting.php index 04b6a606..5ac8a083 100644 --- a/application/migrations/004_add_date_format_setting.php +++ b/application/migrations/004_add_date_format_setting.php @@ -19,10 +19,13 @@ class Migration_Add_date_format_setting extends EA_Migration { */ public function up() { - $this->db->insert('settings', [ - 'name' => 'date_format', - 'value' => 'DMY' - ]); + if ( ! $this->db->get_where('settings', ['name' => 'date_format'])->num_rows()) + { + $this->db->insert('settings', [ + 'name' => 'date_format', + 'value' => 'DMY' + ]); + } } /** @@ -32,6 +35,9 @@ class Migration_Add_date_format_setting extends EA_Migration { */ public function down() { - $this->db->delete('settings', ['name' => 'date_format']); + if ($this->db->get_where('settings', ['name' => 'date_format'])->num_rows()) + { + $this->db->delete('settings', ['name' => 'date_format']); + } } } diff --git a/application/migrations/005_add_require_captcha_setting.php b/application/migrations/005_add_require_captcha_setting.php index dd98bf29..14e8e212 100644 --- a/application/migrations/005_add_require_captcha_setting.php +++ b/application/migrations/005_add_require_captcha_setting.php @@ -19,10 +19,13 @@ class Migration_Add_require_captcha_setting extends EA_Migration { */ public function up() { - $this->db->insert('settings', [ - 'name' => 'require_captcha', - 'value' => '0' - ]); + if ( ! $this->db->get_where('settings', ['name' => 'require_captcha'])->num_rows()) + { + $this->db->insert('settings', [ + 'name' => 'require_captcha', + 'value' => '0' + ]); + } } /** @@ -32,6 +35,9 @@ class Migration_Add_require_captcha_setting extends EA_Migration { */ public function down() { - $this->db->delete('settings', ['name' => 'require_captcha']); + if ($this->db->get_where('settings', ['name' => 'require_captcha'])->num_rows()) + { + $this->db->delete('settings', ['name' => 'require_captcha']); + } } }