Addin validation if table exists see #4662

skala
Julio Montoya 13 years ago
parent 4db3767e9c
commit d280694759
  1. 26
      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) { foreach ($list as $row_course) {
// Now use the $c_q_list
if (!$singleDbForm) { // otherwise just use the main one if (!$singleDbForm) { // otherwise just use the main one
iDatabase::select_db($row_course['db_name']); iDatabase::select_db($row_course['db_name']);
} }
Log::notice('Course 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) { foreach ($c_q_list as $query) {
if ($singleDbForm) { 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); $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"; $work_table = $row_course['db_name'].".student_publication";
$item_table = $row_course['db_name'].".item_property"; $item_table = $row_course['db_name'].".item_property";
if ($singleDbForm) { if ($singleDbForm) {
$work_table = "$prefix{$row_course['db_name']}_student_publication"; $work_table = "$prefix{$row_course['db_name']}_student_publication";
$item_table = $row_course['db_name'].".item_property"; $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 */ /* Fixes the work subfolder and work with no parent issues */
//1. Searching for works with no parents //1. Searching for works with no parents
@ -454,9 +456,6 @@ if (defined('SYSTEM_INSTALLATION')) {
/* End of work fix */ /* End of work fix */
//Course tables to be migrated //Course tables to be migrated
$table_list = array( $table_list = array(
'announcement', 'announcement',
@ -553,11 +552,15 @@ if (defined('SYSTEM_INSTALLATION')) {
$count = $old_count = 0; $count = $old_count = 0;
foreach ($table_list as $table) { foreach ($table_list as $table) {
$just_table_name = $table;
$old_table = $row_course['db_name'].".".$table; $old_table = $row_course['db_name'].".".$table;
if ($singleDbForm) { if ($singleDbForm) {
$old_table = "$prefix{$row_course['db_name']}_".$table; $old_table = "$prefix{$row_course['db_name']}_".$table;
$just_table_name = "$prefix{$row_course['db_name']}_".$table;
} }
$course_id = $row_course['id']; $course_id = $row_course['id'];
$new_table = DB_COURSE_PREFIX.$table; $new_table = DB_COURSE_PREFIX.$table;
if (!$singleDbForm) { if (!$singleDbForm) {
@ -568,6 +571,11 @@ if (defined('SYSTEM_INSTALLATION')) {
} }
//Count of rows //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"; $sql = "SELECT count(*) FROM $old_table";
$result = iDatabase::query($sql); $result = iDatabase::query($sql);
@ -576,8 +584,9 @@ if (defined('SYSTEM_INSTALLATION')) {
$row = iDatabase::fetch_row($result); $row = iDatabase::fetch_row($result);
$old_count = $row[0]; $old_count = $row[0];
} else { } 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"); Log::notice("# rows in $old_table: $old_count");
$sql = "SELECT * FROM $old_table"; $sql = "SELECT * FROM $old_table";
@ -594,7 +603,7 @@ if (defined('SYSTEM_INSTALLATION')) {
$errors[$old_table][] = $row; $errors[$old_table][] = $row;
} }
} }
Log::notice("# rows inserted in $new_table: $count"); Log::notice("#rows inserted in $new_table: $count");
if ($old_count != $count) { if ($old_count != $count) {
Log::error("ERROR count of new and old table doesn't match: $old_count - $new_table"); Log::error("ERROR count of new and old table doesn't match: $old_count - $new_table");
@ -602,6 +611,9 @@ if (defined('SYSTEM_INSTALLATION')) {
Log::error(print_r($errors, 1)); Log::error(print_r($errors, 1));
error_log(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 -------->>'); Log::notice('<<<------- end -------->>');
} }

Loading…
Cancel
Save