Addin validation if table exists see #4662

skala
Julio Montoya 13 years ago
parent 4db3767e9c
commit d280694759
  1. 24
      main/install/update-db-1.8.8-1.9.0.inc.php

@ -317,13 +317,12 @@ if (defined('SYSTEM_INSTALLATION')) {
}
foreach ($list as $row_course) {
// Now use the $c_q_list
if (!$singleDbForm) { // otherwise just use the main one
iDatabase::select_db($row_course['db_name']);
}
Log::notice('Course db ' . $row_course['db_name']);
// Now use the $c_q_list
foreach ($c_q_list as $query) {
if ($singleDbForm) {
$query = preg_replace('/^(UPDATE|ALTER TABLE|CREATE TABLE|DROP TABLE|INSERT INTO|DELETE FROM)\s+(\w*)(.*)$/', "$1 $prefix{$row_course['db_name']}_$2$3", $query);
@ -340,6 +339,7 @@ if (defined('SYSTEM_INSTALLATION')) {
$work_table = $row_course['db_name'].".student_publication";
$item_table = $row_course['db_name'].".item_property";
if ($singleDbForm) {
$work_table = "$prefix{$row_course['db_name']}_student_publication";
$item_table = $row_course['db_name'].".item_property";
@ -353,6 +353,8 @@ if (defined('SYSTEM_INSTALLATION')) {
}
/* Start work fix */
/* Fixes the work subfolder and work with no parent issues */
//1. Searching for works with no parents
@ -454,9 +456,6 @@ if (defined('SYSTEM_INSTALLATION')) {
/* End of work fix */
//Course tables to be migrated
$table_list = array(
'announcement',
@ -553,11 +552,15 @@ if (defined('SYSTEM_INSTALLATION')) {
$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;
}
$course_id = $row_course['id'];
$new_table = DB_COURSE_PREFIX.$table;
if (!$singleDbForm) {
@ -568,6 +571,11 @@ if (defined('SYSTEM_INSTALLATION')) {
}
//Count of rows
$sql = "SHOW TABLES LIKE '$just_table_name'";
$result = iDatabase::query($sql);
if (Database::num_rows($result)) {
$sql = "SELECT count(*) FROM $old_table";
$result = iDatabase::query($sql);
@ -576,8 +584,9 @@ if (defined('SYSTEM_INSTALLATION')) {
$row = iDatabase::fetch_row($result);
$old_count = $row[0];
} else {
Log::error("Seems that the table $old_table doesn't exists ");
Log::error("Count(*) in table $old_table failed");
}
Log::notice("# rows in $old_table: $old_count");
$sql = "SELECT * FROM $old_table";
@ -602,6 +611,9 @@ if (defined('SYSTEM_INSTALLATION')) {
Log::error(print_r($errors, 1));
error_log(print_r($errors, 1));
}
} else {
Log::error("Seems that the table $old_table doesn't exists ");
}
}
Log::notice('<<<------- end -------->>');
}

Loading…
Cancel
Save