update-db-1.8.6.2-1.8.7.inc.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Chamilo LMS
  5. *
  6. * Update the Chamilo database from an older Chamilo version
  7. * Notice : This script has to be included by index.php
  8. * or update_courses.php (deprecated).
  9. *
  10. * @package chamilo.install
  11. * @todo
  12. * - conditional changing of tables. Currently we execute for example
  13. * ALTER TABLE $dbNameForm.cours
  14. * instructions without checking wether this is necessary.
  15. * - reorganise code into functions
  16. * @todo use database library
  17. */
  18. $old_file_version = '1.8.6.2';
  19. $new_file_version = '1.8.7';
  20. // Check if we come from index.php or update_courses.php - otherwise display error msg
  21. if (defined('SYSTEM_INSTALLATION')) {
  22. // Check if the current Chamilo install is eligible for update
  23. if (!file_exists('../inc/conf/configuration.php')) {
  24. echo '<strong>'.get_lang('Error').' !</strong> Chamilo '.implode('|', $updateFromVersion).' '.get_lang('HasNotBeenFound').'.<br /><br />
  25. '.get_lang('PleasGoBackToStep1').'.
  26. <p><button type="submit" class="back" name="step1" value="&lt; '.get_lang('Back').'">'.get_lang('Back').'</button></p>
  27. </td></tr></table></form></body></html>';
  28. exit ();
  29. }
  30. $_configuration['db_glue'] = get_config_param('dbGlu');
  31. if ($singleDbForm) {
  32. $_configuration['table_prefix'] = get_config_param('courseTablePrefix');
  33. $_configuration['main_database'] = get_config_param('mainDbName');
  34. $_configuration['db_prefix'] = get_config_param('dbNamePrefix');
  35. }
  36. $dbScormForm = preg_replace('/[^a-zA-Z0-9_\-]/', '', $dbScormForm);
  37. if (!empty($dbPrefixForm) && strpos($dbScormForm, $dbPrefixForm) !== 0) {
  38. $dbScormForm = $dbPrefixForm.$dbScormForm;
  39. }
  40. if (empty($dbScormForm) || $dbScormForm == 'mysql' || $dbScormForm == $dbPrefixForm) {
  41. $dbScormForm = $dbPrefixForm.'scorm';
  42. }
  43. /* Normal upgrade procedure: start by updating main, statistic, user databases */
  44. // If this script has been included by index.php, not update_courses.php, so
  45. // that we want to change the main databases as well...
  46. $only_test = false;
  47. $log = 0;
  48. if (defined('SYSTEM_INSTALLATION')) {
  49. if ($singleDbForm) {
  50. $dbStatsForm = $dbNameForm;
  51. $dbScormForm = $dbNameForm;
  52. $dbUserForm = $dbNameForm;
  53. }
  54. /**
  55. * Update the databases "pre" migration
  56. */
  57. include '../lang/english/create_course.inc.php';
  58. if ($languageForm != 'english') {
  59. // languageForm has been escaped in index.php
  60. include '../lang/'.$languageForm.'/create_course.inc.php';
  61. }
  62. // Get the main queries list (m_q_list)
  63. $m_q_list = get_sql_file_contents('migrate-db-'.$old_file_version.'-'.$new_file_version.'-pre.sql', 'main');
  64. if (count($m_q_list) > 0) {
  65. // Now use the $m_q_list
  66. /**
  67. * We connect to the right DB first to make sure we can use the queries
  68. * without a database name
  69. */
  70. if (strlen($dbNameForm) > 40) {
  71. error_log('Database name '.$dbNameForm.' is too long, skipping', 0);
  72. } elseif (!in_array($dbNameForm, $dblist)) {
  73. error_log('Database '.$dbNameForm.' was not found, skipping', 0);
  74. } else {
  75. Database::select_db($dbNameForm);
  76. foreach ($m_q_list as $query){
  77. if ($only_test) {
  78. error_log("Database::query($dbNameForm,$query)", 0);
  79. } else {
  80. $res = Database::query($query);
  81. if ($log) {
  82. error_log("In $dbNameForm, executed: $query", 0);
  83. }
  84. if ($res === false) {
  85. error_log('Error in '.$query.': '.Database::error());
  86. }
  87. }
  88. }
  89. $tables = Database::get_tables($dbNameForm);
  90. foreach ($tables as $table) {
  91. $query = "ALTER TABLE `".$table."` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;";
  92. $res = Database::query($query);
  93. if ($res === false) {
  94. error_log('Error in '.$query.': '.Database::error());
  95. }
  96. }
  97. $query = "ALTER DATABASE `".$dbNameForm."` DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;";
  98. $res = Database::query($query);
  99. if ($res === false) {
  100. error_log('Error in '.$query.': '.Database::error());
  101. }
  102. }
  103. }
  104. if (DATE_TIME_INSTALLED) {
  105. // Converting dates and times to UTC using the default timezone of PHP
  106. // Converting gradebook dates and times
  107. $timezone = date_default_timezone_get();
  108. // Calculating the offset
  109. $dateTimeZoneCurrent = new DateTimeZone($timezone);
  110. $dateTimeUTC = new DateTime("now", new DateTimeZone('UTC'));
  111. $timeOffsetSeconds = $dateTimeZoneCurrent->getOffset($dateTimeUTC);
  112. $timeOffsetHours = $timeOffsetSeconds / 3600;
  113. $timeOffsetString = "";
  114. if($timeOffsetHours < 0) {
  115. $timeOffsetString .= "-";
  116. $timeOffsetHours = abs($timeOffsetHours);
  117. } else {
  118. $timeOffsetString .= "+";
  119. }
  120. if($timeOffsetHours < 10) {
  121. $timeOffsetString .= "0";
  122. }
  123. $timeOffsetString .= "$timeOffsetHours";
  124. $timeOffsetString .= ":00";
  125. // Executing the queries to convert everything
  126. $queries[] = "UPDATE gradebook_certificate SET created_at = CONVERT_TZ(created_at, '".$timeOffsetString."', '+00:00');";
  127. $queries[] = "UPDATE gradebook_evaluation SET created_at = CONVERT_TZ(created_at, '".$timeOffsetString."', '+00:00');";
  128. $queries[] = "UPDATE gradebook_link SET created_at = CONVERT_TZ(created_at, '".$timeOffsetString."', '+00:00');";
  129. $queries[] = "UPDATE gradebook_linkeval_log SET created_at = CONVERT_TZ(created_at, '".$timeOffsetString."', '+00:00');";
  130. $queries[] = "UPDATE gradebook_result SET created_at = CONVERT_TZ(created_at, '".$timeOffsetString."', '+00:00');";
  131. $queries[] = "UPDATE gradebook_result_log SET created_at = CONVERT_TZ(created_at, '".$timeOffsetString."', '+00:00');";
  132. foreach ($queries as $query) {
  133. Database::query($query);
  134. }
  135. }
  136. // Moving user followed by a human resource manager from hr_dept_id field to user_rel_user table
  137. $query = "SELECT user_id, hr_dept_id FROM $dbNameForm.user";
  138. $result = Database::query($query);
  139. if (Database::num_rows($result) > 0) {
  140. require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
  141. while ($row = Database::fetch_array($result, 'ASSOC')) {
  142. $user_id = $row['user_id'];
  143. $hr_dept_id = $row['hr_dept_id'];
  144. // moving data to user_rel_user table
  145. if (!empty($hr_dept_id)) {
  146. $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." ";
  147. $rs = Database::query($sql);
  148. if (Database::num_rows($rs) == 0) {
  149. $ins = "INSERT INTO $dbNameForm.user_rel_user SET user_id = $user_id, friend_user_id = $hr_dept_id, relation_type = ".USER_RELATION_TYPE_RRHH." ";
  150. Database::query($ins);
  151. }
  152. }
  153. }
  154. // cleaning hr_dept_id field inside user table
  155. $upd = "UPDATE $dbNameForm.user SET hr_dept_id = 0";
  156. Database::query($upd);
  157. }
  158. // Updating score display for each gradebook category
  159. // first we check if there already is migrated data to categoy_id field
  160. $query = "SELECT id FROM $dbNameForm.gradebook_score_display WHERE category_id = 0";
  161. $rs_check = Database::query($query);
  162. if (Database::num_rows($rs_check) > 0) {
  163. // get all gradebook categories id
  164. $a_categories = array();
  165. $query = "SELECT id FROM $dbNameForm.gradebook_category";
  166. $rs_gradebook = Database::query($query);
  167. if (Database::num_rows($rs_gradebook) > 0) {
  168. while($row_gradebook = Database::fetch_row($rs_gradebook)) {
  169. $a_categories[] = $row_gradebook[0];
  170. }
  171. }
  172. // get all gradebook score display
  173. $query = "SELECT * FROM $dbNameForm.gradebook_score_display";
  174. $rs_score_display = Database::query($query);
  175. if (Database::num_rows($rs_score_display) > 0) {
  176. $score_color_percent = api_get_setting('gradebook_score_display_colorsplit');
  177. while ($row_score_display = Database::fetch_array($rs_score_display)) {
  178. $score = $row_score_display['score'];
  179. $display = $row_score_display['display'];
  180. foreach ($a_categories as $category_id) {
  181. $ins = "INSERT INTO $dbNameForm.gradebook_score_display(score, display, category_id, score_color_percent) VALUES('$score', '$display', $category_id, '$score_color_percent')";
  182. Database::query($ins);
  183. }
  184. }
  185. // remove score display with category id = 0
  186. $del = "DELETE FROM $dbNameForm.gradebook_score_display WHERE category_id = 0";
  187. Database::query($del);
  188. }
  189. }
  190. // Now clean the deprecated id_coach field from the session_rel_course table
  191. $m_q_list = get_sql_file_contents('migrate-db-'.$old_file_version.'-'.$new_file_version.'-post.sql', 'main');
  192. if (count($m_q_list) > 0) {
  193. // Now use the $m_q_list
  194. /**
  195. * We connect to the right DB first to make sure we can use the queries
  196. * without a database name
  197. */
  198. if (strlen($dbNameForm) > 40) {
  199. error_log('Database name '.$dbNameForm.' is too long, skipping', 0);
  200. } elseif (!in_array($dbNameForm,$dblist)) {
  201. error_log('Database '.$dbNameForm.' was not found, skipping', 0);
  202. } else {
  203. Database::select_db($dbNameForm);
  204. foreach ($m_q_list as $query) {
  205. if ($only_test) {
  206. error_log("Database::query($dbNameForm,$query)", 0);
  207. } else {
  208. $res = Database::query($query);
  209. if ($log) {
  210. error_log("In $dbNameForm, executed: $query", 0);
  211. }
  212. }
  213. }
  214. }
  215. }
  216. // Get the stats queries list (s_q_list)
  217. $s_q_list = get_sql_file_contents('migrate-db-'.$old_file_version.'-'.$new_file_version.'-pre.sql', 'stats');
  218. if (count($s_q_list) > 0) {
  219. // Now use the $s_q_list
  220. /**
  221. * We connect to the right DB first to make sure we can use the queries
  222. * without a database name
  223. */
  224. if (strlen($dbStatsForm) > 40) {
  225. error_log('Database name '.$dbStatsForm.' is too long, skipping', 0);
  226. } elseif (!in_array($dbStatsForm, $dblist)){
  227. error_log('Database '.$dbStatsForm.' was not found, skipping', 0);
  228. } else {
  229. Database::select_db($dbStatsForm);
  230. foreach ($s_q_list as $query) {
  231. if ($only_test) {
  232. error_log("Database::query($dbStatsForm,$query)", 0);
  233. } else {
  234. $res = Database::query($query);
  235. if ($log) {
  236. error_log("In $dbStatsForm, executed: $query", 0);
  237. }
  238. if ($res === false) {
  239. error_log('Error in '.$query.': '.Database::error());
  240. }
  241. }
  242. }
  243. $tables = Database::get_tables($dbStatsForm);
  244. foreach ($tables as $table) {
  245. $query = "ALTER TABLE `".$table."` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;";
  246. $res = Database::query($query);
  247. if ($res === false) {
  248. error_log('Error in '.$query.': '.Database::error());
  249. }
  250. }
  251. $query = "ALTER DATABASE `".$dbStatsForm."` DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;";
  252. $res = Database::query($query);
  253. if ($res === false) {
  254. error_log('Error in '.$query.': '.Database::error());
  255. }
  256. // chamilo_stat.track_e_attempt table update changing id by id_auto
  257. $sql = "SELECT exe_id, question_id, course_code, answer FROM $dbStatsForm.track_e_attempt";
  258. $result = Database::query($sql);
  259. if (Database::num_rows($result) > 0) {
  260. while ($row = Database::fetch_array($result)) {
  261. $course_code = $row['course_code'];
  262. $course_info = api_get_course_info($course_code);
  263. $my_course_db = $course_info['dbName'];
  264. $question_id = $row['question_id'];
  265. $answer = $row['answer'];
  266. $exe_id = $row['exe_id'];
  267. //getting the type question id
  268. $sql_question = "SELECT type FROM $my_course_db.quiz_question where id = $question_id";
  269. $res_question = Database::query($sql_question);
  270. $row = Database::fetch_array($res_question);
  271. $type = $row['type'];
  272. require_once api_get_path(SYS_CODE_PATH).'exercice/question.class.php';
  273. //this type of questions produce problems in the track_e_attempt table
  274. if (in_array($type, array(UNIQUE_ANSWER, MULTIPLE_ANSWER, MATCHING, MULTIPLE_ANSWER_COMBINATION))) {
  275. $sql_question = "SELECT id_auto FROM $my_course_db.quiz_answer where question_id = $question_id and id = $answer";
  276. $res_question = Database::query($sql_question);
  277. $row = Database::fetch_array($res_question);
  278. $id_auto = $row['id_auto'];
  279. if (!empty($id_auto)) {
  280. $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 ";
  281. Database::query($sql);
  282. }
  283. }
  284. }
  285. }
  286. }
  287. }
  288. // Get the user queries list (u_q_list)
  289. $u_q_list = get_sql_file_contents('migrate-db-'.$old_file_version.'-'.$new_file_version.'-pre.sql', 'user');
  290. if (count($u_q_list) > 0) {
  291. // Now use the $u_q_list
  292. /**
  293. * We connect to the right DB first to make sure we can use the queries
  294. * without a database name
  295. */
  296. if (strlen($dbUserForm) > 40) {
  297. error_log('Database name '.$dbUserForm.' is too long, skipping', 0);
  298. } elseif (!in_array($dbUserForm,$dblist)) {
  299. error_log('Database '.$dbUserForm.' was not found, skipping', 0);
  300. } else {
  301. Database::select_db($dbUserForm);
  302. foreach ($u_q_list as $query) {
  303. if ($only_test) {
  304. error_log("Database::query($dbUserForm,$query)", 0);
  305. error_log("In $dbUserForm, executed: $query", 0);
  306. } else {
  307. $res = Database::query($query);
  308. if ($res === false) {
  309. error_log('Error in '.$query.': '.Database::error());
  310. }
  311. }
  312. }
  313. $tables = Database::get_tables($dbUserForm);
  314. foreach ($tables as $table) {
  315. $query = "ALTER TABLE `".$table."` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;";
  316. $res = Database::query($query);
  317. if ($res === false) {
  318. error_log('Error in '.$query.': '.Database::error());
  319. }
  320. }
  321. $query = "ALTER DATABASE `".$dbUserForm."` DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;";
  322. $res = Database::query($query);
  323. if ($res === false) {
  324. error_log('Error in '.$query.': '.Database::error());
  325. }
  326. }
  327. }
  328. // The SCORM database doesn't need a change in the pre-migrate part - ignore
  329. }
  330. $prefix = '';
  331. if ($singleDbForm) {
  332. $prefix = get_config_param ('table_prefix');
  333. }
  334. // Get the courses databases queries list (c_q_list)
  335. $c_q_list = get_sql_file_contents('migrate-db-'.$old_file_version.'-'.$new_file_version.'-pre.sql', 'course');
  336. if (count($c_q_list) > 0) {
  337. // Get the courses list
  338. if (strlen($dbNameForm) > 40) {
  339. error_log('Database name '.$dbNameForm.' is too long, skipping', 0);
  340. } elseif(!in_array($dbNameForm, $dblist)) {
  341. error_log('Database '.$dbNameForm.' was not found, skipping', 0);
  342. } else {
  343. Database::select_db($dbNameForm);
  344. $res = Database::query("SELECT code,db_name,directory,course_language FROM course WHERE target_course_code IS NULL ORDER BY code");
  345. if ($res === false) { die('Error while querying the courses list in update_db-1.8.6.2-1.8.7.inc.php'); }
  346. if (Database::num_rows($res) > 0) {
  347. $i = 0;
  348. $list = array();
  349. while ($row = Database::fetch_array($res)) {
  350. $list[] = $row;
  351. $i++;
  352. }
  353. foreach ($list as $row_course) {
  354. // Now use the $c_q_list
  355. /**
  356. * We connect to the right DB first to make sure we can use the queries
  357. * without a database name
  358. */
  359. if (!$singleDbForm) { // otherwise just use the main one
  360. Database::select_db($row_course['db_name']);
  361. }
  362. foreach ($c_q_list as $query) {
  363. if ($singleDbForm) {
  364. $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);
  365. }
  366. if ($only_test) {
  367. error_log("Database::query(".$row_course['db_name'].",$query)", 0);
  368. } else {
  369. $res = Database::query($query);
  370. if ($log) {
  371. error_log("In ".$row_course['db_name'].", executed: $query", 0);
  372. }
  373. if ($res === false) {
  374. error_log('Error in '.$query.': '.Database::error());
  375. }
  376. }
  377. }
  378. if (!$singleDbForm) {
  379. $tables = Database::get_tables($row_course['db_name']);
  380. foreach ($tables as $table) {
  381. $query = "ALTER TABLE `".$table."` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;";
  382. $res = Database::query($query);
  383. if ($res === false) {
  384. error_log('Error in '.$query.': '.Database::error());
  385. }
  386. }
  387. $query = "ALTER DATABASE `".$row_course['db_name']."` DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;";
  388. $res = Database::query($query);
  389. if ($res === false) {
  390. error_log('Error in '.$query.': '.Database::error());
  391. }
  392. }
  393. $t_student_publication = $row_course['db_name'].".student_publication";
  394. $t_item_property = $row_course['db_name'].".item_property";
  395. if ($singleDbForm) {
  396. $t_student_publication = "$prefix{$row_course['db_name']}_student_publication";
  397. $t_item_property = "$prefix{$row_course['db_name']}_item_property";
  398. }
  399. $sql_insert_user = "SELECT ref, insert_user_id FROM $t_item_property WHERE tool='work'";
  400. $rs_insert_user = Database::query($sql_insert_user);
  401. if ($rs_insert_user === false) {
  402. error_log('Could not query insert_user_id table: '.Database::error());
  403. } else {
  404. if (Database::num_rows($rs_insert_user) > 0) {
  405. while ($row_ids = Database::fetch_array($rs_insert_user)) {
  406. $user_id = $row_ids['insert_user_id'];
  407. $ref = $row_ids['ref'];
  408. $sql_upd = "UPDATE $t_student_publication SET user_id='$user_id' WHERE id='$ref'";
  409. Database::query($sql_upd);
  410. }
  411. }
  412. }
  413. //updating parent_id of the student_publication table
  414. $sql = 'SELECT id, url, parent_id FROM '.$t_student_publication;
  415. $result = Database::query($sql);
  416. if (Database::num_rows($result) > 0) {
  417. $items = Database::store_result($result);
  418. $directory_list = $file_list=array();
  419. foreach($items as $item) {
  420. $student_slash = substr($item['url'], 0, 1);
  421. //means this is a directory
  422. if ($student_slash == '/') {
  423. $directory_list[$item['id']]= $item['url'];
  424. } else {
  425. // this is a file with no parents
  426. if ($item['parent_id'] == 0)
  427. $file_list []= $item;
  428. }
  429. }
  430. if (is_array($file_list) && count($file_list) > 0) {
  431. foreach ($file_list as $file) {
  432. $parent_id = 0;
  433. if (is_array($directory_list) && count($directory_list) > 0) {
  434. foreach($directory_list as $id => $dir) {
  435. $pos = strpos($file['url'], $dir.'/');
  436. if ($pos !== false) {
  437. $parent_id = $id;
  438. break;
  439. }
  440. }
  441. }
  442. if ($parent_id != 0 ) {
  443. $sql = 'UPDATE '.$t_student_publication.' SET parent_id = '.$parent_id.' WHERE id = '.$file['id'].'';
  444. Database::query($sql);
  445. }
  446. }
  447. }
  448. }
  449. }
  450. }
  451. }
  452. }
  453. // Get the courses databases queries list (c_q_list)
  454. $c_q_list = get_sql_file_contents('migrate-db-'.$old_file_version.'-'.$new_file_version.'-post.sql', 'course');
  455. if (count($c_q_list) > 0) {
  456. // Get the courses list
  457. if (strlen($dbNameForm) > 40) {
  458. error_log('Database name '.$dbNameForm.' is too long, skipping', 0);
  459. } elseif (!in_array($dbNameForm, $dblist)) {
  460. error_log('Database '.$dbNameForm.' was not found, skipping', 0);
  461. } else {
  462. Database::select_db($dbNameForm);
  463. $res = Database::query("SELECT code,db_name,directory,course_language FROM course WHERE target_course_code IS NULL");
  464. if ($res === false) { die('Error while querying the courses list in update_db-1.8.6.2-1.8.7.inc.php'); }
  465. if (Database::num_rows($res) > 0) {
  466. $i = 0;
  467. while ($row = Database::fetch_array($res)) {
  468. $list[] = $row;
  469. $i++;
  470. }
  471. foreach ($list as $row) {
  472. // Now use the $c_q_list
  473. /**
  474. * We connect to the right DB first to make sure we can use the queries
  475. * without a database name
  476. */
  477. $prefix_course = $prefix;
  478. if ($singleDbForm) {
  479. $prefix_course = $prefix.$row['db_name']."_";
  480. } else {
  481. Database::select_db($row['db_name']);
  482. }
  483. foreach($c_q_list as $query) {
  484. if ($singleDbForm) { //otherwise just use the main one
  485. $query = preg_replace('/^(UPDATE|ALTER TABLE|CREATE TABLE|DROP TABLE|INSERT INTO|DELETE FROM)\s+(\w*)(.*)$/', "$1 $prefix$2$3", $query);
  486. }
  487. if ($only_test) {
  488. error_log("Database::query(".$row['db_name'].",$query)", 0);
  489. } else {
  490. $res = Database::query($query);
  491. if ($log) {
  492. error_log("In ".$row['db_name'].", executed: $query", 0);
  493. }
  494. }
  495. }
  496. }
  497. }
  498. }
  499. }
  500. } else {
  501. echo 'You are not allowed here !';
  502. }