mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-12-26 00:23:33 +03:00
Corrections in the migration classes (update secure, defensive checks, #438).
This commit is contained in:
parent
6fe70d0723
commit
6df2389287
9 changed files with 165 additions and 28 deletions
|
@ -15,12 +15,21 @@ class Migration_Add_google_analytics_setting extends CI_Migration {
|
|||
public function up()
|
||||
{
|
||||
$this->load->model('settings_model');
|
||||
$this->settings_model->set_setting('google_analytics_code', '');
|
||||
|
||||
try
|
||||
{
|
||||
$this->settings_model->get_setting('google_analytics_code');
|
||||
}
|
||||
catch (Exception $exception)
|
||||
{
|
||||
$this->settings_model->set_setting('google_analytics_code', '');
|
||||
}
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
$this->load->model('settings_model');
|
||||
|
||||
$this->settings_model->remove_setting('google_analytics_code');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,12 +15,21 @@ class Migration_Add_customer_notifications_setting extends CI_Migration {
|
|||
public function up()
|
||||
{
|
||||
$this->load->model('settings_model');
|
||||
$this->settings_model->set_setting('customer_notifications', '1');
|
||||
|
||||
try
|
||||
{
|
||||
$this->settings_model->get_setting('customer_notifications');
|
||||
}
|
||||
catch (Exception $exception)
|
||||
{
|
||||
$this->settings_model->set_setting('customer_notifications', '1');
|
||||
}
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
$this->load->model('settings_model');
|
||||
|
||||
$this->settings_model->remove_setting('customer_notifications');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,12 +15,21 @@ class Migration_Add_date_format_setting extends CI_Migration {
|
|||
public function up()
|
||||
{
|
||||
$this->load->model('settings_model');
|
||||
$this->settings_model->set_setting('date_format', DATE_FORMAT_DMY);
|
||||
|
||||
try
|
||||
{
|
||||
$this->settings_model->get_setting('date_format');
|
||||
}
|
||||
catch (Exception $exception)
|
||||
{
|
||||
$this->settings_model->set_setting('date_format', DATE_FORMAT_DMY);
|
||||
}
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
$this->load->model('settings_model');
|
||||
|
||||
$this->settings_model->remove_setting('date_format');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,12 +15,21 @@ class Migration_Add_require_captcha_setting extends CI_Migration {
|
|||
public function up()
|
||||
{
|
||||
$this->load->model('settings_model');
|
||||
$this->settings_model->set_setting('require_captcha', '1');
|
||||
|
||||
try
|
||||
{
|
||||
$this->settings_model->get_setting('require_captcha');
|
||||
}
|
||||
catch (Exception $exception)
|
||||
{
|
||||
$this->settings_model->set_setting('require_captcha', '1');
|
||||
}
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
$this->load->model('settings_model');
|
||||
|
||||
$this->settings_model->remove_setting('require_captcha');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,11 +14,8 @@
|
|||
class Migration_Add_calendar_view_setting extends CI_Migration {
|
||||
public function up()
|
||||
{
|
||||
$this->load->dbforge();
|
||||
|
||||
$fields = $this->db->list_fields('ea_user_settings');
|
||||
|
||||
if (!in_array('calendar_view', $fields, true)) {
|
||||
if ( ! $this->db->field_exists('calendar_view', 'ea_user_settings'))
|
||||
{
|
||||
$fields = [
|
||||
'calendar_view' => [
|
||||
'type' => 'VARCHAR',
|
||||
|
@ -26,16 +23,18 @@ class Migration_Add_calendar_view_setting extends CI_Migration {
|
|||
'default' => 'default'
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
$this->dbforge->add_column('ea_user_settings', $fields);
|
||||
|
||||
|
||||
$this->db->update('ea_user_settings', ['calendar_view' => 'default']);
|
||||
}
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
$this->load->dbforge();
|
||||
$this->dbforge->drop_column('ea_user_settings', 'calendar_view');
|
||||
if ($this->db->field_exists('calendar_view', 'ea_user_settings'))
|
||||
{
|
||||
$this->dbforge->drop_column('ea_user_settings', 'calendar_view_calendar');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,8 @@
|
|||
class Migration_Add_service_availabilities_type extends CI_Migration {
|
||||
public function up()
|
||||
{
|
||||
if (!$this->db->field_exists('availabilities_type', 'ea_services')) {
|
||||
if ( ! $this->db->field_exists('availabilities_type', 'ea_services'))
|
||||
{
|
||||
$fields = [
|
||||
'availabilities_type' => [
|
||||
'type' => 'VARCHAR',
|
||||
|
@ -23,16 +24,17 @@ class Migration_Add_service_availabilities_type extends CI_Migration {
|
|||
'after' => 'description'
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
$this->dbforge->add_column('ea_services', $fields);
|
||||
|
||||
|
||||
$this->db->update('ea_services', ['availabilities_type' => 'flexible']);
|
||||
}
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
if ($this->db->field_exists('availabilities_type', 'ea_services')) {
|
||||
if ($this->db->field_exists('availabilities_type', 'ea_services'))
|
||||
{
|
||||
$this->dbforge->drop_column('ea_services', 'availabilities_type');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,8 @@
|
|||
class Migration_Add_service_attendants_number extends CI_Migration {
|
||||
public function up()
|
||||
{
|
||||
if (!$this->db->field_exists('attendants_number', 'ea_services')) {
|
||||
if ( ! $this->db->field_exists('attendants_number', 'ea_services'))
|
||||
{
|
||||
$fields = [
|
||||
'attendants_number' => [
|
||||
'type' => 'INT',
|
||||
|
@ -23,16 +24,17 @@ class Migration_Add_service_attendants_number extends CI_Migration {
|
|||
'after' => 'availabilities_type'
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
$this->dbforge->add_column('ea_services', $fields);
|
||||
|
||||
|
||||
$this->db->update('ea_services', ['attendants_number' => '1']);
|
||||
}
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
if (!$this->db->field_exists('attendants_number', 'ea_services')) {
|
||||
if ($this->db->field_exists('attendants_number', 'ea_services'))
|
||||
{
|
||||
$this->dbforge->drop_column('ea_services', 'attendants_number');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,18 @@
|
|||
class Migration_Change_column_types extends CI_Migration {
|
||||
public function up()
|
||||
{
|
||||
// Drop table constraints.
|
||||
$this->db->query('ALTER TABLE ea_appointments DROP FOREIGN KEY ea_appointments_ibfk_2');
|
||||
$this->db->query('ALTER TABLE ea_appointments DROP FOREIGN KEY ea_appointments_ibfk_3');
|
||||
$this->db->query('ALTER TABLE ea_appointments DROP FOREIGN KEY ea_appointments_ibfk_4');
|
||||
$this->db->query('ALTER TABLE ea_secretaries_providers DROP FOREIGN KEY fk_ea_secretaries_providers_1');
|
||||
$this->db->query('ALTER TABLE ea_secretaries_providers DROP FOREIGN KEY fk_ea_secretaries_providers_2');
|
||||
$this->db->query('ALTER TABLE ea_services_providers DROP FOREIGN KEY ea_services_providers_ibfk_1');
|
||||
$this->db->query('ALTER TABLE ea_services_providers DROP FOREIGN KEY ea_services_providers_ibfk_2');
|
||||
$this->db->query('ALTER TABLE ea_services DROP FOREIGN KEY ea_services_ibfk_1');
|
||||
$this->db->query('ALTER TABLE ea_users DROP FOREIGN KEY ea_users_ibfk_1');
|
||||
$this->db->query('ALTER TABLE ea_user_settings DROP FOREIGN KEY ea_user_settings_ibfk_1');
|
||||
|
||||
// Appointments
|
||||
$fields = [
|
||||
'id' => [
|
||||
|
@ -97,7 +109,7 @@ class Migration_Change_column_types extends CI_Migration {
|
|||
]
|
||||
];
|
||||
|
||||
$this->dbforge->modify_column('ea_roles', $fields);
|
||||
$this->dbforge->modify_column('ea_secretaries_providers', $fields);
|
||||
|
||||
// Services
|
||||
$fields = [
|
||||
|
@ -165,7 +177,7 @@ class Migration_Change_column_types extends CI_Migration {
|
|||
'auto_increment' => TRUE
|
||||
],
|
||||
'id_roles' => [
|
||||
'name' => 'id',
|
||||
'name' => 'id_roles',
|
||||
'type' => 'int',
|
||||
'constraint' => '11'
|
||||
]
|
||||
|
@ -183,10 +195,65 @@ class Migration_Change_column_types extends CI_Migration {
|
|||
];
|
||||
|
||||
$this->dbforge->modify_column('ea_user_settings', $fields);
|
||||
|
||||
// Add table constraints again.
|
||||
$this->db->query('ALTER TABLE `ea_appointments`
|
||||
ADD CONSTRAINT `ea_appointments_ea_users_customer` FOREIGN KEY (`id_users_customer`) REFERENCES `ea_users` (`id`)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE,
|
||||
ADD CONSTRAINT `ea_appointments_ea_services` FOREIGN KEY (`id_services`) REFERENCES `ea_services` (`id`)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE,
|
||||
ADD CONSTRAINT `ea_appointments_ea_users_provider` FOREIGN KEY (`id_users_provider`) REFERENCES `ea_users` (`id`)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE');
|
||||
|
||||
$this->db->query('ALTER TABLE `ea_secretaries_providers`
|
||||
ADD CONSTRAINT `ea_secretaries_ea_users_secretary` FOREIGN KEY (`id_users_secretary`) REFERENCES `ea_users` (`id`)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE,
|
||||
ADD CONSTRAINT `ea_secretaries_ea_users_provider` FOREIGN KEY (`id_users_provider`) REFERENCES `ea_users` (`id`)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE');
|
||||
|
||||
$this->db->query('ALTER TABLE `ea_services`
|
||||
ADD CONSTRAINT `ea_services_ea_service_categories` FOREIGN KEY (`id_service_categories`) REFERENCES `ea_service_categories` (`id`)
|
||||
ON DELETE SET NULL
|
||||
ON UPDATE CASCADE');
|
||||
|
||||
$this->db->query('ALTER TABLE `ea_services_providers`
|
||||
ADD CONSTRAINT `ea_services_providers_ea_users_provider` FOREIGN KEY (`id_users`) REFERENCES `ea_users` (`id`)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE,
|
||||
ADD CONSTRAINT `ea_services_providers_ea_services` FOREIGN KEY (`id_services`) REFERENCES `ea_services` (`id`)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE');
|
||||
|
||||
$this->db->query('ALTER TABLE `ea_users`
|
||||
ADD CONSTRAINT `ea_users_ea_roles` FOREIGN KEY (`id_roles`) REFERENCES `ea_roles` (`id`)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE');
|
||||
|
||||
$this->db->query('ALTER TABLE `ea_user_settings`
|
||||
ADD CONSTRAINT `ea_user_settings_ea_users` FOREIGN KEY (`id_users`) REFERENCES `ea_users` (`id`)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE');
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
// Drop table constraints.
|
||||
$this->db->query('ALTER TABLE ea_appointments DROP FOREIGN KEY ea_appointments_ea_services');
|
||||
$this->db->query('ALTER TABLE ea_appointments DROP FOREIGN KEY ea_appointments_ea_users_customer');
|
||||
$this->db->query('ALTER TABLE ea_appointments DROP FOREIGN KEY ea_appointments_ea_users_provider');
|
||||
$this->db->query('ALTER TABLE ea_secretaries_providers DROP FOREIGN KEY ea_secretaries_ea_users_secretary');
|
||||
$this->db->query('ALTER TABLE ea_secretaries_providers DROP FOREIGN KEY ea_secretaries_ea_users_provider');
|
||||
$this->db->query('ALTER TABLE ea_services_providers DROP FOREIGN KEY ea_services_providers_ea_users_provider');
|
||||
$this->db->query('ALTER TABLE ea_services_providers DROP FOREIGN KEY ea_services_providers_ea_services');
|
||||
$this->db->query('ALTER TABLE ea_services DROP FOREIGN KEY ea_services_ea_service_categories');
|
||||
$this->db->query('ALTER TABLE ea_users DROP FOREIGN KEY ea_users_ea_roles');
|
||||
$this->db->query('ALTER TABLE ea_user_settings DROP FOREIGN KEY ea_user_settings_ea_users');
|
||||
|
||||
// Appointments
|
||||
$fields = [
|
||||
'id' => [
|
||||
|
@ -356,5 +423,28 @@ class Migration_Change_column_types extends CI_Migration {
|
|||
];
|
||||
|
||||
$this->dbforge->modify_column('ea_user_settings', $fields);
|
||||
|
||||
// Add database constraints.
|
||||
$this->db->query('ALTER TABLE `ea_appointments`
|
||||
ADD CONSTRAINT `ea_appointments_ibfk_2` FOREIGN KEY (`id_users_customer`) REFERENCES `ea_users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
ADD CONSTRAINT `ea_appointments_ibfk_3` FOREIGN KEY (`id_services`) REFERENCES `ea_services` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
ADD CONSTRAINT `ea_appointments_ibfk_4` FOREIGN KEY (`id_users_provider`) REFERENCES `ea_users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE');
|
||||
|
||||
$this->db->query('ALTER TABLE `ea_secretaries_providers`
|
||||
ADD CONSTRAINT `fk_ea_secretaries_providers_1` FOREIGN KEY (`id_users_secretary`) REFERENCES `ea_users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
ADD CONSTRAINT `fk_ea_secretaries_providers_2` FOREIGN KEY (`id_users_provider`) REFERENCES `ea_users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE');
|
||||
|
||||
$this->db->query('ALTER TABLE `ea_services`
|
||||
ADD CONSTRAINT `ea_services_ibfk_1` FOREIGN KEY (`id_service_categories`) REFERENCES `ea_service_categories` (`id`) ON DELETE SET NULL ON UPDATE CASCADE');
|
||||
|
||||
$this->db->query('ALTER TABLE `ea_services_providers`
|
||||
ADD CONSTRAINT `ea_services_providers_ibfk_1` FOREIGN KEY (`id_users`) REFERENCES `ea_users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
ADD CONSTRAINT `ea_services_providers_ibfk_2` FOREIGN KEY (`id_services`) REFERENCES `ea_services` (`id`) ON DELETE CASCADE ON UPDATE CASCADE');
|
||||
|
||||
$this->db->query('ALTER TABLE `ea_users`
|
||||
ADD CONSTRAINT `ea_users_ibfk_1` FOREIGN KEY (`id_roles`) REFERENCES `ea_roles` (`id`) ON DELETE CASCADE ON UPDATE CASCADE');
|
||||
|
||||
$this->db->query('ALTER TABLE `ea_user_settings`
|
||||
ADD CONSTRAINT `ea_user_settings_ibfk_1` FOREIGN KEY (`id_users`) REFERENCES `ea_users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,14 +14,22 @@
|
|||
class Migration_Add_time_format_setting extends CI_Migration {
|
||||
public function up()
|
||||
{
|
||||
$this->db->insert('ea_settings', [
|
||||
'name' => 'time_format',
|
||||
'value' => 'regular'
|
||||
]);
|
||||
$this->load->model('settings_model');
|
||||
|
||||
try
|
||||
{
|
||||
$this->settings_model->get_setting('time_format');
|
||||
}
|
||||
catch (Exception $exception)
|
||||
{
|
||||
$this->settings_model->set_setting('time_format', 'regular');
|
||||
}
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
$this->db->delete('ea_settings', ['name' => 'time_format']);
|
||||
$this->load->model('settings_model');
|
||||
|
||||
$this->settings_model->remove_setting('time_format');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue