From 15cef85fa7130c29fd43a89d33f37915d8af7595 Mon Sep 17 00:00:00 2001 From: Lukas Velek Date: Fri, 5 Apr 2024 13:40:50 +0200 Subject: [PATCH 1/2] SQL script creation 1 --- app/Core/DB/Scripts/database_defaults.sql | 19 ++ app/Core/DB/Scripts/database_indexes.sql | 29 ++ app/Core/DB/Scripts/database_tables.sql | 385 ++++++++++++++++++++++ 3 files changed, 433 insertions(+) create mode 100644 app/Core/DB/Scripts/database_defaults.sql create mode 100644 app/Core/DB/Scripts/database_indexes.sql create mode 100644 app/Core/DB/Scripts/database_tables.sql diff --git a/app/Core/DB/Scripts/database_defaults.sql b/app/Core/DB/Scripts/database_defaults.sql new file mode 100644 index 0000000..6c3e5ae --- /dev/null +++ b/app/Core/DB/Scripts/database_defaults.sql @@ -0,0 +1,19 @@ +-- USERS +INSERT INTO `users` (`firstname`, `lastname`, `password`, `username`) +SELECT 'Service', 'User', '$2y$10$Eb34bkiy.Gq/YxkSOyzZYe8egq70wdZTmH56ftMzmGSyBXZFwd9sG', 'service_user' +WHERE NOT EXISTS (SELECT 1 FROM `users` WHERE `username` = 'service_user') + +INSERT INTO `users` (`firstname`, `lastname`, `password`, `username`) +SELECT 'Administrator', ' ', '$2y$10$1UNSYh.T5ft0d3HFuyTpJ.i6rIM9DQxoA7Viri1JoyNbWQ15FHVJK', 'admin' +WHERE NOT EXISTS (SELECT 1 FROM `users` WHERE `username` = 'admin') + +-- GROUPS +INSERT INTO `groups` (`name`, `code`) +SELECT 'Administrators', 'ADMINISTRATORS' +WHERE NOT EXISTS (SELECT 1 FROM `groups` WHERE `code` = 'ADMINISTRATORS') + +INSERT INTO `groups` (`name`, `code`) +SELECT 'Archive Manager', 'ARCHMAN' +WHERE NOT EXISTS (SELECT 1 FROM `groups` WHERE `code` = 'ARCHMAN') + +-- USER GROUP RELATIONS diff --git a/app/Core/DB/Scripts/database_indexes.sql b/app/Core/DB/Scripts/database_indexes.sql new file mode 100644 index 0000000..83c075c --- /dev/null +++ b/app/Core/DB/Scripts/database_indexes.sql @@ -0,0 +1,29 @@ +CREATE INDEX `documents_1` ON `documents` (id_folder) +CREATE INDEX `documents_2` ON `documents` (status) +CREATE INDEX `document_comments_1` ON `document_comments` (id_document) +CREATE INDEX `document_sharing_1` ON `document_sharing` (id_user, id_document) +CREATE INDEX `document_filters_1` ON `document_filters` (id_author) +CREATE INDEX `document_reports_1` ON `document_reports` (id_user) +CREATE INDEX `user_bulk_rights_1` ON `user_bulk_rights` (id_user) +CREATE INDEX `user_action_rights_1` ON `user_action_rights` (id_user) +CREATE INDEX `user_metadata_rights_1` ON `user_metadata_rights` (id_user, id_metadata) +CREATE INDEX `ribbon_user_rights_1` ON `ribbon_user_rights` (id_ribbon, id_user) +CREATE INDEX `group_bulk_rights_1` ON `group_bulk_rights` (id_group) +CREATE INDEX `group_action_rights_1` ON `group_action_rights` (id_group) +CREATE INDEX `group_metadata_rights_1` ON `group_metadata_rights` (id_group, id_metadata) +CREATE INDEX `ribbon_group_rights_1` ON `ribbon_group_rights` (id_ribbon, id_group) +CREATE INDEX `metadata_values_1` ON `metadata_values` (id_metadata) +CREATE INDEX `folders_1` ON `folders` (id_parent_folder) +CREATE INDEX `processes_1` ON `processes` (id_document) +CREATE INDEX `processes_2` ON `processes` (id_author) +CREATE INDEX `processes_3` ON `processes` (workflow1, workflow2, workflow3, workflow4) +CREATE INDEX `process_comments_1` ON `process_comments` (id_process) +CREATE INDEX `notifications_1` ON `notifications` (id_user) +CREATE INDEX `password_reset_hashes_1` ON `password_reset_hashes` (id_user) +CREATE INDEX `ribbons_1` ON `ribbons` (id_parent_ribbon) +CREATE INDEX `file_storage_locations_1` ON `file_storage_locations` (type) +CREATE INDEX `file_storage_locations_2` ON `file_storage_locations` (name) +CREATE INDEX `services_1` ON `services` (system_name) +CREATE INDEX `users_1` ON `users` (last_login_hash) +CREATE INDEX `document_metadata_history_1` ON `document_metadata_history` (id_document) +CREATE INDEX `document_locks_1` ON `document_locks` (id_document, status) \ No newline at end of file diff --git a/app/Core/DB/Scripts/database_tables.sql b/app/Core/DB/Scripts/database_tables.sql new file mode 100644 index 0000000..fd7ad8f --- /dev/null +++ b/app/Core/DB/Scripts/database_tables.sql @@ -0,0 +1,385 @@ +CREATE TABLE IF NOT EXISTS `users` ( + `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `firstname` VARCHAR(256) NOT NULL, + `lastname` VARCHAR(256) NOT NULL, + `username` VARCHAR(256) NOT NULL, + `password` VARCHAR(256) NULL, + `status` INT(2) NOT NULL DEFAULT 1, + `email` VARCHAR(256) NULL, + `address_street` VARCHAR(256) NULL, + `address_house_number` VARCHAR(256) NULL, + `address_city` VARCHAR(256) NULL, + `address_zip_code` VARCHAR(256) NULL, + `address_country` VARCHAR(256) NULL, + `date_created` DATETIME NOT NULL DEFAULT current_timestamp(), + `date_password_changed` DATETIME NOT NULL, + `password_change_status` INT(2) NOT NULL DEFAULT 1, + `default_user_page_url` VARCHAR(256) NULL, + `date_updated` DATETIME NOT NULL DEFAULT current_timestamp(), + `default_user_datetime_format` VARCHAR(256) NULL, + `last_login_hash` VARCHAR(256) NULL +) + +CREATE TABLE IF NOT EXISTS `documents` ( + `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `id_author` INT(32) NOT NULL, + `id_officer` INT(32) NULL, + `name` VARCHAR(256) NOT NULL, + `status` INT(32) NOT NULL, + `date_created` DATETIME NOT NULL DEFAULT current_timestamp(), + `id_manager` INT(32) NOT NULL, + `id_group` INT(32) NOT NULL, + `is_deleted` INT(2) NOT NULL DEFAULT 0, + `rank` VARCHAR(256) NOT NULL, + `id_folder` INT(32) NULL, + `file` VARCHAR(256) NULL, + `shred_year` VARCHAR(4) NOT NULL, + `after_shred_action` VARCHAR(256) NOT NULL, + `shredding_status` INT(32) NOT NULL, + `date_updated` DATETIME NOT NULL DEFAULT current_timestamp(), + `id_archive_document` INT(32) NULL, + `id_archive_box` INT(32) NULL, + `id_archive_archive` INT(32) NULL +) + +CREATE TABLE IF NOT EXISTS `user_bulk_rights` ( + `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `id_user` INT(32) NOT NULL, + `action_name` VARCHAR(256) NOT NULL, + `is_executable` INT(2) DEFAULT 0 +) + +CREATE TABLE IF NOT EXISTS `groups` ( + `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `name` VARCHAR(256) NOT NULL, + `date_created` DATETIME NOT NULL DEFAULT current_timestamp(), + `code` VARCHAR(256) NULL +) + +CREATE TABLE IF NOT EXISTS `group_users` ( + `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `id_user` INT(32) NOT NULL, + `id_group` INT(32) NOT NULL, + `is_manager` INT(2) NOT NULL DEFAULT 0 +) + +CREATE TABLE IF NOT EXISTS `processes` ( + `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `id_document` INT(32) NULL, + `workflow1` INT(32) NULL, + `workflow2` INT(32) NULL, + `workflow3` INT(32) NULL, + `workflow4` INT(32) NULL, + `workflow_status` INT(32) NULL, + `type` INT(2) NOT NULL, + `status` INT(2) NOT NULL DEFAULT 1, + `date_created` DATETIME NOT NULL DEFAULT current_timestamp(), + `id_author` INT(32) NOT NULL, + `date_updated` DATETIME NOT NULL DEFAULT current_timestamp(), + `is_archive` INT(2) NOT NULL DEFAULT 0 +) + +CREATE TABLE IF NOT EXISTS `user_action_rights` ( + `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `id_user` INT(32) NOT NULL, + `action_name` VARCHAR(256) NOT NULL, + `is_executable` INT(2) DEFAULT 0 +) + +CREATE TABLE IF NOT EXISTS `group_action_rights` ( + `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `id_group` INT(32) NOT NULL, + `action_name` VARCHAR(256) NOT NULL, + `is_executable` INT(2) DEFAULT 0 +) + +CREATE TABLE IF NOT EXISTS `group_bulk_rights` ( + `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `id_group` INT(32) NOT NULL, + `action_name` VARCHAR(256) NOT NULL, + `is_executable` INT(2) DEFAULT 0 +) + +CREATE TABLE IF NOT EXISTS `metadata` ( + `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `name` VARCHAR(256) NOT NULL, + `text` VARCHAR(256) NOT NULL, + `table_name` VARCHAR(256) NOT NULL, + `is_system` INT(2) NOT NULL DEFAULT 0, + `input_type` VARCHAR(256) NOT NULL, + `length` VARCHAR(256) NOT NULL, + `select_external_enum_name` VARCHAR(256) NULL, + `is_readonly` INT(2) NOT NULL DEFAULT 0 +) + +CREATE TABLE IF NOT EXISTS `metadata_values` ( + `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `id_metadata` INT(32) NOT NULL, + `name` VARCHAR(256) NOT NULL, + `value` VARCHAR(256) NOT NULL, + `is_default` INT(2) NOT NULL DEFAULT 0 +) + +CREATE TABLE IF NOT EXISTS `user_metadata_rights` ( + `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `id_metadata` INT(32) NOT NULL, + `id_user` INT(32) NOT NULL, + `view` INT(2) NOT NULL DEFAULT 0, + `edit` INT(2) NOT NULL DEFAULT 0, + `view_values` INT(2) NOT NULL DEFAULT 0, + `edit_values` INT(2) NOT NULL DEFAULT 0 +) + +CREATE TABLE IF NOT EXISTS `group_metadata_rights` ( + `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `id_metadata` INT(32) NOT NULL, + `id_group` INT(32) NOT NULL, + `view` INT(2) NOT NULL DEFAULT 0, + `edit` INT(2) NOT NULL DEFAULT 0, + `view_values` INT(2) NOT NULL DEFAULT 0, + `edit_values` INT(2) NOT NULL DEFAULT 0 +) + +CREATE TABLE IF NOT EXISTS `folders` ( + `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `id_parent_folder` INT(32) NULL, + `name` VARCHAR(256) NOT NULL, + `description` VARCHAR(256) NULL, + `date_created` DATETIME NOT NULL DEFAULT current_timestamp(), + `nest_level` INT(32) NOT NULL, + `ordering` INT(32) NOT NULL +) + +CREATE TABLE IF NOT EXISTS `service_config` ( + `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `name` VARCHAR(256) NOT NULL, + `key` VARCHAR(256) NOT NULL, + `value` VARCHAR(256) NOT NULL +) + +CREATE TABLE IF NOT EXISTS `document_comments` ( + `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `id_author` INT(32) NOT NULL, + `id_document` INT(32) NOT NULL, + `text` TEXT, + `date_created` DATETIME NOT NULL DEFAULT current_timestamp() +) + +CREATE TABLE IF NOT EXISTS `process_comments` ( + `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `id_author` INT(32) NOT NULL, + `id_process` INT(32) NOT NULL, + `text` VARCHAR(256), + `date_created` DATETIME NOT NULL DEFAULT current_timestamp() +) + +CREATE TABLE IF NOT EXISTS `user_widgets` ( + `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `id_user` INT(32) NOT NULL, + `location` VARCHAR(256) NOT NULL, + `widget_name` VARCHAR(256) NOT NULL, + `date_created` DATETIME NOT NULL DEFAULT current_timestamp() +) + +CREATE TABLE IF NOT EXISTS `document_sharing` ( + `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `id_author` INT(32) NOT NULL, + `id_user` INT(32) NOT NULL, + `id_document` INT(32) NOT NULL, + `date_from` DATETIME NOT NULL DEFAULT current_timestamp(), + `date_to` DATETIME NOT NULL, + `date_created` DATETIME NOT NULL DEFAULT current_timestamp(), + `hash` VARCHAR(256) NOT NULL +) + +CREATE TABLE IF NOT EXISTS `notifications` ( + `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `id_user` INT(32) NOT NULL, + `text` TEXT NOT NULL, + `status` INT(2) NOT NULL DEFAULT 1, + `date_created` DATETIME NOT NULL DEFAULT current_timestamp(), + `action` VARCHAR(256) NOT NULL +) + +CREATE TABLE IF NOT EXISTS `service_log` ( + `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `name` VARCHAR(256) NOT NULL, + `text` TEXT NOT NULL, + `date_created` DATETIME NOT NULL DEFAULT current_timestamp() +) + +CREATE TABLE IF NOT EXISTS `mail_queue` ( + `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `recipient` VARCHAR(256) NOT NULL, + `title` VARCHAR(256) NOT NULL, + `body` TEXT NOT NULL, + `date_created` DATETIME NOT NULL DEFAULT current_timestamp() +) + +CREATE TABLE IF NOT EXISTS `password_reset_hashes` ( + `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `id_user` INT(32) NOT NULL, + `hash` VARCHAR(256), + `date_created` DATETIME NOT NULL DEFAULT current_timestamp() +) + +CREATE TABLE IF NOT EXISTS `document_stats` ( + `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `total_count` INT(32) NOT NULL, + `shredded_count` INT(32) NOT NULL, + `archived_count` INT(32) NOT NULL, + `new_count` INT(32) NOT NULL, + `waiting_for_archivation_count` INT(32) NOT NULL, + `date_created` DATETIME NOT NULL DEFAULT current_timestamp() +) + +CREATE TABLE IF NOT EXISTS `process_stats` ( + `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `total_count` INT(32) NOT NULL, + `in_progress_count` INT(32) NOT NULL, + `finished_count` INT(32) NOT NULL, + `date_created` DATETIME NOT NULL DEFAULT current_timestamp() +) + +CREATE TABLE IF NOT EXISTS `ribbons` ( + `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `id_parent_ribbon` INT(32) NULL, + `name` VARCHAR(256) NOT NULL, + `code` VARCHAR(256) NOT NULL, + `title` VARCHAR(256) NULL, + `image` VARCHAR(256) NULL, + `is_visible` INT(2) NOT NULL DEFAULT 1, + `is_system` INT(2) NOT NULL DEFAULT 1, + `page_url` VARCHAR(256) NOT NULL, + `ribbon_right` INT(32) NOT NULL +) + +CREATE TABLE IF NOT EXISTS `ribbon_user_rights` ( + `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `id_ribbon` INT(32) NOT NULL, + `id_user` INT(32) NOT NULL, + `can_see` INT(2) NOT NULL DEFAULT 0, + `can_edit` INT(2) NOT NULL DEFAULT 0, + `can_delete` INT(2) NOT NULL DEFAULT 0 +) + +CREATE TABLE IF NOT EXISTS `ribbon_group_rights` ( + `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `id_ribbon` INT(32) NOT NULL, + `id_group` INT(32) NOT NULL, + `can_see` INT(2) NOT NULL DEFAULT 0, + `can_edit` INT(2) NOT NULL DEFAULT 0, + `can_delete` INT(2) NOT NULL DEFAULT 0 +) + +CREATE TABLE IF NOT EXISTS `document_filters` ( + `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `id_author` INT(32) NULL, + `name` VARCHAR(256) NOT NULL, + `description` VARCHAR(256) NULL, + `filter_sql` TEXT NOT NULL, + `has_ordering` INT(2) NOT NULL DEFAULT 0 +) + +CREATE TABLE IF NOT EXISTS `user_connections` ( + `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `id_user1` INT(32) NOT NULL, + `id_user2` INT(32) NOT NULL +) + +CREATE TABLE IF NOT EXISTS `archive_documents` ( + `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `date_created` DATETIME NOT NULL DEFAULT current_timestamp(), + `name` VARCHAR(256) NOT NULL, + `id_parent_archive_entity` INT(32) NULL, + `status` INT(2) NOT NULL DEFAULT 1 +) + +CREATE TABLE IF NOT EXISTS `archive_boxes` ( + `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `date_created` DATETIME NOT NULL DEFAULT current_timestamp(), + `name` VARCHAR(256) NOT NULL, + `id_parent_archive_entity` INT(32) NULL, + `status` INT(2) NOT NULL DEFAULT 1 +) + +CREATE TABLE IF NOT EXISTS `archive_archives` ( + `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `date_created` DATETIME NOT NULL DEFAULT current_timestamp(), + `name` VARCHAR(256) NOT NULL, + `id_parent_archive_entity` INT(32) NULL, + `status` INT(2) NOT NULL DEFAULT 1 +) + +CREATE TABLE IF NOT EXISTS `document_reports` ( + `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `sql_string` TEXT NOT NULL, + `id_user` INT(32) NOT NULL, + `status` INT(2) NOT NULL DEFAULT 1, + `date_created` DATETIME NOT NULL DEFAULT current_timestamp(), + `date_updated` DATETIME NOT NULL DEFAULT current_timestamp(), + `file_src` VARCHAR(256) NULL, + `file_format` VARCHAR(256) NOT NULL, + `file_name` VARCHAR(256) NULL, + `id_file_storage_location` INT(32) NULL +) + +CREATE TABLE IF NOT EXISTS `file_storage_locations` ( + `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `name` VARCHAR(256) NOT NULL, + `path` VARCHAR(256) NOT NULL, + `is_default` INT(2) NOT NULL DEFAULT 0, + `is_active` INT(2) NOT NULL DEFAULT 1, + `order` INT(32) NOT NULL, + `is_system` INT(2) NOT NULL DEFAULT 0, + `type` VARCHAR(256) NOT NULL, + `absolute_path` VARCHAR(256) NOT NULL +) + +CREATE TABLE IF NOT EXISTS `calendar_events` ( + `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `title` VARCHAR(256) NOT NULL, + `color` VARCHAR(256) NOT NULL, + `tag` VARCHAR(256) NULL, + `date_from` VARCHAR(256) NOT NULL, + `date_to` VARCHAR(256) NULL, + `time` VARCHAR(256) NOT NULL, + `date_created` DATETIME NOT NULL DEFAULT current_timestamp() +) + +CREATE TABLE IF NOT EXISTS `db_transaction_log` ( + `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `id_calling_user` INT(32) NULL, + `time_taken` VARCHAR(256) NOT NULL, + `date_created` DATETIME NOT NULL DEFAULT current_timestamp() +) + +CREATE TABLE IF NOT EXISTS `services` ( + `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `system_name` VARCHAR(256) NOT NULL, + `display_name` VARCHAR(256) NOT NULL, + `description` VARCHAR(256) NOT NULL, + `is_enabled` INT(2) NOT NULL DEFAULT 1, + `is_system` INT(2) NOT NULL DEFAULT 0, + `date_created` DATETIME NOT NULL DEFAULT current_timestamp() +) + +CREATE TABLE IF NOT EXISTS `document_metadata_history` ( + `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `id_user` INT(32) NOT NULL, + `id_document` INT(32) NOT NULL, + `metadata_name` VARCHAR(256) NOT NULL, + `metadata_value` VARCHAR(256) NULL, + `date_created` DATETIME NOT NULL DEFAULT current_timestamp() +) + +CREATE TABLE IF NOT EXISTS `document_locks` ( + `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `id_document` INT(32) NOT NULL, + `id_user` INT(32) NULL, + `id_process` INT(32) NULL, + `description` TEXT NOT NULL, + `status` INT(2) NOT NULL DEFAULT 1, + `date_created` DATETIME NOT NULL DEFAULT current_timestamp(), + `date_updated` DATETIME NOT NULL DEFAULT current_timestamp() +) From 24d451bd65d004e61083b122c2ad259881210c61 Mon Sep 17 00:00:00 2001 From: Lukas Velek Date: Fri, 5 Apr 2024 14:26:36 +0200 Subject: [PATCH 2/2] SQL scripts 2 --- app/Core/DB/Scripts/database_defaults.sql | 80 ++++++++++++++++++++++- app/Core/DB/Scripts/database_services.sql | 29 ++++++++ app/Core/DB/Scripts/database_tables.sql | 80 +++++++++++------------ app/ajax/Ajax.php | 3 +- app/core/db/DatabaseInstaller.php | 1 + app/dms_loader.php | 3 +- 6 files changed, 153 insertions(+), 43 deletions(-) create mode 100644 app/Core/DB/Scripts/database_services.sql diff --git a/app/Core/DB/Scripts/database_defaults.sql b/app/Core/DB/Scripts/database_defaults.sql index 6c3e5ae..52fa725 100644 --- a/app/Core/DB/Scripts/database_defaults.sql +++ b/app/Core/DB/Scripts/database_defaults.sql @@ -16,4 +16,82 @@ INSERT INTO `groups` (`name`, `code`) SELECT 'Archive Manager', 'ARCHMAN' WHERE NOT EXISTS (SELECT 1 FROM `groups` WHERE `code` = 'ARCHMAN') --- USER GROUP RELATIONS +-- METADATA +INSERT INTO `metadata` (`name`, `text`, `table_name`, `is_system`, `input_type`, `length`) +VALUES ('rank', 'Rank', 'documents', '1', 'select', '256') + +INSERT INTO `metadata` (`name`, `text`, `table_name`, `is_system`, `input_type`, `length`) +VALUES ('status', 'Status', 'documents', '1', 'select', '256') + +INSERT INTO `metadata` (`name`, `text`, `table_name`, `is_system`, `input_type`, `length`) +VALUES ('after_shred_action', 'Action after shredding', 'documents', '1', 'select', '256') + +INSERT INTO `metadata` (`name`, `text`, `table_name`, `is_system`, `input_type`, `length`) +VALUES ('shredding_status', 'Shredding status', 'documents', '1', 'select', '256') + +INSERT INTO `metadata` (`name`, `text`, `table_name`, `is_system`, `input_type`, `length`) +VALUES ('status', 'Status', 'users', '1', 'select', '256') + +INSERT INTO `metadata` (`name`, `text`, `table_name`, `is_system`, `input_type`, `length`) +VALUES ('status', 'Status', 'processes', '1', 'select', '256') + +INSERT INTO `metadata` (`name`, `text`, `table_name`, `is_system`, `input_type`, `length`) +VALUES ('type', 'Type', 'processes', '1', 'select', '256') + +INSERT INTO `metadata` (`name`, `text`, `table_name`, `is_system`, `input_type`, `length`) +VALUES ('status', 'Status', 'archive', '1', 'select', '256') + +INSERT INTO `metadata` (`name`, `text`, `table_name`, `is_system`, `input_type`, `length`) +VALUES ('type', 'Type', 'archive', '1', 'select', '256') + +-- SERVICE CONFIG +INSERT INTO `service_config` (`name`, `key`, `value`) +VALUES ('LogRotateService', 'files_keep_length', '7') + +INSERT INTO `service_config` (`name`, `key`, `value`) +VALUES ('LogRotateService', 'service_run_period', '7') + +INSERT INTO `service_config` (`name`, `key`, `value`) +VALUES ('LogRotateService', 'archive_old_logs', '1') + +INSERT INTO `service_config` (`name`, `key`, `value`) +VALUES ('PasswordPolicyService', 'password_change_period', '30') + +INSERT INTO `service_config` (`name`, `key`, `value`) +VALUES ('PasswordPolicyService', 'password_change_force_administrators', '0') + +INSERT INTO `service_config` (`name`, `key`, `value`) +VALUES ('PasswordPolicyService', 'password_change_force', '0') + +INSERT INTO `service_config` (`name`, `key`, `value`) +VALUES ('PasswordPolicyService', 'service_run_period', '30') + +INSERT INTO `service_config` (`name`, `key`, `value`) +VALUES ('NotificationManagerService', 'notification_keep_length', '1') + +INSERT INTO `service_config` (`name`, `key`, `value`) +VALUES ('NotificationManagerService', 'service_run_period', '7') + +INSERT INTO `service_config` (`name`, `key`, `value`) +VALUES ('NotificationManagerService', 'notification_keep_unseen_service_user', '1') + +INSERT INTO `service_config` (`name`, `key`, `value`) +VALUES ('CacheRotateService', 'service_run_period', '1') + +INSERT INTO `service_config` (`name`, `key`, `value`) +VALUES ('FileManagerService', 'service_run_period', '30') + +INSERT INTO `service_config` (`name`, `key`, `value`) +VALUES ('ShreddingSuggestionService', 'service_run_period', '30') + +INSERT INTO `service_config` (`name`, `key`, `value`) +VALUES ('MailService', 'service_run_period', '1') + +INSERT INTO `service_config` (`name`, `key`, `value`) +VALUES ('DocumentArchivationService', 'service_run_period', '7') + +INSERT INTO `service_config` (`name`, `key`, `value`) +VALUES ('DeclinedDocumentRemoverService', 'service_run_period', '30') + +INSERT INTO `service_config` (`name`, `key`, `value`) +VALUES ('DocumentReportGeneratorService', 'service_run_period', '1') \ No newline at end of file diff --git a/app/Core/DB/Scripts/database_services.sql b/app/Core/DB/Scripts/database_services.sql new file mode 100644 index 0000000..ac1297b --- /dev/null +++ b/app/Core/DB/Scripts/database_services.sql @@ -0,0 +1,29 @@ +INSERT INTO `services` (`system_name`, `display_name`, `description`, `is_enabled`, `is_system`) +VALUES ('LogRotateService', 'Log rotate', 'Deletes old log files', '1', '1') + +INSERT INTO `services` (`system_name`, `display_name`, `description`, `is_enabled`, `is_system`) +VALUES ('CacheRotateService', 'Cache rotate', 'Deletes old cache files', '1', '1') + +INSERT INTO `services` (`system_name`, `display_name`, `description`, `is_enabled`, `is_system`) +VALUES ('FileManagerService', 'File manager', 'Deletes old unused files', '1', '1') + +INSERT INTO `services` (`system_name`, `display_name`, `description`, `is_enabled`, `is_system`) +VALUES ('ShreddingSuggestionService', 'Shredding suggestion', 'Suggests documents for shredding', '1', '1') + +INSERT INTO `services` (`system_name`, `display_name`, `description`, `is_enabled`, `is_system`) +VALUES ('PasswordPolicyService', 'Password policy', 'Checks if passwords have been changed in a period of time', '1', '1') + +INSERT INTO `services` (`system_name`, `display_name`, `description`, `is_enabled`, `is_system`) +VALUES ('MailService', 'Mail service', 'Service responsible for sending emails', '1', '1') + +INSERT INTO `services` (`system_name`, `display_name`, `description`, `is_enabled`, `is_system`) +VALUES ('NotificationManagerService', 'Notification manager', 'Service responsible for deleting old notifications', '1', '1') + +INSERT INTO `services` (`system_name`, `display_name`, `description`, `is_enabled`, `is_system`) +VALUES ('DocumentArchivationService', 'Document archivator', 'Archives documents waiting for archivation', '1', '1') + +INSERT INTO `services` (`system_name`, `display_name`, `description`, `is_enabled`, `is_system`) +VALUES ('DeclinedDocumentRemoverService', 'Declined document remover', 'Deletes declined documents', '1', '1') + +INSERT INTO `services` (`system_name`, `display_name`, `description`, `is_enabled`, `is_system`) +VALUES ('DocumentReportGeneratorService', 'Document report generator', 'Generates document reports', '1', '1') \ No newline at end of file diff --git a/app/Core/DB/Scripts/database_tables.sql b/app/Core/DB/Scripts/database_tables.sql index fd7ad8f..0ab08fc 100644 --- a/app/Core/DB/Scripts/database_tables.sql +++ b/app/Core/DB/Scripts/database_tables.sql @@ -18,7 +18,7 @@ CREATE TABLE IF NOT EXISTS `users` ( `date_updated` DATETIME NOT NULL DEFAULT current_timestamp(), `default_user_datetime_format` VARCHAR(256) NULL, `last_login_hash` VARCHAR(256) NULL -) +); CREATE TABLE IF NOT EXISTS `documents` ( `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, @@ -40,28 +40,28 @@ CREATE TABLE IF NOT EXISTS `documents` ( `id_archive_document` INT(32) NULL, `id_archive_box` INT(32) NULL, `id_archive_archive` INT(32) NULL -) +); CREATE TABLE IF NOT EXISTS `user_bulk_rights` ( `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, `id_user` INT(32) NOT NULL, `action_name` VARCHAR(256) NOT NULL, `is_executable` INT(2) DEFAULT 0 -) +); CREATE TABLE IF NOT EXISTS `groups` ( `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, `name` VARCHAR(256) NOT NULL, `date_created` DATETIME NOT NULL DEFAULT current_timestamp(), `code` VARCHAR(256) NULL -) +); CREATE TABLE IF NOT EXISTS `group_users` ( `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, `id_user` INT(32) NOT NULL, `id_group` INT(32) NOT NULL, `is_manager` INT(2) NOT NULL DEFAULT 0 -) +); CREATE TABLE IF NOT EXISTS `processes` ( `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, @@ -77,28 +77,28 @@ CREATE TABLE IF NOT EXISTS `processes` ( `id_author` INT(32) NOT NULL, `date_updated` DATETIME NOT NULL DEFAULT current_timestamp(), `is_archive` INT(2) NOT NULL DEFAULT 0 -) +); CREATE TABLE IF NOT EXISTS `user_action_rights` ( `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, `id_user` INT(32) NOT NULL, `action_name` VARCHAR(256) NOT NULL, `is_executable` INT(2) DEFAULT 0 -) +); CREATE TABLE IF NOT EXISTS `group_action_rights` ( `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, `id_group` INT(32) NOT NULL, `action_name` VARCHAR(256) NOT NULL, `is_executable` INT(2) DEFAULT 0 -) +); CREATE TABLE IF NOT EXISTS `group_bulk_rights` ( `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, `id_group` INT(32) NOT NULL, `action_name` VARCHAR(256) NOT NULL, `is_executable` INT(2) DEFAULT 0 -) +); CREATE TABLE IF NOT EXISTS `metadata` ( `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, @@ -110,7 +110,7 @@ CREATE TABLE IF NOT EXISTS `metadata` ( `length` VARCHAR(256) NOT NULL, `select_external_enum_name` VARCHAR(256) NULL, `is_readonly` INT(2) NOT NULL DEFAULT 0 -) +); CREATE TABLE IF NOT EXISTS `metadata_values` ( `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, @@ -118,7 +118,7 @@ CREATE TABLE IF NOT EXISTS `metadata_values` ( `name` VARCHAR(256) NOT NULL, `value` VARCHAR(256) NOT NULL, `is_default` INT(2) NOT NULL DEFAULT 0 -) +); CREATE TABLE IF NOT EXISTS `user_metadata_rights` ( `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, @@ -128,7 +128,7 @@ CREATE TABLE IF NOT EXISTS `user_metadata_rights` ( `edit` INT(2) NOT NULL DEFAULT 0, `view_values` INT(2) NOT NULL DEFAULT 0, `edit_values` INT(2) NOT NULL DEFAULT 0 -) +); CREATE TABLE IF NOT EXISTS `group_metadata_rights` ( `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, @@ -138,7 +138,7 @@ CREATE TABLE IF NOT EXISTS `group_metadata_rights` ( `edit` INT(2) NOT NULL DEFAULT 0, `view_values` INT(2) NOT NULL DEFAULT 0, `edit_values` INT(2) NOT NULL DEFAULT 0 -) +); CREATE TABLE IF NOT EXISTS `folders` ( `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, @@ -148,14 +148,14 @@ CREATE TABLE IF NOT EXISTS `folders` ( `date_created` DATETIME NOT NULL DEFAULT current_timestamp(), `nest_level` INT(32) NOT NULL, `ordering` INT(32) NOT NULL -) +); CREATE TABLE IF NOT EXISTS `service_config` ( `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, `name` VARCHAR(256) NOT NULL, `key` VARCHAR(256) NOT NULL, `value` VARCHAR(256) NOT NULL -) +); CREATE TABLE IF NOT EXISTS `document_comments` ( `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, @@ -163,7 +163,7 @@ CREATE TABLE IF NOT EXISTS `document_comments` ( `id_document` INT(32) NOT NULL, `text` TEXT, `date_created` DATETIME NOT NULL DEFAULT current_timestamp() -) +); CREATE TABLE IF NOT EXISTS `process_comments` ( `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, @@ -171,7 +171,7 @@ CREATE TABLE IF NOT EXISTS `process_comments` ( `id_process` INT(32) NOT NULL, `text` VARCHAR(256), `date_created` DATETIME NOT NULL DEFAULT current_timestamp() -) +); CREATE TABLE IF NOT EXISTS `user_widgets` ( `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, @@ -179,7 +179,7 @@ CREATE TABLE IF NOT EXISTS `user_widgets` ( `location` VARCHAR(256) NOT NULL, `widget_name` VARCHAR(256) NOT NULL, `date_created` DATETIME NOT NULL DEFAULT current_timestamp() -) +); CREATE TABLE IF NOT EXISTS `document_sharing` ( `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, @@ -190,7 +190,7 @@ CREATE TABLE IF NOT EXISTS `document_sharing` ( `date_to` DATETIME NOT NULL, `date_created` DATETIME NOT NULL DEFAULT current_timestamp(), `hash` VARCHAR(256) NOT NULL -) +); CREATE TABLE IF NOT EXISTS `notifications` ( `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, @@ -199,14 +199,14 @@ CREATE TABLE IF NOT EXISTS `notifications` ( `status` INT(2) NOT NULL DEFAULT 1, `date_created` DATETIME NOT NULL DEFAULT current_timestamp(), `action` VARCHAR(256) NOT NULL -) +); CREATE TABLE IF NOT EXISTS `service_log` ( `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, `name` VARCHAR(256) NOT NULL, `text` TEXT NOT NULL, `date_created` DATETIME NOT NULL DEFAULT current_timestamp() -) +); CREATE TABLE IF NOT EXISTS `mail_queue` ( `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, @@ -214,14 +214,14 @@ CREATE TABLE IF NOT EXISTS `mail_queue` ( `title` VARCHAR(256) NOT NULL, `body` TEXT NOT NULL, `date_created` DATETIME NOT NULL DEFAULT current_timestamp() -) +); CREATE TABLE IF NOT EXISTS `password_reset_hashes` ( `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, `id_user` INT(32) NOT NULL, `hash` VARCHAR(256), `date_created` DATETIME NOT NULL DEFAULT current_timestamp() -) +); CREATE TABLE IF NOT EXISTS `document_stats` ( `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, @@ -231,7 +231,7 @@ CREATE TABLE IF NOT EXISTS `document_stats` ( `new_count` INT(32) NOT NULL, `waiting_for_archivation_count` INT(32) NOT NULL, `date_created` DATETIME NOT NULL DEFAULT current_timestamp() -) +); CREATE TABLE IF NOT EXISTS `process_stats` ( `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, @@ -239,7 +239,7 @@ CREATE TABLE IF NOT EXISTS `process_stats` ( `in_progress_count` INT(32) NOT NULL, `finished_count` INT(32) NOT NULL, `date_created` DATETIME NOT NULL DEFAULT current_timestamp() -) +); CREATE TABLE IF NOT EXISTS `ribbons` ( `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, @@ -252,7 +252,7 @@ CREATE TABLE IF NOT EXISTS `ribbons` ( `is_system` INT(2) NOT NULL DEFAULT 1, `page_url` VARCHAR(256) NOT NULL, `ribbon_right` INT(32) NOT NULL -) +); CREATE TABLE IF NOT EXISTS `ribbon_user_rights` ( `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, @@ -261,7 +261,7 @@ CREATE TABLE IF NOT EXISTS `ribbon_user_rights` ( `can_see` INT(2) NOT NULL DEFAULT 0, `can_edit` INT(2) NOT NULL DEFAULT 0, `can_delete` INT(2) NOT NULL DEFAULT 0 -) +); CREATE TABLE IF NOT EXISTS `ribbon_group_rights` ( `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, @@ -270,7 +270,7 @@ CREATE TABLE IF NOT EXISTS `ribbon_group_rights` ( `can_see` INT(2) NOT NULL DEFAULT 0, `can_edit` INT(2) NOT NULL DEFAULT 0, `can_delete` INT(2) NOT NULL DEFAULT 0 -) +); CREATE TABLE IF NOT EXISTS `document_filters` ( `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, @@ -279,13 +279,13 @@ CREATE TABLE IF NOT EXISTS `document_filters` ( `description` VARCHAR(256) NULL, `filter_sql` TEXT NOT NULL, `has_ordering` INT(2) NOT NULL DEFAULT 0 -) +); CREATE TABLE IF NOT EXISTS `user_connections` ( `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, `id_user1` INT(32) NOT NULL, `id_user2` INT(32) NOT NULL -) +); CREATE TABLE IF NOT EXISTS `archive_documents` ( `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, @@ -293,7 +293,7 @@ CREATE TABLE IF NOT EXISTS `archive_documents` ( `name` VARCHAR(256) NOT NULL, `id_parent_archive_entity` INT(32) NULL, `status` INT(2) NOT NULL DEFAULT 1 -) +); CREATE TABLE IF NOT EXISTS `archive_boxes` ( `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, @@ -301,7 +301,7 @@ CREATE TABLE IF NOT EXISTS `archive_boxes` ( `name` VARCHAR(256) NOT NULL, `id_parent_archive_entity` INT(32) NULL, `status` INT(2) NOT NULL DEFAULT 1 -) +); CREATE TABLE IF NOT EXISTS `archive_archives` ( `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, @@ -309,7 +309,7 @@ CREATE TABLE IF NOT EXISTS `archive_archives` ( `name` VARCHAR(256) NOT NULL, `id_parent_archive_entity` INT(32) NULL, `status` INT(2) NOT NULL DEFAULT 1 -) +); CREATE TABLE IF NOT EXISTS `document_reports` ( `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, @@ -322,7 +322,7 @@ CREATE TABLE IF NOT EXISTS `document_reports` ( `file_format` VARCHAR(256) NOT NULL, `file_name` VARCHAR(256) NULL, `id_file_storage_location` INT(32) NULL -) +); CREATE TABLE IF NOT EXISTS `file_storage_locations` ( `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, @@ -334,7 +334,7 @@ CREATE TABLE IF NOT EXISTS `file_storage_locations` ( `is_system` INT(2) NOT NULL DEFAULT 0, `type` VARCHAR(256) NOT NULL, `absolute_path` VARCHAR(256) NOT NULL -) +); CREATE TABLE IF NOT EXISTS `calendar_events` ( `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, @@ -345,14 +345,14 @@ CREATE TABLE IF NOT EXISTS `calendar_events` ( `date_to` VARCHAR(256) NULL, `time` VARCHAR(256) NOT NULL, `date_created` DATETIME NOT NULL DEFAULT current_timestamp() -) +); CREATE TABLE IF NOT EXISTS `db_transaction_log` ( `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, `id_calling_user` INT(32) NULL, `time_taken` VARCHAR(256) NOT NULL, `date_created` DATETIME NOT NULL DEFAULT current_timestamp() -) +); CREATE TABLE IF NOT EXISTS `services` ( `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, @@ -362,7 +362,7 @@ CREATE TABLE IF NOT EXISTS `services` ( `is_enabled` INT(2) NOT NULL DEFAULT 1, `is_system` INT(2) NOT NULL DEFAULT 0, `date_created` DATETIME NOT NULL DEFAULT current_timestamp() -) +); CREATE TABLE IF NOT EXISTS `document_metadata_history` ( `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, @@ -371,7 +371,7 @@ CREATE TABLE IF NOT EXISTS `document_metadata_history` ( `metadata_name` VARCHAR(256) NOT NULL, `metadata_value` VARCHAR(256) NULL, `date_created` DATETIME NOT NULL DEFAULT current_timestamp() -) +); CREATE TABLE IF NOT EXISTS `document_locks` ( `id` INT(32) NOT NULL PRIMARY KEY AUTO_INCREMENT, @@ -382,4 +382,4 @@ CREATE TABLE IF NOT EXISTS `document_locks` ( `status` INT(2) NOT NULL DEFAULT 1, `date_created` DATETIME NOT NULL DEFAULT current_timestamp(), `date_updated` DATETIME NOT NULL DEFAULT current_timestamp() -) +); diff --git a/app/ajax/Ajax.php b/app/ajax/Ajax.php index 16bd45d..83f61d7 100644 --- a/app/ajax/Ajax.php +++ b/app/ajax/Ajax.php @@ -73,7 +73,8 @@ function loadDependencies2(array &$dependencies, string $dir) { 'png', 'gif', 'jpg', - 'svg' + 'svg', + 'sql' ); foreach($content as $c) { diff --git a/app/core/db/DatabaseInstaller.php b/app/core/db/DatabaseInstaller.php index 70214eb..392e18f 100644 --- a/app/core/db/DatabaseInstaller.php +++ b/app/core/db/DatabaseInstaller.php @@ -16,6 +16,7 @@ use DMS\Constants\UserActionRights; use DMS\Constants\UserStatus; use DMS\Core\CryptManager; +use DMS\Core\FileManager; use DMS\Core\Logger\Logger; /** diff --git a/app/dms_loader.php b/app/dms_loader.php index 2c63642..33e2b7c 100644 --- a/app/dms_loader.php +++ b/app/dms_loader.php @@ -49,7 +49,8 @@ function loadDependencies(array &$dependencies, string $dir) { 'png', 'gif', 'jpg', - 'svg' + 'svg', + 'sql' ); foreach($content as $c) {