if (count($c_q_list) > 0) { // Get the courses list if (strlen($dbNameForm) > 40) { Log::error('Database name '.$dbNameForm.' is too long, skipping'); } elseif (!in_array($dbNameForm, $dblist)) { Log::error('Database '.$dbNameForm.' was not found, skipping'); } else { iDatabase::select_db($dbNameForm); $res = iDatabase::query("SELECT code,db_name,directory,course_language 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.6-1.8.6.1.inc.php'); } if (iDatabase::num_rows($res) > 0) { $i = 0; $list = array(); while ($row = iDatabase::fetch_array($res)) { $list[] = $row; $i++; } foreach ($list as $row_course) { // Now use the $c_q_list /** * We connect to the right DB first to make sure we can use the queries * without a database name */ if (!$singleDbForm) { //otherwise just use the main one iDatabase::select_db($row_course['db_name']); } Log::notice('Course db ' . $row_course['db_name']); foreach ($c_q_list as $query) {
fclose($fh); $sys_course_path = $pathForm . 'courses/'; //$tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE); //// Linking (The following line is disabled, connection has been already done) //$res = @iDatabase::connect(array('server' => $dbHostForm, 'username' => $dbUsernameForm, 'password' => $dbPassForm)); //iDatabase::select_db($dbNameForm, $link); iDatabase::select_db($dbNameForm); $db_name = $dbNameForm; $sql = "SELECT * FROM $db_name.course"; Log::notice('Getting courses for files updates: ' . $sql); $result = iDatabase::query($sql); while ($courses_directories = iDatabase::fetch_array($result)) { $currentCourseRepositorySys = $sys_course_path . $courses_directories['directory'] . '/'; $db_name = $courses_directories['db_name']; $origCRS = $updatePath . 'courses/' . $courses_directories['directory']; if (!is_dir($origCRS)) { Log::error('Directory ' . $origCRS . ' does not exist. Skipping.'); continue; } // Move everything to the new hierarchy (from old path to new path) Log::notice('Renaming ' . $origCRS . ' to ' . $sys_course_path . $courses_directories['directory']); rename($origCRS, $sys_course_path . $courses_directories['directory']); Log::notice('Creating dirs in ' . $currentCourseRepositorySys);
$old_count = $row[0]; } else { Log::error("Count(*) in table $old_table failed"); } Log::notice("# rows in $old_table: $old_count"); $sql = "SELECT * FROM $old_table"; $result = iDatabase::query($sql); $count = 0; /* Loads the main database */ iDatabase::select_db($dbNameForm); 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; } } Log::notice("#rows inserted in $new_table: $count"); if ($old_count != $count) { Log::error("ERROR count of new and old table doesn't match: $old_count - $new_table"); Log::error("Check the results: "); Log::error(print_r($errors, 1)); error_log(print_r($errors, 1));
$t_course_description = $row_course['db_name'].".course_description"; if ($singleDbForm) { $t_course_description = "$prefix{$row_course['db_name']}_course_description"; } // Get all ids and update description_type field with them from course_description table $sql_sel = "SELECT id FROM $t_course_description"; $rs_sel = iDatabase::query($sql_sel); if ($rs_sel === false) { Log::error('Could not query course_description ids table: '.iDatabase::error()); } else { if (iDatabase::num_rows($rs_sel) > 0) { while ($row_ids = iDatabase::fetch_array($rs_sel)) { $description_id = $row_ids['id']; $sql_upd = "UPDATE $t_course_description SET description_type='$description_id' WHERE id='$description_id'"; iDatabase::query($sql_upd); } } } } } } } } else { echo 'You are not allowed here !' . __FILE__;