From b3a91ac99a2b92f41864de55e3aefceff5616929 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Thu, 23 Jul 2015 15:08:38 +0200 Subject: [PATCH] Fix upgrade process. --- app/Migrations/Schema/V110/Version110.php | 48 ++-- .../Schema/V110/Version20150505132304.php | 106 -------- .../Schema/V110/Version20150507152600.php | 23 +- .../Schema/V110/Version20150511133949.php | 2 +- .../Schema/V110/Version20150522112023.php | 1 + .../Schema/V110/Version20150527101600.php | 1 - .../Schema/V110/Version20150603181728.php | 3 - .../Schema/V110/Version20150713132630.php | 12 +- main/admin/sub_language.class.php | 5 + main/inc/lib/database.constants.inc.php | 4 +- main/install/index.php | 2 +- main/install/install.lib.php | 240 ++++++++++++------ .../CoreBundle/Entity/GradeComponents.php | 21 +- src/Chamilo/CoreBundle/Entity/GradeModel.php | 21 +- .../CoreBundle/Entity/GradebookCategory.php | 20 +- .../Entity/GradebookCertificate.php | 21 +- .../CoreBundle/Entity/GradebookEvaluation.php | 21 +- .../CoreBundle/Entity/GradebookLink.php | 22 +- .../Entity/GradebookLinkevalLog.php | 1 + .../CoreBundle/Entity/GradebookResult.php | 1 + .../CoreBundle/Entity/GradebookResultLog.php | 1 + .../Entity/GradebookScoreDisplay.php | 1 + .../CoreBundle/Entity/SettingsCurrent.php | 4 +- .../CoreBundle/Entity/SettingsOptions.php | 23 +- 24 files changed, 304 insertions(+), 300 deletions(-) create mode 100644 main/admin/sub_language.class.php diff --git a/app/Migrations/Schema/V110/Version110.php b/app/Migrations/Schema/V110/Version110.php index c74fe545b2..f07a829920 100644 --- a/app/Migrations/Schema/V110/Version110.php +++ b/app/Migrations/Schema/V110/Version110.php @@ -29,10 +29,10 @@ class Version110 extends AbstractMigrationChamilo $this->addSql("CREATE TABLE IF NOT EXISTS hook_observer( id int UNSIGNED NOT NULL AUTO_INCREMENT, class_name varchar(255) UNIQUE, path varchar(255) NOT NULL, plugin_name varchar(255) NULL, PRIMARY KEY PK_hook_management_hook_observer(id))"); $this->addSql("CREATE TABLE IF NOT EXISTS hook_event( id int UNSIGNED NOT NULL AUTO_INCREMENT, class_name varchar(255) UNIQUE, description varchar(255), PRIMARY KEY PK_hook_management_hook_event(id))"); $this->addSql("CREATE TABLE IF NOT EXISTS hook_call( id int UNSIGNED NOT NULL AUTO_INCREMENT, hook_event_id int UNSIGNED NOT NULL, hook_observer_id int UNSIGNED NOT NULL, type tinyint NOT NULL, hook_order int UNSIGNED NOT NULL, enabled tinyint NOT NULL, PRIMARY KEY PK_hook_management_hook_call(id))"); - $this->addSql("CREATE TABLE IF NOT EXISTS c_student_publication_rel_document (id INT PRIMARY KEY NOT NULL AUTO_INCREMENT, work_id INT NOT NULL, document_id INT NOT NULL, c_id INT NOT NULL)"); - $this->addSql("CREATE TABLE IF NOT EXISTS c_student_publication_rel_user (id INT PRIMARY KEY NOT NULL AUTO_INCREMENT, work_id INT NOT NULL, user_id INT NOT NULL, c_id INT NOT NULL)"); - $this->addSql("CREATE TABLE IF NOT EXISTS c_student_publication_comment (id INT PRIMARY KEY NOT NULL AUTO_INCREMENT, work_id INT NOT NULL, c_id INT NOT NULL, comment text, file VARCHAR(255), user_id int NOT NULL, sent_at datetime NOT NULL)"); - $this->addSql("CREATE TABLE IF NOT EXISTS c_attendance_calendar_rel_group (id int NOT NULL auto_increment PRIMARY KEY, c_id INT NOT NULL, group_id INT NOT NULL, calendar_id INT NOT NULL)"); + $this->addSql("CREATE TABLE IF NOT EXISTS c_student_publication_rel_document (iid INT PRIMARY KEY NOT NULL AUTO_INCREMENT, id INT, work_id INT NOT NULL, document_id INT NOT NULL, c_id INT NOT NULL)"); + $this->addSql("CREATE TABLE IF NOT EXISTS c_student_publication_rel_user (iid INT PRIMARY KEY NOT NULL AUTO_INCREMENT, id INT, work_id INT NOT NULL, user_id INT NOT NULL, c_id INT NOT NULL)"); + $this->addSql("CREATE TABLE IF NOT EXISTS c_student_publication_comment (iid INT PRIMARY KEY NOT NULL AUTO_INCREMENT, id INT, work_id INT NOT NULL, c_id INT NOT NULL, comment text, file VARCHAR(255), user_id int NOT NULL, sent_at datetime NOT NULL)"); + $this->addSql("CREATE TABLE IF NOT EXISTS c_attendance_calendar_rel_group (iid int NOT NULL auto_increment PRIMARY KEY, id INT, c_id INT NOT NULL, group_id INT NOT NULL, calendar_id INT NOT NULL)"); //$this->addSql("ALTER TABLE skill_rel_user ADD COLUMN course_id INT NOT NULL DEFAULT 0 AFTER id"); //$this->addSql("ALTER TABLE skill_rel_user ADD COLUMN session_id INT NOT NULL DEFAULT 0 AFTER course_id"); @@ -178,9 +178,9 @@ class Version110 extends AbstractMigrationChamilo //'c_role_user', 'c_student_publication', 'c_student_publication_assignment', - //'c_student_publication_comment', - //'c_student_publication_rel_document', - //'c_student_publication_rel_user', + 'c_student_publication_comment', + 'c_student_publication_rel_document', + 'c_student_publication_rel_user', //'c_survey', //'c_survey_answer', 'c_survey_group', @@ -201,20 +201,19 @@ class Version110 extends AbstractMigrationChamilo ]; foreach ($tables as $table) { - $this->addSql("ALTER TABLE $table MODIFY COLUMN id int unsigned DEFAULT NULL"); - $this->addSql("ALTER TABLE $table MODIFY COLUMN c_id int unsigned DEFAULT NULL"); - $this->addSql("ALTER TABLE $table DROP PRIMARY KEY"); - $this->addSql("ALTER TABLE $table ADD COLUMN iid int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT"); + if ($schema->hasTable($table)) { + $this->addSql("ALTER TABLE $table MODIFY COLUMN id int unsigned DEFAULT NULL"); + $this->addSql("ALTER TABLE $table MODIFY COLUMN c_id int unsigned DEFAULT NULL"); + $this->addSql("ALTER TABLE $table DROP PRIMARY KEY"); + $this->addSql("ALTER TABLE $table ADD COLUMN iid int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT"); + } } - $this->addSql("ALTER TABLE c_attendance_calendar_rel_group MODIFY COLUMN id int unsigned DEFAULT NULL"); - $this->addSql("ALTER TABLE c_attendance_calendar_rel_group DROP PRIMARY KEY"); - $this->addSql("ALTER TABLE c_attendance_calendar_rel_group ADD COLUMN iid int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT"); - - $this->addSql("ALTER TABLE c_student_publication_comment MODIFY COLUMN id int unsigned DEFAULT NULL"); - $this->addSql("ALTER TABLE c_student_publication_comment DROP PRIMARY KEY"); - $this->addSql("ALTER TABLE c_student_publication_comment ADD COLUMN iid int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT"); - + if ($schema->hasTable('c_attendance_calendar_rel_group')) { + $this->addSql("ALTER TABLE c_attendance_calendar_rel_group MODIFY COLUMN id int unsigned DEFAULT NULL"); + $this->addSql("ALTER TABLE c_attendance_calendar_rel_group DROP PRIMARY KEY"); + $this->addSql("ALTER TABLE c_attendance_calendar_rel_group ADD COLUMN iid int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT"); + } $this->addSql("ALTER TABLE c_attendance_sheet MODIFY COLUMN c_id int unsigned DEFAULT NULL"); $this->addSql("ALTER TABLE c_attendance_sheet DROP PRIMARY KEY"); @@ -334,7 +333,7 @@ class Version110 extends AbstractMigrationChamilo $this->addSql("ALTER TABLE c_quiz_answer MODIFY COLUMN c_id int unsigned DEFAULT NULL"); $this->addSql("ALTER TABLE c_quiz_answer MODIFY COLUMN id_auto int unsigned DEFAULT NULL"); $this->addSql("ALTER TABLE c_quiz_answer DROP PRIMARY KEY"); - $this->addSql("ALTER TABLE c_quiz_answer MODIFY COLUMN id_auto int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT"); + $this->addSql("ALTER TABLE c_quiz_answer ADD COLUMN iid int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT"); $this->addSql("ALTER TABLE c_quiz_question_rel_category MODIFY COLUMN c_id int unsigned DEFAULT NULL"); $this->addSql("ALTER TABLE c_quiz_question_rel_category MODIFY COLUMN question_id int unsigned DEFAULT NULL"); @@ -441,6 +440,11 @@ class Version110 extends AbstractMigrationChamilo $this->addSql("UPDATE access_url_rel_course SET c_id = (SELECT id FROM course WHERE code = course_code)"); + $this->addSql("ALTER TABLE settings_current DROP INDEX unique_setting"); + $this->addSql("ALTER TABLE settings_options DROP INDEX unique_setting_option"); + + $this->addSql("DELETE FROM settings_current WHERE variable = 'wcag_anysurfer_public_pages'"); + $this->addSql("DELETE FROM settings_current WHERE variable = 'wcag_anysurfer_public_pages'"); $this->addSql("DELETE FROM settings_options WHERE variable = 'wcag_anysurfer_public_pages'"); $this->addSql("DELETE FROM settings_current WHERE variable = 'advanced_filemanager'"); @@ -460,10 +464,6 @@ class Version110 extends AbstractMigrationChamilo $this->addSql("INSERT INTO settings_options (variable, value, display_text) VALUES ('enabled_mathjax', 'true', 'Yes')"); $this->addSql("INSERT INTO settings_options (variable, value, display_text) VALUES ('enabled_mathjax', 'false', 'No')"); - $this->addSql("INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('enabled_mathjax', NULL, 'radio', 'Editor', 'false', 'EnableMathJaxTitle', 'EnableMathJaxComment', NULL, NULL, 0)"); - $this->addSql("INSERT INTO settings_options (variable, value, display_text) VALUES ('enabled_mathjax', 'true', 'Yes')"); - $this->addSql("INSERT INTO settings_options (variable, value, display_text) VALUES ('enabled_mathjax', 'false', 'No')"); - $this->addSql("INSERT INTO language (original_name, english_name, isocode, dokeos_folder, available) VALUES ('Føroyskt', 'faroese', 'fo', 'faroese', 0), ('Tagalog', 'tagalog', 'tl', 'tagalog',1), ('Tibetan', 'tibetan', 'bo', 'tibetan', 0), ('isiXhosa', 'xhosa', 'xh', 'xhosa', 0)"); $this->addSql("DELETE FROM settings_options WHERE variable = 'show_glossary_in_extra_tools'"); diff --git a/app/Migrations/Schema/V110/Version20150505132304.php b/app/Migrations/Schema/V110/Version20150505132304.php index 37083607b6..6272390854 100644 --- a/app/Migrations/Schema/V110/Version20150505132304.php +++ b/app/Migrations/Schema/V110/Version20150505132304.php @@ -3,11 +3,7 @@ namespace Application\Migrations\Schema\V110; -use Chamilo\CoreBundle\Entity\ExtraField; -use Chamilo\CoreBundle\Entity\ExtraFieldOptions; -use Chamilo\CoreBundle\Entity\ExtraFieldValues; use Application\Migrations\AbstractMigrationChamilo; -use Database; use Doctrine\DBAL\Schema\Schema; /** @@ -49,109 +45,7 @@ class Version20150505132304 extends AbstractMigrationChamilo */ public function postUp(Schema $schema) { - // Extra fields - $extraFieldTables = [ - ExtraField::USER_FIELD_TYPE => Database::get_main_table(TABLE_MAIN_USER_FIELD), - ExtraField::COURSE_FIELD_TYPE => Database::get_main_table(TABLE_MAIN_COURSE_FIELD), - //ExtraField::LP_FIELD_TYPE => Database::get_main_table(TABLE_MAIN_LP_FIELD), - ExtraField::SESSION_FIELD_TYPE => Database::get_main_table(TABLE_MAIN_SESSION_FIELD), - //ExtraField::CALENDAR_FIELD_TYPE => Database::get_main_table(TABLE_MAIN_CALENDAR_EVENT_FIELD), - //ExtraField::QUESTION_FIELD_TYPE => Database::get_main_table(TABLE_MAIN_CALENDAR_EVENT_FIELD), - //ExtraField::USER_FIELD_TYPE => //Database::get_main_table(TABLE_MAIN_SPECIFIC_FIELD), - ]; - $em = $this->getEntityManager(); - $connection = $em->getConnection(); - - foreach ($extraFieldTables as $type => $table) { - //continue; - $sql = "SELECT * FROM $table "; - $result = $connection->query($sql); - $fields = $result->fetchAll(); - - foreach ($fields as $field) { - $originalId = $field['id']; - $extraField = new ExtraField(); - $extraField - ->setExtraFieldType($type) - ->setVariable($field['field_variable']) - ->setFieldType($field['field_type']) - ->setDisplayText($field['field_display_text']) - ->setDefaultValue($field['field_default_value']) - ->setFieldOrder($field['field_order']) - ->setVisible($field['field_visible']) - ->setChangeable($field['field_changeable']) - ->setFilter($field['field_filter']); - - $em->persist($extraField); - $em->flush(); - - $values = array(); - switch ($type) { - case ExtraField::USER_FIELD_TYPE: - $optionTable = Database::get_main_table( - TABLE_MAIN_USER_FIELD_OPTIONS - ); - $valueTable = Database::get_main_table( - TABLE_MAIN_USER_FIELD_VALUES - ); - $handlerId = 'user_id'; - break; - case ExtraField::COURSE_FIELD_TYPE: - $optionTable = Database::get_main_table( - TABLE_MAIN_COURSE_FIELD_OPTIONS - ); - $valueTable = Database::get_main_table( - TABLE_MAIN_COURSE_FIELD_VALUES - ); - $handlerId = 'c_id'; - break; - case ExtraField::SESSION_FIELD_TYPE: - $optionTable = Database::get_main_table( - TABLE_MAIN_SESSION_FIELD_OPTIONS - ); - $valueTable = Database::get_main_table( - TABLE_MAIN_SESSION_FIELD_VALUES - ); - $handlerId = 'session_id'; - break; - } - - if (!empty($optionTable)) { - - $sql = "SELECT * FROM $optionTable WHERE field_id = $originalId "; - $result = $connection->query($sql); - $options = $result->fetchAll(); - - foreach ($options as $option) { - $extraFieldOption = new ExtraFieldOptions(); - $extraFieldOption - ->setDisplayText($option['option_display_text']) - ->setField($extraField) - ->setOptionOrder($option['option_order']) - ->setValue($option['option_value']); - $em->persist($extraFieldOption); - $em->flush(); - } - - $sql = "SELECT * FROM $valueTable WHERE field_id = $originalId "; - $result = $connection->query($sql); - $values = $result->fetchAll(); - } - - if (!empty($values)) { - foreach ($values as $value) { - $extraFieldValue = new ExtraFieldValues(); - $extraFieldValue - ->setValue($value['field_value']) - ->setField($extraField) - ->setItemId($value[$handlerId]); - $em->persist($extraFieldValue); - $em->flush(); - } - } - } - } } /** diff --git a/app/Migrations/Schema/V110/Version20150507152600.php b/app/Migrations/Schema/V110/Version20150507152600.php index 4db8feb7c8..a42d9a2760 100644 --- a/app/Migrations/Schema/V110/Version20150507152600.php +++ b/app/Migrations/Schema/V110/Version20150507152600.php @@ -28,12 +28,13 @@ class Version20150507152600 extends AbstractMigrationChamilo // Setting $_configuration['hide_home_top_when_connected'] = true; $value = api_get_configuration_value('hide_home_top_when_connected'); + $this->addSettingCurrent( 'hide_home_top_when_connected', '', 'radio', 'Platform', - ($value?'true':'false'), + ($value ? 'true' : 'false'), 'HideHomeTopContentWhenLoggedInText', 'HideHomeTopContentWhenLoggedInComment', null, @@ -41,7 +42,10 @@ class Version20150507152600 extends AbstractMigrationChamilo 1, true, false, - [0 => ['value' => 'true', 'text' => 'Yes'], 1 => ['value' => 'false', 'text' => 'No']] + [ + 0 => ['value' => 'true', 'text' => 'Yes'], + 1 => ['value' => 'false', 'text' => 'No'], + ] ); // Hide the global announcements for non-connected users @@ -60,7 +64,10 @@ class Version20150507152600 extends AbstractMigrationChamilo 1, true, false, - [0 => ['value' => 'true', 'text' => 'Yes'], 1 => ['value' => 'false', 'text' => 'No']] + [ + 0 => ['value' => 'true', 'text' => 'Yes'], + 1 => ['value' => 'false', 'text' => 'No'], + ] ); // Use this course as template for all new courses (define course real ID as value) @@ -79,7 +86,10 @@ class Version20150507152600 extends AbstractMigrationChamilo 1, true, false, - [0 => ['value' => 'true', 'text' => 'Yes'], 1 => ['value' => 'false', 'text' => 'No']] + [ + 0 => ['value' => 'true', 'text' => 'Yes'], + 1 => ['value' => 'false', 'text' => 'No'], + ] ); // Add password strength checker @@ -98,7 +108,10 @@ class Version20150507152600 extends AbstractMigrationChamilo 1, true, false, - [0 => ['value' => 'true', 'text' => 'Yes'], 1 => ['value' => 'false', 'text' => 'No']] + [ + 0 => ['value' => 'true', 'text' => 'Yes'], + 1 => ['value' => 'false', 'text' => 'No'], + ] ); // Enable captcha diff --git a/app/Migrations/Schema/V110/Version20150511133949.php b/app/Migrations/Schema/V110/Version20150511133949.php index 544e0b86bb..222888187a 100644 --- a/app/Migrations/Schema/V110/Version20150511133949.php +++ b/app/Migrations/Schema/V110/Version20150511133949.php @@ -18,7 +18,7 @@ class Version20150511133949 extends AbstractMigrationChamilo { $this->addSql('ALTER TABLE user ADD salt VARCHAR(255) NOT NULL'); $this->addSql('ALTER TABLE user ADD username_canonical VARCHAR(100) NOT NULL'); - $this->addSql('CREATE UNIQUE INDEX UNIQ_8D93D64992FC23A8 ON user (username_canonical)'); + //$this->addSql('CREATE UNIQUE INDEX UNIQ_8D93D64992FC23A8 ON user (username_canonical)'); $this->addSql('ALTER TABLE user CHANGE password password VARCHAR(255) NOT NULL'); $this->addSql("INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('allow_teachers_to_create_sessions', NULL,'radio','Session','false','AllowTeachersToCreateSessionsTitle','AllowTeachersToCreateSessionsComment', NULL, NULL, 0)"); diff --git a/app/Migrations/Schema/V110/Version20150522112023.php b/app/Migrations/Schema/V110/Version20150522112023.php index 753c196e15..f6de38b9ad 100644 --- a/app/Migrations/Schema/V110/Version20150522112023.php +++ b/app/Migrations/Schema/V110/Version20150522112023.php @@ -22,6 +22,7 @@ class Version20150522112023 extends AbstractMigrationChamilo $this->addSql('ALTER TABLE usergroup ADD group_type INT NOT NULL, ADD created_at DATETIME NOT NULL, ADD updated_at DATETIME NOT NULL'); $this->addSql('ALTER TABLE usergroup ADD picture VARCHAR(255) DEFAULT NULL, ADD url VARCHAR(255) DEFAULT NULL, ADD visibility VARCHAR(255) NOT NULL, ADD allow_members_leave_group INT NOT NULL, CHANGE description description LONGTEXT DEFAULT NULL'); $this->addSql('CREATE TABLE usergroup_rel_usergroup (id INT AUTO_INCREMENT NOT NULL, group_id INT NOT NULL, subgroup_id INT NOT NULL, relation_type INT NOT NULL, PRIMARY KEY(id));'); + $this->addSql('ALTER TABLE usergroup_rel_user ADD relation_type INT'); if (!$schema->hasTable('access_url_rel_usergroup')) { $this->addSql( diff --git a/app/Migrations/Schema/V110/Version20150527101600.php b/app/Migrations/Schema/V110/Version20150527101600.php index f0e78389b3..7b2735b07f 100644 --- a/app/Migrations/Schema/V110/Version20150527101600.php +++ b/app/Migrations/Schema/V110/Version20150527101600.php @@ -52,5 +52,4 @@ class Version20150527101600 extends AbstractMigrationChamilo $this->addSql("DELETE FROM settings_options WHERE variable = 'gamification_mode'"); $this->addSql("DELETE FROM settings_current WHERE variable = 'gamification_mode'"); } - } diff --git a/app/Migrations/Schema/V110/Version20150603181728.php b/app/Migrations/Schema/V110/Version20150603181728.php index 28c0e857fc..7ad418fca7 100644 --- a/app/Migrations/Schema/V110/Version20150603181728.php +++ b/app/Migrations/Schema/V110/Version20150603181728.php @@ -17,9 +17,6 @@ class Version20150603181728 extends AbstractMigrationChamilo public function up(Schema $schema) { $this->addSql('ALTER TABLE c_lp ADD max_attempts INT NOT NULL, ADD subscribe_users INT NOT NULL DEFAULT 0'); - - $this->addSql('DELETE FROM c_item_property TABLE c_lp ADD max_attempts INT NOT NULL, ADD subscribe_users INT NOT NULL DEFAULT 0'); - $this->addSql('ALTER TABLE c_item_property CHANGE c_id c_id INT DEFAULT NULL, CHANGE insert_user_id insert_user_id INT DEFAULT NULL, CHANGE start_visible start_visible DATETIME DEFAULT NULL, CHANGE end_visible end_visible DATETIME DEFAULT NULL, CHANGE session_id session_id INT DEFAULT NULL'); $this->addSql('ALTER TABLE c_item_property ADD CONSTRAINT FK_1D84C18191D79BD3 FOREIGN KEY (c_id) REFERENCES course (id)'); $this->addSql('ALTER TABLE c_item_property ADD CONSTRAINT FK_1D84C181330D47E9 FOREIGN KEY (to_group_id) REFERENCES c_group_info (iid)'); diff --git a/app/Migrations/Schema/V110/Version20150713132630.php b/app/Migrations/Schema/V110/Version20150713132630.php index 7f0015e15f..cf6b694587 100644 --- a/app/Migrations/Schema/V110/Version20150713132630.php +++ b/app/Migrations/Schema/V110/Version20150713132630.php @@ -18,9 +18,15 @@ class Version20150713132630 extends AbstractMigrationChamilo */ public function up(Schema $schema) { - $this->addSql('ALTER TABLE c_student_publication ADD url_correction VARCHAR(255) DEFAULT NULL'); - $this->addSql('ALTER TABLE c_student_publication ADD title_correction VARCHAR(255) DEFAULT NULL'); - $this->addSql('ALTER TABLE c_student_publication ADD document_id INT NOT NULL'); + if ($schema->hasTable('c_student_publication')) { + $this->addSql('ALTER TABLE c_student_publication ADD url_correction VARCHAR(255) DEFAULT NULL'); + $this->addSql('ALTER TABLE c_student_publication ADD title_correction VARCHAR(255) DEFAULT NULL'); + if (!$schema->getTable('c_student_publication')->hasColumn('document_id')) { + $this->addSql( + 'ALTER TABLE c_student_publication ADD document_id INT NOT NULL' + ); + } + } } /** diff --git a/main/admin/sub_language.class.php b/main/admin/sub_language.class.php new file mode 100644 index 0000000000..8d7fc6371e --- /dev/null +++ b/main/admin/sub_language.class.php @@ -0,0 +1,5 @@ +getConnection()); + fixIds($manager); include 'update-files-1.9.0-1.10.0.inc.php'; // Only updates the configuration.inc.php with the new version diff --git a/main/install/install.lib.php b/main/install/install.lib.php index a8528ff9d7..73395a0b8e 100755 --- a/main/install/install.lib.php +++ b/main/install/install.lib.php @@ -11,7 +11,9 @@ */ use Doctrine\ORM\EntityManager; -use Doctrine\DBAL\Connection; +use Chamilo\CoreBundle\Entity\ExtraField; +use Chamilo\CoreBundle\Entity\ExtraFieldOptions; +use Chamilo\CoreBundle\Entity\ExtraFieldValues; /* CONSTANTS */ define('SYSTEM_CONFIG_FILENAME', 'configuration.dist.php'); @@ -1942,11 +1944,10 @@ function migrate($chamiloVersion, EntityManager $manager) } } -/** -* @param Connection $connection - */ -function fixIds(Connection $connection) +function fixIds(EntityManager $em) { + $connection = $em->getConnection(); + $sql = "SELECT * FROM c_lp_item"; $result = $connection->fetchAll($sql); foreach ($result as $item) { @@ -1959,43 +1960,43 @@ function fixIds(Connection $connection) switch ($item['item_type']) { case TOOL_LINK: - $sql = "SELECT * c_link WHERE c_id = $courseId AND id = $ref"; - $data = $connection->fetchArray($sql); + $sql = "SELECT * FROM c_link WHERE c_id = $courseId AND id = $ref"; + $data = $connection->fetchAssoc($sql); if ($data) { $newId = $data['iid']; } break; case TOOL_STUDENTPUBLICATION: - $sql = "SELECT * c_student_publication WHERE c_id = $courseId AND id = $ref"; - $data = $connection->fetchArray($sql); + $sql = "SELECT * FROM c_student_publication WHERE c_id = $courseId AND id = $ref"; + $data = $connection->fetchAssoc($sql); if ($data) { $newId = $data['iid']; } break; case TOOL_QUIZ: - $sql = "SELECT * c_quiz WHERE c_id = $courseId AND id = $ref"; - $data = $connection->fetchArray($sql); + $sql = "SELECT * FROM c_quiz WHERE c_id = $courseId AND id = $ref"; + $data = $connection->fetchAssoc($sql); if ($data) { $newId = $data['iid']; } break; case TOOL_DOCUMENT: - $sql = "SELECT * c_document WHERE c_id = $courseId AND id = $ref"; - $data = $connection->fetchArray($sql); + $sql = "SELECT * FROM c_document WHERE c_id = $courseId AND id = $ref"; + $data = $connection->fetchAssoc($sql); if ($data) { $newId = $data['iid']; } break; case TOOL_FORUM: - $sql = "SELECT * c_forum_forum WHERE c_id = $courseId AND id = $ref"; - $data = $connection->fetchArray($sql); + $sql = "SELECT * FROM c_forum_forum WHERE c_id = $courseId AND id = $ref"; + $data = $connection->fetchAssoc($sql); if ($data) { $newId = $data['iid']; } break; case 'thread': - $sql = "SELECT * c_forum_thread WHERE c_id = $courseId AND id = $ref"; - $data = $connection->fetchArray($sql); + $sql = "SELECT * FROM c_forum_thread WHERE c_id = $courseId AND id = $ref"; + $data = $connection->fetchAssoc($sql); if ($data) { $newId = $data['iid']; } @@ -2051,9 +2052,9 @@ function fixIds(Connection $connection) // Fix group id if (!empty($groupId)) { - $sql = "SELECT * c_group_info + $sql = "SELECT * FROM c_group_info WHERE c_id = $courseId AND id = $groupId LIMIT 1"; - $data = $connection->fetchArray($sql); + $data = $connection->fetchAssoc($sql); if (!empty($data)) { $newGroupId = $data['iid']; $sql = "UPDATE $table SET group_id = $newGroupId @@ -2082,8 +2083,8 @@ function fixIds(Connection $connection) // Fix group id if (!empty($groupId)) { - $sql = "SELECT * c_group_info WHERE c_id = $courseId AND id = $groupId"; - $data = $connection->fetchArray($sql); + $sql = "SELECT * FROM c_group_info WHERE c_id = $courseId AND id = $groupId"; + $data = $connection->fetchAssoc($sql); if (!empty($data)) { $newGroupId = $data['iid']; $sql = "UPDATE c_item_property SET to_group_id = $newGroupId @@ -2096,42 +2097,34 @@ function fixIds(Connection $connection) } } - $sql = null; - + $sql = ''; + $newId = ''; switch ($item['tool']) { case TOOL_LINK: - $sql = "SELECT * c_link WHERE c_id = $courseId AND id = $ref "; - $data = $connection->fetchArray($sql); - $newId = $data['iid']; + $sql = "SELECT * FROM c_link WHERE c_id = $courseId AND id = $ref "; break; case TOOL_STUDENTPUBLICATION: - $sql = "SELECT * c_student_publication WHERE c_id = $courseId AND id = $ref"; - $data = $connection->fetchArray($sql); - $newId = $data['iid']; + $sql = "SELECT * FROM c_student_publication WHERE c_id = $courseId AND id = $ref"; break; case TOOL_QUIZ: - $sql = "SELECT * c_quiz WHERE c_id = $courseId AND id = $ref"; - $data = $connection->fetchArray($sql); - $newId = $data['iid']; + $sql = "SELECT * FROM c_quiz WHERE c_id = $courseId AND id = $ref"; break; case TOOL_DOCUMENT: - $sql = "SELECT * c_document WHERE c_id = $courseId AND id = $ref"; - $data = $connection->fetchArray($sql); - $newId = $data['iid']; + $sql = "SELECT * FROM c_document WHERE c_id = $courseId AND id = $ref"; break; case TOOL_FORUM: - $sql = "SELECT * c_forum_forum WHERE c_id = $courseId AND id = $ref"; - $data = $connection->fetchArray($sql); - $newId = $data['iid']; + $sql = "SELECT * FROM c_forum_forum WHERE c_id = $courseId AND id = $ref"; break; case 'thread': - $sql = "SELECT * c_forum_thread WHERE c_id = $courseId AND id = $ref"; - $data = $connection->fetchArray($sql); - $newId = $data['iid']; + $sql = "SELECT * FROM c_forum_thread WHERE c_id = $courseId AND id = $ref"; break; } - if (!empty($sql)) { + if (!empty($sql) && !empty($newId)) { + $data = $connection->fetchAssoc($sql); + if (isset($data['iid'])) { + $newId = $data['iid']; + } $sql = "UPDATE c_item_property SET ref = $newId WHERE iid = $iid"; $connection->executeQuery($sql); } @@ -2141,52 +2134,47 @@ function fixIds(Connection $connection) $sql = "SELECT * FROM gradebook_link"; $result = $connection->fetchAll($sql); foreach ($result as $item) { - $courseId = $item['c_id']; + $courseCode = $item['course_code']; + $courseInfo = api_get_course_info($courseCode); + + if (empty($courseInfo)) { + continue; + } + $courseId = $courseInfo['real_id']; $ref = $item['ref_id']; - $sql = null; + $iid = $item['id']; + $sql = ''; - switch ($item['tool']) { - case TOOL_LINK: - $sql = "SELECT * c_link WHERE c_id = $courseId AND id = $ref "; - $data = $connection->fetchArray($sql); - $newId = $data['iid']; + switch ($item['type']) { + case LINK_LEARNPATH: + $sql = "SELECT * FROM c_link WHERE c_id = $courseId AND id = $ref "; break; - case TOOL_STUDENTPUBLICATION: - $sql = "SELECT * c_student_publication WHERE c_id = $courseId AND id = $ref"; - $data = $connection->fetchArray($sql); - $newId = $data['iid']; + case LINK_STUDENTPUBLICATION: + $sql = "SELECT * FROM c_student_publication WHERE c_id = $courseId AND id = $ref"; break; - case TOOL_QUIZ: - $sql = "SELECT * c_quiz WHERE c_id = $courseId AND id = $ref"; - $data = $connection->fetchArray($sql); - $newId = $data['iid']; + case LINK_EXERCISE: + $sql = "SELECT * FROM c_quiz WHERE c_id = $courseId AND id = $ref"; break; - case TOOL_DOCUMENT: - $sql = "SELECT * c_document WHERE c_id = $courseId AND id = $ref"; - $data = $connection->fetchArray($sql); - $newId = $data['iid']; + case LINK_ATTENDANCE: + //$sql = "SELECT * FROM c_document WHERE c_id = $courseId AND id = $ref"; break; - case TOOL_FORUM: - $sql = "SELECT * c_forum_forum WHERE c_id = $courseId AND id = $ref"; - $data = $connection->fetchArray($sql); - $newId = $data['iid']; - break; - case 'thread': - $sql = "SELECT * c_forum_thread WHERE c_id = $courseId AND id = $ref"; - $data = $connection->fetchArray($sql); - $newId = $data['iid']; + case LINK_FORUM_THREAD: + $sql = "SELECT * FROM c_forum_thread WHERE c_id = $courseId AND id = $ref"; break; } if (!empty($sql)) { - $sql = "UPDATE c_item_property SET ref_id = $newId WHERE iid = $iid"; - $connection->executeQuery($sql); + $data = $connection->fetchAssoc($sql); + if (isset($data) && isset($data['iid'])) { + $newId = $data['iid']; + $sql = "UPDATE gradebook_link SET ref_id = $newId + WHERE id = $iid"; + $connection->executeQuery($sql); + } } } - - $sql = "SELECT * FROM groups"; $result = $connection->executeQuery($sql); $groups = $result->fetchAll(); @@ -2281,13 +2269,115 @@ function fixIds(Connection $connection) if (isset($oldGroups[$data['group_id']])) { $data['group_id'] = $oldGroups[$data['group_id']]; $sql = "INSERT INTO usergroup_rel_tag (tag_id, usergroup_id) - VALUES ('{$data['tag_id']}', '{$data['group_id']}')"; + VALUES ('{$data['tag_id']}', '{$data['group_id']}')"; $connection->executeQuery($sql); } } } } + + // Extra fields + $extraFieldTables = [ + ExtraField::USER_FIELD_TYPE => Database::get_main_table(TABLE_MAIN_USER_FIELD), + ExtraField::COURSE_FIELD_TYPE => Database::get_main_table(TABLE_MAIN_COURSE_FIELD), + //ExtraField::LP_FIELD_TYPE => Database::get_main_table(TABLE_MAIN_LP_FIELD), + ExtraField::SESSION_FIELD_TYPE => Database::get_main_table(TABLE_MAIN_SESSION_FIELD), + //ExtraField::CALENDAR_FIELD_TYPE => Database::get_main_table(TABLE_MAIN_CALENDAR_EVENT_FIELD), + //ExtraField::QUESTION_FIELD_TYPE => Database::get_main_table(TABLE_MAIN_CALENDAR_EVENT_FIELD), + //ExtraField::USER_FIELD_TYPE => //Database::get_main_table(TABLE_MAIN_SPECIFIC_FIELD), + ]; + + foreach ($extraFieldTables as $type => $table) { + //continue; + $sql = "SELECT * FROM $table "; + $result = $connection->query($sql); + $fields = $result->fetchAll(); + + foreach ($fields as $field) { + $originalId = $field['id']; + $extraField = new ExtraField(); + $extraField + ->setExtraFieldType($type) + ->setVariable($field['field_variable']) + ->setFieldType($field['field_type']) + ->setDisplayText($field['field_display_text']) + ->setDefaultValue($field['field_default_value']) + ->setFieldOrder($field['field_order']) + ->setVisible($field['field_visible']) + ->setChangeable($field['field_changeable']) + ->setFilter($field['field_filter']); + + $em->persist($extraField); + $em->flush(); + + $values = array(); + switch ($type) { + case ExtraField::USER_FIELD_TYPE: + $optionTable = Database::get_main_table( + TABLE_MAIN_USER_FIELD_OPTIONS + ); + $valueTable = Database::get_main_table( + TABLE_MAIN_USER_FIELD_VALUES + ); + $handlerId = 'user_id'; + break; + case ExtraField::COURSE_FIELD_TYPE: + $optionTable = Database::get_main_table( + TABLE_MAIN_COURSE_FIELD_OPTIONS + ); + $valueTable = Database::get_main_table( + TABLE_MAIN_COURSE_FIELD_VALUES + ); + $handlerId = 'c_id'; + break; + case ExtraField::SESSION_FIELD_TYPE: + $optionTable = Database::get_main_table( + TABLE_MAIN_SESSION_FIELD_OPTIONS + ); + $valueTable = Database::get_main_table( + TABLE_MAIN_SESSION_FIELD_VALUES + ); + $handlerId = 'session_id'; + break; + } + + if (!empty($optionTable)) { + + $sql = "SELECT * FROM $optionTable WHERE field_id = $originalId "; + $result = $connection->query($sql); + $options = $result->fetchAll(); + + foreach ($options as $option) { + $extraFieldOption = new ExtraFieldOptions(); + $extraFieldOption + ->setDisplayText($option['option_display_text']) + ->setField($extraField) + ->setOptionOrder($option['option_order']) + ->setValue($option['option_value']); + $em->persist($extraFieldOption); + $em->flush(); + } + + $sql = "SELECT * FROM $valueTable WHERE field_id = $originalId "; + $result = $connection->query($sql); + $values = $result->fetchAll(); + } + + if (!empty($values)) { + foreach ($values as $value) { + $extraFieldValue = new ExtraFieldValues(); + $extraFieldValue + ->setValue($value['field_value']) + ->setField($extraField) + ->setItemId($value[$handlerId]); + $em->persist($extraFieldValue); + $em->flush(); + } + } + } + } + } /** diff --git a/src/Chamilo/CoreBundle/Entity/GradeComponents.php b/src/Chamilo/CoreBundle/Entity/GradeComponents.php index 2be19b22fc..5a18e92992 100644 --- a/src/Chamilo/CoreBundle/Entity/GradeComponents.php +++ b/src/Chamilo/CoreBundle/Entity/GradeComponents.php @@ -1,4 +1,5 @@