From 63fe77215575a8d001587fe906ffcb457b9de4ca Mon Sep 17 00:00:00 2001 From: Alex Tselegidis Date: Thu, 23 Apr 2020 20:36:43 +0200 Subject: [PATCH] The installation procedure will not use the assets/sql files but execute the migrations instead. --- application/controllers/Installation.php | 57 ++++-- application/helpers/installation_helper.php | 46 ----- application/views/general/installation.php | 2 +- assets/sql/data.sql | 31 --- assets/sql/index.html | 10 - assets/sql/structure.sql | 204 -------------------- 6 files changed, 38 insertions(+), 312 deletions(-) delete mode 100644 assets/sql/data.sql delete mode 100644 assets/sql/index.html delete mode 100755 assets/sql/structure.sql diff --git a/application/controllers/Installation.php b/application/controllers/Installation.php index b6f79c69..dc77dbc2 100644 --- a/application/controllers/Installation.php +++ b/application/controllers/Installation.php @@ -25,6 +25,7 @@ * @property CI_Cache cache * @property CI_DB_query_builder db * @property CI_Security security + * @property CI_Migration migration * @property Google_Sync google_sync * @property Ics_file ics_file * @property Appointments_Model appointments_model @@ -97,27 +98,14 @@ class Installation extends CI_Controller { $this->load->model('services_model'); $this->load->model('providers_model'); $this->load->library('session'); + $this->load->library('migration'); $admin = $this->input->post('admin'); $company = $this->input->post('company'); - - // Create the Easy!Appointments database structure. - $file_contents = file_get_contents(__DIR__ . '/../../assets/sql/structure.sql'); - $sql_queries = explode(';', $file_contents); - array_pop($sql_queries); - foreach ($sql_queries as $query) + if ( ! $this->migration->current()) { - $this->db->query($query); - } - - // Insert default Easy!Appointments entries into the database. - $file_contents = file_get_contents(__DIR__ . '/../../assets/sql/data.sql'); - $sql_queries = explode(';', $file_contents); - array_pop($sql_queries); - foreach ($sql_queries as $query) - { - $this->db->query($query); + throw new Exception($this->migration->error_string()); } // Insert admin @@ -138,10 +126,39 @@ class Installation extends CI_Controller { $this->settings_model->set_setting('company_link', $company['company_link']); // Create sample records. - $sample_service = get_sample_service(); - $sample_service['id'] = $this->services_model->add($sample_service); - $sample_provider = get_sample_provider(); - $sample_provider['services'][] = $sample_service['id']; + $services = [ + 'name' => 'Test Service', + 'duration' => 30, + 'price' => 50.0, + 'currency' => 'Euro', + 'description' => 'This is a test service automatically inserted by the installer.', + 'availabilities_type' => 'flexible', + 'attendants_number' => 1, + 'id_service_categories' => NULL + ]; + $services['id'] = $this->services_model->add($services); + + $sample_provider = [ + 'first_name' => 'John', + 'last_name' => 'Doe', + 'email' => 'john@example.org', + 'phone_number' => '0123456789', + 'services' => [ + $services['id'] + ], + 'settings' => [ + 'username' => 'johndoe', + 'password' => '59fe9d073a9c3c606a7e01e402dca4b49b6aa517bd0fdf940c46cb13a7b63dd0', + 'salt' => 'dc5570debc71fc1fe94b1b0aee444fcde5b8cb83d62a6a2b736ead6557d7a2e1', + 'working_plan' => '{"monday":{"start":"09:00","end":"18:00","breaks":[{"start":"14:30","end":"15:00"}]},"tuesday":{"start":"09:00","end":"18:00","breaks":[{"start":"14:30","end":"15:00"}]},"wednesday":{"start":"09:00","end":"18:00","breaks":[{"start":"14:30","end":"15:00"}]},"thursday":{"start":"09:00","end":"18:00","breaks":[{"start":"14:30","end":"15:00"}]},"friday":{"start":"09:00","end":"18:00","breaks":[{"start":"14:30","end":"15:00"}]},"saturday":null,"sunday":null}', + 'notifications' => FALSE, + 'google_sync' => FALSE, + 'sync_past_days' => 5, + 'sync_future_days' => 5, + 'calendar_view' => CALENDAR_VIEW_DEFAULT + ] + ]; + $this->providers_model->add($sample_provider); $response = AJAX_SUCCESS; diff --git a/application/helpers/installation_helper.php b/application/helpers/installation_helper.php index 3ed27bca..63c8bcac 100644 --- a/application/helpers/installation_helper.php +++ b/application/helpers/installation_helper.php @@ -27,49 +27,3 @@ function is_ea_installed() return $framework->db->table_exists('ea_users'); } - -/** - * Get the data of a sample service. - * - * @return array - */ -function get_sample_service() -{ - return [ - 'name' => 'Test Service', - 'duration' => 30, - 'price' => 50.0, - 'currency' => 'Euro', - 'description' => 'This is a test service automatically inserted by the installer.', - 'availabilities_type' => 'flexible', - 'attendants_number' => 1, - 'id_service_categories' => NULL - ]; -} - -/** - * Get the data of a sample provider. - * - * @return array - */ -function get_sample_provider() -{ - return [ - 'first_name' => 'John', - 'last_name' => 'Doe', - 'email' => 'john@doe.com', - 'phone_number' => '0123456789', - 'services' => [], - 'settings' => [ - 'username' => 'johndoe', - 'password' => '59fe9d073a9c3c606a7e01e402dca4b49b6aa517bd0fdf940c46cb13a7b63dd0', - 'salt' => 'dc5570debc71fc1fe94b1b0aee444fcde5b8cb83d62a6a2b736ead6557d7a2e1', - 'working_plan' => '{"monday":{"start":"09:00","end":"18:00","breaks":[{"start":"14:30","end":"15:00"}]},"tuesday":{"start":"09:00","end":"18:00","breaks":[{"start":"14:30","end":"15:00"}]},"wednesday":{"start":"09:00","end":"18:00","breaks":[{"start":"14:30","end":"15:00"}]},"thursday":{"start":"09:00","end":"18:00","breaks":[{"start":"14:30","end":"15:00"}]},"friday":{"start":"09:00","end":"18:00","breaks":[{"start":"14:30","end":"15:00"}]},"saturday":null,"sunday":null}', - 'notifications' => FALSE, - 'google_sync' => FALSE, - 'sync_past_days' => 5, - 'sync_future_days' => 5, - 'calendar_view' => CALENDAR_VIEW_DEFAULT - ] - ]; -} diff --git a/application/views/general/installation.php b/application/views/general/installation.php index 9147f0dc..b3874ed2 100755 --- a/application/views/general/installation.php +++ b/application/views/general/installation.php @@ -181,8 +181,8 @@ + - diff --git a/assets/sql/data.sql b/assets/sql/data.sql deleted file mode 100644 index dd98ad2e..00000000 --- a/assets/sql/data.sql +++ /dev/null @@ -1,31 +0,0 @@ -INSERT INTO - `ea_roles` (`id`, `name`, `slug`, `is_admin`, `appointments`, `customers`, `services`, `users`, `system_settings`, `user_settings`) -VALUES - (1, 'Administrator', 'admin', 1, 15, 15, 15, 15, 15, 15), - (2, 'Provider', 'provider', 0, 15, 15, 0, 0, 0, 15), - (3, 'Customer', 'customer', 0, 0, 0, 0, 0, 0, 0), - (4, 'Secretary', 'secretary', 0, 15, 15, 0, 0, 0, 15); - -INSERT INTO - `ea_settings` (`name`, `value`) -VALUES - ('company_working_plan', - '{"sunday":{"start":"09:00","end":"18:00","breaks":[{"start":"11:20","end":"11:30"},{"start":"14:30","end":"15:00"}]},"monday":{"start":"09:00","end":"18:00","breaks":[{"start":"11:20","end":"11:30"},{"start":"14:30","end":"15:00"}]},"tuesday":{"start":"09:00","end":"18:00","breaks":[{"start":"11:20","end":"11:30"},{"start":"14:30","end":"15:00"}]},"wednesday":{"start":"09:00","end":"18:00","breaks":[{"start":"11:20","end":"11:30"},{"start":"14:30","end":"15:00"}]},"thursday":{"start":"09:00","end":"18:00","breaks":[{"start":"11:20","end":"11:30"},{"start":"14:30","end":"15:00"}]},"friday":{"start":"09:00","end":"18:00","breaks":[{"start":"11:20","end":"11:30"},{"start":"14:30","end":"15:00"}]},"saturday":{"start":"09:00","end":"18:00","breaks":[{"start":"11:20","end":"11:30"},{"start":"14:30","end":"15:00"}]}}'), - ('book_advance_timeout', '30'), - ('google_analytics_code', ''), - ('customer_notifications', '1'), - ('date_format', 'DMY'), - ('time_format', 'regular'), - ('require_captcha', '0'), - ('display_cookie_notice', '0'), - ('cookie_notice_content', 'Cookie notice content.'), - ('display_terms_and_conditions', '0'), - ('terms_and_conditions_content', 'Terms and conditions content.'), - ('display_privacy_policy', '0'), - ('privacy_policy_content', 'Privacy policy content.'), - ('first_weekday', 'sunday'), - ('require_phone_number', '1'), - ('api_token', ''), - ('display_any_provider', '1'); - -INSERT INTO `ea_migrations` VALUES ('19'); diff --git a/assets/sql/index.html b/assets/sql/index.html deleted file mode 100644 index c942a79c..00000000 --- a/assets/sql/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - - 403 Forbidden - - - -

Directory access is forbidden.

- - - \ No newline at end of file diff --git a/assets/sql/structure.sql b/assets/sql/structure.sql deleted file mode 100755 index 195d8aa8..00000000 --- a/assets/sql/structure.sql +++ /dev/null @@ -1,204 +0,0 @@ -SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; -SET time_zone = "+00:00"; - -CREATE TABLE IF NOT EXISTS `ea_appointments` ( - `id` INT(11) NOT NULL AUTO_INCREMENT, - `book_datetime` DATETIME, - `start_datetime` DATETIME, - `end_datetime` DATETIME, - `timezone` VARCHAR(256) DEFAULT 'UTC', - `location` TEXT, - `notes` TEXT, - `hash` TEXT, - `is_unavailable` TINYINT(4) DEFAULT '0', - `id_users_provider` INT(11), - `id_users_customer` INT(11), - `id_services` INT(11), - `id_google_calendar` TEXT, - PRIMARY KEY (`id`), - KEY `id_users_customer` (`id_users_customer`), - KEY `id_services` (`id_services`), - KEY `id_users_provider` (`id_users_provider`) -) - ENGINE = InnoDB - DEFAULT CHARSET = utf8; - -CREATE TABLE IF NOT EXISTS `ea_consents` ( - `id` INT(11) NOT NULL AUTO_INCREMENT, - `created` TIMESTAMP, - `modified` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP - ON UPDATE CURRENT_TIMESTAMP, - `first_name` VARCHAR(256), - `last_name` VARCHAR(256), - `email` VARCHAR(512), - `ip` VARCHAR(256), - `type` VARCHAR(256), - PRIMARY KEY (`id`) -) - ENGINE = InnoDB - DEFAULT CHARSET = utf8; - -CREATE TABLE `ea_migrations` ( - `version` INT(11) NOT NULL -) - ENGINE = InnoDB - DEFAULT CHARSET = utf8; - -CREATE TABLE IF NOT EXISTS `ea_roles` ( - `id` INT(11) NOT NULL AUTO_INCREMENT, - `name` VARCHAR(256), - `slug` VARCHAR(256), - `is_admin` TINYINT(4), - `appointments` INT(11), - `customers` INT(11), - `services` INT(11), - `users` INT(11), - `system_settings` INT(11), - `user_settings` INT(11), - PRIMARY KEY (`id`) -) - ENGINE = InnoDB - DEFAULT CHARSET = utf8; - - -CREATE TABLE IF NOT EXISTS `ea_secretaries_providers` ( - `id_users_secretary` INT(11) NOT NULL, - `id_users_provider` INT(11) NOT NULL, - PRIMARY KEY (`id_users_secretary`, `id_users_provider`), - KEY `id_users_secretary` (`id_users_secretary`), - KEY `id_users_provider` (`id_users_provider`) -) - ENGINE = InnoDB - DEFAULT CHARSET = utf8; - - -CREATE TABLE IF NOT EXISTS `ea_services` ( - `id` INT(11) NOT NULL AUTO_INCREMENT, - `name` VARCHAR(256), - `duration` INT(11), - `price` DECIMAL(10, 2), - `currency` VARCHAR(32), - `description` TEXT, - `location` TEXT, - `availabilities_type` VARCHAR(32) DEFAULT 'flexible', - `attendants_number` INT(11) DEFAULT '1', - `id_service_categories` INT(11), - PRIMARY KEY (`id`), - KEY `id_service_categories` (`id_service_categories`) -) - ENGINE = InnoDB - DEFAULT CHARSET = utf8; - - -CREATE TABLE IF NOT EXISTS `ea_services_providers` ( - `id_users` INT(11) NOT NULL, - `id_services` INT(11) NOT NULL, - PRIMARY KEY (`id_users`, `id_services`), - KEY `id_services` (`id_services`) -) - ENGINE = InnoDB - DEFAULT CHARSET = utf8; - - -CREATE TABLE IF NOT EXISTS `ea_service_categories` ( - `id` INT(11) NOT NULL AUTO_INCREMENT, - `name` VARCHAR(256), - `description` TEXT, - PRIMARY KEY (`id`) -) - ENGINE = InnoDB - DEFAULT CHARSET = utf8; - - -CREATE TABLE IF NOT EXISTS `ea_settings` ( - `id` INT(11) NOT NULL AUTO_INCREMENT, - `name` VARCHAR(512), - `value` LONGTEXT, - PRIMARY KEY (`id`) -) - ENGINE = InnoDB - DEFAULT CHARSET = utf8; - - -CREATE TABLE IF NOT EXISTS `ea_users` ( - `id` INT(11) NOT NULL AUTO_INCREMENT, - `first_name` VARCHAR(256), - `last_name` VARCHAR(512), - `email` VARCHAR(512), - `mobile_number` VARCHAR(128), - `phone_number` VARCHAR(128), - `address` VARCHAR(256), - `city` VARCHAR(256), - `state` VARCHAR(128), - `zip_code` VARCHAR(64), - `notes` TEXT, - `timezone` VARCHAR(256), - `id_roles` INT(11) NOT NULL, - PRIMARY KEY (`id`), - KEY `id_roles` (`id_roles`) -) - ENGINE = InnoDB - DEFAULT CHARSET = utf8; - - -CREATE TABLE IF NOT EXISTS `ea_user_settings` ( - `id_users` INT(11) NOT NULL, - `username` VARCHAR(256), - `password` VARCHAR(512), - `salt` VARCHAR(512), - `working_plan` TEXT, - `extra_working_plan` TEXT, - `notifications` TINYINT(4) DEFAULT '0', - `google_sync` TINYINT(4) DEFAULT '0', - `google_token` TEXT, - `google_calendar` VARCHAR(128), - `sync_past_days` INT(11) DEFAULT '5', - `sync_future_days` INT(11) DEFAULT '5', - `calendar_view` VARCHAR(32) DEFAULT 'default', - PRIMARY KEY (`id_users`) -) - ENGINE = InnoDB - DEFAULT CHARSET = utf8; - - -ALTER TABLE `ea_appointments` - ADD CONSTRAINT `appointments_users_customer` FOREIGN KEY (`id_users_customer`) REFERENCES `ea_users` (`id`) - ON DELETE CASCADE - ON UPDATE CASCADE, - ADD CONSTRAINT `appointments_services` FOREIGN KEY (`id_services`) REFERENCES `ea_services` (`id`) - ON DELETE CASCADE - ON UPDATE CASCADE, - ADD CONSTRAINT `appointments_users_provider` FOREIGN KEY (`id_users_provider`) REFERENCES `ea_users` (`id`) - ON DELETE CASCADE - ON UPDATE CASCADE; - -ALTER TABLE `ea_secretaries_providers` - ADD CONSTRAINT `secretaries_users_secretary` FOREIGN KEY (`id_users_secretary`) REFERENCES `ea_users` (`id`) - ON DELETE CASCADE - ON UPDATE CASCADE, - ADD CONSTRAINT `secretaries_users_provider` FOREIGN KEY (`id_users_provider`) REFERENCES `ea_users` (`id`) - ON DELETE CASCADE - ON UPDATE CASCADE; - -ALTER TABLE `ea_services` - ADD CONSTRAINT `services_service_categories` FOREIGN KEY (`id_service_categories`) REFERENCES `ea_service_categories` (`id`) - ON DELETE SET NULL - ON UPDATE CASCADE; - -ALTER TABLE `ea_services_providers` - ADD CONSTRAINT `services_providers_users_provider` FOREIGN KEY (`id_users`) REFERENCES `ea_users` (`id`) - ON DELETE CASCADE - ON UPDATE CASCADE, - ADD CONSTRAINT `services_providers_services` FOREIGN KEY (`id_services`) REFERENCES `ea_services` (`id`) - ON DELETE CASCADE - ON UPDATE CASCADE; - -ALTER TABLE `ea_users` - ADD CONSTRAINT `users_roles` FOREIGN KEY (`id_roles`) REFERENCES `ea_roles` (`id`) - ON DELETE CASCADE - ON UPDATE CASCADE; - -ALTER TABLE `ea_user_settings` - ADD CONSTRAINT `user_settings_users` FOREIGN KEY (`id_users`) REFERENCES `ea_users` (`id`) - ON DELETE CASCADE - ON UPDATE CASCADE;