From 29423647b65afb9f7c5bcca459fc35974a0c9420 Mon Sep 17 00:00:00 2001 From: Alex Tselegidis Date: Mon, 20 Dec 2021 08:07:57 +0100 Subject: [PATCH] Added migration for displayed/required booking fields --- .../022_add_booking_field_settings.php | 106 ++++++++++++++++++ .../022_add_show_field_settings.php | 57 ---------- 2 files changed, 106 insertions(+), 57 deletions(-) create mode 100644 application/migrations/022_add_booking_field_settings.php delete mode 100644 application/migrations/022_add_show_field_settings.php diff --git a/application/migrations/022_add_booking_field_settings.php b/application/migrations/022_add_booking_field_settings.php new file mode 100644 index 00000000..b47ecea0 --- /dev/null +++ b/application/migrations/022_add_booking_field_settings.php @@ -0,0 +1,106 @@ + + * @copyright Copyright (c) Alex Tselegidis + * @license https://opensource.org/licenses/GPL-3.0 - GPLv3 + * @link https://easyappointments.org + * @since v1.5.0 + * ---------------------------------------------------------------------------- */ + +class Migration_Add_booking_field_settings extends EA_Migration { + /** + * @var array + */ + private $fields = [ + 'first_name' => [ + 'display' => '1', + 'require' => '1', + ], + 'last_name' => [ + 'display' => '1', + 'require' => '1', + ], + 'email' => [ + 'display' => '1', + 'require' => '1', + ], + 'phone_number' => [ + 'display' => '1', + 'require' => '1', + ], + 'address' => [ + 'display' => '1', + 'require' => '0', + ], + 'city' => [ + 'display' => '1', + 'require' => '0', + ], + 'zip_code' => [ + 'display' => '1', + 'require' => '0', + ], + 'notes' => [ + 'display' => '1', + 'require' => '0', + ], + ]; + + /** + * Upgrade method. + */ + public function up() + { + foreach ($this->fields as $field => $props) + { + foreach ($props as $prop => $value) + { + $setting_name = $prop . '_' . $field; + + if ($this->db->get_where('settings', ['name' => $setting_name])->num_rows()) + { + $setting = $this->db->get_where('settings', [ + 'name' => $setting_name, + ])->row_array(); + + $value = $setting['value']; // Use existing value. + + $this->db->delete('settings', ['name' => $setting_name]); + } + + if ( ! $this->db->get_where('settings', ['name' => $setting_name])->num_rows()) + { + $this->db->insert('settings', [ + 'name' => $setting_name, + 'value' => $value + ]); + } + } + } + } + + /** + * Downgrade method. + */ + public function down() + { + foreach ($this->fields as $field => $props) + { + foreach ($props as $prop => $value) + { + $setting_name = $prop . '_' . $field; + + if ($this->db->get_where('settings', ['name' => $setting_name])->num_rows()) + { + $this->db->delete('settings', [ + 'name' => $setting_name, + ]); + } + } + } + } +} diff --git a/application/migrations/022_add_show_field_settings.php b/application/migrations/022_add_show_field_settings.php deleted file mode 100644 index c58d22fb..00000000 --- a/application/migrations/022_add_show_field_settings.php +++ /dev/null @@ -1,57 +0,0 @@ - - * @copyright Copyright (c) Alex Tselegidis - * @license https://opensource.org/licenses/GPL-3.0 - GPLv3 - * @link https://easyappointments.org - * @since v1.5.0 - * ---------------------------------------------------------------------------- */ - -class Migration_Add_show_field_settings extends EA_Migration { - /** - * Upgrade method. - */ - public function up() - { - $this->db->insert('settings', [ - 'name' => 'show_phone_number', - 'value' => '1' - ]); - - $this->db->insert('settings', [ - 'name' => 'show_address', - 'value' => '1' - ]); - - $this->db->insert('settings', [ - 'name' => 'show_city', - 'value' => '1' - ]); - - $this->db->insert('settings', [ - 'name' => 'show_zip_code', - 'value' => '1' - ]); - - $this->db->insert('settings', [ - 'name' => 'show_notes', - 'value' => '1' - ]); - } - - /** - * Downgrade method. - */ - public function down() - { - $this->db->delete('settings', ['name' => 'show_phone_number']); - $this->db->delete('settings', ['name' => 'show_address']); - $this->db->delete('settings', ['name' => 'show_city']); - $this->db->delete('settings', ['name' => 'show_zip_code']); - $this->db->delete('settings', ['name' => 'show_notes']); - } -}