Browse Source

#4694 add feedback during installation

Laurent Opprecht 13 years ago
parent
commit
aa3dafc3af
1 changed files with 178 additions and 183 deletions
  1. 178 183
      main/install/update-db-1.8.6.2-1.8.7.inc.php

+ 178 - 183
main/install/update-db-1.8.6.2-1.8.7.inc.php

@@ -1,4 +1,5 @@
 <?php
+
 /* For licensing terms, see /license.txt */
 
 /**
@@ -26,11 +27,11 @@ if (defined('SYSTEM_INSTALLATION')) {
 
     // Check if the current Chamilo install is eligible for update
     if (!file_exists('../inc/conf/configuration.php')) {
-        echo '<strong>'.get_lang('Error').' !</strong> Chamilo '.implode('|', $updateFromVersion).' '.get_lang('HasNotBeenFound').'.<br /><br />
-                                '.get_lang('PleasGoBackToStep1').'.
-                                <p><button type="submit" class="back" name="step1" value="&lt; '.get_lang('Back').'">'.get_lang('Back').'</button></p>
+        echo '<strong>' . get_lang('Error') . ' !</strong> Chamilo ' . implode('|', $updateFromVersion) . ' ' . get_lang('HasNotBeenFound') . '.<br /><br />
+                                ' . get_lang('PleasGoBackToStep1') . '.
+                                <p><button type="submit" class="back" name="step1" value="&lt; ' . get_lang('Back') . '">' . get_lang('Back') . '</button></p>
                                 </td></tr></table></form></body></html>';
-        exit ();
+        exit();
     }
 
     $_configuration['db_glue'] = get_config_param('dbGlu');
@@ -41,14 +42,14 @@ if (defined('SYSTEM_INSTALLATION')) {
         $_configuration['db_prefix'] = get_config_param('dbNamePrefix');
     }
 
-	$dbScormForm = preg_replace('/[^a-zA-Z0-9_\-]/', '', $dbScormForm);
+    $dbScormForm = preg_replace('/[^a-zA-Z0-9_\-]/', '', $dbScormForm);
 
-	if (!empty($dbPrefixForm) && strpos($dbScormForm, $dbPrefixForm) !== 0) {
-        $dbScormForm = $dbPrefixForm.$dbScormForm;
+    if (!empty($dbPrefixForm) && strpos($dbScormForm, $dbPrefixForm) !== 0) {
+        $dbScormForm = $dbPrefixForm . $dbScormForm;
     }
 
     if (empty($dbScormForm) || $dbScormForm == 'mysql' || $dbScormForm == $dbPrefixForm) {
-        $dbScormForm = $dbPrefixForm.'scorm';
+        $dbScormForm = $dbPrefixForm . 'scorm';
     }
 
     /*   Normal upgrade procedure: start by updating main, statistic, user databases */
