diff --git a/db-bootstrap/1_create_translations_tables.sql b/db-bootstrap/1_create_translations_tables.sql index 67cb4a0..7182bdb 100644 --- a/db-bootstrap/1_create_translations_tables.sql +++ b/db-bootstrap/1_create_translations_tables.sql @@ -8,7 +8,7 @@ CREATE TABLE `translations` ( -- TRANSLATIONS_LANGUAGES DROP TABLE IF EXISTS `translations_languages`; -CREATE TABLE `translation_language` ( +CREATE TABLE `translation_languages` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `translation_id` int(11) unsigned DEFAULT NULL, `anrs_string_id` int(11) DEFAULT NULL, @@ -30,6 +30,7 @@ CREATE TABLE `translation_language` ( `themes_string_id` int(11) DEFAULT NULL, `threats_string_id` int(11) DEFAULT NULL, `vulnerabilities_string_id` int(11) DEFAULT NULL, + `instances_risks_op_string_id` int(11) DEFAULT NULL, PRIMARY KEY (`id`), KEY `translation_id` (`translation_id`), CONSTRAINT `translations_ibfk_1` FOREIGN KEY (`translation_id`) REFERENCES `translations` (`id`) @@ -61,6 +62,7 @@ BEGIN ALTER TABLE `themes` ADD label_translation_id INT(11); ALTER TABLE `threats` ADD description_translation_id INT(11), ADD label_translation_id INT(11); ALTER TABLE `vulnerabilities` ADD description_translation_id INT(11), ADD label_translation_id INT(11); + ALTER TABLE `instances_risks_op` ADD risk_cache_label_id INT(11), ADD risk_cache_description_id INT(11); END;; DELIMITER ; diff --git a/db-bootstrap/1_create_translations_tables_cli.sql b/db-bootstrap/1_create_translations_tables_cli.sql new file mode 100644 index 0000000..0b62834 --- /dev/null +++ b/db-bootstrap/1_create_translations_tables_cli.sql @@ -0,0 +1,65 @@ +SET foreign_key_checks = 0; + +DROP TABLE IF EXISTS `translations`; +CREATE TABLE `translations` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `ISO` text DEFAULT NULL, + `content` text DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- TRANSLATIONS_LANGUAGES +DROP TABLE IF EXISTS `translations_languages`; +CREATE TABLE `translation_languages` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `translation_id` int(11) unsigned DEFAULT NULL, + `anrs_string_id` int(11) DEFAULT NULL, + `assets_string_id` int(11) DEFAULT NULL, + `instances_string_id` int(11) DEFAULT NULL, + `measures_string_id` int(11) DEFAULT NULL, + `objects_string_id` int(11) DEFAULT NULL, + `objects_categories_string_id` int(11) DEFAULT NULL, + `questions_string_id` int(11) DEFAULT NULL, + `questions_choices_string_id` int(11) DEFAULT NULL, + `rolf_risks_string_id` int(11) DEFAULT NULL, + `rolf_tags_string_id` int(11) DEFAULT NULL, + `scales_comments_string_id` int(11) DEFAULT NULL, + `scales_impact_types_string_id` int(11) DEFAULT NULL, + `themes_string_id` int(11) DEFAULT NULL, + `threats_string_id` int(11) DEFAULT NULL, + `vulnerabilities_string_id` int(11) DEFAULT NULL, + `instances_risks_op_string_id` int(11) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `translation_id` (`translation_id`), + CONSTRAINT `translations_ibfk_1` FOREIGN KEY (`translation_id`) REFERENCES `translations` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + + +-- +-- Procedure to add new columns for ids translation into entity tables +DROP PROCEDURE IF EXISTS add_new_translation_id_columns; +DELIMITER ;; +CREATE PROCEDURE add_new_translation_id_columns () +BEGIN + ALTER TABLE `anrs` ADD description_translation_id INT(11), ADD label_translation_id INT(11); + ALTER TABLE `assets` ADD description_translation_id INT(11), ADD label_translation_id INT(11); + ALTER TABLE `instances` ADD name_translation_id INT(11), ADD label_translation_id INT(11); + ALTER TABLE `measures` ADD description_translation_id INT(11); + ALTER TABLE `objects` ADD name_translation_id INT(11), ADD label_translation_id INT(11); + ALTER TABLE `objects_categories` ADD label_translation_id INT(11); + ALTER TABLE `questions` ADD label_translation_id INT(11); + ALTER TABLE `questions_choices` ADD label_translation_id INT(11); + ALTER TABLE `rolf_risks` ADD description_translation_id INT(11), ADD label_translation_id INT(11); + ALTER TABLE `rolf_tags` ADD label_translation_id INT(11); + ALTER TABLE `scales_comments` ADD comment_translation_id INT(11); + ALTER TABLE `scales_impact_types` ADD label_translation_id INT(11); + ALTER TABLE `themes` ADD label_translation_id INT(11); + ALTER TABLE `threats` ADD description_translation_id INT(11), ADD label_translation_id INT(11); + ALTER TABLE `vulnerabilities` ADD description_translation_id INT(11), ADD label_translation_id INT(11); + ALTER TABLE `instances_risks_op` ADD risk_cache_label_id INT(11), ADD risk_cache_description_id INT(11); +END;; +DELIMITER ; + +CALL add_new_translation_id_columns; + +SET foreign_key_checks = 1; diff --git a/db-bootstrap/2_fill_entities_tables.sql b/db-bootstrap/2_fill_entities_tables.sql index 07def90..3d80082 100644 --- a/db-bootstrap/2_fill_entities_tables.sql +++ b/db-bootstrap/2_fill_entities_tables.sql @@ -658,6 +658,52 @@ END;; DELIMITER ; +-- INSTANCES_RISKS_OP +DROP PROCEDURE IF EXISTS fill_instances_risks_op_data; +DELIMITER ;; +CREATE PROCEDURE fill_instances_risks_op_data () + BEGIN + DECLARE i INT DEFAULT 0; + DECLARE j INT DEFAULT 0; + DECLARE entity_table_length INT DEFAULT 0; + DECLARE entity_description_translation_id INT DEFAULT 0; + DECLARE entity_label_translation_id INT DEFAULT 0; + + SET entity_table_length = (SELECT COUNT(*) FROM `instances_risks_op`); + + WHILE i < entity_table_length DO + SET entity_description_translation_id = i + 1; + + SET @entity_id = (SELECT `id` FROM `instances_risks_op` LIMIT 1 OFFSET i); + + SET @query = CONCAT('UPDATE `vulnerabilities` SET `risk_cache_description_translation_id` = ', entity_description_translation_id, ' WHERE `id` = ', @entity_id); + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET i = i + 1; + + IF i = entity_table_length THEN SET @entity_id_for_following_translation = i + 1; + END IF; + END WHILE; + + WHILE j < entity_table_length DO + SET entity_label_translation_id = @entity_id_for_following_translation; + + SET @entity_id = (SELECT `id` FROM `instances_risks_op` LIMIT 1 OFFSET j); + + SET @query = CONCAT('UPDATE `vulnerabilities` SET `risk_cache_label_translation_id` = ', entity_label_translation_id, ' WHERE `id` = ', @entity_id); + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + SET @entity_id_for_following_translation = @entity_id_for_following_translation + 1; + END WHILE; + + END;; +DELIMITER ; + -- Call procedures CALL `fill_anrs_data`; CALL `fill_assets_data`; @@ -677,4 +723,5 @@ CALL `fill_scales_comments_data`; CALL `fill_scales_impact_types_data`; CALL `fill_themes_data`; CALL `fill_threats_data`; -CALL `fill_vulnerabilities_data`; \ No newline at end of file +CALL `fill_vulnerabilities_data`; +CALL `fill_instances_risks_op_data`; \ No newline at end of file diff --git a/db-bootstrap/2_fill_entities_tables_cli.sql b/db-bootstrap/2_fill_entities_tables_cli.sql new file mode 100644 index 0000000..f81002f --- /dev/null +++ b/db-bootstrap/2_fill_entities_tables_cli.sql @@ -0,0 +1,608 @@ +-- Procedures to fill translations_id columns (for entity tables) + +-- ANRS +DROP PROCEDURE IF EXISTS fill_anrs_data; +DELIMITER ;; +CREATE PROCEDURE fill_anrs_data () +BEGIN + DECLARE i INT DEFAULT 0; + DECLARE j INT DEFAULT 0; + DECLARE entity_table_length INT DEFAULT 0; + DECLARE entity_description_translation_id INT DEFAULT 0; + DECLARE entity_label_translation_id INT DEFAULT 0; + + SET entity_table_length = (SELECT COUNT(*) FROM `anrs`); + + WHILE i < entity_table_length DO + SET entity_description_translation_id = i + 1; + + SET @entity_id = (SELECT `id` FROM `anrs` LIMIT 1 OFFSET i); + + SET @query = CONCAT('UPDATE `anrs` SET `description_translation_id` = ', entity_description_translation_id, ' WHERE `id` = ', @entity_id); + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET i = i + 1; + + IF i = entity_table_length THEN SET @entity_id_for_following_translation = i + 1; + END IF; + END WHILE; + + WHILE j < entity_table_length DO + SET entity_label_translation_id = @entity_id_for_following_translation; + + SET @entity_id = (SELECT `id` FROM `anrs` LIMIT 1 OFFSET j); + + SET @query = CONCAT('UPDATE `anrs` SET `label_translation_id` = ', entity_label_translation_id, ' WHERE `id` = ', @entity_id); + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + SET @entity_id_for_following_translation = @entity_id_for_following_translation + 1; + END WHILE; + +END;; +DELIMITER ; + +-- ASSETS +DROP PROCEDURE IF EXISTS fill_assets_data; +DELIMITER ;; +CREATE PROCEDURE fill_assets_data () +BEGIN + DECLARE i INT DEFAULT 0; + DECLARE j INT DEFAULT 0; + DECLARE entity_table_length INT DEFAULT 0; + DECLARE entity_description_translation_id INT DEFAULT 0; + DECLARE entity_label_translation_id INT DEFAULT 0; + + SET entity_table_length = (SELECT COUNT(*) FROM `assets`); + + WHILE i < entity_table_length DO + SET entity_description_translation_id = i + 1; + + SET @entity_id = (SELECT `id` FROM `assets` LIMIT 1 OFFSET i); + + SET @query = CONCAT('UPDATE `assets` SET `description_translation_id` = ', entity_description_translation_id, ' WHERE `id` = ', @entity_id); + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET i = i + 1; + + IF i = entity_table_length THEN SET @entity_id_for_following_translation = i + 1; + END IF; + END WHILE; + + WHILE j < entity_table_length DO + SET entity_label_translation_id = @entity_id_for_following_translation; + + SET @entity_id = (SELECT `id` FROM `assets` LIMIT 1 OFFSET j); + + SET @query = CONCAT('UPDATE `assets` SET `label_translation_id` = ', entity_label_translation_id, ' WHERE `id` = ', @entity_id); + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + SET @entity_id_for_following_translation = @entity_id_for_following_translation + 1; + END WHILE; + +END;; +DELIMITER ; + +-- GUIDES +DROP PROCEDURE IF EXISTS fill_guides_data; + +-- GUIDES_ITEMS +DROP PROCEDURE IF EXISTS fill_guides_items_data; + +-- HISTORICALS +DROP PROCEDURE IF EXISTS fill_historicals_data; + +-- INSTANCES +DROP PROCEDURE IF EXISTS fill_instances_data; +DELIMITER ;; +CREATE PROCEDURE fill_instances_data () +BEGIN + DECLARE i INT DEFAULT 0; + DECLARE j INT DEFAULT 0; + DECLARE entity_table_length INT DEFAULT 0; + DECLARE entity_name_translation_id INT DEFAULT 0; + DECLARE entity_label_translation_id INT DEFAULT 0; + + SET entity_table_length = (SELECT COUNT(*) FROM `instances`); + + WHILE i < entity_table_length DO + SET entity_name_translation_id = i + 1; + + SET @entity_id = (SELECT `id` FROM `instances` LIMIT 1 OFFSET i); + + SET @query = CONCAT('UPDATE `instances` SET `name_translation_id` = ', entity_name_translation_id, ' WHERE `id` = ', @entity_id); + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET i = i + 1; + + IF i = entity_table_length THEN SET @entity_id_for_following_translation = i + 1; + END IF; + END WHILE; + + WHILE j < entity_table_length DO + SET entity_label_translation_id = @entity_id_for_following_translation; + + SET @entity_id = (SELECT `id` FROM `instances` LIMIT 1 OFFSET j); + + SET @query = CONCAT('UPDATE `instances` SET `label_translation_id` = ', entity_label_translation_id, ' WHERE `id` = ', @entity_id); + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + SET @entity_id_for_following_translation = @entity_id_for_following_translation + 1; + END WHILE; + +END;; +DELIMITER ; + +-- MEASURES +DROP PROCEDURE IF EXISTS fill_measures_data; +DELIMITER ;; +CREATE PROCEDURE fill_measures_data () +BEGIN + DECLARE i INT DEFAULT 0; + DECLARE entity_table_length INT DEFAULT 0; + DECLARE entity_description_translation_id INT DEFAULT 0; + + SET entity_table_length = (SELECT COUNT(*) FROM `measures`); + + WHILE i < entity_table_length DO + SET entity_description_translation_id = i + 1; + + SET @entity_id = (SELECT `id` FROM `measures` LIMIT 1 OFFSET i); + + SET @query = CONCAT('UPDATE `measures` SET `description_translation_id` = ', entity_description_translation_id, ' WHERE `id` = ', @entity_id); + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET i = i + 1; + END WHILE; +END;; +DELIMITER ; + +-- MODELS +DROP PROCEDURE IF EXISTS fill_models_data; + +-- OBJECTS +DROP PROCEDURE IF EXISTS fill_objects_data; +DELIMITER ;; +CREATE PROCEDURE fill_objects_data () +BEGIN + DECLARE i INT DEFAULT 0; + DECLARE j INT DEFAULT 0; + DECLARE entity_table_length INT DEFAULT 0; + DECLARE entity_name_translation_id INT DEFAULT 0; + DECLARE entity_label_translation_id INT DEFAULT 0; + + SET entity_table_length = (SELECT COUNT(*) FROM `objects`); + + WHILE i < entity_table_length DO + SET entity_name_translation_id = i + 1; + + SET @entity_id = (SELECT `id` FROM `objects` LIMIT 1 OFFSET i); + + SET @query = CONCAT('UPDATE `objects` SET `name_translation_id` = ', entity_name_translation_id, ' WHERE `id` = ', @entity_id); + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET i = i + 1; + + IF i = entity_table_length THEN SET @entity_id_for_following_translation = i + 1; + END IF; + END WHILE; + + WHILE j < entity_table_length DO + SET entity_label_translation_id = @entity_id_for_following_translation; + + SET @entity_id = (SELECT `id` FROM `objects` LIMIT 1 OFFSET j); + + SET @query = CONCAT('UPDATE `objects` SET `label_translation_id` = ', entity_label_translation_id, ' WHERE `id` = ', @entity_id); + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + SET @entity_id_for_following_translation = @entity_id_for_following_translation + 1; + END WHILE; + +END;; +DELIMITER ; + +-- OBJECTS_CATEGORIES +DROP PROCEDURE IF EXISTS fill_objects_categories_data; +DELIMITER ;; +CREATE PROCEDURE fill_objects_categories_data () +BEGIN + DECLARE i INT DEFAULT 0; + DECLARE entity_table_length INT DEFAULT 0; + DECLARE entity_label_translation_id INT DEFAULT 0; + + SET entity_table_length = (SELECT COUNT(*) FROM `objects_categories`); + + WHILE i < entity_table_length DO + SET entity_label_translation_id = i + 1; + + SET @entity_id = (SELECT `id` FROM `objects_categories` LIMIT 1 OFFSET i); + + SET @query = CONCAT('UPDATE `objects_categories` SET `label_translation_id` = ', entity_label_translation_id, ' WHERE `id` = ', @entity_id); + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET i = i + 1; + END WHILE; +END;; +DELIMITER ; + +-- QUESTIONS +DROP PROCEDURE IF EXISTS fill_questions_data; +DELIMITER ;; +CREATE PROCEDURE fill_questions_data () +BEGIN + DECLARE i INT DEFAULT 0; + DECLARE entity_table_length INT DEFAULT 0; + DECLARE entity_label_translation_id INT DEFAULT 0; + + SET entity_table_length = (SELECT COUNT(*) FROM `questions`); + + WHILE i < entity_table_length DO + SET entity_label_translation_id = i + 1; + + SET @entity_id = (SELECT `id` FROM `questions` LIMIT 1 OFFSET i); + + SET @query = CONCAT('UPDATE `questions` SET `label_translation_id` = ', entity_label_translation_id, ' WHERE `id` = ', @entity_id); + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET i = i + 1; + END WHILE; +END;; +DELIMITER ; + +-- QUESTIONS_CHOICES +DROP PROCEDURE IF EXISTS fill_questions_choices_data; +DELIMITER ;; +CREATE PROCEDURE fill_questions_choices_data () +BEGIN + DECLARE i INT DEFAULT 0; + DECLARE entity_table_length INT DEFAULT 0; + DECLARE entity_label_translation_id INT DEFAULT 0; + + SET entity_table_length = (SELECT COUNT(*) FROM `questions_choices`); + + WHILE i < entity_table_length DO + SET entity_label_translation_id = i + 1; + + SET @entity_id = (SELECT `id` FROM `questions_choices` LIMIT 1 OFFSET i); + + SET @query = CONCAT('UPDATE `questions_choices` SET `label_translation_id` = ', entity_label_translation_id, ' WHERE `id` = ', @entity_id); + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET i = i + 1; + END WHILE; +END;; +DELIMITER ; + +-- ROLF_RISKS +DROP PROCEDURE IF EXISTS fill_rolf_risks_data; +DELIMITER ;; +CREATE PROCEDURE fill_rolf_risks_data () +BEGIN + DECLARE i INT DEFAULT 0; + DECLARE j INT DEFAULT 0; + DECLARE entity_table_length INT DEFAULT 0; + DECLARE entity_description_translation_id INT DEFAULT 0; + DECLARE entity_label_translation_id INT DEFAULT 0; + + SET entity_table_length = (SELECT COUNT(*) FROM `rolf_risks`); + + WHILE i < entity_table_length DO + SET entity_description_translation_id = i + 1; + + SET @entity_id = (SELECT `id` FROM `rolf_risks` LIMIT 1 OFFSET i); + + SET @query = CONCAT('UPDATE `rolf_risks` SET `description_translation_id` = ', entity_description_translation_id, ' WHERE `id` = ', @entity_id); + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET i = i + 1; + + IF i = entity_table_length THEN SET @entity_id_for_following_translation = i + 1; + END IF; + END WHILE; + + WHILE j < entity_table_length DO + SET entity_label_translation_id = @entity_id_for_following_translation; + + SET @entity_id = (SELECT `id` FROM `rolf_risks` LIMIT 1 OFFSET j); + + SET @query = CONCAT('UPDATE `rolf_risks` SET `label_translation_id` = ', entity_label_translation_id, ' WHERE `id` = ', @entity_id); + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + SET @entity_id_for_following_translation = @entity_id_for_following_translation + 1; + END WHILE; + +END;; +DELIMITER ; + +-- ROLF_TAGS +DROP PROCEDURE IF EXISTS fill_rolf_tags_data; +DELIMITER ;; +CREATE PROCEDURE fill_rolf_tags_data () +BEGIN + DECLARE i INT DEFAULT 0; + DECLARE entity_table_length INT DEFAULT 0; + DECLARE entity_label_translation_id INT DEFAULT 0; + + SET entity_table_length = (SELECT COUNT(*) FROM `rolf_tags`); + + WHILE i < entity_table_length DO + SET entity_label_translation_id = i + 1; + + SET @entity_id = (SELECT `id` FROM `rolf_tags` LIMIT 1 OFFSET i); + + SET @query = CONCAT('UPDATE `rolf_tags` SET `label_translation_id` = ', entity_label_translation_id, ' WHERE `id` = ', @entity_id); + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET i = i + 1; + END WHILE; +END;; +DELIMITER ; + +-- SCALES_COMMENTS +DROP PROCEDURE IF EXISTS fill_scales_comments_data; +DELIMITER ;; +CREATE PROCEDURE fill_scales_comments_data () +BEGIN + DECLARE i INT DEFAULT 0; + DECLARE entity_table_length INT DEFAULT 0; + DECLARE entity_comment_translation_id INT DEFAULT 0; + + SET entity_table_length = (SELECT COUNT(*) FROM `scales_comments`); + + WHILE i < entity_table_length DO + SET entity_comment_translation_id = i + 1; + + SET @entity_id = (SELECT `id` FROM `scales_comments` LIMIT 1 OFFSET i); + + SET @query = CONCAT('UPDATE `scales_comments` SET `comment_translation_id` = ', entity_comment_translation_id, ' WHERE `id` = ', @entity_id); + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET i = i + 1; + END WHILE; +END;; +DELIMITER ; + +-- SCALES_IMPACT_TYPES +DROP PROCEDURE IF EXISTS fill_scales_impact_types_data; +DELIMITER ;; +CREATE PROCEDURE fill_scales_impact_types_data () +BEGIN + DECLARE i INT DEFAULT 0; + DECLARE entity_table_length INT DEFAULT 0; + DECLARE entity_label_translation_id INT DEFAULT 0; + + SET entity_table_length = (SELECT COUNT(*) FROM `scales_impact_types`); + + WHILE i < entity_table_length DO + SET entity_label_translation_id = i + 1; + + SET @entity_id = (SELECT `id` FROM `scales_impact_types` LIMIT 1 OFFSET i); + + SET @query = CONCAT('UPDATE `scales_impact_types` SET `label_translation_id` = ', entity_label_translation_id, ' WHERE `id` = ', @entity_id); + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET i = i + 1; + END WHILE; +END;; +DELIMITER ; + +-- THEMES +DROP PROCEDURE IF EXISTS fill_themes_data; +DELIMITER ;; +CREATE PROCEDURE fill_themes_data () +BEGIN + DECLARE i INT DEFAULT 0; + DECLARE entity_table_length INT DEFAULT 0; + DECLARE entity_label_translation_id INT DEFAULT 0; + + SET entity_table_length = (SELECT COUNT(*) FROM `themes`); + + WHILE i < entity_table_length DO + SET entity_label_translation_id = i + 1; + + SET @entity_id = (SELECT `id` FROM `themes` LIMIT 1 OFFSET i); + + SET @query = CONCAT('UPDATE `themes` SET `label_translation_id` = ', entity_label_translation_id, ' WHERE `id` = ', @entity_id); + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET i = i + 1; + END WHILE; +END;; +DELIMITER ; + +-- THREATS +DROP PROCEDURE IF EXISTS fill_threats_data; +DELIMITER ;; +CREATE PROCEDURE fill_threats_data () +BEGIN + DECLARE i INT DEFAULT 0; + DECLARE j INT DEFAULT 0; + DECLARE entity_table_length INT DEFAULT 0; + DECLARE entity_description_translation_id INT DEFAULT 0; + DECLARE entity_label_translation_id INT DEFAULT 0; + + SET entity_table_length = (SELECT COUNT(*) FROM `threats`); + + WHILE i < entity_table_length DO + SET entity_description_translation_id = i + 1; + + SET @entity_id = (SELECT `id` FROM `threats` LIMIT 1 OFFSET i); + + SET @query = CONCAT('UPDATE `threats` SET `description_translation_id` = ', entity_description_translation_id, ' WHERE `id` = ', @entity_id); + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET i = i + 1; + + IF i = entity_table_length THEN SET @entity_id_for_following_translation = i + 1; + END IF; + END WHILE; + + WHILE j < entity_table_length DO + SET entity_label_translation_id = @entity_id_for_following_translation; + + SET @entity_id = (SELECT `id` FROM `threats` LIMIT 1 OFFSET j); + + SET @query = CONCAT('UPDATE `threats` SET `label_translation_id` = ', entity_label_translation_id, ' WHERE `id` = ', @entity_id); + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + SET @entity_id_for_following_translation = @entity_id_for_following_translation + 1; + END WHILE; + +END;; +DELIMITER ; + +-- VULNERABILITIES +DROP PROCEDURE IF EXISTS fill_vulnerabilities_data; +DELIMITER ;; +CREATE PROCEDURE fill_vulnerabilities_data () +BEGIN + DECLARE i INT DEFAULT 0; + DECLARE j INT DEFAULT 0; + DECLARE entity_table_length INT DEFAULT 0; + DECLARE entity_description_translation_id INT DEFAULT 0; + DECLARE entity_label_translation_id INT DEFAULT 0; + + SET entity_table_length = (SELECT COUNT(*) FROM `vulnerabilities`); + + WHILE i < entity_table_length DO + SET entity_description_translation_id = i + 1; + + SET @entity_id = (SELECT `id` FROM `vulnerabilities` LIMIT 1 OFFSET i); + + SET @query = CONCAT('UPDATE `vulnerabilities` SET `description_translation_id` = ', entity_description_translation_id, ' WHERE `id` = ', @entity_id); + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET i = i + 1; + + IF i = entity_table_length THEN SET @entity_id_for_following_translation = i + 1; + END IF; + END WHILE; + + WHILE j < entity_table_length DO + SET entity_label_translation_id = @entity_id_for_following_translation; + + SET @entity_id = (SELECT `id` FROM `vulnerabilities` LIMIT 1 OFFSET j); + + SET @query = CONCAT('UPDATE `vulnerabilities` SET `label_translation_id` = ', entity_label_translation_id, ' WHERE `id` = ', @entity_id); + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + SET @entity_id_for_following_translation = @entity_id_for_following_translation + 1; + END WHILE; + +END;; +DELIMITER ; + +-- INSTANCES_RISKS_OP +DROP PROCEDURE IF EXISTS fill_instances_risks_op_data; +DELIMITER ;; +CREATE PROCEDURE fill_instances_risks_op_data () + BEGIN + DECLARE i INT DEFAULT 0; + DECLARE j INT DEFAULT 0; + DECLARE entity_table_length INT DEFAULT 0; + DECLARE entity_description_translation_id INT DEFAULT 0; + DECLARE entity_label_translation_id INT DEFAULT 0; + + SET entity_table_length = (SELECT COUNT(*) FROM `instances_risks_op`); + + WHILE i < entity_table_length DO + SET entity_description_translation_id = i + 1; + + SET @entity_id = (SELECT `id` FROM `instances_risks_op` LIMIT 1 OFFSET i); + + SET @query = CONCAT('UPDATE `vulnerabilities` SET `risk_cache_description_translation_id` = ', entity_description_translation_id, ' WHERE `id` = ', @entity_id); + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET i = i + 1; + + IF i = entity_table_length THEN SET @entity_id_for_following_translation = i + 1; + END IF; + END WHILE; + + WHILE j < entity_table_length DO + SET entity_label_translation_id = @entity_id_for_following_translation; + + SET @entity_id = (SELECT `id` FROM `instances_risks_op` LIMIT 1 OFFSET j); + + SET @query = CONCAT('UPDATE `vulnerabilities` SET `risk_cache_label_translation_id` = ', entity_label_translation_id, ' WHERE `id` = ', @entity_id); + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + SET @entity_id_for_following_translation = @entity_id_for_following_translation + 1; + END WHILE; + + END;; +DELIMITER ; + + +-- Call procedures +CALL `fill_anrs_data`; +CALL `fill_assets_data`; +CALL `fill_instances_data`; +CALL `fill_measures_data`; +CALL `fill_objects_data`; +CALL `fill_objects_categories_data`; +CALL `fill_questions_data`; +CALL `fill_questions_choices_data`; +CALL `fill_rolf_risks_data`; +CALL `fill_rolf_tags_data`; +CALL `fill_scales_comments_data`; +CALL `fill_scales_impact_types_data`; +CALL `fill_themes_data`; +CALL `fill_threats_data`; +CALL `fill_vulnerabilities_data`; +CALL `fill_instances_risks_op_data`; \ No newline at end of file diff --git a/db-bootstrap/3_fill translations_tables.sql b/db-bootstrap/3_fill translations_tables.sql index 2292a4a..05cdfb1 100644 --- a/db-bootstrap/3_fill translations_tables.sql +++ b/db-bootstrap/3_fill translations_tables.sql @@ -55,7 +55,7 @@ BEGIN DEALLOCATE PREPARE statement; SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `anrs_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `anrs_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); PREPARE statement FROM @query; EXECUTE statement; DEALLOCATE PREPARE statement; @@ -65,7 +65,7 @@ BEGIN DEALLOCATE PREPARE statement; SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `anrs_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `anrs_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); PREPARE statement FROM @query; EXECUTE statement; DEALLOCATE PREPARE statement; @@ -111,7 +111,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `assets_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `assets_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); PREPARE statement FROM @query; @@ -140,7 +140,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `assets_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `assets_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); PREPARE statement FROM @query; @@ -169,7 +169,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `assets_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `assets_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); PREPARE statement FROM @query; @@ -196,7 +196,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `assets_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `assets_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); PREPARE statement FROM @query; @@ -224,7 +224,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `assets_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `assets_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); PREPARE statement FROM @query; @@ -253,7 +253,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `assets_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `assets_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); PREPARE statement FROM @query; @@ -282,7 +282,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `assets_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `assets_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); PREPARE statement FROM @query; @@ -309,7 +309,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `assets_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `assets_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); PREPARE statement FROM @query; @@ -353,7 +353,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `guides_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `guides_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); PREPARE statement FROM @query; @@ -382,7 +382,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `guides_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `guides_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); PREPARE statement FROM @query; @@ -411,7 +411,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `guides_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `guides_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); PREPARE statement FROM @query; @@ -438,7 +438,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `guides_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `guides_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); PREPARE statement FROM @query; @@ -497,7 +497,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `guides_items_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `guides_items_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); PREPARE statement FROM @query; EXECUTE statement; @@ -543,7 +543,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `measures_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `measures_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); PREPARE statement FROM @query; @@ -572,7 +572,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `measures_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `measures_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); PREPARE statement FROM @query; @@ -601,7 +601,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `measures_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `measures_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); PREPARE statement FROM @query; @@ -628,7 +628,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `measures_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `measures_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); PREPARE statement FROM @query; @@ -696,7 +696,7 @@ BEGIN DEALLOCATE PREPARE statement; SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `models_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `models_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); PREPARE statement FROM @query; EXECUTE statement; DEALLOCATE PREPARE statement; @@ -706,7 +706,7 @@ BEGIN DEALLOCATE PREPARE statement; SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `models_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `models_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); PREPARE statement FROM @query; EXECUTE statement; DEALLOCATE PREPARE statement; @@ -751,7 +751,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `objects_string_id`) VALUES (', @new_translation_id ,',', @current_entity_name_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `objects_string_id`) VALUES (', @new_translation_id ,',', @current_entity_name_id ,')'); PREPARE statement FROM @query; @@ -780,7 +780,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `objects_string_id`) VALUES (', @new_translation_id ,',', @current_entity_name_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `objects_string_id`) VALUES (', @new_translation_id ,',', @current_entity_name_id ,')'); PREPARE statement FROM @query; @@ -809,7 +809,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `objects_string_id`) VALUES (', @new_translation_id ,',', @current_entity_name_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `objects_string_id`) VALUES (', @new_translation_id ,',', @current_entity_name_id ,')'); PREPARE statement FROM @query; @@ -836,7 +836,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `objects_string_id`) VALUES (', @new_translation_id ,',', @current_entity_name_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `objects_string_id`) VALUES (', @new_translation_id ,',', @current_entity_name_id ,')'); PREPARE statement FROM @query; @@ -864,7 +864,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `objects_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `objects_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); PREPARE statement FROM @query; @@ -893,7 +893,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `objects_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `objects_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); PREPARE statement FROM @query; @@ -922,7 +922,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `objects_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `objects_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); PREPARE statement FROM @query; @@ -949,7 +949,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `objects_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `objects_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); PREPARE statement FROM @query; @@ -1010,7 +1010,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `objects_categories_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `objects_categories_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); PREPARE statement FROM @query; EXECUTE statement; @@ -1056,7 +1056,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `questions_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `questions_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); PREPARE statement FROM @query; @@ -1085,7 +1085,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `questions_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `questions_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); PREPARE statement FROM @query; @@ -1114,7 +1114,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `questions_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `questions_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); PREPARE statement FROM @query; @@ -1141,7 +1141,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `questions_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `questions_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); PREPARE statement FROM @query; @@ -1155,6 +1155,135 @@ END;; DELIMITER ; +-- HISTORICALS +DROP PROCEDURE IF EXISTS duplicate_data_historicals; +DELIMITER ;; +CREATE PROCEDURE `duplicate_data_historicals`() + BEGIN + DECLARE i INT DEFAULT 1; + DECLARE j INT DEFAULT 0; + DECLARE iso_from_entity TEXT DEFAULT NULL; + DECLARE entity_table_length INT DEFAULT 0; + + SET entity_table_length = (SELECT COUNT(*) FROM `historicals`); + + SET j = 0; + SET iso_from_entity = 'FR'; + + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM historicals LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM historicals WHERE `id` = @current_entity_id); + + SET @label_content = (SELECT `label1` FROM `historicals` LIMIT 1 OFFSET j); + SET @label_content_replaced = REPLACE(@label_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @label_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `historicals_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + + SET j = 0; + SET iso_from_entity = 'EN'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM historicals LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM historicals WHERE `id` = @current_entity_id); + + SET @label_content = (SELECT `label2` FROM `historicals` LIMIT 1 OFFSET j); + SET @label_content_replaced = REPLACE(@label_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @label_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `historicals_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + + SET j = 0; + SET iso_from_entity = 'DE'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM historicals LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM historicals WHERE `id` = @current_entity_id); + + SET @label_content = (SELECT `label3` FROM `historicals` LIMIT 1 OFFSET j); + SET @label_content_replaced = REPLACE(@label_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @label_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `historicals_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + END WHILE; + + SET j = 0; + SET iso_from_entity = 'NL'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM historicals LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM historicals WHERE `id` = @current_entity_id); + + SET @label_content = (SELECT `label4` FROM `historicals` LIMIT 1 OFFSET j); + SET @label_content_replaced = REPLACE(@label_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @label_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `historicals_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + END;; +DELIMITER ; + + -- QUESTIONS_CHOICES DROP PROCEDURE IF EXISTS duplicate_data_questions_choices; DELIMITER ;; @@ -1201,7 +1330,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `questions_choices_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `questions_choices_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); PREPARE statement FROM @query; EXECUTE statement; @@ -1251,7 +1380,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `rolf_risks_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `rolf_risks_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); PREPARE statement FROM @query; @@ -1285,7 +1414,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `rolf_risks_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `rolf_risks_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); PREPARE statement FROM @query; @@ -1319,7 +1448,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `rolf_risks_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `rolf_risks_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); PREPARE statement FROM @query; @@ -1351,7 +1480,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `rolf_risks_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `rolf_risks_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); PREPARE statement FROM @query; @@ -1383,7 +1512,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `rolf_risks_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `rolf_risks_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); PREPARE statement FROM @query; @@ -1416,7 +1545,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `rolf_risks_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `rolf_risks_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); PREPARE statement FROM @query; @@ -1449,7 +1578,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `rolf_risks_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `rolf_risks_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); PREPARE statement FROM @query; @@ -1480,7 +1609,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `rolf_risks_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `rolf_risks_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); PREPARE statement FROM @query; @@ -1524,7 +1653,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `rolf_tags_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `rolf_tags_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); PREPARE statement FROM @query; @@ -1553,7 +1682,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `rolf_tags_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `rolf_tags_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); PREPARE statement FROM @query; @@ -1582,7 +1711,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `rolf_tags_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `rolf_tags_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); PREPARE statement FROM @query; @@ -1609,7 +1738,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `rolf_tags_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `rolf_tags_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); PREPARE statement FROM @query; @@ -1652,7 +1781,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `scales_comments_string_id`) VALUES (', @new_translation_id ,',', @current_entity_comment_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `scales_comments_string_id`) VALUES (', @new_translation_id ,',', @current_entity_comment_id ,')'); PREPARE statement FROM @query; @@ -1681,7 +1810,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `scales_comments_string_id`) VALUES (', @new_translation_id ,',', @current_entity_comment_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `scales_comments_string_id`) VALUES (', @new_translation_id ,',', @current_entity_comment_id ,')'); PREPARE statement FROM @query; @@ -1710,7 +1839,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `scales_comments_string_id`) VALUES (', @new_translation_id ,',', @current_entity_comment_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `scales_comments_string_id`) VALUES (', @new_translation_id ,',', @current_entity_comment_id ,')'); PREPARE statement FROM @query; @@ -1737,7 +1866,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `scales_comments_string_id`) VALUES (', @new_translation_id ,',', @current_entity_comment_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `scales_comments_string_id`) VALUES (', @new_translation_id ,',', @current_entity_comment_id ,')'); PREPARE statement FROM @query; @@ -1797,7 +1926,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `scales_impact_types_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `scales_impact_types_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); PREPARE statement FROM @query; EXECUTE statement; @@ -1860,7 +1989,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `themes_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `themes_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); PREPARE statement FROM @query; EXECUTE statement; @@ -1906,7 +2035,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `threats_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `threats_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); PREPARE statement FROM @query; @@ -1935,7 +2064,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `threats_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `threats_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); PREPARE statement FROM @query; @@ -1964,7 +2093,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `threats_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `threats_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); PREPARE statement FROM @query; @@ -1991,7 +2120,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `threats_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `threats_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); PREPARE statement FROM @query; @@ -2019,7 +2148,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `threats_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `threats_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); PREPARE statement FROM @query; @@ -2048,7 +2177,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `threats_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `threats_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); PREPARE statement FROM @query; @@ -2077,7 +2206,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `threats_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `threats_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); PREPARE statement FROM @query; @@ -2104,7 +2233,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `threats_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `threats_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); PREPARE statement FROM @query; @@ -2153,7 +2282,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `vulnerabilities_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `vulnerabilities_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); PREPARE statement FROM @query; @@ -2187,7 +2316,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `vulnerabilities_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `vulnerabilities_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); PREPARE statement FROM @query; @@ -2221,7 +2350,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `vulnerabilities_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `vulnerabilities_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); PREPARE statement FROM @query; @@ -2253,7 +2382,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `vulnerabilities_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `vulnerabilities_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); PREPARE statement FROM @query; @@ -2285,7 +2414,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `vulnerabilities_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `vulnerabilities_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); PREPARE statement FROM @query; @@ -2318,7 +2447,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `vulnerabilities_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `vulnerabilities_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); PREPARE statement FROM @query; @@ -2350,7 +2479,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `vulnerabilities_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `vulnerabilities_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); PREPARE statement FROM @query; @@ -2381,7 +2510,7 @@ BEGIN SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); - SET @query = CONCAT('INSERT INTO `translation_language` (`translation_id`, `vulnerabilities_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `vulnerabilities_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); PREPARE statement FROM @query; @@ -2396,6 +2525,286 @@ END;; DELIMITER ; +-- INSTANCES_RISKS_OP +DROP PROCEDURE IF EXISTS duplicate_data_instances_risks_op; +DELIMITER ;; +CREATE PROCEDURE `duplicate_data_instances_risks_op`() + BEGIN + DECLARE i INT DEFAULT 1; + DECLARE j INT DEFAULT 0; + DECLARE iso_from_entity TEXT DEFAULT NULL; + DECLARE entity_table_length INT DEFAULT 0; + + SET entity_table_length = (SELECT COUNT(*) FROM `instances_risks_op`); + + SET j = 0; + SET iso_from_entity = 'FR'; + + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM instances_risks_op LIMIT 1 OFFSET j); + SET @current_entity_description_id = (SELECT `risk_cache_description_translation_id` FROM instances_risks_op WHERE `id` = @current_entity_id); + + SET @description_content = (SELECT `risk_cache_description1` FROM `instances_risks_op` LIMIT 1 OFFSET j); + SET @description_content_replaced = REPLACE(@description_content, "'","''"); + + IF @description_content_replaced IS NULL THEN + SET @query = CONCAT('INSERT INTO `translations`(`ISO`) VALUES (\'', iso_from_entity ,'\')') ; + ELSE + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @description_content_replaced, '\')') ; + END IF; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `instances_risks_ops_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + + SET j = 0; + SET iso_from_entity = 'EN'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM instances_risks_op LIMIT 1 OFFSET j); + SET @current_entity_description_id = (SELECT `risk_cache_description_translation_id` FROM instances_risks_op WHERE `id` = @current_entity_id); + + SET @description_content = (SELECT `risk_cache_description2` FROM `instances_risks_op` LIMIT 1 OFFSET j); + SET @description_content_replaced = REPLACE(@description_content, "'","''"); + + IF @description_content_replaced IS NULL THEN + SET @query = CONCAT('INSERT INTO `translations`(`ISO`) VALUES (\'', iso_from_entity ,'\')') ; + ELSE + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @description_content_replaced, '\')') ; + END IF; + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `instances_risks_ops_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + + END WHILE; + + + SET j = 0; + SET iso_from_entity = 'DE'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM instances_risks_op LIMIT 1 OFFSET j); + SET @current_entity_description_id = (SELECT `risk_cache_description_translation_id` FROM instances_risks_op WHERE `id` = @current_entity_id); + + SET @description_content = (SELECT `risk_cache_description3` FROM `instances_risks_op` LIMIT 1 OFFSET j); + SET @description_content_replaced = REPLACE(@description_content, "'","''"); + + IF @description_content_replaced IS NULL THEN + SET @query = CONCAT('INSERT INTO `translations`(`ISO`) VALUES (\'', iso_from_entity ,'\')') ; + ELSE + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @description_content_replaced, '\')') ; + END IF; + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `instances_risks_ops_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + SET j = 0; + SET iso_from_entity = 'NL'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM instances_risks_op LIMIT 1 OFFSET j); + SET @current_entity_description_id = (SELECT `risk_cache_description_translation_id` FROM instances_risks_op WHERE `id` = @current_entity_id); + + SET @description_content = (SELECT `risk_cache_description4` FROM `instances_risks_op` LIMIT 1 OFFSET j); + SET @description_content_replaced = REPLACE(@description_content, "'","''"); + + IF @description_content_replaced IS NULL THEN + SET @query = CONCAT('INSERT INTO `translations`(`ISO`) VALUES (\'', iso_from_entity ,'\')') ; + ELSE + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @description_content_replaced, '\')') ; + END IF; + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `instances_risks_ops_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + + END WHILE; + + SET j = 0; + SET iso_from_entity = 'FR'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM vulnerabilities LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM instances_risks_op WHERE `id` = @current_entity_id); + + SET @label_content = (SELECT `risk_cache_label1` FROM `instances_risks_op` LIMIT 1 OFFSET j); + SET @label_content_replaced = REPLACE(@label_content, "'","''"); + + IF @label_content_replaced IS NULL THEN + SET @query = CONCAT('INSERT INTO `translations`(`ISO`) VALUES (\'', iso_from_entity ,'\')') ; + ELSE + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @label_content_replaced, '\')') ; + END IF; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `instances_risks_ops_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + + SET j = 0; + SET iso_from_entity = 'EN'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM vulnerabilities LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM instances_risks_op WHERE `id` = @current_entity_id); + + SET @label_content = (SELECT `risk_cache_label2` FROM `instances_risks_op` LIMIT 1 OFFSET j); + SET @label_content_replaced = REPLACE(@label_content, "'","''"); + + IF @label_content_replaced IS NULL THEN + SET @query = CONCAT('INSERT INTO `translations`(`ISO`) VALUES (\'', iso_from_entity ,'\')') ; + ELSE + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @label_content_replaced, '\')') ; + END IF; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `instances_risks_ops_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + SET j = 0; + SET iso_from_entity = 'DE'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM vulnerabilities LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM instances_risks_op WHERE `id` = @current_entity_id); + + SET @label_content = (SELECT `risk_cache_label3` FROM `instances_risks_op` LIMIT 1 OFFSET j); + SET @label_content_replaced = REPLACE(@label_content, "'","''"); + + IF @label_content_replaced IS NULL THEN + SET @query = CONCAT('INSERT INTO `translations`(`ISO`) VALUES (\'', iso_from_entity ,'\')') ; + ELSE + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @label_content_replaced, '\')') ; + END IF; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `instances_risks_ops_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + END WHILE; + + SET j = 0; + SET iso_from_entity = 'NL'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM vulnerabilities LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM instances_risks_op WHERE `id` = @current_entity_id); + + SET @label_content = (SELECT `risk_cache_label4` FROM `instances_risks_op` LIMIT 1 OFFSET j); + SET @label_content_replaced = REPLACE(@label_content, "'","''"); + + IF @label_content_replaced IS NULL THEN + SET @query = CONCAT('INSERT INTO `translations`(`ISO`) VALUES (\'', iso_from_entity ,'\')') ; + ELSE + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @label_content_replaced, '\')') ; + END IF; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `instances_risks_ops_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + END;; +DELIMITER ; + + -- Call procedures that duplicate data CALL `duplicate_data_anrs`; CALL `duplicate_data_assets`; @@ -2414,6 +2823,8 @@ CALL `duplicate_data_scales_impact_types`; CALL `duplicate_data_themes`; CALL `duplicate_data_threats`; CALL `duplicate_data_vulnerabilities`; +CALL `duplicate_data_instances_risks_op`; +CALL `duplicate_data_historicals`; @@ -2438,7 +2849,7 @@ BEGIN ALTER TABLE scales_comments DROP COLUMN comment1, DROP COLUMN comment2, DROP COLUMN comment3, DROP COLUMN comment4; ALTER TABLE scales_impact_types DROP COLUMN label1, DROP COLUMN label2, DROP COLUMN label3, DROP COLUMN label4; ALTER TABLE themes DROP COLUMN label1, DROP COLUMN label2, DROP COLUMN label3, DROP COLUMN label4; - ALTER TABLE threats DROP COLUMN label1, DROP COLUMN label2, DROP COLUMN label3, DROP COLUMN label4; + ALTER TABLE threats DROP COLUMN label1, DROP COLUMN label2, DROP COLUMN label3, DROP COLUMN label4, DROP COLUMN description1, DROP COLUMN description2, DROP COLUMN description3, DROP COLUMN description4; ALTER TABLE rolf_risks DROP COLUMN label1, DROP COLUMN label2, DROP COLUMN label3, DROP COLUMN label4, DROP COLUMN description1, DROP COLUMN description2, DROP COLUMN description3, DROP COLUMN description4; ALTER TABLE vulnerabilities DROP COLUMN label1, DROP COLUMN label2, DROP COLUMN label3, DROP COLUMN label4, DROP COLUMN description1, DROP COLUMN description2, DROP COLUMN description3, DROP COLUMN description4; END;; diff --git a/db-bootstrap/3_fill translations_tables_cli.sql b/db-bootstrap/3_fill translations_tables_cli.sql new file mode 100644 index 0000000..bacad6e --- /dev/null +++ b/db-bootstrap/3_fill translations_tables_cli.sql @@ -0,0 +1,2454 @@ +-- Procedures to fill `translations` and translation_language tables + +-- ANRS +DROP PROCEDURE IF EXISTS duplicate_data_anrs; +DELIMITER ;; +CREATE PROCEDURE duplicate_data_anrs () +BEGIN + DECLARE i INT DEFAULT 1; + DECLARE j INT DEFAULT 0; + DECLARE column_name_label_to_copy TEXT DEFAULT NULL; + DECLARE column_name_description_to_copy TEXT DEFAULT NULL; + DECLARE iso_from_entity TEXT DEFAULT NULL; + DECLARE entity_table_length INT DEFAULT 0; + + SET entity_table_length = (SELECT COUNT(*) FROM `anrs`); + + WHILE i < 5 DO + SET column_name_label_to_copy = CONCAT('label', i); + SET column_name_description_to_copy = CONCAT('description', i); + + CASE + WHEN i = 1 THEN SET iso_from_entity = 'FR'; + WHEN i = 2 THEN SET iso_from_entity = 'EN'; + WHEN i = 3 THEN SET iso_from_entity = 'DE'; + WHEN i = 4 THEN SET iso_from_entity = 'NL'; + ELSE + BEGIN + END; + END CASE; + + SET j = 0; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM anrs LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM anrs WHERE `id` = @current_entity_id); + SET @current_entity_description_id = (SELECT `description_translation_id` FROM anrs WHERE `id` = @current_entity_id); + SET @entity_label_value = ""; + SET @entity_description_value = ""; + + SET @entity_label_value_query = CONCAT('SELECT ', column_name_label_to_copy,' INTO @entity_label_value FROM `anrs` LIMIT 1 OFFSET ', j); + PREPARE statement FROM @entity_label_value_query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @entity_description_value_query = CONCAT('SELECT ', column_name_description_to_copy,' INTO @entity_description_value FROM `anrs` LIMIT 1 OFFSET ', j); + PREPARE statement FROM @entity_description_value_query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @queryLabel = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @entity_label_value, '\')') ; + SET @queryDescription = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @entity_description_value, '\')') ; + + PREPARE statement FROM @queryLabel; + EXECUTE statement; + DEALLOCATE PREPARE statement; + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `anrs_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + PREPARE statement FROM @queryDescription; + EXECUTE statement; + DEALLOCATE PREPARE statement; + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `anrs_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + END WHILE; + + SET i = i + 1; + + END WHILE; + +END;; +DELIMITER ; + + +-- ASSETS +DROP PROCEDURE IF EXISTS duplicate_data_assets; +DELIMITER ;; +CREATE PROCEDURE `duplicate_data_assets`() +BEGIN + DECLARE i INT DEFAULT 1; + DECLARE j INT DEFAULT 0; + DECLARE iso_from_entity TEXT DEFAULT NULL; + DECLARE entity_table_length INT DEFAULT 0; + + SET entity_table_length = (SELECT COUNT(*) FROM `assets`); + + SET j = 0; + SET iso_from_entity = 'FR'; + + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM assets LIMIT 1 OFFSET j); + SET @current_entity_description_id = (SELECT `description_translation_id` FROM assets WHERE `id` = @current_entity_id); + + SET @description_content = (SELECT `description1` FROM `assets` LIMIT 1 OFFSET j); + SET @description_content_replaced = REPLACE(@description_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @description_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `assets_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + + SET j = 0; + SET iso_from_entity = 'EN'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM assets LIMIT 1 OFFSET j); + SET @current_entity_description_id = (SELECT `description_translation_id` FROM assets WHERE `id` = @current_entity_id); + + SET @description_content = (SELECT `description2` FROM `assets` LIMIT 1 OFFSET j); + SET @description_content_replaced = REPLACE(@description_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @description_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `assets_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + + SET j = 0; + SET iso_from_entity = 'DE'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM assets LIMIT 1 OFFSET j); + SET @current_entity_description_id = (SELECT `description_translation_id` FROM assets WHERE `id` = @current_entity_id); + + SET @description_content = (SELECT `description3` FROM `assets` LIMIT 1 OFFSET j); + SET @description_content_replaced = REPLACE(@description_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @description_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `assets_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + END WHILE; + + SET j = 0; + SET iso_from_entity = 'NL'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM assets LIMIT 1 OFFSET j); + SET @current_entity_description_id = (SELECT `description_translation_id` FROM assets WHERE `id` = @current_entity_id); + + SET @description_content = (SELECT `description4` FROM `assets` LIMIT 1 OFFSET j); + SET @description_content_replaced = REPLACE(@description_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @description_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `assets_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + SET j = 0; + SET iso_from_entity = 'FR'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM assets LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM assets WHERE `id` = @current_entity_id); + + SET @label_content = (SELECT `label1` FROM `assets` LIMIT 1 OFFSET j); + SET @label_content_replaced = REPLACE(@label_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @label_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `assets_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + + SET j = 0; + SET iso_from_entity = 'EN'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM assets LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM assets WHERE `id` = @current_entity_id); + + SET @label_content = (SELECT `label2` FROM `assets` LIMIT 1 OFFSET j); + SET @label_content_replaced = REPLACE(@label_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @label_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `assets_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + + SET j = 0; + SET iso_from_entity = 'DE'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM assets LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM assets WHERE `id` = @current_entity_id); + + SET @label_content = (SELECT `label3` FROM `assets` LIMIT 1 OFFSET j); + SET @label_content_replaced = REPLACE(@label_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @label_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `assets_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + END WHILE; + + SET j = 0; + SET iso_from_entity = 'NL'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM assets LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM assets WHERE `id` = @current_entity_id); + + SET @label_content = (SELECT `label4` FROM `assets` LIMIT 1 OFFSET j); + SET @label_content_replaced = REPLACE(@label_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @label_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `assets_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + +END;; +DELIMITER ; + +-- GUIDES +DROP PROCEDURE IF EXISTS duplicate_data_guides; + +-- GUIDES_ITEMS +DROP PROCEDURE IF EXISTS duplicate_data_guides_items; + +-- MEASURES +DROP PROCEDURE IF EXISTS duplicate_data_measures; +DELIMITER ;; +CREATE PROCEDURE `duplicate_data_measures`() +BEGIN + DECLARE i INT DEFAULT 1; + DECLARE j INT DEFAULT 0; + DECLARE iso_from_entity TEXT DEFAULT NULL; + DECLARE entity_table_length INT DEFAULT 0; + + SET entity_table_length = (SELECT COUNT(*) FROM `measures`); + + SET j = 0; + SET iso_from_entity = 'FR'; + + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM measures LIMIT 1 OFFSET j); + SET @current_entity_description_id = (SELECT `description_translation_id` FROM measures WHERE `id` = @current_entity_id); + + SET @description_content = (SELECT `description1` FROM `measures` LIMIT 1 OFFSET j); + SET @description_content_replaced = REPLACE(@description_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @description_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `measures_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + + SET j = 0; + SET iso_from_entity = 'EN'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM measures LIMIT 1 OFFSET j); + SET @current_entity_description_id = (SELECT `description_translation_id` FROM measures WHERE `id` = @current_entity_id); + + SET @description_content = (SELECT `description2` FROM `measures` LIMIT 1 OFFSET j); + SET @description_content_replaced = REPLACE(@description_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @description_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `measures_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + + SET j = 0; + SET iso_from_entity = 'DE'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM measures LIMIT 1 OFFSET j); + SET @current_entity_description_id = (SELECT `description_translation_id` FROM measures WHERE `id` = @current_entity_id); + + SET @description_content = (SELECT `description3` FROM `measures` LIMIT 1 OFFSET j); + SET @description_content_replaced = REPLACE(@description_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @description_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `measures_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + END WHILE; + + SET j = 0; + SET iso_from_entity = 'NL'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM measures LIMIT 1 OFFSET j); + SET @current_entity_description_id = (SELECT `description_translation_id` FROM measures WHERE `id` = @current_entity_id); + + SET @description_content = (SELECT `description4` FROM `measures` LIMIT 1 OFFSET j); + SET @description_content_replaced = REPLACE(@description_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @description_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `measures_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; +END;; +DELIMITER ; + +-- MODELS +DROP PROCEDURE IF EXISTS fill_models_data; + +-- OBJECTS +DROP PROCEDURE IF EXISTS duplicate_data_objects; +DELIMITER ;; +CREATE PROCEDURE `duplicate_data_objects`() +BEGIN + DECLARE i INT DEFAULT 1; + DECLARE j INT DEFAULT 0; + DECLARE iso_from_entity TEXT DEFAULT NULL; + DECLARE entity_table_length INT DEFAULT 0; + + SET entity_table_length = (SELECT COUNT(*) FROM `objects`); + + SET j = 0; + SET iso_from_entity = 'FR'; + + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM objects LIMIT 1 OFFSET j); + SET @current_entity_name_id = (SELECT `name_translation_id` FROM objects WHERE `id` = @current_entity_id); + + SET @name_content = (SELECT `name1` FROM `objects` LIMIT 1 OFFSET j); + SET @name_content_replaced = REPLACE(@name_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @name_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `objects_string_id`) VALUES (', @new_translation_id ,',', @current_entity_name_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + + SET j = 0; + SET iso_from_entity = 'EN'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM objects LIMIT 1 OFFSET j); + SET @current_entity_name_id = (SELECT `name_translation_id` FROM objects WHERE `id` = @current_entity_id); + + SET @name_content = (SELECT `name2` FROM `objects` LIMIT 1 OFFSET j); + SET @name_content_replaced = REPLACE(@name_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @name_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `objects_string_id`) VALUES (', @new_translation_id ,',', @current_entity_name_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + + SET j = 0; + SET iso_from_entity = 'DE'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM objects LIMIT 1 OFFSET j); + SET @current_entity_name_id = (SELECT `name_translation_id` FROM objects WHERE `id` = @current_entity_id); + + SET @name_content = (SELECT `name3` FROM `objects` LIMIT 1 OFFSET j); + SET @name_content_replaced = REPLACE(@name_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @name_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `objects_string_id`) VALUES (', @new_translation_id ,',', @current_entity_name_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + END WHILE; + + SET j = 0; + SET iso_from_entity = 'NL'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM objects LIMIT 1 OFFSET j); + SET @current_entity_name_id = (SELECT `name_translation_id` FROM objects WHERE `id` = @current_entity_id); + + SET @name_content = (SELECT `name4` FROM `objects` LIMIT 1 OFFSET j); + SET @name_content_replaced = REPLACE(@name_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @name_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `objects_string_id`) VALUES (', @new_translation_id ,',', @current_entity_name_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + SET j = 0; + SET iso_from_entity = 'FR'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM objects LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM objects WHERE `id` = @current_entity_id); + + SET @label_content = (SELECT `label1` FROM `objects` LIMIT 1 OFFSET j); + SET @label_content_replaced = REPLACE(@label_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @label_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `objects_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + + SET j = 0; + SET iso_from_entity = 'EN'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM objects LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM objects WHERE `id` = @current_entity_id); + + SET @label_content = (SELECT `label2` FROM `objects` LIMIT 1 OFFSET j); + SET @label_content_replaced = REPLACE(@label_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @label_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `objects_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + + SET j = 0; + SET iso_from_entity = 'DE'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM objects LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM objects WHERE `id` = @current_entity_id); + + SET @label_content = (SELECT `label3` FROM `objects` LIMIT 1 OFFSET j); + SET @label_content_replaced = REPLACE(@label_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @label_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `objects_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + END WHILE; + + SET j = 0; + SET iso_from_entity = 'NL'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM objects LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM objects WHERE `id` = @current_entity_id); + + SET @label_content = (SELECT `label4` FROM `objects` LIMIT 1 OFFSET j); + SET @label_content_replaced = REPLACE(@label_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @label_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `objects_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + +END;; +DELIMITER ; + +-- OBJECTS_CATEGORIES +DROP PROCEDURE IF EXISTS duplicate_data_objects_categories; +DELIMITER ;; +CREATE PROCEDURE duplicate_data_objects_categories () +BEGIN + DECLARE i INT DEFAULT 1; + DECLARE j INT DEFAULT 0; + DECLARE column_name_to_copy TEXT DEFAULT NULL; + DECLARE iso_from_entity TEXT DEFAULT NULL; + DECLARE entity_table_length INT DEFAULT 0; + + SET entity_table_length = (SELECT COUNT(*) FROM `objects_categories`); + + WHILE i < 5 DO + SET column_name_to_copy = CONCAT('label', i); + + CASE + WHEN i = 1 THEN SET iso_from_entity = 'FR'; + WHEN i = 2 THEN SET iso_from_entity = 'EN'; + WHEN i = 3 THEN SET iso_from_entity = 'DE'; + WHEN i = 4 THEN SET iso_from_entity = 'NL'; + ELSE + BEGIN + END; + END CASE; + + SET j = 0; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM objects_categories LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM objects_categories WHERE `id` = @current_entity_id); + SET @entity_label_value = ""; + + SET @entity_label_value_query = CONCAT('SELECT ', column_name_to_copy,' INTO @entity_label_value FROM `objects_categories` LIMIT 1 OFFSET ', j); + PREPARE statement FROM @entity_label_value_query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @entity_label_value, '\')') ; + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `objects_categories_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + END WHILE; + + SET i = i + 1; + + END WHILE; + +END;; +DELIMITER ; + +-- QUESTIONS +DROP PROCEDURE IF EXISTS duplicate_data_questions; +DELIMITER ;; +CREATE PROCEDURE `duplicate_data_questions`() +BEGIN + DECLARE i INT DEFAULT 1; + DECLARE j INT DEFAULT 0; + DECLARE iso_from_entity TEXT DEFAULT NULL; + DECLARE entity_table_length INT DEFAULT 0; + + SET entity_table_length = (SELECT COUNT(*) FROM `questions`); + + SET j = 0; + SET iso_from_entity = 'FR'; + + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM questions LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM questions WHERE `id` = @current_entity_id); + + SET @label_content = (SELECT `label1` FROM `questions` LIMIT 1 OFFSET j); + SET @label_content_replaced = REPLACE(@label_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @label_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `questions_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + + SET j = 0; + SET iso_from_entity = 'EN'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM questions LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM questions WHERE `id` = @current_entity_id); + + SET @label_content = (SELECT `label2` FROM `questions` LIMIT 1 OFFSET j); + SET @label_content_replaced = REPLACE(@label_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @label_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `questions_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + + SET j = 0; + SET iso_from_entity = 'DE'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM questions LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM questions WHERE `id` = @current_entity_id); + + SET @label_content = (SELECT `label3` FROM `questions` LIMIT 1 OFFSET j); + SET @label_content_replaced = REPLACE(@label_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @label_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `questions_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + END WHILE; + + SET j = 0; + SET iso_from_entity = 'NL'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM questions LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM questions WHERE `id` = @current_entity_id); + + SET @label_content = (SELECT `label4` FROM `questions` LIMIT 1 OFFSET j); + SET @label_content_replaced = REPLACE(@label_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @label_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `questions_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; +END;; +DELIMITER ; + +-- QUESTIONS_CHOICES +DROP PROCEDURE IF EXISTS duplicate_data_questions_choices; +DELIMITER ;; +CREATE PROCEDURE duplicate_data_questions_choices () +BEGIN + DECLARE i INT DEFAULT 1; + DECLARE j INT DEFAULT 0; + DECLARE column_name_to_copy TEXT DEFAULT NULL; + DECLARE iso_from_entity TEXT DEFAULT NULL; + DECLARE entity_table_length INT DEFAULT 0; + + SET entity_table_length = (SELECT COUNT(*) FROM `questions_choices`); + + WHILE i < 5 DO + SET column_name_to_copy = CONCAT('label', i); + + CASE + WHEN i = 1 THEN SET iso_from_entity = 'FR'; + WHEN i = 2 THEN SET iso_from_entity = 'EN'; + WHEN i = 3 THEN SET iso_from_entity = 'DE'; + WHEN i = 4 THEN SET iso_from_entity = 'NL'; + ELSE + BEGIN + END; + END CASE; + + SET j = 0; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM questions_choices LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM questions_choices WHERE `id` = @current_entity_id); + SET @entity_label_value = ""; + + SET @entity_label_value_query = CONCAT('SELECT ', column_name_to_copy,' INTO @entity_label_value FROM `questions_choices` LIMIT 1 OFFSET ', j); + PREPARE statement FROM @entity_label_value_query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @entity_label_value, '\')') ; + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `questions_choices_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + END WHILE; + + SET i = i + 1; + + END WHILE; + +END;; +DELIMITER ; + +-- ROLF_RISKS +DROP PROCEDURE IF EXISTS duplicate_data_rolf_risks; +DELIMITER ;; +CREATE PROCEDURE `duplicate_data_rolf_risks`() +BEGIN + DECLARE i INT DEFAULT 1; + DECLARE j INT DEFAULT 0; + DECLARE iso_from_entity TEXT DEFAULT NULL; + DECLARE entity_table_length INT DEFAULT 0; + + SET entity_table_length = (SELECT COUNT(*) FROM `rolf_risks`); + + SET j = 0; + SET iso_from_entity = 'FR'; + + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM rolf_risks LIMIT 1 OFFSET j); + SET @current_entity_description_id = (SELECT `description_translation_id` FROM rolf_risks WHERE `id` = @current_entity_id); + + SET @description_content = (SELECT `description1` FROM `rolf_risks` LIMIT 1 OFFSET j); + SET @description_content_replaced = REPLACE(@description_content, "'","''"); + + IF @description_content_replaced IS NULL THEN + SET @query = CONCAT('INSERT INTO `translations`(`ISO`) VALUES (\'', iso_from_entity ,'\')') ; + ELSE + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @description_content_replaced, '\')') ; + END IF; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `rolf_risks_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + + SET j = 0; + SET iso_from_entity = 'EN'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM rolf_risks LIMIT 1 OFFSET j); + SET @current_entity_description_id = (SELECT `description_translation_id` FROM rolf_risks WHERE `id` = @current_entity_id); + + SET @description_content = (SELECT `description2` FROM `rolf_risks` LIMIT 1 OFFSET j); + SET @description_content_replaced = REPLACE(@description_content, "'","''"); + + IF @description_content_replaced IS NULL THEN + SET @query = CONCAT('INSERT INTO `translations`(`ISO`) VALUES (\'', iso_from_entity ,'\')') ; + ELSE + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @description_content_replaced, '\')') ; + END IF; + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `rolf_risks_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + + SET j = 0; + SET iso_from_entity = 'DE'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM rolf_risks LIMIT 1 OFFSET j); + SET @current_entity_description_id = (SELECT `description_translation_id` FROM rolf_risks WHERE `id` = @current_entity_id); + + SET @description_content = (SELECT `description3` FROM `rolf_risks` LIMIT 1 OFFSET j); + SET @description_content_replaced = REPLACE(@description_content, "'","''"); + + IF @description_content_replaced IS NULL THEN + SET @query = CONCAT('INSERT INTO `translations`(`ISO`) VALUES (\'', iso_from_entity ,'\')') ; + ELSE + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @description_content_replaced, '\')') ; + END IF; + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `rolf_risks_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + END WHILE; + + SET j = 0; + SET iso_from_entity = 'NL'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM rolf_risks LIMIT 1 OFFSET j); + SET @current_entity_description_id = (SELECT `description_translation_id` FROM rolf_risks WHERE `id` = @current_entity_id); + + SET @description_content = (SELECT `description4` FROM `rolf_risks` LIMIT 1 OFFSET j); + SET @description_content_replaced = REPLACE(@description_content, "'","''"); + + IF @description_content_replaced IS NULL THEN + SET @query = CONCAT('INSERT INTO `translations`(`ISO`) VALUES (\'', iso_from_entity ,'\')') ; + ELSE + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @description_content_replaced, '\')') ; + END IF; + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `rolf_risks_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + SET j = 0; + SET iso_from_entity = 'FR'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM rolf_risks LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM rolf_risks WHERE `id` = @current_entity_id); + + SET @label_content = (SELECT `label1` FROM `rolf_risks` LIMIT 1 OFFSET j); + SET @label_content_replaced = REPLACE(@label_content, "'","''"); + + IF @label_content_replaced IS NULL THEN + SET @query = CONCAT('INSERT INTO `translations`(`ISO`) VALUES (\'', iso_from_entity ,'\')') ; + ELSE + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @label_content_replaced, '\')') ; + END IF; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `rolf_risks_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + + SET j = 0; + SET iso_from_entity = 'EN'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM rolf_risks LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM rolf_risks WHERE `id` = @current_entity_id); + + SET @label_content = (SELECT `label2` FROM `rolf_risks` LIMIT 1 OFFSET j); + SET @label_content_replaced = REPLACE(@label_content, "'","''"); + + IF @label_content_replaced IS NULL THEN + SET @query = CONCAT('INSERT INTO `translations`(`ISO`) VALUES (\'', iso_from_entity ,'\')') ; + ELSE + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @label_content_replaced, '\')') ; + END IF; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `rolf_risks_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + + SET j = 0; + SET iso_from_entity = 'DE'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM rolf_risks LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM rolf_risks WHERE `id` = @current_entity_id); + + SET @label_content = (SELECT `label3` FROM `rolf_risks` LIMIT 1 OFFSET j); + SET @label_content_replaced = REPLACE(@label_content, "'","''"); + + IF @label_content_replaced IS NULL THEN + SET @query = CONCAT('INSERT INTO `translations`(`ISO`) VALUES (\'', iso_from_entity ,'\')') ; + ELSE + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @label_content_replaced, '\')') ; + END IF; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `rolf_risks_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + END WHILE; + + SET j = 0; + SET iso_from_entity = 'NL'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM rolf_risks LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM rolf_risks WHERE `id` = @current_entity_id); + + SET @label_content = (SELECT `label4` FROM `rolf_risks` LIMIT 1 OFFSET j); + SET @label_content_replaced = REPLACE(@label_content, "'","''"); + + IF @label_content_replaced IS NULL THEN + SET @query = CONCAT('INSERT INTO `translations`(`ISO`) VALUES (\'', iso_from_entity ,'\')') ; + ELSE + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @label_content_replaced, '\')') ; + END IF; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `rolf_risks_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + +END;; +DELIMITER ; + +-- ROLF_TAGS +DROP PROCEDURE IF EXISTS duplicate_data_rolf_tags; +DELIMITER ;; +CREATE PROCEDURE `duplicate_data_rolf_tags`() +BEGIN + DECLARE i INT DEFAULT 1; + DECLARE j INT DEFAULT 0; + DECLARE iso_from_entity TEXT DEFAULT NULL; + DECLARE entity_table_length INT DEFAULT 0; + + SET entity_table_length = (SELECT COUNT(*) FROM `rolf_tags`); + + SET j = 0; + SET iso_from_entity = 'FR'; + + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM rolf_tags LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM rolf_tags WHERE `id` = @current_entity_id); + + SET @label_content = (SELECT `label1` FROM `rolf_tags` LIMIT 1 OFFSET j); + SET @label_content_replaced = REPLACE(@label_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @label_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `rolf_tags_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + + SET j = 0; + SET iso_from_entity = 'EN'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM rolf_tags LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM rolf_tags WHERE `id` = @current_entity_id); + + SET @label_content = (SELECT `label2` FROM `rolf_tags` LIMIT 1 OFFSET j); + SET @label_content_replaced = REPLACE(@label_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @label_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `rolf_tags_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + + SET j = 0; + SET iso_from_entity = 'DE'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM rolf_tags LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM rolf_tags WHERE `id` = @current_entity_id); + + SET @label_content = (SELECT `label3` FROM `rolf_tags` LIMIT 1 OFFSET j); + SET @label_content_replaced = REPLACE(@label_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @label_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `rolf_tags_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + END WHILE; + + SET j = 0; + SET iso_from_entity = 'NL'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM rolf_tags LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM rolf_tags WHERE `id` = @current_entity_id); + + SET @label_content = (SELECT `label4` FROM `rolf_tags` LIMIT 1 OFFSET j); + SET @label_content_replaced = REPLACE(@label_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @label_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `rolf_tags_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; +END;; +DELIMITER ; + +-- SCALES_COMMENTS +DROP PROCEDURE IF EXISTS duplicate_data_scales_comments; +DELIMITER ;; +CREATE PROCEDURE `duplicate_data_scales_comments`() +BEGIN + DECLARE i INT DEFAULT 1; + DECLARE j INT DEFAULT 0; + DECLARE iso_from_entity TEXT DEFAULT NULL; + DECLARE entity_table_length INT DEFAULT 0; + + SET entity_table_length = (SELECT COUNT(*) FROM `scales_comments`); + + SET j = 0; + SET iso_from_entity = 'FR'; + + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM scales_comments LIMIT 1 OFFSET j); + SET @current_entity_comment_id = (SELECT `comment_translation_id` FROM scales_comments WHERE `id` = @current_entity_id); + + SET @comment_content = (SELECT `comment1` FROM `scales_comments` LIMIT 1 OFFSET j); + SET @comment_content_replaced = REPLACE(@comment_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @comment_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `scales_comments_string_id`) VALUES (', @new_translation_id ,',', @current_entity_comment_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + + SET j = 0; + SET iso_from_entity = 'EN'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM scales_comments LIMIT 1 OFFSET j); + SET @current_entity_comment_id = (SELECT `comment_translation_id` FROM scales_comments WHERE `id` = @current_entity_id); + + SET @comment_content = (SELECT `comment2` FROM `scales_comments` LIMIT 1 OFFSET j); + SET @comment_content_replaced = REPLACE(@comment_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @comment_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `scales_comments_string_id`) VALUES (', @new_translation_id ,',', @current_entity_comment_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + + SET j = 0; + SET iso_from_entity = 'DE'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM scales_comments LIMIT 1 OFFSET j); + SET @current_entity_comment_id = (SELECT `comment_translation_id` FROM scales_comments WHERE `id` = @current_entity_id); + + SET @comment_content = (SELECT `comment3` FROM `scales_comments` LIMIT 1 OFFSET j); + SET @comment_content_replaced = REPLACE(@comment_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @comment_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `scales_comments_string_id`) VALUES (', @new_translation_id ,',', @current_entity_comment_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + END WHILE; + + SET j = 0; + SET iso_from_entity = 'NL'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM scales_comments LIMIT 1 OFFSET j); + SET @current_entity_comment_id = (SELECT `comment_translation_id` FROM scales_comments WHERE `id` = @current_entity_id); + + SET @comment_content = (SELECT `comment4` FROM `scales_comments` LIMIT 1 OFFSET j); + SET @comment_content_replaced = REPLACE(@comment_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @comment_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `scales_comments_string_id`) VALUES (', @new_translation_id ,',', @current_entity_comment_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; +END;; +DELIMITER ; + +-- SCALES_IMPACT_TYPES +DROP PROCEDURE IF EXISTS duplicate_data_scales_impact_types; +DELIMITER ;; +CREATE PROCEDURE duplicate_data_scales_impact_types () +BEGIN + DECLARE i INT DEFAULT 1; + DECLARE j INT DEFAULT 0; + DECLARE column_name_to_copy TEXT DEFAULT NULL; + DECLARE iso_from_entity TEXT DEFAULT NULL; + DECLARE entity_table_length INT DEFAULT 0; + + SET entity_table_length = (SELECT COUNT(*) FROM `scales_impact_types`); + + WHILE i < 5 DO + SET column_name_to_copy = CONCAT('label', i); + + CASE + WHEN i = 1 THEN SET iso_from_entity = 'FR'; + WHEN i = 2 THEN SET iso_from_entity = 'EN'; + WHEN i = 3 THEN SET iso_from_entity = 'DE'; + WHEN i = 4 THEN SET iso_from_entity = 'NL'; + ELSE + BEGIN + END; + END CASE; + + SET j = 0; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM scales_impact_types LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM scales_impact_types WHERE `id` = @current_entity_id); + SET @entity_label_value = ""; + + SET @entity_label_value_query = CONCAT('SELECT ', column_name_to_copy,' INTO @entity_label_value FROM `scales_impact_types` LIMIT 1 OFFSET ', j); + PREPARE statement FROM @entity_label_value_query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @entity_label_value, '\')') ; + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `scales_impact_types_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + END WHILE; + + SET i = i + 1; + + END WHILE; + +END;; +DELIMITER ; + +-- THEMES +DROP PROCEDURE IF EXISTS duplicate_data_themes; +DELIMITER ;; +CREATE PROCEDURE duplicate_data_themes () +BEGIN + DECLARE i INT DEFAULT 1; + DECLARE j INT DEFAULT 0; + DECLARE column_name_to_copy TEXT DEFAULT NULL; + DECLARE iso_from_entity TEXT DEFAULT NULL; + DECLARE entity_table_length INT DEFAULT 0; + + SET entity_table_length = (SELECT COUNT(*) FROM `themes`); + + WHILE i < 5 DO + SET column_name_to_copy = CONCAT('label', i); + + CASE + WHEN i = 1 THEN SET iso_from_entity = 'FR'; + WHEN i = 2 THEN SET iso_from_entity = 'EN'; + WHEN i = 3 THEN SET iso_from_entity = 'DE'; + WHEN i = 4 THEN SET iso_from_entity = 'NL'; + ELSE + BEGIN + END; + END CASE; + + SET j = 0; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM themes LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM themes WHERE `id` = @current_entity_id); + SET @entity_label_value = ""; + + SET @entity_label_value_query = CONCAT('SELECT ', column_name_to_copy,' INTO @entity_label_value FROM `themes` LIMIT 1 OFFSET ', j); + PREPARE statement FROM @entity_label_value_query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @entity_label_value, '\')') ; + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `themes_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + END WHILE; + + SET i = i + 1; + + END WHILE; + +END;; +DELIMITER ; + +-- THREATS +DROP PROCEDURE IF EXISTS duplicate_data_threats; +DELIMITER ;; +CREATE PROCEDURE `duplicate_data_threats`() +BEGIN + DECLARE i INT DEFAULT 1; + DECLARE j INT DEFAULT 0; + DECLARE iso_from_entity TEXT DEFAULT NULL; + DECLARE entity_table_length INT DEFAULT 0; + + SET entity_table_length = (SELECT COUNT(*) FROM `threats`); + + SET j = 0; + SET iso_from_entity = 'FR'; + + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM threats LIMIT 1 OFFSET j); + SET @current_entity_description_id = (SELECT `description_translation_id` FROM threats WHERE `id` = @current_entity_id); + + SET @description_content = (SELECT `description1` FROM `threats` LIMIT 1 OFFSET j); + SET @description_content_replaced = REPLACE(@description_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @description_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `threats_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + + SET j = 0; + SET iso_from_entity = 'EN'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM threats LIMIT 1 OFFSET j); + SET @current_entity_description_id = (SELECT `description_translation_id` FROM threats WHERE `id` = @current_entity_id); + + SET @description_content = (SELECT `description2` FROM `threats` LIMIT 1 OFFSET j); + SET @description_content_replaced = REPLACE(@description_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @description_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `threats_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + + SET j = 0; + SET iso_from_entity = 'DE'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM threats LIMIT 1 OFFSET j); + SET @current_entity_description_id = (SELECT `description_translation_id` FROM threats WHERE `id` = @current_entity_id); + + SET @description_content = (SELECT `description3` FROM `threats` LIMIT 1 OFFSET j); + SET @description_content_replaced = REPLACE(@description_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @description_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `threats_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + END WHILE; + + SET j = 0; + SET iso_from_entity = 'NL'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM threats LIMIT 1 OFFSET j); + SET @current_entity_description_id = (SELECT `description_translation_id` FROM threats WHERE `id` = @current_entity_id); + + SET @description_content = (SELECT `description4` FROM `threats` LIMIT 1 OFFSET j); + SET @description_content_replaced = REPLACE(@description_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @description_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `threats_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + SET j = 0; + SET iso_from_entity = 'FR'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM threats LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM threats WHERE `id` = @current_entity_id); + + SET @label_content = (SELECT `label1` FROM `threats` LIMIT 1 OFFSET j); + SET @label_content_replaced = REPLACE(@label_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @label_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `threats_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + + SET j = 0; + SET iso_from_entity = 'EN'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM threats LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM threats WHERE `id` = @current_entity_id); + + SET @label_content = (SELECT `label2` FROM `threats` LIMIT 1 OFFSET j); + SET @label_content_replaced = REPLACE(@label_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @label_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `threats_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + + SET j = 0; + SET iso_from_entity = 'DE'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM threats LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM threats WHERE `id` = @current_entity_id); + + SET @label_content = (SELECT `label3` FROM `threats` LIMIT 1 OFFSET j); + SET @label_content_replaced = REPLACE(@label_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @label_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `threats_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + END WHILE; + + SET j = 0; + SET iso_from_entity = 'NL'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM threats LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM threats WHERE `id` = @current_entity_id); + + SET @label_content = (SELECT `label4` FROM `threats` LIMIT 1 OFFSET j); + SET @label_content_replaced = REPLACE(@label_content, "'","''"); + + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @label_content_replaced, '\')') ; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `threats_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + +END;; +DELIMITER ; + +-- VULNERABILITIES +DROP PROCEDURE IF EXISTS duplicate_data_vulnerabilities; +DELIMITER ;; +CREATE PROCEDURE `duplicate_data_vulnerabilities`() +BEGIN + DECLARE i INT DEFAULT 1; + DECLARE j INT DEFAULT 0; + DECLARE iso_from_entity TEXT DEFAULT NULL; + DECLARE entity_table_length INT DEFAULT 0; + + SET entity_table_length = (SELECT COUNT(*) FROM `vulnerabilities`); + + SET j = 0; + SET iso_from_entity = 'FR'; + + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM vulnerabilities LIMIT 1 OFFSET j); + SET @current_entity_description_id = (SELECT `description_translation_id` FROM vulnerabilities WHERE `id` = @current_entity_id); + + SET @description_content = (SELECT `description1` FROM `vulnerabilities` LIMIT 1 OFFSET j); + SET @description_content_replaced = REPLACE(@description_content, "'","''"); + + IF @description_content_replaced IS NULL THEN + SET @query = CONCAT('INSERT INTO `translations`(`ISO`) VALUES (\'', iso_from_entity ,'\')') ; + ELSE + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @description_content_replaced, '\')') ; + END IF; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `vulnerabilities_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + + SET j = 0; + SET iso_from_entity = 'EN'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM vulnerabilities LIMIT 1 OFFSET j); + SET @current_entity_description_id = (SELECT `description_translation_id` FROM vulnerabilities WHERE `id` = @current_entity_id); + + SET @description_content = (SELECT `description2` FROM `vulnerabilities` LIMIT 1 OFFSET j); + SET @description_content_replaced = REPLACE(@description_content, "'","''"); + + IF @description_content_replaced IS NULL THEN + SET @query = CONCAT('INSERT INTO `translations`(`ISO`) VALUES (\'', iso_from_entity ,'\')') ; + ELSE + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @description_content_replaced, '\')') ; + END IF; + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `vulnerabilities_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + + SET j = 0; + SET iso_from_entity = 'DE'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM vulnerabilities LIMIT 1 OFFSET j); + SET @current_entity_description_id = (SELECT `description_translation_id` FROM vulnerabilities WHERE `id` = @current_entity_id); + + SET @description_content = (SELECT `description3` FROM `vulnerabilities` LIMIT 1 OFFSET j); + SET @description_content_replaced = REPLACE(@description_content, "'","''"); + + IF @description_content_replaced IS NULL THEN + SET @query = CONCAT('INSERT INTO `translations`(`ISO`) VALUES (\'', iso_from_entity ,'\')') ; + ELSE + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @description_content_replaced, '\')') ; + END IF; + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `vulnerabilities_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + END WHILE; + + SET j = 0; + SET iso_from_entity = 'NL'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM vulnerabilities LIMIT 1 OFFSET j); + SET @current_entity_description_id = (SELECT `description_translation_id` FROM vulnerabilities WHERE `id` = @current_entity_id); + + SET @description_content = (SELECT `description4` FROM `vulnerabilities` LIMIT 1 OFFSET j); + SET @description_content_replaced = REPLACE(@description_content, "'","''"); + + IF @description_content_replaced IS NULL THEN + SET @query = CONCAT('INSERT INTO `translations`(`ISO`) VALUES (\'', iso_from_entity ,'\')') ; + ELSE + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @description_content_replaced, '\')') ; + END IF; + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `vulnerabilities_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + SET j = 0; + SET iso_from_entity = 'FR'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM vulnerabilities LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM vulnerabilities WHERE `id` = @current_entity_id); + + SET @label_content = (SELECT `label1` FROM `vulnerabilities` LIMIT 1 OFFSET j); + SET @label_content_replaced = REPLACE(@label_content, "'","''"); + + IF @label_content_replaced IS NULL THEN + SET @query = CONCAT('INSERT INTO `translations`(`ISO`) VALUES (\'', iso_from_entity ,'\')') ; + ELSE + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @label_content_replaced, '\')') ; + END IF; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `vulnerabilities_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + + SET j = 0; + SET iso_from_entity = 'EN'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM vulnerabilities LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM vulnerabilities WHERE `id` = @current_entity_id); + + SET @label_content = (SELECT `label2` FROM `vulnerabilities` LIMIT 1 OFFSET j); + SET @label_content_replaced = REPLACE(@label_content, "'","''"); + + IF @label_content_replaced IS NULL THEN + SET @query = CONCAT('INSERT INTO `translations`(`ISO`) VALUES (\'', iso_from_entity ,'\')') ; + ELSE + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @label_content_replaced, '\')') ; + END IF; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `vulnerabilities_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + SET j = 0; + SET iso_from_entity = 'DE'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM vulnerabilities LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM vulnerabilities WHERE `id` = @current_entity_id); + + SET @label_content = (SELECT `label3` FROM `vulnerabilities` LIMIT 1 OFFSET j); + SET @label_content_replaced = REPLACE(@label_content, "'","''"); + + IF @label_content_replaced IS NULL THEN + SET @query = CONCAT('INSERT INTO `translations`(`ISO`) VALUES (\'', iso_from_entity ,'\')') ; + ELSE + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @label_content_replaced, '\')') ; + END IF; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `vulnerabilities_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + END WHILE; + + SET j = 0; + SET iso_from_entity = 'NL'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM vulnerabilities LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM vulnerabilities WHERE `id` = @current_entity_id); + + SET @label_content = (SELECT `label4` FROM `vulnerabilities` LIMIT 1 OFFSET j); + SET @label_content_replaced = REPLACE(@label_content, "'","''"); + + IF @label_content_replaced IS NULL THEN + SET @query = CONCAT('INSERT INTO `translations`(`ISO`) VALUES (\'', iso_from_entity ,'\')') ; + ELSE + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @label_content_replaced, '\')') ; + END IF; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `vulnerabilities_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + +END;; +DELIMITER ; + + +-- INSTANCES_RISKS_OP +DROP PROCEDURE IF EXISTS duplicate_data_instances_risks_op; +DELIMITER ;; +CREATE PROCEDURE `duplicate_data_instances_risks_op`() + BEGIN + DECLARE i INT DEFAULT 1; + DECLARE j INT DEFAULT 0; + DECLARE iso_from_entity TEXT DEFAULT NULL; + DECLARE entity_table_length INT DEFAULT 0; + + SET entity_table_length = (SELECT COUNT(*) FROM `instances_risks_op`); + + SET j = 0; + SET iso_from_entity = 'FR'; + + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM instances_risks_op LIMIT 1 OFFSET j); + SET @current_entity_description_id = (SELECT `risk_cache_description_translation_id` FROM instances_risks_op WHERE `id` = @current_entity_id); + + SET @description_content = (SELECT `risk_cache_description1` FROM `instances_risks_op` LIMIT 1 OFFSET j); + SET @description_content_replaced = REPLACE(@description_content, "'","''"); + + IF @description_content_replaced IS NULL THEN + SET @query = CONCAT('INSERT INTO `translations`(`ISO`) VALUES (\'', iso_from_entity ,'\')') ; + ELSE + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @description_content_replaced, '\')') ; + END IF; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `instances_risks_ops_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + + SET j = 0; + SET iso_from_entity = 'EN'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM instances_risks_op LIMIT 1 OFFSET j); + SET @current_entity_description_id = (SELECT `risk_cache_description_translation_id` FROM instances_risks_op WHERE `id` = @current_entity_id); + + SET @description_content = (SELECT `risk_cache_description2` FROM `instances_risks_op` LIMIT 1 OFFSET j); + SET @description_content_replaced = REPLACE(@description_content, "'","''"); + + IF @description_content_replaced IS NULL THEN + SET @query = CONCAT('INSERT INTO `translations`(`ISO`) VALUES (\'', iso_from_entity ,'\')') ; + ELSE + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @description_content_replaced, '\')') ; + END IF; + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `instances_risks_ops_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + + END WHILE; + + + SET j = 0; + SET iso_from_entity = 'DE'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM instances_risks_op LIMIT 1 OFFSET j); + SET @current_entity_description_id = (SELECT `risk_cache_description_translation_id` FROM instances_risks_op WHERE `id` = @current_entity_id); + + SET @description_content = (SELECT `risk_cache_description3` FROM `instances_risks_op` LIMIT 1 OFFSET j); + SET @description_content_replaced = REPLACE(@description_content, "'","''"); + + IF @description_content_replaced IS NULL THEN + SET @query = CONCAT('INSERT INTO `translations`(`ISO`) VALUES (\'', iso_from_entity ,'\')') ; + ELSE + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @description_content_replaced, '\')') ; + END IF; + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `instances_risks_ops_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + SET j = 0; + SET iso_from_entity = 'NL'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM instances_risks_op LIMIT 1 OFFSET j); + SET @current_entity_description_id = (SELECT `risk_cache_description_translation_id` FROM instances_risks_op WHERE `id` = @current_entity_id); + + SET @description_content = (SELECT `risk_cache_description4` FROM `instances_risks_op` LIMIT 1 OFFSET j); + SET @description_content_replaced = REPLACE(@description_content, "'","''"); + + IF @description_content_replaced IS NULL THEN + SET @query = CONCAT('INSERT INTO `translations`(`ISO`) VALUES (\'', iso_from_entity ,'\')') ; + ELSE + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @description_content_replaced, '\')') ; + END IF; + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `instances_risks_ops_string_id`) VALUES (', @new_translation_id ,',', @current_entity_description_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + + END WHILE; + + SET j = 0; + SET iso_from_entity = 'FR'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM vulnerabilities LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM instances_risks_op WHERE `id` = @current_entity_id); + + SET @label_content = (SELECT `risk_cache_label1` FROM `instances_risks_op` LIMIT 1 OFFSET j); + SET @label_content_replaced = REPLACE(@label_content, "'","''"); + + IF @label_content_replaced IS NULL THEN + SET @query = CONCAT('INSERT INTO `translations`(`ISO`) VALUES (\'', iso_from_entity ,'\')') ; + ELSE + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @label_content_replaced, '\')') ; + END IF; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `instances_risks_ops_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + + SET j = 0; + SET iso_from_entity = 'EN'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM vulnerabilities LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM instances_risks_op WHERE `id` = @current_entity_id); + + SET @label_content = (SELECT `risk_cache_label2` FROM `instances_risks_op` LIMIT 1 OFFSET j); + SET @label_content_replaced = REPLACE(@label_content, "'","''"); + + IF @label_content_replaced IS NULL THEN + SET @query = CONCAT('INSERT INTO `translations`(`ISO`) VALUES (\'', iso_from_entity ,'\')') ; + ELSE + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @label_content_replaced, '\')') ; + END IF; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `instances_risks_ops_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + SET j = 0; + SET iso_from_entity = 'DE'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM vulnerabilities LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM instances_risks_op WHERE `id` = @current_entity_id); + + SET @label_content = (SELECT `risk_cache_label3` FROM `instances_risks_op` LIMIT 1 OFFSET j); + SET @label_content_replaced = REPLACE(@label_content, "'","''"); + + IF @label_content_replaced IS NULL THEN + SET @query = CONCAT('INSERT INTO `translations`(`ISO`) VALUES (\'', iso_from_entity ,'\')') ; + ELSE + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @label_content_replaced, '\')') ; + END IF; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `instances_risks_ops_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + END WHILE; + + SET j = 0; + SET iso_from_entity = 'NL'; + WHILE j < entity_table_length DO + + SET @current_entity_id = (SELECT `id` FROM vulnerabilities LIMIT 1 OFFSET j); + SET @current_entity_label_id = (SELECT `label_translation_id` FROM instances_risks_op WHERE `id` = @current_entity_id); + + SET @label_content = (SELECT `risk_cache_label4` FROM `instances_risks_op` LIMIT 1 OFFSET j); + SET @label_content_replaced = REPLACE(@label_content, "'","''"); + + IF @label_content_replaced IS NULL THEN + SET @query = CONCAT('INSERT INTO `translations`(`ISO`) VALUES (\'', iso_from_entity ,'\')') ; + ELSE + SET @query = CONCAT('INSERT INTO `translations`(`ISO`, `content`) VALUES (\'', iso_from_entity ,'\',\'', @label_content_replaced, '\')') ; + END IF; + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET @new_translation_id = (SELECT `id` FROM `translations` ORDER BY `id` DESC LIMIT 1); + + SET @query = CONCAT('INSERT INTO `translation_languages` (`translation_id`, `instances_risks_ops_string_id`) VALUES (', @new_translation_id ,',', @current_entity_label_id ,')'); + + + PREPARE statement FROM @query; + EXECUTE statement; + DEALLOCATE PREPARE statement; + + SET j = j + 1; + + END WHILE; + + END;; +DELIMITER ; + +-- Call procedures that duplicate data +CALL `duplicate_data_anrs`; +CALL `duplicate_data_assets`; +CALL `duplicate_data_measures`; +CALL `duplicate_data_objects`; +CALL `duplicate_data_objects_categories`; +CALL `duplicate_data_questions`; +CALL `duplicate_data_questions_choices`; +CALL `duplicate_data_rolf_risks`; +CALL `duplicate_data_rolf_tags`; +CALL `duplicate_data_scales_comments`; +CALL `duplicate_data_scales_impact_types`; +CALL `duplicate_data_themes`; +CALL `duplicate_data_threats`; +CALL `duplicate_data_vulnerabilities`; +CALL `duplicate_data_instances_risks_op`; + + +-- Procedure to delete old hard-codded translations columns in tables +DROP PROCEDURE IF EXISTS delete_old_translation_columns; +DELIMITER ;; +CREATE PROCEDURE delete_old_translation_columns () +BEGIN + ALTER TABLE anrs DROP COLUMN label1, DROP COLUMN label2, DROP COLUMN label3, DROP COLUMN label4, DROP COLUMN description1, DROP COLUMN description2, DROP COLUMN description3, DROP COLUMN description4; + ALTER TABLE assets DROP COLUMN label1, DROP COLUMN label2, DROP COLUMN label3, DROP COLUMN label4, DROP COLUMN description1, DROP COLUMN description2, DROP COLUMN description3, DROP COLUMN description4; + ALTER TABLE instances DROP COLUMN label1, DROP COLUMN label2, DROP COLUMN label3, DROP COLUMN label4, DROP COLUMN name1, DROP COLUMN name2, DROP COLUMN name3, DROP COLUMN name4; + ALTER TABLE measures DROP COLUMN description1, DROP COLUMN description2, DROP COLUMN description3, DROP COLUMN description4; + ALTER TABLE objects DROP COLUMN label1, DROP COLUMN label2, DROP COLUMN label3, DROP COLUMN label4, DROP COLUMN name1, DROP COLUMN name2, DROP COLUMN name3, DROP COLUMN name4; + ALTER TABLE objects_categories DROP COLUMN label1, DROP COLUMN label2, DROP COLUMN label3, DROP COLUMN label4; + ALTER TABLE questions DROP COLUMN label1, DROP COLUMN label2, DROP COLUMN label3, DROP COLUMN label4; + ALTER TABLE questions_choices DROP COLUMN label1, DROP COLUMN label2, DROP COLUMN label3, DROP COLUMN label4; + ALTER TABLE rolf_tags DROP COLUMN label1, DROP COLUMN label2, DROP COLUMN label3, DROP COLUMN label4; + ALTER TABLE scales_comments DROP COLUMN comment1, DROP COLUMN comment2, DROP COLUMN comment3, DROP COLUMN comment4; + ALTER TABLE scales_impact_types DROP COLUMN label1, DROP COLUMN label2, DROP COLUMN label3, DROP COLUMN label4; + ALTER TABLE themes DROP COLUMN label1, DROP COLUMN label2, DROP COLUMN label3, DROP COLUMN label4; + ALTER TABLE threats DROP COLUMN label1, DROP COLUMN label2, DROP COLUMN label3, DROP COLUMN label4, DROP COLUMN description1, DROP COLUMN description2, DROP COLUMN description3, DROP COLUMN description4; + ALTER TABLE rolf_risks DROP COLUMN label1, DROP COLUMN label2, DROP COLUMN label3, DROP COLUMN label4, DROP COLUMN description1, DROP COLUMN description2, DROP COLUMN description3, DROP COLUMN description4; + ALTER TABLE vulnerabilities DROP COLUMN label1, DROP COLUMN label2, DROP COLUMN label3, DROP COLUMN label4, DROP COLUMN description1, DROP COLUMN description2, DROP COLUMN description3, DROP COLUMN description4; +END;; +DELIMITER ; + +CALL delete_old_translation_columns; \ No newline at end of file diff --git a/db-bootstrap/change_columns_name_cli.sql b/db-bootstrap/change_columns_name_cli.sql new file mode 100644 index 0000000..625c30d --- /dev/null +++ b/db-bootstrap/change_columns_name_cli.sql @@ -0,0 +1,11 @@ +ALTER TABLE `instances` CHANGE `c` `confidentiality` int(11) DEFAULT '-1'; +ALTER TABLE `instances` CHANGE `i` `integrity` int(11) DEFAULT '-1'; +ALTER TABLE `instances` CHANGE `d` `availability` int(11) DEFAULT '-1'; + +ALTER TABLE `instances_consequences` CHANGE `c` `confidentiality` tinyint(4) DEFAULT '-1'; +ALTER TABLE `instances_consequences` CHANGE `i` `integrity` tinyint(4) DEFAULT '-1'; +ALTER TABLE `instances_consequences` CHANGE `d` `availability` tinyint(4) DEFAULT '-1'; + +ALTER TABLE `threats` CHANGE `c` `confidentiality` tinyint(4) DEFAULT '0'; +ALTER TABLE `threats` CHANGE `i` `integrity` tinyint(4) DEFAULT '0'; +ALTER TABLE `threats` CHANGE `d` `availability` tinyint(4) DEFAULT '0'; \ No newline at end of file