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']); - } -}