diff --git a/app/config/console-config.php b/app/config/console-config.php index cc8c7d55d8..9d903fe6cf 100644 --- a/app/config/console-config.php +++ b/app/config/console-config.php @@ -1,5 +1,7 @@ setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache); @@ -7,26 +9,45 @@ use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\Common\Annotations\AnnotationRegistry; use Symfony\Component\Yaml\Parser; -AnnotationRegistry::registerFile(api_get_path(SYS_PATH)."vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php"); +$sysPath = __DIR__."/../../"; + +AnnotationRegistry::registerFile($sysPath."vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php"); $reader = new AnnotationReader(); -$driverImpl = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader, array(api_get_path(SYS_PATH)."tests/doctrine_console/mapping")); +$driverImpl = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader, array($sysPath."tests/doctrine_console/mapping")); $config->setMetadataDriverImpl($driverImpl); $config->setProxyDir(__DIR__ . '/Proxies'); $config->setProxyNamespace('Proxies'); $courseList = CourseManager::get_real_course_list(); -//$courseList = array(); -$configurationPath = api_get_path(SYS_PATH).'main/inc/conf/'; +$configurationPath = $sysPath.'main/inc/conf/'; $newConfigurationFile = $configurationPath.'configuration.yml'; +//Including configuration.php +$configurationFile = $configurationPath.'configuration.php'; + +if (is_file($configurationFile) && file_exists($configurationFile)) { + require $configurationFile; +} + +//Merge with the configuration.yml file, if exits if (is_file($newConfigurationFile) && file_exists($newConfigurationFile)) { $yaml = new Parser(); - $_configuration = $yaml->parse(file_get_contents($newConfigurationFile)); + $_configurationYML = $yaml->parse(file_get_contents($newConfigurationFile)); + + if (isset($_configuration)) { + $_configuration = array_merge($_configuration, $_configurationYML); + } else { + $_configuration = $_configurationYML; + } } +$app['chamilo.log'] = $app['cache.path'].'chamilo-cli.log'; + +// Loading db connections + $connectionOptions = array(); if (!empty($courseList)) { diff --git a/main/inc/lib/main_api.lib.php b/main/inc/lib/main_api.lib.php index c94e882123..81b61caf67 100644 --- a/main/inc/lib/main_api.lib.php +++ b/main/inc/lib/main_api.lib.php @@ -3411,10 +3411,10 @@ function api_get_languages_combo($name = 'language', $chozen=true) { */ function api_display_language_form($hide_if_no_choice = false) { - // Retrieve a complete list of all the languages. + // Retrieve a complete list of all the languages $language_list = api_get_languages(); - if (count($language_list['name']) <= 1 && $hide_if_no_choice) { + if (!empty($language_list) && count($language_list['name']) <= 1 && $hide_if_no_choice) { return; //don't show any form } @@ -3430,12 +3430,10 @@ function api_display_language_form($hide_if_no_choice = false) { $folder = $language_list['folder']; // This line is probably no longer needed. $html = ' '; $html .= '
'; diff --git a/main/install/1.9.0/migrate-db-1.8.8-1.9.0-pre.sql b/main/install/1.9.0/migrate-db-1.8.8-1.9.0-pre.sql index 456d18f85d..4df8bb7ea2 100755 --- a/main/install/1.9.0/migrate-db-1.8.8-1.9.0-pre.sql +++ b/main/install/1.9.0/migrate-db-1.8.8-1.9.0-pre.sql @@ -323,22 +323,4 @@ ALTER TABLE track_e_hotpotatoes ADD COLUMN id INTEGER NOT NULL AUTO_INCREMENT, A CREATE TABLE track_e_attempt_coeff ( id int unsigned not null auto_increment primary key, attempt_id INT NOT NULL, marks_coeff float(6,2)); -- xxUSERxx -ALTER TABLE personal_agenda ADD COLUMN all_day INTEGER NOT NULL DEFAULT 0; - --- xxCOURSExx -CREATE TABLE IF NOT EXISTS metadata (c_id INT NOT NULL, eid VARCHAR(250) NOT NULL, mdxmltext TEXT default '', md5 CHAR(32) default '', htmlcache1 TEXT default '', htmlcache2 TEXT default '', indexabletext TEXT default '', PRIMARY KEY (c_id, eid)) - -ALTER TABLE lp ADD COLUMN hide_toc_frame INT NOT NULL DEFAULT 0; -ALTER TABLE lp ADD COLUMN seriousgame_mode INT NOT NULL DEFAULT 0; -ALTER TABLE lp_item_view modify column suspend_data longtext; -ALTER TABLE quiz ADD COLUMN review_answers INT NOT NULL DEFAULT 0; -ALTER TABLE student_publication ADD COLUMN contains_file INTEGER NOT NULL DEFAULT 1; -ALTER TABLE student_publication ADD COLUMN allow_text_assignment INTEGER NOT NULL DEFAULT 0; -ALTER TABLE quiz ADD COLUMN random_by_category INT NOT NULL DEFAULT 0; -ALTER TABLE quiz ADD COLUMN text_when_finished TEXT DEFAULT NULL; -ALTER TABLE quiz ADD COLUMN display_category_name INT NOT NULL DEFAULT 1; -ALTER TABLE quiz ADD COLUMN pass_percentage INT DEFAULT NULL; -INSERT INTO course_setting(variable,value,category) VALUES ('allow_public_certificates', 0, 'certificates'); - -ALTER TABLE quiz_answer ADD COLUMN answer_code char(10) default ''; -ALTER TABLE quiz_question ADD COLUMN question_code char(10) default ''; \ No newline at end of file +ALTER TABLE personal_agenda ADD COLUMN all_day INTEGER NOT NULL DEFAULT 0; \ No newline at end of file diff --git a/main/install/1.9.0/update-db-1.8.8-1.9.0.inc.php b/main/install/1.9.0/update-db-1.8.8-1.9.0.inc.php index 2ce281a4c6..e66a0d0686 100755 --- a/main/install/1.9.0/update-db-1.8.8-1.9.0.inc.php +++ b/main/install/1.9.0/update-db-1.8.8-1.9.0.inc.php @@ -12,11 +12,13 @@ $new_file_version = '1.9.0'; if (defined('SYSTEM_INSTALLATION')) { - $only_test = false; + $mainConnection = $this->getHelper('main_database')->getConnection(); - $singleDbForm = false; + $mainConnection->beginTransaction(); + $singleDbForm = $_configuration['single_database']; $dbNameForm = $_configuration['main_database']; + $dbStatsForm = isset($_configuration['statistics_database']) ? $_configuration['statistics_database'] : $_configuration['main_database']; $dbUserForm = isset($_configuration['user_personal_database']) ? $_configuration['user_personal_database'] : $_configuration['main_database']; @@ -29,8 +31,8 @@ if (defined('SYSTEM_INSTALLATION')) { if ($session_mode == 'true') { - $sql = "UPDATE $dbNameForm.settings_current SET selected_value = 'true' WHERE variable='use_session_mode' "; - $result = iDatabase::query($sql); + $sql = "UPDATE settings_current SET selected_value = 'true' WHERE variable='use_session_mode' "; + $mainConnection->executeQuery($sql); $sql = "SELECT * FROM $dbNameForm.class"; $result = iDatabase::query($sql); @@ -38,6 +40,7 @@ if (defined('SYSTEM_INSTALLATION')) { $new_table = "$dbNameForm.usergroup"; $classes_added = 0; $mapping_classes = array(); + if (Database::num_rows($result)) { while($row = iDatabase::fetch_array($result, 'ASSOC')) { $old_id = $row['id']; @@ -54,16 +57,20 @@ if (defined('SYSTEM_INSTALLATION')) { $sql = "SELECT * FROM $dbNameForm.class_user"; $result = iDatabase::query($sql); $new_table = "$dbNameForm.usergroup_rel_user"; + if (Database::num_rows($result)) { while ($row = iDatabase::fetch_array($result, 'ASSOC')) { - $values = array('usergroup_id' => $mapping_classes[$row['class_id']], - 'user_id' => $row['user_id']); + $values = array( + 'usergroup_id' => $mapping_classes[$row['class_id']], + 'user_id' => $row['user_id'] + ); iDatabase::insert($new_table, $values); } } $sql = "SELECT * FROM $dbNameForm.course_rel_class"; $result = iDatabase::query($sql); + $new_table = "$dbNameForm.usergroup_rel_course"; if (Database::num_rows($result)) { @@ -74,12 +81,13 @@ if (defined('SYSTEM_INSTALLATION')) { $result_course = iDatabase::query($sql_course); $result_course = Database::fetch_array($result_course); $course_id = $result_course['id']; - $values = array('usergroup_id' => $mapping_classes[$row['class_id']], - 'course_id' => $course_id); + $values = array( + 'usergroup_id' => $mapping_classes[$row['class_id']], + 'course_id' => $course_id + ); iDatabase::insert($new_table, $values); } } - $app['monolog']->addInfo("#classes added $classes_added"); } @@ -151,8 +159,8 @@ if (defined('SYSTEM_INSTALLATION')) { iDatabase::query($sql); } - $this->dropCourseTables(); + $this->createCourseTables($output); $prefix = ''; @@ -162,43 +170,144 @@ if (defined('SYSTEM_INSTALLATION')) { $app['monolog']->addInfo("Database prefix: '$prefix'"); - // Get the courses databases queries list (c_q_list) + iDatabase::select_db($dbNameForm); + $res = iDatabase::query("SELECT id, code, db_name, directory, course_language, id as real_id FROM course WHERE target_course_code IS NULL ORDER BY code"); - // Get the courses list - if (strlen($dbNameForm) > 40) { - $app['monolog']->addError('Database name '.$dbNameForm.' is too long, skipping'); - } elseif(!in_array($dbNameForm, $dblist)) { - $app['monolog']->addError('Database '.$dbNameForm.' was not found, skipping'); - } else { - iDatabase::select_db($dbNameForm); - $res = iDatabase::query("SELECT id, code, db_name, directory, course_language, id as real_id FROM course WHERE target_course_code IS NULL ORDER BY code"); + if ($res === false) { die('Error while querying the courses list in update_db-1.8.8-1.9.0.inc.php'); } - if ($res === false) { die('Error while querying the courses list in update_db-1.8.8-1.9.0.inc.php'); } + $errors = array(); - $errors = array(); + if (iDatabase::num_rows($res) > 0) { + $i = 0; + $list = array(); + while ($row = iDatabase::fetch_array($res)) { + $list[] = $row; + $i++; + } - if (iDatabase::num_rows($res) > 0) { - $i = 0; - $list = array(); - while ($row = iDatabase::fetch_array($res)) { - $list[] = $row; - $i++; + foreach ($list as $row_course) { + if (!$singleDbForm) { + // otherwise just use the main one + iDatabase::select_db($row_course['db_name']); } + $app['monolog']->addInfo('Course db ' . $row_course['db_name']); - foreach ($list as $row_course) { - if (!$singleDbForm) { // otherwise just use the main one - iDatabase::select_db($row_course['db_name']); - } - $app['monolog']->addInfo('Course db ' . $row_course['db_name']); - $work_table = $row_course['db_name'].".student_publication"; - $item_table = $row_course['db_name'].".item_property"; + if (!$singleDbForm) { + // otherwise just use the main one + iDatabase::select_db($row_course['db_name']); + } else { + iDatabase::select_db($dbNameForm); + } + + //Course tables to be migrated + $table_list = array( + 'announcement', + 'announcement_attachment', + 'attendance', + 'attendance_calendar', + 'attendance_result', + 'attendance_sheet', + 'attendance_sheet_log', + 'blog', + 'blog_attachment', + 'blog_comment', + 'blog_post', + 'blog_rating', + 'blog_rel_user', + 'blog_task', + 'blog_task_rel_user', + 'calendar_event', + 'calendar_event_attachment', + 'calendar_event_repeat', + 'calendar_event_repeat_not', + 'chat_connected', + 'course_description', + 'course_setting', + 'document', + 'dropbox_category', + 'dropbox_feedback', + 'dropbox_file', + 'dropbox_person', + 'dropbox_post', + 'forum_attachment', + 'forum_category', + 'forum_forum', + 'forum_mailcue', + 'forum_notification', + 'forum_post', + 'forum_thread', + 'forum_thread_qualify', + 'forum_thread_qualify_log', + 'glossary', + 'group_category', + 'group_info', + 'group_rel_tutor', + 'group_rel_user', + 'item_property', + 'link', + 'link_category', + 'lp', + 'lp_item', + 'lp_item_view', + 'lp_iv_interaction', + 'lp_iv_objective', + 'lp_view', + 'notebook', + 'metadata', + 'online_connected', + 'online_link', + 'permission_group', + 'permission_task', + 'permission_user', + 'quiz', + 'quiz_answer', + 'quiz_question', + 'quiz_question_option', + 'quiz_rel_question', + 'resource', + 'role', + 'role_group', + 'role_permissions', + 'role_user', + 'student_publication', + 'student_publication_assignment', + 'survey', + 'survey_answer', + 'survey_group', + 'survey_invitation', + 'survey_question', + 'survey_question_option', + 'thematic', + 'thematic_advance', + 'thematic_plan', + 'tool', + 'tool_intro', + 'userinfo_content', + 'userinfo_def', + 'wiki', + 'wiki_conf', + 'wiki_discuss', + 'wiki_mailcue' + ); + + $app['monolog']->addInfo('<<<------- Loading DB course '.$row_course['db_name'].' -------->>'); + + $count = $old_count = 0; + foreach ($table_list as $table) { + $just_table_name = $table; + $old_table = $row_course['db_name'].".".$table; if ($singleDbForm) { - $work_table = "$prefix{$row_course['db_name']}_student_publication"; - $item_table = $row_course['db_name'].".item_property"; + $old_table = "$prefix{$row_course['db_name']}_".$table; + $just_table_name = "$prefix{$row_course['db_name']}_".$table; } + $course_id = $row_course['id']; + $new_table = DB_COURSE_PREFIX.$table; + + //Use the old database (if this is the case) + if (!$singleDbForm) { // otherwise just use the main one iDatabase::select_db($row_course['db_name']); @@ -206,310 +315,205 @@ if (defined('SYSTEM_INSTALLATION')) { iDatabase::select_db($dbNameForm); } + //Count of rows + $sql = "SHOW TABLES LIKE '$just_table_name'"; + $result = iDatabase::query($sql); - /* Start work fix */ - - /* Fixes the work subfolder and work with no parent issues */ - - //1. Searching for works with no parents - $sql = "SELECT * FROM $work_table WHERE parent_id = 0 AND filetype ='file'"; - $result = Database::query($sql); + if (Database::num_rows($result)) { - $work_list = array(); + $sql = "SELECT count(*) FROM $old_table"; + $result = iDatabase::query($sql); - if (Database::num_rows($result)) { - while ($row = Database::fetch_array($result, 'ASSOC')) { - $work_list[] = $row; + $old_count = 0; + if ($result) { + $row = iDatabase::fetch_row($result); + $old_count = $row[0]; + } else { + $app['monolog']->addError("Count(*) in table $old_table failed"); } - } - $today = api_get_utc_datetime(); - $user_id = 1; - require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php'; + $app['monolog']->addInfo("# rows in $old_table: $old_count"); - $sys_course_path = api_get_path(SYS_COURSE_PATH); - $course_dir = $sys_course_path . $row_course['directory']; - $base_work_dir = $course_dir . '/work'; + $sql = "SELECT * FROM $old_table"; + $result = iDatabase::query($sql); - //2. Looping if there are works with no parents - if (!empty($work_list)) { - $work_dir_created = array(); - - foreach ($work_list as $work) { - $session_id = intval($work['session_id']); - $group_id = intval($work['post_group_id']); - $work_key = $session_id.$group_id; - - //Only create the folder once - if (!isset($work_dir_created[$work_key])) { - - $dir_name = "default_tasks_".$group_id."_".$session_id; - - //2.1 Creating a new work folder - $sql = "INSERT INTO $work_table SET - url = 'work/".$dir_name."', - title = 'Tasks', - description = '', - author = '', - active = '1', - accepted = '1', - filetype = 'folder', - post_group_id = '$group_id', - sent_date = '".$today."', - parent_id = '0', - qualificator_id = '', - user_id = '".$user_id."'"; - iDatabase::query($sql); + $count = 0; - $id = Database::insert_id(); - //2.2 Adding the folder in item property - if ($id) { - //api_item_property_update($row_course, 'work', $id, 'DirectoryCreated', $user_id, $group_id, null, 0, 0 , $session_id); - $sql = "INSERT INTO $item_table (tool, ref, insert_date, insert_user_id, lastedit_date, lastedit_type, lastedit_user_id, to_group_id, visibility, id_session) - VALUES ('work','$id','$today', '$user_id', '$today', 'DirectoryCreated','$user_id', '$group_id', '1', '$session_id')"; - - iDatabase::query($sql); - $work_dir_created[$work_key] = $id; - create_unexisting_work_directory($base_work_dir, $dir_name); - $final_dir = $base_work_dir.'/'.$dir_name; - } - } else { - $final_dir = $base_work_dir.'/'.$dir_name; - } + /* Loads the main database */ + iDatabase::select_db($dbNameForm); - //2.3 Updating the url - if (!empty($work_dir_created[$work_key])) { - $parent_id = $work_dir_created[$work_key]; - $new_url = "work/".$dir_name.'/'.basename($work['url']); - $new_url = Database::escape_string($new_url);$sql = "UPDATE $work_table SET url = '$new_url', parent_id = $parent_id, contains_file = '1' WHERE id = {$work['id']}"; - iDatabase::query($sql); - if (is_dir($final_dir)) { - rename($course_dir.'/'.$work['url'], $course_dir.'/'.$new_url); - } + while($row = iDatabase::fetch_array($result, 'ASSOC')) { + $row['c_id'] = $course_id; + $id = iDatabase::insert($new_table, $row); + if (is_numeric($id)) { + $count++; + } else { + $errors[$old_table][] = $row; } } - } - //3.0 Moving subfolders to the root - $sql = "SELECT * FROM $work_table WHERE parent_id <> 0 AND filetype ='folder'"; - $result = Database::query($sql); - $work_list = array(); + $app['monolog']->addInfo("#rows inserted in $new_table: $count"); - if (Database::num_rows($result)) { - while ($row = Database::fetch_array($result, 'ASSOC')) { - $work_list[] = $row; - } - if (!empty($work_list)) { - foreach ($work_list as $work_folder) { - $folder_id = $work_folder['id']; - check_work($folder_id, $work_folder['url'], $work_table, $base_work_dir); - } + if ($old_count != $count) { + $app['monolog']->addError("ERROR count of new and old table doesn't match: $old_count - $new_table"); + $app['monolog']->addError("Check the results: "); + $app['monolog']->addError(print_r($errors, 1)); + error_log(print_r($errors, 1)); } + } else { + $app['monolog']->addError("Seems that the table $old_table doesn't exists "); } + } + $app['monolog']->addInfo('<<<------- end -------->>'); + } - /* End of work fix */ - - //Course tables to be migrated - $table_list = array( - 'announcement', - 'announcement_attachment', - 'attendance', - 'attendance_calendar', - 'attendance_result', - 'attendance_sheet', - 'attendance_sheet_log', - 'blog', - 'blog_attachment', - 'blog_comment', - 'blog_post', - 'blog_rating', - 'blog_rel_user', - 'blog_task', - 'blog_task_rel_user', - 'calendar_event', - 'calendar_event_attachment', - 'calendar_event_repeat', - 'calendar_event_repeat_not', - 'chat_connected', - 'course_description', - 'course_setting', - 'document', - 'dropbox_category', - 'dropbox_feedback', - 'dropbox_file', - 'dropbox_person', - 'dropbox_post', - 'forum_attachment', - 'forum_category', - 'forum_forum', - 'forum_mailcue', - 'forum_notification', - 'forum_post', - 'forum_thread', - 'forum_thread_qualify', - 'forum_thread_qualify_log', - 'glossary', - 'group_category', - 'group_info', - 'group_rel_tutor', - 'group_rel_user', - 'item_property', - 'link', - 'link_category', - 'lp', - 'lp_item', - 'lp_item_view', - 'lp_iv_interaction', - 'lp_iv_objective', - 'lp_view', - 'notebook', - 'metadata', - 'online_connected', - 'online_link', - 'permission_group', - 'permission_task', - 'permission_user', - 'quiz', - 'quiz_answer', - 'quiz_question', - 'quiz_question_option', - 'quiz_rel_question', - 'resource', - 'role', - 'role_group', - 'role_permissions', - 'role_user', - 'student_publication', - 'student_publication_assignment', - 'survey', - 'survey_answer', - 'survey_group', - 'survey_invitation', - 'survey_question', - 'survey_question_option', - 'thematic', - 'thematic_advance', - 'thematic_plan', - 'tool', - 'tool_intro', - 'userinfo_content', - 'userinfo_def', - 'wiki', - 'wiki_conf', - 'wiki_discuss', - 'wiki_mailcue' - ); - - $app['monolog']->addInfo('<<<------- Loading DB course '.$row_course['db_name'].' -------->>'); - - $count = $old_count = 0; - foreach ($table_list as $table) { - $just_table_name = $table; - $old_table = $row_course['db_name'].".".$table; - if ($singleDbForm) { - $old_table = "$prefix{$row_course['db_name']}_".$table; - $just_table_name = "$prefix{$row_course['db_name']}_".$table; - } + /* Start work fix */ - $course_id = $row_course['id']; - $new_table = DB_COURSE_PREFIX.$table; + /* Fixes the work subfolder and work with no parent issues */ - //Use the old database (if this is the case) + $courseList = \CourseManager::get_real_course_list(); - if (!$singleDbForm) { - // otherwise just use the main one - iDatabase::select_db($row_course['db_name']); - } else { - iDatabase::select_db($dbNameForm); - } + $work_table = $_configuration['main_database'].".student_publication"; + $item_table = $_configuration['main_database'].".item_property"; - //Count of rows - $sql = "SHOW TABLES LIKE '$just_table_name'"; - $result = iDatabase::query($sql); + require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php'; + $sys_course_path = api_get_path(SYS_COURSE_PATH); + $today = api_get_utc_datetime(); + $user_id = 1; - if (Database::num_rows($result)) { + foreach ($courseList as $course) { + $courseId = $course['real_id']; - $sql = "SELECT count(*) FROM $old_table"; - $result = iDatabase::query($sql); + //1. Searching for works with no parents + $sql = "SELECT * FROM $work_table WHERE parent_id = 0 AND filetype ='file' AND c_id = $courseId "; + $result = Database::query($sql); - $old_count = 0; - if ($result) { - $row = iDatabase::fetch_row($result); - $old_count = $row[0]; - } else { - $app['monolog']->addError("Count(*) in table $old_table failed"); - } + $work_list = array(); - $app['monolog']->addInfo("# rows in $old_table: $old_count"); - - $sql = "SELECT * FROM $old_table"; - $result = iDatabase::query($sql); - - $count = 0; + if (Database::num_rows($result)) { + while ($row = Database::fetch_array($result, 'ASSOC')) { + $work_list[] = $row; + } + } - /* Loads the main database */ - iDatabase::select_db($dbNameForm); + $course_dir = $sys_course_path.$course['directory']; + $base_work_dir = $course_dir.'/work'; + + //2. Looping if there are works with no parents + if (!empty($work_list)) { + $work_dir_created = array(); + + foreach ($work_list as $work) { + $session_id = intval($work['session_id']); + $group_id = intval($work['post_group_id']); + $work_key = $session_id.$group_id; + + //Only create the folder once + if (!isset($work_dir_created[$work_key])) { + + $dir_name = "default_tasks_".$group_id."_".$session_id; + + //2.1 Creating a new work folder + $sql = "INSERT INTO $work_table SET + c_id = '$courseId', + url = 'work/".$dir_name."', + title = 'Tasks', + description = '', + author = '', + active = '1', + accepted = '1', + filetype = 'folder', + post_group_id = '$group_id', + sent_date = '".$today."', + parent_id = '0', + qualificator_id = '', + user_id = '".$user_id."'"; + iDatabase::query($sql); + + $id = Database::insert_id(); + //2.2 Adding the folder in item property + if ($id) { + //api_item_property_update($row_course, 'work', $id, 'DirectoryCreated', $user_id, $group_id, null, 0, 0 , $session_id); + $sql = "INSERT INTO $item_table (c_id, tool, ref, insert_date, insert_user_id, lastedit_date, lastedit_type, lastedit_user_id, to_group_id, visibility, id_session) + VALUES ('$courseId', 'work','$id','$today', '$user_id', '$today', 'DirectoryCreated','$user_id', '$group_id', '1', '$session_id')"; - while($row = iDatabase::fetch_array($result, 'ASSOC')) { - $row['c_id'] = $course_id; - $id = iDatabase::insert($new_table, $row); - if (is_numeric($id)) { - $count++; - } else { - $errors[$old_table][] = $row; - } + iDatabase::query($sql); + $work_dir_created[$work_key] = $id; + create_unexisting_work_directory($base_work_dir, $dir_name); + $final_dir = $base_work_dir.'/'.$dir_name; } - $app['monolog']->addInfo("#rows inserted in $new_table: $count"); + } else { + $final_dir = $base_work_dir.'/'.$dir_name; + } - if ($old_count != $count) { - $app['monolog']->addError("ERROR count of new and old table doesn't match: $old_count - $new_table"); - $app['monolog']->addError("Check the results: "); - $app['monolog']->addError(print_r($errors, 1)); - error_log(print_r($errors, 1)); + //2.3 Updating the url + if (!empty($work_dir_created[$work_key])) { + $parent_id = $work_dir_created[$work_key]; + $new_url = "work/".$dir_name.'/'.basename($work['url']); + $new_url = Database::escape_string($new_url); + $sql = "UPDATE $work_table SET url = '$new_url', parent_id = $parent_id, contains_file = '1' WHERE id = {$work['id']} AND c_id = $courseId"; + iDatabase::query($sql); + if (is_dir($final_dir)) { + rename($course_dir.'/'.$work['url'], $course_dir.'/'.$new_url); } - } else { - $app['monolog']->addError("Seems that the table $old_table doesn't exists "); } } - $app['monolog']->addInfo('<<<------- end -------->>'); + } + + //3.0 Moving subfolders to the root + $sql = "SELECT * FROM $work_table WHERE parent_id <> 0 AND filetype ='folder' AND c_id = $courseId"; + $result = Database::query($sql); + $work_list = array(); + + if (Database::num_rows($result)) { + while ($row = Database::fetch_array($result, 'ASSOC')) { + $work_list[] = $row; + } + if (!empty($work_list)) { + foreach ($work_list as $work_folder) { + $folder_id = $work_folder['id']; + check_work($folder_id, $work_folder['url'], $work_table, $base_work_dir, $courseId); + } + } } } + /* End of work fix */ } } else { echo 'You are not allowed here !' . __FILE__; } -function check_work($folder_id, $work_url, $work_table, $base_work_dir) { +function check_work($folder_id, $work_url, $work_table, $base_work_dir, $courseId) { $uniq_id = uniqid(); //Looking for subfolders - $sql = "SELECT * FROM $work_table WHERE parent_id = $folder_id AND filetype ='folder'"; + $sql = "SELECT * FROM $work_table WHERE parent_id = $folder_id AND filetype ='folder' AND c_id = $courseId"; $result = Database::query($sql); if (Database::num_rows($result)) { while ($row = Database::fetch_array($result, 'ASSOC')) { - check_work($row['id'], $row['url'], $work_table, $base_work_dir); + check_work($row['id'], $row['url'], $work_table, $base_work_dir, $courseId); } } //Moving the subfolder in the root $new_url = '/'.basename($work_url).'_mv_'.$uniq_id; $new_url = Database::escape_string($new_url); - $sql = "UPDATE $work_table SET url = '$new_url', parent_id = 0 WHERE id = $folder_id"; + $sql = "UPDATE $work_table SET url = '$new_url', parent_id = 0 WHERE id = $folder_id AND c_id = $courseId"; iDatabase::query($sql); if (is_dir($base_work_dir.$work_url)) { rename($base_work_dir.$work_url, $base_work_dir.$new_url); //Rename all files inside the folder - $sql = "SELECT * FROM $work_table WHERE parent_id = $folder_id AND filetype ='file'"; + $sql = "SELECT * FROM $work_table WHERE parent_id = $folder_id AND filetype ='file' AND c_id = $courseId"; $result = Database::query($sql); if (Database::num_rows($result)) { while ($row = Database::fetch_array($result, 'ASSOC')) { $new_url = "work".$new_url.'/'.basename($row['url']); $new_url = Database::escape_string($new_url); - $sql = "UPDATE $work_table SET url = '$new_url', parent_id = $folder_id, contains_file = '1' WHERE id = {$row['id']}"; + $sql = "UPDATE $work_table SET url = '$new_url', parent_id = $folder_id, contains_file = '1' WHERE id = {$row['id']} AND c_id = $courseId"; iDatabase::query($sql); } } diff --git a/src/ChamiloLMS/Command/Database/InstallCommand.php b/src/ChamiloLMS/Command/Database/InstallCommand.php index a46966c75d..4586ac09d4 100644 --- a/src/ChamiloLMS/Command/Database/InstallCommand.php +++ b/src/ChamiloLMS/Command/Database/InstallCommand.php @@ -192,6 +192,7 @@ class InstallCommand extends CommonCommand $avoidVariables = array( 'main_database', //default is chamilo 'db_glue', + 'table_prefix', 'code_append', 'course_folder', 'db_admin_path', @@ -305,6 +306,9 @@ class InstallCommand extends CommonCommand $configurationPath = $this->getHelper('configuration')->getConfigurationPath(); $newConfigurationArray['system_version'] = $version; + $newConfigurationArray['db_glue'] = '`.`'; + $newConfigurationArray['db_prefix'] = ''; + $dumper = new Dumper(); $yaml = $dumper->dump($newConfigurationArray, 2); //inline $newConfigurationFile = $configurationPath.'configuration.yml'; diff --git a/src/ChamiloLMS/Command/Database/UpgradeCommand.php b/src/ChamiloLMS/Command/Database/UpgradeCommand.php index 7d49bcb1b0..018f815fab 100644 --- a/src/ChamiloLMS/Command/Database/UpgradeCommand.php +++ b/src/ChamiloLMS/Command/Database/UpgradeCommand.php @@ -202,7 +202,7 @@ class UpgradeCommand extends CommonCommand //Checking system_version if (!isset($_configuration['system_version']) || empty($_configuration['system_version'])) { - $output->writeln("You have something wrong in your Chamilo installation check it with chamilo:status."); + $output->writeln("You have something wrong in your Chamilo conf file. Check it with chamilo:status."); exit; } @@ -303,25 +303,28 @@ class UpgradeCommand extends CommonCommand */ public function startMigration($fromVersion, $toVersion, $dryRun, $output) { + //used by monolog global $app; + //Needed when using require file $_configuration = $this->getHelper('configuration')->getConfiguration(); $installPath = api_get_path(SYS_CODE_PATH).'install/'.$toVersion.'/'; $versionInfo = $this->getAvailableVersionInfo($toVersion); - //Filling sqlList with "pre" db changes + //Filling sqlList array with "pre" db changes if (isset($versionInfo['pre']) && !empty($versionInfo['pre'])) { $sqlToInstall = $installPath.$versionInfo['pre']; - $this->processSQLFile($sqlToInstall, $output); + $this->fillQueryList($sqlToInstall, $output); } - //Filling sqlList with "post" db changes + //Filling sqlList array with "post" db changes if (isset($versionInfo['post']) && !empty($versionInfo['post'])) { $sqlToInstall = $installPath.$versionInfo['post']; - $this->processSQLFile($sqlToInstall, $output); + $this->fillQueryList($sqlToInstall, $output); } + //Processing sql query list depending of the section $result = $this->processQueryList($output, $toVersion, $dryRun); //Processing "db" changes @@ -329,7 +332,6 @@ class UpgradeCommand extends CommonCommand $sqlToInstall = $installPath.$versionInfo['update_db']; if (is_file($sqlToInstall) && file_exists($sqlToInstall)) { $output->writeln("Executing update db: '$sqlToInstall'"); - $dblist = \Database::get_databases(); require $sqlToInstall; } } @@ -339,7 +341,6 @@ class UpgradeCommand extends CommonCommand $sqlToInstall = $installPath.$versionInfo['update_files']; if (is_file($sqlToInstall) && file_exists($sqlToInstall)) { $output->writeln("Executing update files: '$sqlToInstall'"); - $dblist = \Database::get_databases(); require $sqlToInstall; } } @@ -372,6 +373,13 @@ class UpgradeCommand extends CommonCommand /** * + * Process the queryList array and executes queries to the correct section (main, user, course, etc) + * + * @param $output + * @param $version + * @param $dryRun + * @return bool + * @throws \Exception */ public function processQueryList($output, $version, $dryRun) { @@ -399,7 +407,6 @@ class UpgradeCommand extends CommonCommand $conn->beginTransaction(); - foreach ($queryList as $query) { if ($dryRun) { $output->writeln($query); @@ -424,10 +431,12 @@ class UpgradeCommand extends CommonCommand } } else { $output->writeln(sprintf("Nothing to execute for section $section!")); + return false; } } } + return true; } @@ -435,7 +444,7 @@ class UpgradeCommand extends CommonCommand * @param string $sqlFilePath * @param $output */ - public function processSQLFile($sqlFilePath, $output) + public function fillQueryList($sqlFilePath, $output) { if (is_file($sqlFilePath) && file_exists($sqlFilePath)) { $output->writeln(sprintf("Processing file '%s'... ", $sqlFilePath)); @@ -583,6 +592,7 @@ class UpgradeCommand extends CommonCommand if (file_exists($newConfigurationFile)) { $yaml = new Parser(); + return $yaml->parse(file_get_contents($newConfigurationFile)); } else { @@ -703,7 +713,9 @@ class UpgradeCommand extends CommonCommand } - /* Executed only before create_course_tables() */ + /** + * Executed only before createCourseTables() + */ public function dropCourseTables() { $list = \CourseManager::get_course_tables(); @@ -713,6 +725,10 @@ class UpgradeCommand extends CommonCommand } } + /** + * Creates the course tables with the prefix c_ + * @param $output + */ public function createCourseTables($output) { $command = $this->getApplication()->find('dbal:import'); diff --git a/src/ChamiloLMS/Controller/IndexController.php b/src/ChamiloLMS/Controller/IndexController.php index f99b03bca5..e737f25b78 100644 --- a/src/ChamiloLMS/Controller/IndexController.php +++ b/src/ChamiloLMS/Controller/IndexController.php @@ -112,6 +112,8 @@ class IndexController// extends Controller facebook_connect(); } + //$app['url_generator']->generator('index'); + $this->setLoginForm($app); if (!api_is_anonymous()) { diff --git a/src/ChamiloLMS/Migrations/Version8.php b/src/ChamiloLMS/Migrations/Version8.php index 85744bdfca..fa01fd9ec1 100755 --- a/src/ChamiloLMS/Migrations/Version8.php +++ b/src/ChamiloLMS/Migrations/Version8.php @@ -5,6 +5,11 @@ namespace ChamiloLMS\Migrations; use Doctrine\DBAL\Migrations\AbstractMigration, Doctrine\DBAL\Schema\Schema; + +/** + * Manages the migration to version 1.8.0 + * @package ChamiloLMS\Controller\Migrations + */ class Version8 extends AbstractMigration { public function up(Schema $schema)