@@ -71,11 +72,11 @@ if (defined('SYSTEM_INSTALLATION')) {
 
         if ($languageForm != 'english') {
             // languageForm has been escaped in index.php
-            include '../lang/'.$languageForm.'/create_course.inc.php';
+            include '../lang/' . $languageForm . '/create_course.inc.php';
         }
 
         // Get the main queries list (m_q_list)
-        $m_q_list = get_sql_file_contents('migrate-db-'.$old_file_version.'-'.$new_file_version.'-pre.sql', 'main');
+        $m_q_list = get_sql_file_contents('migrate-db-' . $old_file_version . '-' . $new_file_version . '-pre.sql', 'main');
         if (count($m_q_list) > 0) {
             // Now use the $m_q_list
             /**
@@ -83,36 +84,36 @@ if (defined('SYSTEM_INSTALLATION')) {
              * without a database name
              */
             if (strlen($dbNameForm) > 40) {
-                 Log::error('Database name '.$dbNameForm.' is too long, skipping');
+                Log::error('Database name ' . $dbNameForm . ' is too long, skipping');
             } elseif (!in_array($dbNameForm, $dblist)) {
-                 Log::error('Database '.$dbNameForm.' was not found, skipping');
+                Log::error('Database ' . $dbNameForm . ' was not found, skipping');
             } else {
                 Database::select_db($dbNameForm);
-                foreach ($m_q_list as $query){
+                foreach ($m_q_list as $query) {
                     if ($only_test) {
-                         Log::notice("Database::query($dbNameForm,$query)");
+                        Log::notice("Database::query($dbNameForm,$query)");
                     } else {
                         $res = Database::query($query);
                         if ($log) {
-                             Log::notice("In $dbNameForm, executed: $query");
+                            Log::notice("In $dbNameForm, executed: $query");
                         }
                         if ($res === false) {
-                        	 Log::error('Error in '.$query.': '.Database::error());
+                            Log::error('Error in ' . $query . ': ' . Database::error());
                         }
                     }
                 }
                 $tables = Database::get_tables($dbNameForm);
                 foreach ($tables as $table) {
-            	    $query = "ALTER TABLE `".$table."` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;";
+                    $query = "ALTER TABLE `" . $table . "` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;";
                     $res = Database::query($query);
                     if ($res === false) {
-                          Log::error('Error in '.$query.': '.Database::error());
+                        Log::error('Error in ' . $query . ': ' . Database::error());
                     }
                 }
-            	$query = "ALTER DATABASE `".$dbNameForm."` DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;";
+                $query = "ALTER DATABASE `" . $dbNameForm . "` DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;";
                 $res = Database::query($query);
                 if ($res === false) {
-                      Log::error('Error in '.$query.': '.Database::error());
+                    Log::error('Error in ' . $query . ': ' . Database::error());
                 }
             }
         }
@@ -127,29 +128,29 @@ if (defined('SYSTEM_INSTALLATION')) {
             $timeOffsetSeconds = $dateTimeZoneCurrent->getOffset($dateTimeUTC);
             $timeOffsetHours = $timeOffsetSeconds / 3600;
             $timeOffsetString = "";
-    
-            if($timeOffsetHours < 0) {
-                    $timeOffsetString .= "-";
-                    $timeOffsetHours = abs($timeOffsetHours);
+
+            if ($timeOffsetHours < 0) {
+                $timeOffsetString .= "-";
+                $timeOffsetHours = abs($timeOffsetHours);
             } else {
-                    $timeOffsetString .= "+";
+                $timeOffsetString .= "+";
             }
-    
-            if($timeOffsetHours < 10) {
-                    $timeOffsetString .= "0";
+
+            if ($timeOffsetHours < 10) {
+                $timeOffsetString .= "0";
             }
-    
+
             $timeOffsetString .= "$timeOffsetHours";
             $timeOffsetString .= ":00";
-    
+
             // Executing the queries to convert everything
-            $queries[] = "UPDATE gradebook_certificate 	SET created_at = CONVERT_TZ(created_at, '".$timeOffsetString."', '+00:00');";
-            $queries[] = "UPDATE gradebook_evaluation 	SET created_at = CONVERT_TZ(created_at, '".$timeOffsetString."', '+00:00');";
-            $queries[] = "UPDATE gradebook_link 		SET created_at = CONVERT_TZ(created_at, '".$timeOffsetString."', '+00:00');";
-            $queries[] = "UPDATE gradebook_linkeval_log SET created_at = CONVERT_TZ(created_at, '".$timeOffsetString."', '+00:00');";
-            $queries[] = "UPDATE gradebook_result 		SET created_at = CONVERT_TZ(created_at, '".$timeOffsetString."', '+00:00');";
-            $queries[] = "UPDATE gradebook_result_log 	SET created_at = CONVERT_TZ(created_at, '".$timeOffsetString."', '+00:00');";
-    
+            $queries[] = "UPDATE gradebook_certificate 	SET created_at = CONVERT_TZ(created_at, '" . $timeOffsetString . "', '+00:00');";
+            $queries[] = "UPDATE gradebook_evaluation 	SET created_at = CONVERT_TZ(created_at, '" . $timeOffsetString . "', '+00:00');";
+            $queries[] = "UPDATE gradebook_link 		SET created_at = CONVERT_TZ(created_at, '" . $timeOffsetString . "', '+00:00');";
+            $queries[] = "UPDATE gradebook_linkeval_log SET created_at = CONVERT_TZ(created_at, '" . $timeOffsetString . "', '+00:00');";
+            $queries[] = "UPDATE gradebook_result 		SET created_at = CONVERT_TZ(created_at, '" . $timeOffsetString . "', '+00:00');";
+            $queries[] = "UPDATE gradebook_result_log 	SET created_at = CONVERT_TZ(created_at, '" . $timeOffsetString . "', '+00:00');";
+
             foreach ($queries as $query) {
                 Database::query($query);
             }
@@ -158,16 +159,16 @@ if (defined('SYSTEM_INSTALLATION')) {
         $query = "SELECT user_id, hr_dept_id  FROM $dbNameForm.user";
         $result = Database::query($query);
         if (Database::num_rows($result) > 0) {
-            require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
+            require_once api_get_path(LIBRARY_PATH) . 'usermanager.lib.php';
             while ($row = Database::fetch_array($result, 'ASSOC')) {
                 $user_id = $row['user_id'];
                 $hr_dept_id = $row['hr_dept_id'];
                 // moving data to user_rel_user table
                 if (!empty($hr_dept_id)) {
-                    $sql = " SELECT id FROM $dbNameForm.user_rel_user WHERE user_id = $user_id AND friend_user_id = $hr_dept_id AND relation_type = ".USER_RELATION_TYPE_RRHH." ";
-                    $rs  = Database::query($sql);
+                    $sql = " SELECT id FROM $dbNameForm.user_rel_user WHERE user_id = $user_id AND friend_user_id = $hr_dept_id AND relation_type = " . USER_RELATION_TYPE_RRHH . " ";
+                    $rs = Database::query($sql);
                     if (Database::num_rows($rs) == 0) {
-                        $ins = "INSERT INTO $dbNameForm.user_rel_user SET user_id = $user_id, friend_user_id = $hr_dept_id, relation_type = ".USER_RELATION_TYPE_RRHH." ";
+                        $ins = "INSERT INTO $dbNameForm.user_rel_user SET user_id = $user_id, friend_user_id = $hr_dept_id, relation_type = " . USER_RELATION_TYPE_RRHH . " ";
                         Database::query($ins);
                     }
                 }
@@ -178,7 +179,6 @@ if (defined('SYSTEM_INSTALLATION')) {
         }
 
         // Updating score display for each gradebook category
-
         // first we check if there already is migrated data to categoy_id field
         $query = "SELECT id FROM $dbNameForm.gradebook_score_display WHERE category_id = 0";
         $rs_check = Database::query($query);
@@ -189,7 +189,7 @@ if (defined('SYSTEM_INSTALLATION')) {
             $query = "SELECT id FROM $dbNameForm.gradebook_category";
             $rs_gradebook = Database::query($query);
             if (Database::num_rows($rs_gradebook) > 0) {
-                while($row_gradebook = Database::fetch_row($rs_gradebook)) {
+                while ($row_gradebook = Database::fetch_row($rs_gradebook)) {
                     $a_categories[] = $row_gradebook[0];
                 }
             }
@@ -214,7 +214,7 @@ if (defined('SYSTEM_INSTALLATION')) {
         }
 
         // Now clean the deprecated id_coach field from the session_rel_course table
-        $m_q_list = get_sql_file_contents('migrate-db-'.$old_file_version.'-'.$new_file_version.'-post.sql', 'main');
+        $m_q_list = get_sql_file_contents('migrate-db-' . $old_file_version . '-' . $new_file_version . '-post.sql', 'main');
         if (count($m_q_list) > 0) {
             // Now use the $m_q_list
             /**
@@ -222,18 +222,18 @@ if (defined('SYSTEM_INSTALLATION')) {
              * without a database name
              */
             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');
+                Log::error('Database name ' . $dbNameForm . ' is too long, skipping');
+            } elseif (!in_array($dbNameForm, $dblist)) {
+                Log::error('Database ' . $dbNameForm . ' was not found, skipping');
             } else {
                 Database::select_db($dbNameForm);
                 foreach ($m_q_list as $query) {
                     if ($only_test) {
-                         Log::notice("Database::query($dbNameForm,$query)");
+                        Log::notice("Database::query($dbNameForm,$query)");
                     } else {
                         $res = Database::query($query);
                         if ($log) {
-                             Log::notice("In $dbNameForm, executed: $query");
+                            Log::notice("In $dbNameForm, executed: $query");
                         }
                     }
                 }
@@ -241,7 +241,7 @@ if (defined('SYSTEM_INSTALLATION')) {
         }
 
         // Get the stats queries list (s_q_list)
-        $s_q_list = get_sql_file_contents('migrate-db-'.$old_file_version.'-'.$new_file_version.'-pre.sql', 'stats');
+        $s_q_list = get_sql_file_contents('migrate-db-' . $old_file_version . '-' . $new_file_version . '-pre.sql', 'stats');
         if (count($s_q_list) > 0) {
             // Now use the $s_q_list
             /**
@@ -249,82 +249,81 @@ if (defined('SYSTEM_INSTALLATION')) {
              * without a database name
              */
             if (strlen($dbStatsForm) > 40) {
-                 Log::error('Database name '.$dbStatsForm.' is too long, skipping');
-            } elseif (!in_array($dbStatsForm, $dblist)){
-                 Log::error('Database '.$dbStatsForm.' was not found, skipping');
+                Log::error('Database name ' . $dbStatsForm . ' is too long, skipping');
+            } elseif (!in_array($dbStatsForm, $dblist)) {
+                Log::error('Database ' . $dbStatsForm . ' was not found, skipping');
             } else {
                 Database::select_db($dbStatsForm);
+                Log::notice('Database: statistics');
 
                 foreach ($s_q_list as $query) {
                     if ($only_test) {
-                         Log::notice("Database::query($dbStatsForm,$query)");
+                        Log::notice("Database::query($dbStatsForm,$query)");
                     } else {
                         $res = Database::query($query);
                         if ($log) {
-                             Log::notice("In $dbStatsForm, executed: $query");
+                            Log::notice("In $dbStatsForm, executed: $query");
                         }
                         if ($res === false) {
-                             Log::error('Error in '.$query.': '.Database::error());
+                            Log::error('Error in ' . $query . ': ' . Database::error());
                         }
                     }
                 }
                 $tables = Database::get_tables($dbStatsForm);
                 foreach ($tables as $table) {
-            	    $query = "ALTER TABLE `".$table."` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;";
+                    $query = "ALTER TABLE `" . $table . "` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;";
                     $res = Database::query($query);
                     if ($res === false) {
-                          Log::error('Error in '.$query.': '.Database::error());
+                        Log::error('Error in ' . $query . ': ' . Database::error());
                     }
                 }
-                $query = "ALTER DATABASE `".$dbStatsForm."` DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;";
+                $query = "ALTER DATABASE `" . $dbStatsForm . "` DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;";
                 $res = Database::query($query);
                 if ($res === false) {
-                      Log::error('Error in '.$query.': '.Database::error());
+                    Log::error('Error in ' . $query . ': ' . Database::error());
                 }
 
 
                 // chamilo_stat.track_e_attempt table update changing id by id_auto
 
-      			$sql = "SELECT exe_id, question_id, course_code, answer FROM $dbStatsForm.track_e_attempt";
+                $sql = "SELECT exe_id, question_id, course_code, answer FROM $dbStatsForm.track_e_attempt";
                 $result = Database::query($sql);
                 if (Database::num_rows($result) > 0) {
-                	while ($row = Database::fetch_array($result)) {
-                		$course_code  	= $row['course_code'];
-                		$course_info 	= api_get_course_info($course_code);
-						$my_course_db 	= $course_info['dbName'];
- 						$question_id  	= $row['question_id'];
-						$answer			= $row['answer'];
-						$exe_id			= $row['exe_id'];
-
-						//getting the type question id
-                		$sql_question = "SELECT type FROM $my_course_db.quiz_question where id = $question_id";
-                		$res_question = Database::query($sql_question);
-                		$row  = Database::fetch_array($res_question);
-                 		$type = $row['type'];
-
-                		require_once api_get_path(SYS_CODE_PATH).'exercice/question.class.php';
-                		//this type of questions produce problems in the track_e_attempt table
-                		if (in_array($type, array(UNIQUE_ANSWER, MULTIPLE_ANSWER, MATCHING, MULTIPLE_ANSWER_COMBINATION))) {
-		            		$sql_question = "SELECT id_auto FROM $my_course_db.quiz_answer where question_id = $question_id and id = $answer";
-		            		$res_question = Database::query($sql_question);
-		            		$row = Database::fetch_array($res_question);
-		            		$id_auto = $row['id_auto'];
-		            		if (!empty($id_auto)) {
-	                			$sql = "UPDATE $dbStatsForm.track_e_attempt SET answer = '$id_auto' WHERE exe_id = $exe_id AND question_id = $question_id AND course_code = '$course_code' and answer = $answer ";
-	                			Database::query($sql);
-		            		}
-                		}
-                	}
+                    while ($row = Database::fetch_array($result)) {
+                        $course_code = $row['course_code'];
+                        $course_info = api_get_course_info($course_code);
+                        $my_course_db = $course_info['dbName'];
+                        $question_id = $row['question_id'];
+                        $answer = $row['answer'];
+                        $exe_id = $row['exe_id'];
+
+                        //getting the type question id
+                        $sql_question = "SELECT type FROM $my_course_db.quiz_question where id = $question_id";
+                        $res_question = Database::query($sql_question);
+                        $row = Database::fetch_array($res_question);
+                        $type = $row['type'];
+
+                        require_once api_get_path(SYS_CODE_PATH) . 'exercice/question.class.php';
+                        //this type of questions produce problems in the track_e_attempt table
+                        if (in_array($type, array(UNIQUE_ANSWER, MULTIPLE_ANSWER, MATCHING, MULTIPLE_ANSWER_COMBINATION))) {
+                            $sql_question = "SELECT id_auto FROM $my_course_db.quiz_answer where question_id = $question_id and id = $answer";
+                            $res_question = Database::query($sql_question);
+                            $row = Database::fetch_array($res_question);
+                            $id_auto = $row['id_auto'];
+                            if (!empty($id_auto)) {
+                                $sql = "UPDATE $dbStatsForm.track_e_attempt SET answer = '$id_auto' WHERE exe_id = $exe_id AND question_id = $question_id AND course_code = '$course_code' and answer = $answer ";
+                                Database::query($sql);
+                            }
+                        }
+                    }
                 }
-
-
             }
         }
 
 
 
         // Get the user queries list (u_q_list)
-        $u_q_list = get_sql_file_contents('migrate-db-'.$old_file_version.'-'.$new_file_version.'-pre.sql', 'user');
+        $u_q_list = get_sql_file_contents('migrate-db-' . $old_file_version . '-' . $new_file_version . '-pre.sql', 'user');
         if (count($u_q_list) > 0) {
             // Now use the $u_q_list
             /**
@@ -332,34 +331,35 @@ if (defined('SYSTEM_INSTALLATION')) {
              * without a database name
              */
             if (strlen($dbUserForm) > 40) {
-                 Log::error('Database name '.$dbUserForm.' is too long, skipping');
-            } elseif (!in_array($dbUserForm,$dblist)) {
-                 Log::error('Database '.$dbUserForm.' was not found, skipping');
+                Log::error('Database name ' . $dbUserForm . ' is too long, skipping');
+            } elseif (!in_array($dbUserForm, $dblist)) {
+                Log::error('Database ' . $dbUserForm . ' was not found, skipping');
             } else {
                 Database::select_db($dbUserForm);
+                Log::notice('Database: user');
                 foreach ($u_q_list as $query) {
                     if ($only_test) {
-                         Log::notice("Database::query($dbUserForm,$query)");
-                         Log::notice("In $dbUserForm, executed: $query");
+                        Log::notice("Database::query($dbUserForm,$query)");
+                        Log::notice("In $dbUserForm, executed: $query");
                     } else {
                         $res = Database::query($query);
                         if ($res === false) {
-                             Log::error('Error in '.$query.': '.Database::error());
+                            Log::error('Error in ' . $query . ': ' . Database::error());
                         }
                     }
                 }
                 $tables = Database::get_tables($dbUserForm);
                 foreach ($tables as $table) {
-            	    $query = "ALTER TABLE `".$table."` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;";
+                    $query = "ALTER TABLE `" . $table . "` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;";
                     $res = Database::query($query);
                     if ($res === false) {
-                          Log::error('Error in '.$query.': '.Database::error());
+                        Log::error('Error in ' . $query . ': ' . Database::error());
                     }
                 }
-                $query = "ALTER DATABASE `".$dbUserForm."` DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;";
+                $query = "ALTER DATABASE `" . $dbUserForm . "` DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;";
                 $res = Database::query($query);
                 if ($res === false) {
-                      Log::error('Error in '.$query.': '.Database::error());
+                    Log::error('Error in ' . $query . ': ' . Database::error());
                 }
             }
         }
@@ -368,22 +368,24 @@ if (defined('SYSTEM_INSTALLATION')) {
 
     $prefix = '';
     if ($singleDbForm) {
-        $prefix =  get_config_param ('table_prefix');
+        $prefix = get_config_param('table_prefix');
     }
 
     // Get the courses databases queries list (c_q_list)
-    $c_q_list = get_sql_file_contents('migrate-db-'.$old_file_version.'-'.$new_file_version.'-pre.sql', 'course');
+    $c_q_list = get_sql_file_contents('migrate-db-' . $old_file_version . '-' . $new_file_version . '-pre.sql', 'course');
     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');
+            Log::error('Database name ' . $dbNameForm . ' is too long, skipping');
+        } elseif (!in_array($dbNameForm, $dblist)) {
+            Log::error('Database ' . $dbNameForm . ' was not found, skipping');
         } else {
             Database::select_db($dbNameForm);
             $res = Database::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.2-1.8.7.inc.php'); }
+            if ($res === false) {
+                die('Error while querying the courses list in update_db-1.8.6.2-1.8.7.inc.php');
+            }
 
             if (Database::num_rows($res) > 0) {
                 $i = 0;
@@ -409,14 +411,14 @@ if (defined('SYSTEM_INSTALLATION')) {
                         }
 
                         if ($only_test) {
-                             Log::notice("Database::query(".$row_course['db_name'].",$query)");
+                            Log::notice("Database::query(" . $row_course['db_name'] . ",$query)");
                         } else {
                             $res = Database::query($query);
                             if ($log) {
-                                 Log::notice("In ".$row_course['db_name'].", executed: $query");
+                                Log::notice("In " . $row_course['db_name'] . ", executed: $query");
                             }
                             if ($res === false) {
-                                 Log::error('Error in '.$query.': '.Database::error());
+                                Log::error('Error in ' . $query . ': ' . Database::error());
                             }
                         }
                     }
@@ -424,20 +426,20 @@ if (defined('SYSTEM_INSTALLATION')) {
                     if (!$singleDbForm) {
                         $tables = Database::get_tables($row_course['db_name']);
                         foreach ($tables as $table) {
-            	            $query = "ALTER TABLE `".$table."` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;";
+                            $query = "ALTER TABLE `" . $table . "` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;";
                             $res = Database::query($query);
                             if ($res === false) {
-                                 Log::error('Error in '.$query.': '.Database::error());
+                                Log::error('Error in ' . $query . ': ' . Database::error());
                             }
                         }
-                    	$query = "ALTER DATABASE `".$row_course['db_name']."` DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;";
-                    	$res = Database::query($query);
+                        $query = "ALTER DATABASE `" . $row_course['db_name'] . "` DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;";
+                        $res = Database::query($query);
                         if ($res === false) {
-                             Log::error('Error in '.$query.': '.Database::error());
+                            Log::error('Error in ' . $query . ': ' . Database::error());
                         }
                     }
-                    $t_student_publication = $row_course['db_name'].".student_publication";
-                    $t_item_property = $row_course['db_name'].".item_property";
+                    $t_student_publication = $row_course['db_name'] . ".student_publication";
+                    $t_item_property = $row_course['db_name'] . ".item_property";
 
                     if ($singleDbForm) {
                         $t_student_publication = "$prefix{$row_course['db_name']}_student_publication";
@@ -449,79 +451,75 @@ if (defined('SYSTEM_INSTALLATION')) {
                     $rs_insert_user = Database::query($sql_insert_user);
 
                     if ($rs_insert_user === false) {
-				    	 Log::error('Could not query insert_user_id table: '.Database::error());
-					} else {
-						if (Database::num_rows($rs_insert_user) > 0) {
-							while ($row_ids = Database::fetch_array($rs_insert_user)) {
-								$user_id = $row_ids['insert_user_id'];
-								$ref = $row_ids['ref'];
-								$sql_upd = "UPDATE $t_student_publication SET user_id='$user_id' WHERE id='$ref'";
-								Database::query($sql_upd);
-							}
-						}
-					}
-
-					//updating parent_id of the student_publication table
-			        $sql = 'SELECT id, url, parent_id FROM '.$t_student_publication;
-					$result = Database::query($sql);
-					if (Database::num_rows($result) > 0) {
-						$items = Database::store_result($result);
-						$directory_list = $file_list=array();
-
-						foreach($items as $item) {
-							$student_slash = substr($item['url'], 0, 1);
-							//means this is a directory
-							if ($student_slash == '/') {
-								$directory_list[$item['id']]= $item['url'];
-							} else {
-							// this is a file with no parents
-								if ($item['parent_id'] == 0)
-									$file_list []= $item;
-							}
-						}
-
-						if (is_array($file_list) && count($file_list) > 0) {
-							foreach ($file_list as $file) {
-								$parent_id = 0;
-								if (is_array($directory_list) && count($directory_list) > 0) {
-									foreach($directory_list as $id => $dir) {
-										$pos = strpos($file['url'], $dir.'/');
-										if ($pos !== false) {
-											$parent_id = $id;
-											break;
-										}
-									}
-								}
-
-								if ($parent_id != 0 ) {
-									$sql = 'UPDATE '.$t_student_publication.' SET parent_id = '.$parent_id.' WHERE id = '.$file['id'].'';
-									Database::query($sql);
-								}
-							}
-						}
-                	}
-
-
-
-
+                        Log::error('Could not query insert_user_id table: ' . Database::error());
+                    } else {
+                        if (Database::num_rows($rs_insert_user) > 0) {
+                            while ($row_ids = Database::fetch_array($rs_insert_user)) {
+                                $user_id = $row_ids['insert_user_id'];
+                                $ref = $row_ids['ref'];
+                                $sql_upd = "UPDATE $t_student_publication SET user_id='$user_id' WHERE id='$ref'";
+                                Database::query($sql_upd);
+                            }
+                        }
+                    }
 
+                    //updating parent_id of the student_publication table
+                    $sql = 'SELECT id, url, parent_id FROM ' . $t_student_publication;
+                    $result = Database::query($sql);
+                    if (Database::num_rows($result) > 0) {
+                        $items = Database::store_result($result);
+                        $directory_list = $file_list = array();
+
+                        foreach ($items as $item) {
+                            $student_slash = substr($item['url'], 0, 1);
+                            //means this is a directory
+                            if ($student_slash == '/') {
+                                $directory_list[$item['id']] = $item['url'];
+                            } else {
+                                // this is a file with no parents
+                                if ($item['parent_id'] == 0)
+                                    $file_list [] = $item;
+                            }
+                        }
 
+                        if (is_array($file_list) && count($file_list) > 0) {
+                            foreach ($file_list as $file) {
+                                $parent_id = 0;
+                                if (is_array($directory_list) && count($directory_list) > 0) {
+                                    foreach ($directory_list as $id => $dir) {
+                                        $pos = strpos($file['url'], $dir . '/');
+                                        if ($pos !== false) {
+                                            $parent_id = $id;
+                                            break;
+                                        }
+                                    }
+                                }
+
+                                if ($parent_id != 0) {
+                                    $sql = 'UPDATE ' . $t_student_publication . ' SET parent_id = ' . $parent_id . ' WHERE id = ' . $file['id'] . '';
+                                    Database::query($sql);
+                                }
+                            }
+                        }
+                    }
                 }
             }
         }
     }
     // Get the courses databases queries list (c_q_list)
-    $c_q_list = get_sql_file_contents('migrate-db-'.$old_file_version.'-'.$new_file_version.'-post.sql', 'course');
+    $c_q_list = get_sql_file_contents('migrate-db-' . $old_file_version . '-' . $new_file_version . '-post.sql', 'course');
     if (count($c_q_list) > 0) {
         // Get the courses list
         if (strlen($dbNameForm) > 40) {
-             Log::error('Database name '.$dbNameForm.' is too long, skipping');
+            Log::error('Database name ' . $dbNameForm . ' is too long, skipping');
         } elseif (!in_array($dbNameForm, $dblist)) {
-             Log::error('Database '.$dbNameForm.' was not found, skipping');
+            Log::error('Database ' . $dbNameForm . ' was not found, skipping');
         } else {
             Database::select_db($dbNameForm);
             $res = Database::query("SELECT code,db_name,directory,course_language FROM course WHERE target_course_code IS NULL");
-            if ($res === false) { die('Error while querying the courses list in update_db-1.8.6.2-1.8.7.inc.php'); }
+            if ($res === false) {
+                die('Error while querying the courses list in update_db-1.8.6.2-1.8.7.inc.php');
+            }
             if (Database::num_rows($res) > 0) {
                 $i = 0;
                 while ($row = Database::fetch_array($res)) {
@@ -536,21 +534,21 @@ if (defined('SYSTEM_INSTALLATION')) {
                      */
                     $prefix_course = $prefix;
                     if ($singleDbForm) {
-                        $prefix_course = $prefix.$row['db_name']."_";
+                        $prefix_course = $prefix . $row['db_name'] . "_";
                     } else {
                         Database::select_db($row['db_name']);
                     }
 
-                    foreach($c_q_list as $query) {
+                    foreach ($c_q_list as $query) {
                         if ($singleDbForm) { //otherwise just use the main one
                             $query = preg_replace('/^(UPDATE|ALTER TABLE|CREATE TABLE|DROP TABLE|INSERT INTO|DELETE FROM)\s+(\w*)(.*)$/', "$1 $prefix$2$3", $query);
                         }
                         if ($only_test) {
-                             Log::notice("Database::query(".$row['db_name'].",$query)");
+                            Log::notice("Database::query(" . $row['db_name'] . ",$query)");
                         } else {
                             $res = Database::query($query);
                             if ($log) {
-                                 Log::notice("In ".$row['db_name'].", executed: $query");
+                                Log::notice("In " . $row['db_name'] . ", executed: $query");
                             }
                         }
                     }
@@ -558,10 +556,7 @@ if (defined('SYSTEM_INSTALLATION')) {
             }
         }
     }
-
-
 } else {
 
     echo 'You are not allowed here !';
-
 }