From f33e1ed4ae4948e337e5fee61adc3580f81dfa80 Mon Sep 17 00:00:00 2001 From: skodak Date: Thu, 15 May 2008 21:40:00 +0000 Subject: [PATCH] MDL-14679 ok, here is the big patch with new dmllib and ddlib API, some code is already converted, XML db editor works; see tracker for details of regressions and TODOs --- admin/cliupgrade.php | 12 +- admin/cron.php | 2 +- admin/index.php | 42 +- admin/innodb.php | 65 +- admin/mnet/access_control.php | 12 +- admin/multilangupgrade.php | 27 +- admin/replace.php | 6 +- admin/roles/manage.php | 39 +- admin/timezone.php | 23 +- .../check_bigints/check_bigints.class.php | 35 +- .../check_defaults/check_defaults.class.php | 68 +- .../check_indexes/check_indexes.class.php | 21 +- .../edit_statement/edit_statement.class.php | 2 +- .../actions/edit_table/edit_table.class.php | 17 +- .../edit_xml_file/edit_xml_file.class.php | 21 +- .../load_xml_file/load_xml_file.class.php | 2 +- .../actions/main_view/main_view.class.php | 4 +- .../new_statement/new_statement.class.php | 9 +- .../new_table_from_mysql.class.php | 14 +- admin/xmldb/actions/test/test.class.php | 381 +-- .../view_reserved_words.class.php | 44 +- .../view_structure_sql.class.php | 29 +- .../view_table_php/view_table_php.class.php | 2 +- .../view_table_sql/view_table_sql.class.php | 32 +- admin/xmldb/index.php | 26 +- auth/cas/auth.php | 4 + auth/ldap/auth.php | 3 + backup/lib.php | 16 +- blocks/admin/block_admin.php | 4 +- blog/lib.php | 2 - calendar/event.php | 4 +- course/edit_form.php | 4 +- course/lib.php | 6 +- enrol/authorize/db/upgrade.php | 2 +- file.php | 26 +- grade/edit/outcome/import.php | 1 - group/index.php | 5 +- group/overview.php | 43 +- help.php | 4 +- index.php | 4 +- lib/accesslib.php | 607 ++-- lib/adminlib.php | 106 +- lib/blocklib.php | 24 +- lib/datalib.php | 103 +- lib/db/install.xml | 20 +- lib/db/upgrade.php | 24 +- lib/db/upgradelib.php | 36 +- lib/ddl/database_manager.php | 1138 +++++++ .../mssql_sql_generator.php} | 187 +- .../mysql_sql_generator.php} | 146 +- .../oracle_sql_generator.php} | 181 +- .../postgres_sql_generator.php} | 140 +- .../sql_generator.php} | 481 +-- lib/ddllib.php | 1445 +-------- lib/dml/adodb_moodle_database.php | 454 +++ lib/dml/adodb_moodle_recordset.php | 38 + lib/dml/moodle_database.php | 1241 +++++++ lib/dml/mssql_adodb_moodle_database.php | 385 +++ lib/dml/mssql_n_adodb_moodle_database.php | 45 + lib/dml/mysql_adodb_moodle_database.php | 26 + lib/dml/mysqli_adodb_moodle_database.php | 203 ++ lib/dml/oci8po_adodb_moodle_database.php | 483 +++ lib/dml/oci8po_adodb_moodle_recordset.php | 41 + lib/dml/odbc_mssql_adodb_moodle_database.php | 45 + lib/dml/pdo_moodle_database.php | 156 + lib/dml/pdo_moodle_recordset.php | 38 + lib/dml/postgres7_adodb_moodle_database.php | 401 +++ lib/dmllib.php | 2860 ++--------------- lib/dmllib_todo.php | 1298 ++++++++ lib/environmentlib.php | 10 +- lib/filelib.php | 8 +- lib/grade/grade_item.php | 6 +- lib/grade/lib_wrapper.php | 3 +- lib/grouplib.php | 127 +- lib/locallib.php | 6 +- lib/moodlelib.php | 30 +- lib/setup.php | 92 +- lib/setuplib.php | 142 - lib/weblib.php | 40 +- lib/xmldb/{classes => }/XMLDBConstants.php | 0 lib/xmldb/{classes => }/XMLDBField.class.php | 0 lib/xmldb/{classes => }/XMLDBFile.class.php | 0 lib/xmldb/{classes => }/XMLDBIndex.class.php | 0 lib/xmldb/{classes => }/XMLDBKey.class.php | 0 lib/xmldb/{classes => }/XMLDBObject.class.php | 0 .../{classes => }/XMLDBStatement.class.php | 49 - .../{classes => }/XMLDBStructure.class.php | 22 - lib/xmldb/{classes => }/XMLDBTable.class.php | 284 -- .../generators/mssql_n/mssql_n.class.php | 44 - .../generators/mysqli/mysqli.class.php | 43 - .../odbc_mssql/odbc_mssql.class.php | 43 - mod/assignment/db/upgrade.php | 30 +- mod/chat/lib.php | 28 +- mod/choice/mod_form.php | 5 +- mod/data/db/upgrade.php | 89 +- mod/data/import.php | 1 - mod/feedback/db/upgrade.php | 71 +- mod/forum/db/upgrade.php | 19 +- mod/glossary/edit.php | 4 +- mod/glossary/edit_form.php | 4 +- mod/hotpot/attempt.php | 10 +- mod/hotpot/db/upgrade.php | 11 +- mod/hotpot/index.php | 2 +- mod/hotpot/lib.php | 10 +- mod/hotpot/restorelib.php | 4 +- mod/hotpot/view.php | 2 +- mod/lesson/db/upgrade.php | 49 +- mod/quiz/report/grading/report.php | 14 +- mod/quiz/report/overview/report.php | 4 +- mod/survey/mod_form.php | 4 +- mod/wiki/ewiki/plugins/page/orphanedpages.php | 4 +- search/indexlib.php | 16 +- 112 files changed, 8187 insertions(+), 6558 deletions(-) create mode 100644 lib/ddl/database_manager.php rename lib/{xmldb/classes/generators/mssql/mssql.class.php => ddl/mssql_sql_generator.php} (77%) rename lib/{xmldb/classes/generators/mysql/mysql.class.php => ddl/mysql_sql_generator.php} (76%) rename lib/{xmldb/classes/generators/oci8po/oci8po.class.php => ddl/oracle_sql_generator.php} (82%) rename lib/{xmldb/classes/generators/postgres7/postgres7.class.php => ddl/postgres_sql_generator.php} (83%) rename lib/{xmldb/classes/generators/XMLDBGenerator.class.php => ddl/sql_generator.php} (73%) create mode 100644 lib/dml/adodb_moodle_database.php create mode 100644 lib/dml/adodb_moodle_recordset.php create mode 100644 lib/dml/moodle_database.php create mode 100644 lib/dml/mssql_adodb_moodle_database.php create mode 100644 lib/dml/mssql_n_adodb_moodle_database.php create mode 100644 lib/dml/mysql_adodb_moodle_database.php create mode 100644 lib/dml/mysqli_adodb_moodle_database.php create mode 100644 lib/dml/oci8po_adodb_moodle_database.php create mode 100644 lib/dml/oci8po_adodb_moodle_recordset.php create mode 100644 lib/dml/odbc_mssql_adodb_moodle_database.php create mode 100644 lib/dml/pdo_moodle_database.php create mode 100644 lib/dml/pdo_moodle_recordset.php create mode 100644 lib/dml/postgres7_adodb_moodle_database.php create mode 100644 lib/dmllib_todo.php rename lib/xmldb/{classes => }/XMLDBConstants.php (100%) rename lib/xmldb/{classes => }/XMLDBField.class.php (100%) rename lib/xmldb/{classes => }/XMLDBFile.class.php (100%) rename lib/xmldb/{classes => }/XMLDBIndex.class.php (100%) rename lib/xmldb/{classes => }/XMLDBKey.class.php (100%) rename lib/xmldb/{classes => }/XMLDBObject.class.php (100%) rename lib/xmldb/{classes => }/XMLDBStatement.class.php (89%) rename lib/xmldb/{classes => }/XMLDBStructure.class.php (96%) rename lib/xmldb/{classes => }/XMLDBTable.class.php (72%) delete mode 100644 lib/xmldb/classes/generators/mssql_n/mssql_n.class.php delete mode 100644 lib/xmldb/classes/generators/mysqli/mysqli.class.php delete mode 100644 lib/xmldb/classes/generators/odbc_mssql/odbc_mssql.class.php diff --git a/admin/cliupgrade.php b/admin/cliupgrade.php index e3ddd7f03c..2b59f6e8ea 100644 --- a/admin/cliupgrade.php +++ b/admin/cliupgrade.php @@ -860,16 +860,16 @@ if ( file_exists(dirname(dirname(__FILE__)) . '/config.php')) { /// Both old .sql files and new install.xml are supported /// But we prioritise install.xml (XMLDB) if present - change_db_encoding(); // first try to change db encoding to utf8 - - if (!setup_is_unicodedb()) { - // If could not convert successfully, throw error, and prevent installation - console_write(STDERR,'unicoderequired', 'admin'); + if (!$DB->setup_is_unicodedb()) { + if (!$DB->change_db_encoding()) { + // If could not convert successfully, throw error, and prevent installation + console_write(STDERR,'unicoderequired', 'admin'); + } } $status = false; if (file_exists("$CFG->libdir/db/install.xml")) { - $status = install_from_xmldb_file("$CFG->libdir/db/install.xml"); //New method + $status = $DB->get_manager()->install_from_xmldb_file("$CFG->libdir/db/install.xml"); //New method } else { console_write(STDERR,"Error: Your database ($CFG->dbtype) is not yet fully supported by Moodle or install.xml is not present. See the lib/db directory.",'',false); } diff --git a/admin/cron.php b/admin/cron.php index e7f3f01441..9c3449cce3 100644 --- a/admin/cron.php +++ b/admin/cron.php @@ -36,7 +36,7 @@ /// Extra debugging (set in config.php) if (!empty($CFG->showcronsql)) { - $db->debug = true; + $DB->set_debug(true); } if (!empty($CFG->showcrondebugging)) { $CFG->debug = DEBUG_DEVELOPER; diff --git a/admin/index.php b/admin/index.php index 09f39f5b16..bdf0af2ea7 100644 --- a/admin/index.php +++ b/admin/index.php @@ -61,14 +61,6 @@ print_error('phpvaron', 'debug', '', array('file_uploads', $documentationlink)); } - if (empty($CFG->prefix) && $CFG->dbfamily != 'mysql') { //Enforce prefixes for everybody but mysql - print_error('prefixcannotbeempty', 'debug', '', array($CFG->prefix, $CFG->dbtype)); - } - - if ($CFG->dbfamily == 'oracle' && strlen($CFG->prefix) > 2) { //Max prefix length for Oracle is 2cc - print_error('prefixlimit', 'debug', '', $CFG->prefix); - } - /// Check that config.php has been edited if ($CFG->wwwroot == "http://example.com/moodle") { @@ -103,8 +95,7 @@ } /// Check if the main tables have been installed yet or not. - - if (! $tables = $db->Metatables() ) { // No tables yet at all. + if (!$tables = $DB->get_tables() ) { // No tables yet at all. $maintables = false; } else { // Check for missing main tables @@ -113,7 +104,7 @@ "course_sections", "log", "log_display", "modules", "user"); foreach ($mtables as $mtable) { - if (!in_array($CFG->prefix.$mtable, $tables)) { + if (!in_array($mtable, $tables)) { $maintables = false; break; } @@ -164,20 +155,21 @@ $CFG->debug = $origdebug; error_reporting($CFG->debug); upgrade_log_start(); - $db->debug = true; + $DB->set_debug(true); /// Both old .sql files and new install.xml are supported /// But we prioritise install.xml (XMLDB) if present - change_db_encoding(); // first try to change db encoding to utf8 - if (!setup_is_unicodedb()) { - // If could not convert successfully, throw error, and prevent installation - print_error('unicoderequired', 'admin'); + if (!$DB->setup_is_unicodedb()) { + if (!$DB->change_db_encoding()) { + // If could not convert successfully, throw error, and prevent installation + print_error('unicoderequired', 'admin'); + } } $status = false; if (file_exists("$CFG->libdir/db/install.xml")) { - $status = install_from_xmldb_file("$CFG->libdir/db/install.xml"); //New method + $status = $DB->get_manager()->install_from_xmldb_file("$CFG->libdir/db/install.xml"); //New method } else { print_error('dbnotsupport', 'debug', '', $CFG->dbtype); } @@ -186,7 +178,7 @@ set_config('unicodedb', 1); /// Continue with the instalation - $db->debug = false; + $DB->set_debug(false); if ($status) { /// Groups install is now in core above. @@ -335,7 +327,7 @@ upgrade_language_pack(); print_heading($strdatabasechecking); - $db->debug=true; + $DB->set_debug(true); /// Launch the old main upgrade (if exists) $status = true; if (function_exists('main_upgrade')) { @@ -345,7 +337,7 @@ if ($status && function_exists('xmldb_main_upgrade')) { $status = xmldb_main_upgrade($CFG->version); } - $db->debug=false; + $DB->set_debug(false); /// If successful, continue upgrading roles and setting everything properly if ($status) { if (!update_capabilities()) { @@ -473,7 +465,7 @@ $newsite->students = get_string("defaultcoursestudents"); $newsite->timemodified = time(); - if (!$newid = insert_record('course', $newsite)) { + if (!$newid = $DB->insert_record('course', $newsite)) { print_error('cannotsetupsite', 'error'); } // make sure course context exists @@ -486,7 +478,7 @@ $cat = new object(); $cat->name = get_string('miscellaneous'); $cat->depth = 1; - if (!$catid = insert_record('course_categories', $cat)) { + if (!$catid = $DB->insert_record('course_categories', $cat)) { print_error('cannotsetupcategory', 'error'); } // make sure category context exists @@ -505,10 +497,10 @@ blocks_repopulate_page($page); //add admin_tree block to site if not already present - if ($admintree = get_record('block', 'name', 'admin_tree')) { + if ($admintree = $DB->get_record('block', array('name'=>'admin_tree'))) { $page = page_create_object(PAGE_COURSE_VIEW, SITEID); blocks_execute_action($page, blocks_get_by_page($page), 'add', (int)$admintree->id, false, false); - if ($admintreeinstance = get_record('block_instance', 'pagetype', $page->type, 'pageid', SITEID, 'blockid', $admintree->id)) { + if ($admintreeinstance = $DB->get_record('block_instance', array('pagetype'=>$page->type, 'pageid'=>SITEID, 'blockid'=>$admintree->id))) { blocks_execute_action($page, blocks_get_by_page($page), 'moveleft', $admintreeinstance, false, false); } } @@ -522,7 +514,7 @@ } /// Check if the guest user exists. If not, create one. - if (! record_exists("user", "username", "guest")) { + if (!$DB->record_exists('user', array('username'=>'guest'))) { if (! $guest = create_guest_record()) { notify("Could not create guest user record !!!"); } diff --git a/admin/innodb.php b/admin/innodb.php index e7d82ac2b4..93238106cb 100644 --- a/admin/innodb.php +++ b/admin/innodb.php @@ -1,43 +1,44 @@ libdir.'/adminlib.php'); + require_once('../config.php'); + require_once($CFG->libdir.'/adminlib.php'); - admin_externalpage_setup('toinodb'); + admin_externalpage_setup('toinodb'); - $confirm = optional_param('confirm', 0, PARAM_BOOL); + $confirm = optional_param('confirm', 0, PARAM_BOOL); - require_login(); + require_login(); - require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)); + require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)); - admin_externalpage_print_header(); - print_heading('Convert all MySQL tables from MYISAM to InnoDB'); + admin_externalpage_print_header(); + print_heading('Convert all MySQL tables from MYISAM to InnoDB'); - if ($CFG->dbfamily != 'mysql') { + if ($CFG->dbfamily != 'mysql') { notice('This function is for MySQL databases only!', 'index.php'); - } - - if (data_submitted() and $confirm and confirm_sesskey()) { - - notify('Please be patient and wait for this to complete...', 'notifysuccess'); - - if ($tables = $db->MetaTables()) { - $db->debug = true; - foreach ($tables as $table) { - execute_sql("ALTER TABLE $table TYPE=INNODB; "); - } - $db->debug = false; - } - notify('... done.', 'notifysuccess'); - print_continue('index.php'); - admin_externalpage_print_footer(); - - } else { - $optionsyes = array('confirm'=>'1', 'sesskey'=>sesskey()); - notice_yesno('Are you sure you want convert all your tables to the InnoDB format?', - 'innodb.php', 'index.php', $optionsyes, NULL, 'post', 'get'); - admin_externalpage_print_footer(); - } + } + + if (data_submitted() and $confirm and confirm_sesskey()) { + + notify('Please be patient and wait for this to complete...', 'notifysuccess'); + + if ($tables = $DB->get_tables()) { + $DB->set_debug(true); + foreach ($tables as $table) { + $fulltable = $DB->get_prefix().$table; + $DB->change_database_structure("ALTER TABLE $fulltable TYPE=INNODB"); + } + $DB->set_debug(false); + } + notify('... done.', 'notifysuccess'); + print_continue('index.php'); + admin_externalpage_print_footer(); + + } else { + $optionsyes = array('confirm'=>'1', 'sesskey'=>sesskey()); + notice_yesno('Are you sure you want convert all your tables to the InnoDB format?', + 'innodb.php', 'index.php', $optionsyes, NULL, 'post', 'get'); + admin_externalpage_print_footer(); + } ?> diff --git a/admin/mnet/access_control.php b/admin/mnet/access_control.php index 9b3a34cebe..e8ebd9ae6f 100644 --- a/admin/mnet/access_control.php +++ b/admin/mnet/access_control.php @@ -19,7 +19,7 @@ admin_externalpage_setup('ssoaccesscontrol'); admin_externalpage_print_header(); if (!extension_loaded('openssl')) { - print_error('requiresopenssl', 'mnet', '', NULL, true); + print_error('requiresopenssl', 'mnet'); } $sitecontext = get_context_instance(CONTEXT_SYSTEM); @@ -27,7 +27,7 @@ $sesskey = sesskey(); $formerror = array(); // grab the mnet hosts and remove the localhost -$mnethosts = get_records_menu('mnet_host', '', '', 'name', 'id, name'); +$mnethosts = $DB->get_records_menu('mnet_host', array(), 'name', 'id, name'); if (array_key_exists($CFG->mnet_localhost_id, $mnethosts)) { unset($mnethosts[$CFG->mnet_localhost_id]); } @@ -39,13 +39,13 @@ if (!empty($action) and confirm_sesskey()) { // boot if insufficient permission if (!has_capability('moodle/user:delete', $sitecontext)) { - error(get_string('nomodifyacl','mnet')); + print_error('nomodifyacl','mnet'); } // fetch the record in question $id = required_param('id', PARAM_INT); if (!$idrec = get_record('mnet_sso_access_control', 'id', $id)) { - error(get_string('recordnoexists','mnet'), "$CFG->wwwroot/$CFG->admin/mnet/access_control.php"); + print_error('recordnoexists','mnet', "$CFG->wwwroot/$CFG->admin/mnet/access_control.php"); } switch ($action) { @@ -60,7 +60,7 @@ if (!empty($action) and confirm_sesskey()) { // require the access parameter, and it must be 'allow' or 'deny' $accessctrl = trim(strtolower(required_param('accessctrl', PARAM_ALPHA))); if ($accessctrl != 'allow' and $accessctrl != 'deny') { - error(get_string('invalidaccessparam', 'mnet') , "$CFG->wwwroot/$CFG->admin/mnet/access_control.php"); + print_error('invalidaccessparam', 'mnet', "$CFG->wwwroot/$CFG->admin/mnet/access_control.php"); } if (mnet_update_sso_access_control($idrec->username, $idrec->mnet_host_id, $accessctrl)) { @@ -84,7 +84,7 @@ if ($form = data_submitted() and confirm_sesskey()) { // check permissions and verify form input if (!has_capability('moodle/user:delete', $sitecontext)) { - error(get_string('nomodifyacl','mnet'), "$CFG->wwwroot/$CFG->admin/mnet/access_control.php"); + print_error('nomodifyacl','mnet', "$CFG->wwwroot/$CFG->admin/mnet/access_control.php"); } if (empty($form->username)) { $formerror['username'] = get_string('enterausername','mnet'); diff --git a/admin/multilangupgrade.php b/admin/multilangupgrade.php index 72dff0ae44..0903b652ab 100644 --- a/admin/multilangupgrade.php +++ b/admin/multilangupgrade.php @@ -24,7 +24,7 @@ if (!$go or !data_submitted() or !confirm_sesskey()) { /// Print a form } -if (!$tables = $db->Metatables() ) { // No tables yet at all. +if (!$tables = $DB->get_tables() ) { // No tables yet at all. print_error('notables', 'debug'); } @@ -38,29 +38,28 @@ while(@ob_end_flush()); echo 'Progress:'; $i = 0; -$skiptables = array($CFG->prefix.'config', $CFG->prefix.'user_students', $CFG->prefix.'user_teachers');//, $CFG->prefix.'sessions2'); +$skiptables = array('config', 'user_students', 'user_teachers');//, 'sessions2'); foreach ($tables as $table) { - if (($CFG->prefix && strpos($table, $CFG->prefix) !== 0) - or strpos($table, $CFG->prefix.'pma') === 0) { // Not our tables + if (strpos($table,'pma') === 0) { // Not our tables continue; } if (in_array($table, $skiptables)) { // Don't process these continue; } - if ($columns = $db->MetaColumns($table, false)) { + $fulltable = $DB->get_prefix().$table; + if ($columns = $DB->get_columns($table)) { if (!array_key_exists('id', $columns) and !array_key_exists('ID', $columns)) { continue; // moodle tables have id } foreach ($columns as $column => $data) { if (in_array($data->type, array('text','mediumtext','longtext','varchar'))) { // Text stuff only // first find candidate records - $rs = get_recordset_sql("SELECT id, $column FROM $table WHERE $column LIKE '%%' OR $column LIKE '%EOF) { - $text = $rs->fields[$column]; - $id = $rs->fields['id']; - + $sql = "SELECT id, $column FROM $fulltable WHERE $column LIKE '%%' OR $column LIKE '%get_recordset_sql($sql)) { + foreach ($rs as $data) { + $text = $data->$column; + $id = $data->id; if ($i % 600 == 0) { echo '
'; } @@ -68,7 +67,6 @@ foreach ($tables as $table) { echo '.'; } $i++; - $rs->MoveNext(); if (empty($text) or is_numeric($text)) { continue; // nothing to do @@ -82,11 +80,10 @@ foreach ($tables as $table) { } if ($newtext != $text) { - $newtext = addslashes($newtext); - execute_sql("UPDATE $table SET $column='$newtext' WHERE id=$id", false); + $DB->execute("UPDATE $fulltable SET $column=? WHERE id=?", array($newtext, $id)); } } - rs_close($rs); + $rs->close(); } } } diff --git a/admin/replace.php b/admin/replace.php index 1a6a2a35d1..cdff6ae39a 100644 --- a/admin/replace.php +++ b/admin/replace.php @@ -34,16 +34,16 @@ if (!data_submitted() or !$search or !$replace or !confirm_sesskey()) { /// Pr print_simple_box_start('center'); -if (!db_replace($search, $replace)) { +if (!db_replace(stripslashes($search), stripslashes($replace))) { print_error('erroroccur', debug); } print_simple_box_end(); /// Rebuild course cache which might be incorrect now -notify('Rebuilding course cache...'); +notify('Rebuilding course cache...', 'notifysuccess'); rebuild_course_cache(); -notify('...finished'); +notify('...finished', 'notifysuccess'); print_continue('index.php'); diff --git a/admin/roles/manage.php b/admin/roles/manage.php index 1d2b94b9ea..afa4cd9805 100755 --- a/admin/roles/manage.php +++ b/admin/roles/manage.php @@ -14,6 +14,9 @@ $confirm = optional_param('confirm', 0, PARAM_BOOL); $cancel = optional_param('cancel', 0, PARAM_BOOL); + $name = stripslashes($name); + $description = stripslashes($description); + $sitecontext = get_context_instance(CONTEXT_SYSTEM); require_capability('moodle/role:manage', $sitecontext); @@ -65,13 +68,13 @@ if (empty($name)) { $errors['name'] = get_string('errorbadrolename', 'role'); - } else if (count_records('role', 'name', $name)) { + } else if ($DB->count_records('role', array('name'=>$name))) { $errors['name'] = get_string('errorexistsrolename', 'role'); } if (empty($shortname)) { $errors['shortname'] = get_string('errorbadroleshortname', 'role'); - } else if (count_records('role', 'shortname', $shortname)) { + } else if ($DB->count_records('role', array('shortname'=>$shortname))) { $errors['shortname'] = get_string('errorexistsroleshortname', 'role'); } @@ -142,7 +145,7 @@ if (empty($name)) { $errors['name'] = get_string('errorbadrolename', 'role'); - } else if ($rs = get_records('role', 'name', $name)) { + } else if ($rs = $DB->get_records('role', array('name'=>$name))) { unset($rs[$roleid]); if (!empty($rs)) { $errors['name'] = get_string('errorexistsrolename', 'role'); @@ -151,7 +154,7 @@ if (empty($shortname)) { $errors['shortname'] = get_string('errorbadroleshortname', 'role'); - } else if ($rs = get_records('role', 'shortname', $shortname)) { + } else if ($rs = $DB->get_records('role', array('shortname'=>$shortname))) { unset($rs[$roleid]); if (!empty($rs)) { $errors['shortname'] = get_string('errorexistsroleshortname', 'role'); @@ -190,11 +193,13 @@ } // edit default caps - $SQL = "SELECT * FROM {$CFG->prefix}role_capabilities - WHERE roleid = $roleid AND capability = '$capname' - AND contextid = $sitecontext->id"; + $SQL = "SELECT * + FROM {role_capabilities} + WHERE roleid = ? AND capability = ? + AND contextid = ?"; + $params = array($roleid, $capname, $sitecontext->id); - $localoverride = get_record_sql($SQL); + $localoverride = $DB->get_record_sql($SQL, $params); if ($localoverride) { // update current overrides if ($value == CAP_INHERIT) { // inherit = delete @@ -204,7 +209,7 @@ $localoverride->permission = $value; $localoverride->timemodified = time(); $localoverride->modifierid = $USER->id; - update_record('role_capabilities', $localoverride); + $DB->update_record('role_capabilities', $localoverride); } } else { // insert a record if ($value != CAP_INHERIT) { @@ -221,7 +226,7 @@ $role->shortname = $shortname; $role->description = $description; - if (!update_record('role', $role)) { + if (!$DB->update_record('role', $role)) { print_error('cannotupdaterole', 'error'); } @@ -331,7 +336,7 @@ } // duplicate current role - $sourcerole = get_record('role','id',$roleid); + $sourcerole = $DB->get_record('role', array('id'=>$roleid)); $fullname = $sourcerole->name; $shortname = $sourcerole->shortname; @@ -351,8 +356,8 @@ $currentfullname = $fullname.$suffixfull; // Limit the size of shortname - database column accepts <= 100 chars $currentshortname = substr($shortname, 0, 100 - strlen($suffixshort)).$suffixshort; - $coursefull = get_record("role","name",addslashes($currentfullname)); - $courseshort = get_record("role","shortname",addslashes($currentshortname)); + $coursefull = $DB->get_record("role", array("name"=>$currentfullname)); + $courseshort = $DB->get_record("role", array("shortname"=>$currentshortname)); $counter++; } while ($coursefull || $courseshort); @@ -365,7 +370,7 @@ mark_context_dirty($sitecontext->path); } - $rolename = get_field('role', 'name', 'id', $newrole); + $rolename = $DB->get_field('role', 'name', array('id'=>$newrole)); add_to_log(SITEID, 'role', 'duplicate', 'admin/roles/manage.php?roleid='.$newrole.'&action=duplicate', $rolename, '', $USER->id); redirect('manage.php'); break; @@ -430,12 +435,12 @@ $role->description = ''; $role->legacytype = ''; } else { - $role = stripslashes_safe($newrole); + $role = $newrole; } } else if ($action == 'edit' and !empty($errors) and !empty($newrole)) { - $role = stripslashes_safe($newrole); + $role = $newrole; } else { - if(!$role = get_record('role', 'id', $roleid)) { + if(!$role = $DB->get_record('role', array('id'=>$roleid))) { print_error('wrongroleid', 'error'); } $role->legacytype = get_legacy_type($role->id); diff --git a/admin/timezone.php b/admin/timezone.php index 94993cc644..1c23e90248 100644 --- a/admin/timezone.php +++ b/admin/timezone.php @@ -2,7 +2,12 @@ require_once('../config.php'); - $zone = optional_param('zone', '', PARAM_PATH); //not a path, but it looks like it anyway + $zone = optional_param('zone', '', PARAM_RAW); + + if (!is_numeric($zone)) { + //not a path, but it looks like it anyway + $zone = clean_param($zone, PARAM_PATH); + } require_login(); @@ -17,24 +22,26 @@ print_heading(""); - if (!empty($zone) and confirm_sesskey()) { - $db->debug = true; + if (data_submitted() and !empty($zone) and confirm_sesskey()) { echo "
"; - execute_sql("UPDATE {$CFG->prefix}user SET timezone = '$zone'"); - $db->debug = false; + $DB->execute("UPDATE {user} SET timezone = ?", array($zone)); echo "
"; $USER->timezone = $zone; + $current = $zone; + notify('Timezone of all users changed', 'notifysuccess'); + } else { + $current = 99; } require_once($CFG->dirroot.'/calendar/lib.php'); $timezones = get_list_of_timezones(); - echo '
'; + echo '
'; echo "$strusers ($strall): "; - choose_from_menu ($timezones, "zone", 99, get_string("serverlocaltime"), "", "99"); + choose_from_menu ($timezones, "zone", $current, get_string("serverlocaltime"), "", "99"); echo "sesskey\" />"; - echo ""; + echo ''; echo "
"; print_footer(); diff --git a/admin/xmldb/actions/check_bigints/check_bigints.class.php b/admin/xmldb/actions/check_bigints/check_bigints.class.php index eb9f8a0e4f..abaa91cb55 100644 --- a/admin/xmldb/actions/check_bigints/check_bigints.class.php +++ b/admin/xmldb/actions/check_bigints/check_bigints.class.php @@ -76,7 +76,10 @@ class check_bigints extends XMLDBAction { $this->does_generate = ACTION_GENERATE_HTML; /// These are always here - global $CFG, $XMLDB, $db; + global $CFG, $XMLDB, $db, $DB; + + $dbman = $DB->get_manager(); + $dbfamily = $DB->get_dbfamily(); /// And we nedd some ddl suff require_once ($CFG->libdir . '/ddllib.php'); @@ -85,7 +88,7 @@ class check_bigints extends XMLDBAction { $wrong_fields = array(); /// Correct fields must be type bigint for MySQL and int8 for PostgreSQL - switch ($CFG->dbfamily) { + switch ($dbfamily) { case 'mysql': $correct_type = 'bigint'; break; @@ -106,7 +109,7 @@ class check_bigints extends XMLDBAction { $o = ''; $o.= '
'; $o.= '

' . $this->str['confirmcheckbigints'] . '

'; - if ($CFG->dbfamily == 'mysql') { + if ($dbfamily == 'mysql') { $o.= '

' . $this->str['mysqlextracheckbigints'] . '

'; } $o.= '
'; @@ -140,10 +143,6 @@ class check_bigints extends XMLDBAction { } /// Load the XML file $xmldb_file = new XMLDBFile($dbdir->path . '/install.xml'); - /// Load the needed XMLDB generator - $classname = 'XMLDB' . $CFG->dbtype; - $generator = new $classname(); - $generator->setPrefix($CFG->prefix); /// Only if the file exists if (!$xmldb_file->fileExists()) { @@ -164,13 +163,11 @@ class check_bigints extends XMLDBAction { /// Foreach table, process its fields foreach ($xmldb_tables as $xmldb_table) { /// Skip table if not exists - if (!table_exists($xmldb_table)) { + if (!$dbman->table_exists($xmldb_table)) { continue; } /// Fetch metadata from phisical DB. All the columns info. - if ($metacolumns = $db->MetaColumns($CFG->prefix . $xmldb_table->getName())) { - $metacolumns = array_change_key_case($metacolumns, CASE_LOWER); - } else { + if (!$metacolumns = $DB->get_columns($xmldb_table->getName())) { //// Skip table if no metacolumns is available for it continue; } @@ -193,7 +190,7 @@ class check_bigints extends XMLDBAction { /// Going to check this field in DB $o.='
  • ' . $this->str['field'] . ': ' . $xmldb_field->getName() . ' '; /// Detect if the phisical field is wrong and, under mysql, check for incorrect signed fields too - if ($metacolumn->type != $correct_type || ($CFG->dbfamily == 'mysql' && $xmldb_field->getUnsigned() && !$metacolumn->unsigned)) { + if ($metacolumn->type != $correct_type || ($dbfamily == 'mysql' && $xmldb_field->getUnsigned() && !$metacolumn->unsigned)) { $o.='' . $this->str['wrong'] . ''; /// Add the wrong field to the list $obj = new object; @@ -233,18 +230,22 @@ class check_bigints extends XMLDBAction { $xmldb_table = $obj->table; $xmldb_field = $obj->field; /// MySQL directly supports this - if ($CFG->dbfamily == 'mysql') { - $sqlarr = $xmldb_table->getAlterFieldSQL($CFG->dbtype, $CFG->prefix, $xmldb_field, true); + +// TODO: move this hack to generators!! + + if ($dbfamily == 'mysql') { + $sqlarr = $dbman->generator->getAlterFieldSQL($xmldb_table, $xmldb_field); /// PostgreSQL (XMLDB implementation) is a bit, er... imperfect. - } else if ($CFG->dbfamily == 'postgres') { - $sqlarr = array('ALTER TABLE ' . $CFG->prefix . $xmldb_table->getName() . + } else if ($dbfamily == 'postgres') { + $sqlarr = array('ALTER TABLE ' . $DB->get_prefix() . $xmldb_table->getName() . ' ALTER COLUMN ' . $xmldb_field->getName() . ' TYPE BIGINT;'); } $r.= '
  • ' . $this->str['table'] . ': ' . $xmldb_table->getName() . '. ' . $this->str['field'] . ': ' . $xmldb_field->getName() . '
  • '; /// Add to output if we have sentences if ($sqlarr) { - $s.= '' . str_replace("\n", '
    ', implode('
    ', $sqlarr)) . '

    '; + $sqlarr = $dbman->generator->getEndedStatements($sqlarr); + $s.= '' . str_replace("\n", implode('
    ', $sqlarr)). '

    '; } } $r.= ' '; diff --git a/admin/xmldb/actions/check_defaults/check_defaults.class.php b/admin/xmldb/actions/check_defaults/check_defaults.class.php index 0b9fa3fa96..5b22238f4c 100644 --- a/admin/xmldb/actions/check_defaults/check_defaults.class.php +++ b/admin/xmldb/actions/check_defaults/check_defaults.class.php @@ -26,7 +26,7 @@ /// This class will check all the default values existing in the DB /// match those specified in the xml specs -/// and providing one SQL script to fix all them. +/// and providing one SQL script to fix all them. class check_defaults extends XMLDBAction { @@ -76,10 +76,11 @@ class check_defaults extends XMLDBAction { $this->does_generate = ACTION_GENERATE_HTML; /// These are always here - global $CFG, $XMLDB, $db; + global $CFG, $XMLDB, $DB; /// And we nedd some ddl suff require_once ($CFG->libdir . '/ddllib.php'); + $dbman = $DB->get_manager(); /// Here we'll acummulate all the wrong fields found $wrong_fields = array(); @@ -125,10 +126,6 @@ class check_defaults extends XMLDBAction { } /// Load the XML file $xmldb_file = new XMLDBFile($dbdir->path . '/install.xml'); - /// Load the needed XMLDB generator - $classname = 'XMLDB' . $CFG->dbtype; - $generator = new $classname(); - $generator->setPrefix($CFG->prefix); /// Only if the file exists if (!$xmldb_file->fileExists()) { @@ -142,7 +139,7 @@ class check_defaults extends XMLDBAction { } /// Arriving here, everything is ok, get the XMLDB structure $structure = $xmldb_file->getStructure(); -//echo "
    "; print_r( $structure ); die;
    +
                         $o.='    
  • ' . str_replace($CFG->dirroot . '/', '', $dbdir->path . '/install.xml'); /// Getting tables if ($xmldb_tables = $structure->getTables()) { @@ -150,14 +147,11 @@ class check_defaults extends XMLDBAction { /// Foreach table, process its fields foreach ($xmldb_tables as $xmldb_table) { /// Skip table if not exists - if (!table_exists($xmldb_table)) { + if (!$dbman->table_exists($xmldb_table)) { continue; } /// Fetch metadata from phisical DB. All the columns info. - if ($metacolumns = $db->MetaColumns($CFG->prefix . $xmldb_table->getName())) { - $metacolumns = array_change_key_case($metacolumns, CASE_LOWER); -// echo "
    ".$xmldb_table->getName(); print_r( $metacolumns ); die;
    -                            } else {
    +                            if (!$metacolumns = $DB->get_columns($xmldb_table->getName())) {
                                 //// Skip table if no metacolumns is available for it
                                     continue;
                                 }
    @@ -167,33 +161,32 @@ class check_defaults extends XMLDBAction {
                                 if ($xmldb_fields = $xmldb_table->getFields()) {
                                     $o.='        
      '; foreach ($xmldb_fields as $xmldb_field) { -//echo "
      "; print_r( $xmldb_field ); die; 
      -
      -                                // Get the default value for the field 
      -                                $xmldbdefault = $xmldb_field->getDefault();
      -                                
      -                                /// If the metadata for that column doesn't exist, skip
      -                                if (!isset($metacolumns[$xmldb_field->getName()])) {
      -                                    continue;
      -                                }
       
      -                                /// To variable for better handling
      -                                $metacolumn = $metacolumns[$xmldb_field->getName()];
      +                                    // Get the default value for the field
      +                                    $xmldbdefault = $xmldb_field->getDefault();
       
      -                                /// Going to check this field in DB
      -                                $o.='            
    • ' . $this->str['field'] . ': ' . $xmldb_field->getName() . ' '; + /// If the metadata for that column doesn't exist or 'id' field found, skip + if (!isset($metacolumns[$xmldb_field->getName()]) or $xmldb_field->getName() == 'id') { + continue; + } - // get the value of the physical default (or blank if there isn't one) - if ($metacolumn->has_default==1) { - $physicaldefault = $metacolumn->default_value; - } - else { - $physicaldefault = ''; - } + /// To variable for better handling + $metacolumn = $metacolumns[$xmldb_field->getName()]; - // there *is* a default and it's wrong - if ($physicaldefault != $xmldbdefault) { - $info = '['.$this->str['shouldbe']." '$xmldbdefault' ".$this->str['butis']. + /// Going to check this field in DB + $o.='
    • ' . $this->str['field'] . ': ' . $xmldb_field->getName() . ' '; + + // get the value of the physical default (or blank if there isn't one) + if ($metacolumn->has_default==1) { + $physicaldefault = $metacolumn->default_value; + } + else { + $physicaldefault = ''; + } + + // there *is* a default and it's wrong + if ($physicaldefault != $xmldbdefault) { + $info = '['.$this->str['shouldbe']." '$xmldbdefault' ".$this->str['butis']. " '$physicaldefault']"; $o.='' . $this->str['wrong'] . " $info"; /// Add the wrong field to the list @@ -237,9 +230,9 @@ class check_defaults extends XMLDBAction { $xmldb_field = $obj->field; $physicaldefault = $obj->physicaldefault; $xmldbdefault = $obj->xmldbdefault; - + // get the alter table command - $sqlarr = $xmldb_table->getAlterFieldSQL($CFG->dbtype, $CFG->prefix, $xmldb_field, true); + $sqlarr = $dbman->generator->getAlterFieldSQL($xmldb_table, $xmldb_field); $r.= '
    • ' . $this->str['table'] . ': ' . $xmldb_table->getName() . '. ' . $this->str['field'] . ': ' . $xmldb_field->getName() . ', ' . @@ -247,6 +240,7 @@ class check_defaults extends XMLDBAction { $this->str['butis'] . ' ' . "'$physicaldefault'" . '
    • '; /// Add to output if we have sentences if ($sqlarr) { + $sqlarr = $dbman->generator->getEndedStatements($sqlarr); $s.= '' . str_replace("\n", '
      ', implode('
      ', $sqlarr)) . '

      '; } } diff --git a/admin/xmldb/actions/check_indexes/check_indexes.class.php b/admin/xmldb/actions/check_indexes/check_indexes.class.php index e5989e6839..a7596b3671 100644 --- a/admin/xmldb/actions/check_indexes/check_indexes.class.php +++ b/admin/xmldb/actions/check_indexes/check_indexes.class.php @@ -74,7 +74,9 @@ class check_indexes extends XMLDBAction { $this->does_generate = ACTION_GENERATE_HTML; /// These are always here - global $CFG, $XMLDB; + global $CFG, $XMLDB, $DB; + + $dbman = $DB->get_manager(); /// And we nedd some ddl suff require_once ($CFG->libdir . '/ddllib.php'); @@ -123,10 +125,6 @@ class check_indexes extends XMLDBAction { } /// Load the XML file $xmldb_file = new XMLDBFile($dbdir->path . '/install.xml'); - /// Load the needed XMLDB generator - $classname = 'XMLDB' . $CFG->dbtype; - $generator = new $classname(); - $generator->setPrefix($CFG->prefix); /// Only if the file exists if (!$xmldb_file->fileExists()) { @@ -147,7 +145,7 @@ class check_indexes extends XMLDBAction { /// Foreach table, process its indexes and keys foreach ($xmldb_tables as $xmldb_table) { /// Skip table if not exists - if (!table_exists($xmldb_table)) { + if (!$dbman->table_exists($xmldb_table)) { continue; } $o.='
    • ' . $xmldb_table->getName(); @@ -163,7 +161,7 @@ class check_indexes extends XMLDBAction { } /// If we aren't creating the keys or the key is a XMLDB_KEY_FOREIGN (not underlying index generated /// automatically by the RDBMS) create the underlying (created by us) index (if doesn't exists) - if (!$generator->getKeySQL($xmldb_table, $xmldb_key) || $xmldb_key->getType() == XMLDB_KEY_FOREIGN) { + if (!$dbman->generator->getKeySQL($xmldb_table, $xmldb_key) || $xmldb_key->getType() == XMLDB_KEY_FOREIGN) { /// Create the interim index $xmldb_index = new XMLDBIndex('anyname'); $xmldb_index->setFields($xmldb_key->getFields()); @@ -177,7 +175,7 @@ class check_indexes extends XMLDBAction { break; } /// Check if the index exists in DB - if (index_exists($xmldb_table, $xmldb_index)) { + if ($dbman->index_exists($xmldb_table, $xmldb_index)) { $o.='' . $this->str['ok'] . ''; } else { $o.='' . $this->str['missing'] . ''; @@ -198,7 +196,7 @@ class check_indexes extends XMLDBAction { foreach ($xmldb_indexes as $xmldb_index) { $o.='
    • ' . $this->str['index'] . ': ' . $xmldb_index->readableInfo() . ' '; /// Check if the index exists in DB - if (index_exists($xmldb_table, $xmldb_index)) { + if ($dbman->index_exists($xmldb_table, $xmldb_index)) { $o.='' . $this->str['ok'] . ''; } else { $o.='' . $this->str['missing'] . ''; @@ -237,11 +235,12 @@ class check_indexes extends XMLDBAction { foreach ($missing_indexes as $obj) { $xmldb_table = $obj->table; $xmldb_index = $obj->index; - $sqlarr = $xmldb_table->getAddIndexSQL($CFG->dbtype, $CFG->prefix, $xmldb_index, true); + $sqlarr = $dbman->generator->getAddIndexSQL($xmldb_table, $xmldb_index); $r.= '
    • ' . $this->str['table'] . ': ' . $xmldb_table->getName() . '. ' . $this->str['index'] . ': ' . $xmldb_index->readableInfo() . '
    • '; + $sqlarr = $dbman->generator->getEndedStatements($sqlarr); $s.= '' . str_replace("\n", '
      ', implode('
      ', $sqlarr)) . '

      '; - + } $r.= '
    '; /// Add the SQL statements (all together) diff --git a/admin/xmldb/actions/edit_statement/edit_statement.class.php b/admin/xmldb/actions/edit_statement/edit_statement.class.php index 7a9608a39f..1e2a5faf79 100644 --- a/admin/xmldb/actions/edit_statement/edit_statement.class.php +++ b/admin/xmldb/actions/edit_statement/edit_statement.class.php @@ -103,7 +103,7 @@ class edit_statement extends XMLDBAction { /// Add the main form $o = '
    '; - $o.= '
    '; + $o.= '
    '; $o.= ' '; $o.= ' '; $o.= ' '; diff --git a/admin/xmldb/actions/edit_table/edit_table.class.php b/admin/xmldb/actions/edit_table/edit_table.class.php index 8fb90d8a4b..d45937b05f 100644 --- a/admin/xmldb/actions/edit_table/edit_table.class.php +++ b/admin/xmldb/actions/edit_table/edit_table.class.php @@ -103,7 +103,7 @@ class edit_table extends XMLDBAction { /// Add the main form $o = ''; - $o.= '
    '; + $o.= '
    '; $o.= ' '; $o.= ' '; $o.= ' '; @@ -150,17 +150,8 @@ class edit_table extends XMLDBAction { $b .= '

    '; $o .= $b; - /// Join all the reserved words into one big array - /// Calculate list of available SQL generators - $plugins = get_list_of_plugins('lib/xmldb/classes/generators'); - $reserved_words = array(); - foreach($plugins as $plugin) { - $classname = 'XMLDB' . $plugin; - $generator = new $classname(); - $reserved_words = array_merge($reserved_words, $generator->getReservedWords()); - } - sort($reserved_words); - $reserved_words = array_unique($reserved_words); + require("$CFG->libdir/ddl/sql_generator.php"); + $reserved_words = sql_generator::getAllReservedWords(); /// Delete any 'changeme' field/key/index $table->deleteField('changeme'); @@ -205,7 +196,7 @@ class edit_table extends XMLDBAction { $b .= '[' . $this->str['delete'] . ']'; } /// Detect if the table name is a reserved word - if (in_array($field->getName(), $reserved_words)) { + if (array_key_exists($field->getName(), $reserved_words)) { $b .= ' ' . $this->str['reserved'] . ''; } /// The readable info diff --git a/admin/xmldb/actions/edit_xml_file/edit_xml_file.class.php b/admin/xmldb/actions/edit_xml_file/edit_xml_file.class.php index d6036a821d..ef2a5bbd27 100644 --- a/admin/xmldb/actions/edit_xml_file/edit_xml_file.class.php +++ b/admin/xmldb/actions/edit_xml_file/edit_xml_file.class.php @@ -72,7 +72,7 @@ class edit_xml_file extends XMLDBAction { $this->does_generate = ACTION_GENERATE_HTML; /// These are always here - global $CFG, $XMLDB; + global $CFG, $XMLDB, $DB; /// Do the job, setting $result as needed @@ -127,7 +127,7 @@ class edit_xml_file extends XMLDBAction { /// The new table button $b .= ' [' . $this->str['newtable'] . ']'; /// The new from MySQL button - if ($CFG->dbfamily == 'mysql') { + if ($DB->get_dbfamily() == 'mysql') { $b .= ' [' . $this->str['newtablefrommysql'] . ']'; } else { $b .= ' [' . $this->str['newtablefrommysql'] . ']'; @@ -146,17 +146,12 @@ class edit_xml_file extends XMLDBAction { $o .= $b; /// Join all the reserved words into one big array /// Calculate list of available SQL generators - $plugins = get_list_of_plugins('lib/xmldb/classes/generators'); - $reserved_words = array(); - foreach($plugins as $plugin) { - $classname = 'XMLDB' . $plugin; - $generator = new $classname(); - $reserved_words = array_merge($reserved_words, $generator->getReservedWords()); - } - sort($reserved_words); - $reserved_words = array_unique($reserved_words); + + require("$CFG->libdir/ddl/sql_generator.php"); + $reserved_words = sql_generator::getAllReservedWords(); + /// Add the tables list - $tables =& $structure->getTables(); + $tables = $structure->getTables(); if ($tables) { $o .= '

    ' . $this->str['tables'] . '

    '; $o .= ''; @@ -190,7 +185,7 @@ class edit_xml_file extends XMLDBAction { $b .= '[' . $this->str['delete'] . ']'; } /// Detect if the table name is a reserved word - if (in_array($table->getName(), $reserved_words)) { + if (array_key_exists($table->getName(), $reserved_words)) { $b .= ' ' . $this->str['reserved'] . ''; } $b .= ''; diff --git a/admin/xmldb/actions/load_xml_file/load_xml_file.class.php b/admin/xmldb/actions/load_xml_file/load_xml_file.class.php index 64e8a34f42..9804fd96a5 100644 --- a/admin/xmldb/actions/load_xml_file/load_xml_file.class.php +++ b/admin/xmldb/actions/load_xml_file/load_xml_file.class.php @@ -95,7 +95,7 @@ class load_xml_file extends XMLDBAction { $loaded = $xmldb_file->loadXMLStructure(); if ($loaded && $xmldb_file->isLoaded()) { $dbdir->xml_loaded = true; - $dbdir->filemtime = filemtime($dbdir->path . '/install.xml'); + $dbdir->filemtime = filemtime($dbdir->path . '/install.xml'); } $dbdir->xml_file = $xmldb_file; } else { diff --git a/admin/xmldb/actions/main_view/main_view.class.php b/admin/xmldb/actions/main_view/main_view.class.php index 8428343e08..4f706a5c0a 100644 --- a/admin/xmldb/actions/main_view/main_view.class.php +++ b/admin/xmldb/actions/main_view/main_view.class.php @@ -68,7 +68,7 @@ class main_view extends XMLDBAction { $this->does_generate = ACTION_GENERATE_HTML; /// These are always here - global $CFG, $XMLDB, $SESSION; + global $CFG, $XMLDB, $SESSION, $DB; /// Get lastused $o = ''; @@ -92,7 +92,7 @@ class main_view extends XMLDBAction { /// The check defaults button $b .= ' [' . $this->str['checkdefaults'] . ']'; /// The check bigints button (only for MySQL and PostgreSQL) MDL-11038a - if ($CFG->dbfamily == 'mysql' || $CFG->dbfamily == 'postgres') { + if ($DB->get_dbfamily() == 'mysql' || $DB->get_dbfamily() == 'postgres') { $b .= ' [' . $this->str['checkbigints'] . ']'; } $b .= '

    '; diff --git a/admin/xmldb/actions/new_statement/new_statement.class.php b/admin/xmldb/actions/new_statement/new_statement.class.php index f80e9bc453..c661cf0cea 100644 --- a/admin/xmldb/actions/new_statement/new_statement.class.php +++ b/admin/xmldb/actions/new_statement/new_statement.class.php @@ -60,7 +60,7 @@ class new_statement extends XMLDBAction { $this->does_generate = ACTION_GENERATE_HTML; /// These are always here - global $CFG, $XMLDB, $db; + global $CFG, $XMLDB, $DB; /// Do the job, setting result as needed /// Get the dir containing the file @@ -86,12 +86,7 @@ class new_statement extends XMLDBAction { /// No postaction here $this->postaction = NULL; /// Get list of tables - $dbtables = $db->MetaTables('TABLES'); - $selecttables = array(); - foreach ($dbtables as $dbtable) { - $dbtable = str_replace($CFG->prefix, '', $dbtable); - $selecttables[$dbtable] = $dbtable; - } + $selecttables = $DB->get_tables(); /// Get list of statement types $typeoptions = array (XMLDB_STATEMENT_INSERT => XMLDBStatement::getXMLDBStatementName(XMLDB_STATEMENT_INSERT), XMLDB_STATEMENT_UPDATE => XMLDBStatement::getXMLDBStatementName(XMLDB_STATEMENT_UPDATE), diff --git a/admin/xmldb/actions/new_table_from_mysql/new_table_from_mysql.class.php b/admin/xmldb/actions/new_table_from_mysql/new_table_from_mysql.class.php index 8541160a18..3a2a3be408 100644 --- a/admin/xmldb/actions/new_table_from_mysql/new_table_from_mysql.class.php +++ b/admin/xmldb/actions/new_table_from_mysql/new_table_from_mysql.class.php @@ -60,7 +60,7 @@ class new_table_from_mysql extends XMLDBAction { $this->does_generate = ACTION_GENERATE_HTML; /// These are always here - global $CFG, $XMLDB, $db; + global $CFG, $XMLDB, $DB; /// Do the job, setting result as needed /// Get the dir containing the file @@ -85,10 +85,9 @@ class new_table_from_mysql extends XMLDBAction { /// No postaction here $this->postaction = NULL; /// Get list of tables - $dbtables = $db->MetaTables('TABLES'); + $dbtables = $DB->get_tables(); $selecttables = array(); foreach ($dbtables as $dbtable) { - $dbtable = strtolower(str_replace($CFG->prefix, '', $dbtable)); $i = $structure->findTableInArray($dbtable); if ($i === NULL) { $selecttables[$dbtable] = $dbtable; @@ -132,14 +131,11 @@ class new_table_from_mysql extends XMLDBAction { $table = new XMLDBTable(strtolower(trim($tableparam))); $table->setComment($table->getName() . ' table retrofitted from MySQL'); /// Get fields info from ADODb - if(!$dbfields = $db->MetaColumns($CFG->prefix . $tableparam)) { - ///Try it without prefix if doesn't exist - $dbfields = $db->MetaColumns($tableparam); - } + $dbfields = $DB->get_columns($tableparam); if ($dbfields) { foreach ($dbfields as $dbfield) { /// Create new XMLDB field - $field = new XMLDBField(strtolower($dbfield->name)); + $field = new XMLDBField($dbfield->name); /// Set field with info retrofitted $field->setFromADOField($dbfield); /// Add field to the table @@ -147,7 +143,7 @@ class new_table_from_mysql extends XMLDBAction { } } /// Get PK, UK and indexes info from ADODb - $dbindexes = $db->MetaIndexes($CFG->prefix . $tableparam, true); + $dbindexes = $DB->get_indexes($tableparam); if ($dbindexes) { $lastkey = NULL; //To temp store the last key processed foreach ($dbindexes as $indexname => $dbindex) { diff --git a/admin/xmldb/actions/test/test.class.php b/admin/xmldb/actions/test/test.class.php index fdca79888e..34cd5103a3 100644 --- a/admin/xmldb/actions/test/test.class.php +++ b/admin/xmldb/actions/test/test.class.php @@ -58,10 +58,10 @@ class test extends XMLDBAction { $this->does_generate = ACTION_GENERATE_HTML; /// These are always here - global $CFG, $XMLDB, $db; - - /// ADD YOUR CODE HERE - require_once ($CFG->libdir . '/ddllib.php'); + global $XMLDB, $DB, $CFG; + $dbman = $DB->get_manager(); + $gen = $dbman->generator; + $dbfamily = $DB->get_dbfamily(); /// Where all the tests will be stored $tests = array(); @@ -74,16 +74,16 @@ class test extends XMLDBAction { /// Silenty drop any previous test tables $table = new XMLDBTable('testtable'); - if (table_exists($table)) { - $status = drop_table($table, true, false); + if ($dbman->table_exists($table)) { + $status = $dbman->drop_table($table, true, false); } $table = new XMLDBTable ('anothertest'); - if (table_exists($table)) { - $status = drop_table($table, true, false); + if ($dbman->table_exists($table)) { + $status = $dbman->drop_table($table, true, false); } $table = new XMLDBTable ('newnameforthetable'); - if (table_exists($table)) { - $status = drop_table($table, true, false); + if ($dbman->table_exists($table)) { + $status = $dbman->drop_table($table, true, false); } /// 1st test. Complete table creation. @@ -118,10 +118,10 @@ class test extends XMLDBAction { /// Get SQL code and execute it $test = new stdClass; - $test->sql = $table->getCreateTableSQL($CFG->dbtype, $CFG->prefix, true); - $test->status = create_table($table, false, false); + $test->sql = $gen->getCreateTableSQL($table); + $test->status = $dbman->create_table($table, false, false); if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['create table'] = $test; @@ -129,10 +129,10 @@ class test extends XMLDBAction { if ($test->status) { /// Get SQL code and execute it $test = new stdClass; - $test->sql = $table->getDropTableSQL($CFG->dbtype, $CFG->prefix, true); - $test->status = drop_table($table, false, false); + $test->sql = $gen->getDropTableSQL($table); + $test->status = $dbman->drop_table($table, false, false); if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['drop table'] = $test; } @@ -150,10 +150,10 @@ class test extends XMLDBAction { $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id')); /// Get SQL code and execute it $test = new stdClass; - $test->sql = $table->getCreateTableSQL($CFG->dbtype, $CFG->prefix, true); - $test->status = create_table($table, false, false); + $test->sql = $gen->getCreateTableSQL($table); + $test->status = $dbman->create_table($table, false, false); if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['create table - 2'] = $test; } @@ -164,13 +164,13 @@ class test extends XMLDBAction { $rec->secondname = 'Dougiamas'; $rec->intro = 'The creator of Moodle'; $rec->grade = 10.0001; - insert_record('anothertest', $rec); + $DB->insert_record('anothertest', $rec); $rec->course = 2; $rec->name = 'Eloy'; $rec->secondname = 'Lafuente'; $rec->intro = 'One poor developer'; $rec->grade = 9.99; - insert_record('anothertest', $rec); + $DB->insert_record('anothertest', $rec); /// 4th test. Adding one complex enum field if ($test->status) { @@ -179,10 +179,10 @@ class test extends XMLDBAction { $field->setAttributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, XMLDB_ENUM, array('single', 'news', 'general', 'social', 'eachuser', 'teacher', 'qanda'), 'general', 'course'); /// Get SQL code and execute it $test = new stdClass; - $test->sql = $table->getAddFieldSQL($CFG->dbtype, $CFG->prefix, $field, true); - $test->status = add_field($table, $field, false, false); + $test->sql = $gen->getAddFieldSQL($table, $field); + $test->status = $dbman->add_field($table, $field, false, false); if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['add enum field'] = $test; } @@ -191,10 +191,10 @@ class test extends XMLDBAction { if ($test->status) { /// Create a new field with complex specs (enums are good candidates) $test = new stdClass; - $test->sql = $table->getDropFieldSQL($CFG->dbtype, $CFG->prefix, $field, true); - $test->status = drop_field($table, $field, false, false); + $test->sql = $gen->getDropFieldSQL($table, $field); + $test->status = $dbman->drop_field($table, $field, false, false); if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['drop enum field'] = $test; } @@ -206,10 +206,10 @@ class test extends XMLDBAction { $field->setAttributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, XMLDB_ENUM, array('single', 'news', 'general', 'social', 'eachuser', 'teacher', 'qanda'), 'general', 'course'); /// Get SQL code and execute it $test = new stdClass; - $test->sql = $table->getAddFieldSQL($CFG->dbtype, $CFG->prefix, $field, true); - $test->status = add_field($table, $field, false, false); + $test->sql = $gen->getAddFieldSQL($table, $field); + $test->status = $dbman->add_field($table, $field, false, false); if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['add enum field again'] = $test; } @@ -221,10 +221,10 @@ class test extends XMLDBAction { $field->setAttributes(XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, 0, 'type'); /// Get SQL code and execute it $test = new stdClass; - $test->sql = $table->getAddFieldSQL($CFG->dbtype, $CFG->prefix, $field, true); - $test->status = add_field($table, $field, false, false); + $test->sql = $gen->getAddFieldSQL($table, $field); + $test->status = $dbman->add_field($table, $field, false, false); if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['add numeric field'] = $test; } @@ -234,10 +234,10 @@ class test extends XMLDBAction { /// Create a new field with complex specs (enums are good candidates) $field = new XMLDBField('type'); $test = new stdClass; - $test->sql = $table->getDropFieldSQL($CFG->dbtype, $CFG->prefix, $field, true); - $test->status = drop_field($table, $field, false, false); + $test->sql = $gen->getDropFieldSQL($table, $field); + $test->status = $dbman->drop_field($table, $field, false, false); if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['drop enum field again'] = $test; } @@ -249,10 +249,10 @@ class test extends XMLDBAction { $field = new XMLDBField('course'); $field->setAttributes(XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, '0'); - $test->sql = $table->getAlterFieldSQL($CFG->dbtype, $CFG->prefix, $field, true); - $test->status = change_field_type($table, $field, false, false); + $test->sql = $gen->getAlterFieldSQL($table, $field); + $test->status = $dbman->change_field_type($table, $field, false, false); if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['change field type (int2char)'] = $test; } @@ -264,10 +264,10 @@ class test extends XMLDBAction { $field = new XMLDBField('course'); $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); - $test->sql = $table->getAlterFieldSQL($CFG->dbtype, $CFG->prefix, $field, true); - $test->status = change_field_type($table, $field, false, false); + $test->sql = $gen->getAlterFieldSQL($table, $field); + $test->status = $dbman->change_field_type($table, $field, false, false); if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['change field type (char2int)'] = $test; } @@ -279,10 +279,10 @@ class test extends XMLDBAction { $field = new XMLDBField('grade'); $field->setAttributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, "test'n drop"); - $test->sql = $table->getAlterFieldSQL($CFG->dbtype, $CFG->prefix, $field, true); - $test->status = change_field_type($table, $field, false, false); + $test->sql = $gen->getAlterFieldSQL($table, $field); + $test->status = $dbman->change_field_type($table, $field, false, false); if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['change field type (number2char)'] = $test; } @@ -294,10 +294,10 @@ class test extends XMLDBAction { $field = new XMLDBField('grade'); $field->setAttributes(XMLDB_TYPE_FLOAT, '20,10', XMLDB_UNSIGNED, null, null, null, null, null); - $test->sql = $table->getAlterFieldSQL($CFG->dbtype, $CFG->prefix, $field, true); - $test->status = change_field_type($table, $field, false, false); + $test->sql = $gen->getAlterFieldSQL($table, $field); + $test->status = $dbman->change_field_type($table, $field, false, false); if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['change field type (char2float)'] = $test; } @@ -309,10 +309,10 @@ class test extends XMLDBAction { $field = new XMLDBField('grade'); $field->setAttributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, 'test'); - $test->sql = $table->getAlterFieldSQL($CFG->dbtype, $CFG->prefix, $field, true); - $test->status = change_field_type($table, $field, false, false); + $test->sql = $gen->getAlterFieldSQL($table, $field); + $test->status = $dbman->change_field_type($table, $field, false, false); if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['change field type (float2char)'] = $test; } @@ -324,10 +324,10 @@ class test extends XMLDBAction { $field = new XMLDBField('grade'); $field->setAttributes(XMLDB_TYPE_NUMBER, '20,10', XMLDB_UNSIGNED, null, null, null, null, null); - $test->sql = $table->getAlterFieldSQL($CFG->dbtype, $CFG->prefix, $field, true); - $test->status = change_field_type($table, $field, false, false); + $test->sql = $gen->getAlterFieldSQL($table, $field); + $test->status = $dbman->change_field_type($table, $field, false, false); if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['change field type (char2number)'] = $test; } @@ -340,10 +340,10 @@ class test extends XMLDBAction { $field = new XMLDBField('intro'); $field->setAttributes(XMLDB_TYPE_TEXT, 'big', null, XMLDB_NOTNULL, null, null, null, null); - $test->sql = $table->getAlterFieldSQL($CFG->dbtype, $CFG->prefix, $field, true); - $test->status = change_field_precision($table, $field, false, false); + $test->sql = $gen->getAlterFieldSQL($table, $field); + $test->status = $dbman->change_field_precision($table, $field, false, false); if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['change field precision (text)'] = $test; } @@ -355,10 +355,10 @@ class test extends XMLDBAction { $field = new XMLDBField('secondname'); $field->setAttributes(XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null, null, null); - $test->sql = $table->getAlterFieldSQL($CFG->dbtype, $CFG->prefix, $field, true); - $test->status = change_field_precision($table, $field, false, false); + $test->sql = $gen->getAlterFieldSQL($table, $field); + $test->status = $dbman->change_field_precision($table, $field, false, false); if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['change field precision (char)'] = $test; } @@ -370,10 +370,10 @@ class test extends XMLDBAction { $field = new XMLDBField('grade'); $field->setAttributes(XMLDB_TYPE_NUMBER, '10,2', null, null, null, null, null, null); - $test->sql = $table->getAlterFieldSQL($CFG->dbtype, $CFG->prefix, $field, true); - $test->status = change_field_precision($table, $field, false, false); + $test->sql = $gen->getAlterFieldSQL($table, $field); + $test->status = $dbman->change_field_precision($table, $field, false, false); if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['change field precision (number)'] = $test; } @@ -385,10 +385,10 @@ class test extends XMLDBAction { $field = new XMLDBField('course'); $field->setAttributes(XMLDB_TYPE_INTEGER, '5', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); - $test->sql = $table->getAlterFieldSQL($CFG->dbtype, $CFG->prefix, $field, true); - $test->status = change_field_precision($table, $field, false, false); + $test->sql = $gen->getAlterFieldSQL($table, $field); + $test->status = $dbman->change_field_precision($table, $field, false, false); if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['change field precision (integer) to smaller one'] = $test; } @@ -400,10 +400,10 @@ class test extends XMLDBAction { $field = new XMLDBField('grade'); $field->setAttributes(XMLDB_TYPE_NUMBER, '10,2', XMLDB_UNSIGNED, null, null, null, null, null); - $test->sql = $table->getAlterFieldSQL($CFG->dbtype, $CFG->prefix, $field, true); - $test->status = change_field_unsigned($table, $field, false, false); + $test->sql = $gen->getAlterFieldSQL($table, $field); + $test->status = $dbman->change_field_unsigned($table, $field, false, false); if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['change field sign (unsigned)'] = $test; } @@ -415,10 +415,10 @@ class test extends XMLDBAction { $field = new XMLDBField('grade'); $field->setAttributes(XMLDB_TYPE_NUMBER, '10,2', null, null, null, null, null, null); - $test->sql = $table->getAlterFieldSQL($CFG->dbtype, $CFG->prefix, $field, true); - $test->status = change_field_unsigned($table, $field, false, false); + $test->sql = $gen->getAlterFieldSQL($table, $field); + $test->status = $dbman->change_field_unsigned($table, $field, false, false); if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['change field sign (signed)'] = $test; } @@ -430,10 +430,10 @@ class test extends XMLDBAction { $field = new XMLDBField('name'); $field->setAttributes(XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, 'Moodle'); - $test->sql = $table->getAlterFieldSQL($CFG->dbtype, $CFG->prefix, $field, true); - $test->status = change_field_notnull($table, $field, false, false); + $test->sql = $gen->getAlterFieldSQL($table, $field); + $test->status = $dbman->change_field_notnull($table, $field, false, false); if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['change field nullability (not null)'] = $test; } @@ -445,10 +445,10 @@ class test extends XMLDBAction { $field = new XMLDBField('name'); $field->setAttributes(XMLDB_TYPE_CHAR, '30', null, null, null, null, null, 'Moodle'); - $test->sql = $table->getAlterFieldSQL($CFG->dbtype, $CFG->prefix, $field, true); - $test->status = change_field_notnull($table, $field, false, false); + $test->sql = $gen->getAlterFieldSQL($table, $field); + $test->status = $dbman->change_field_notnull($table, $field, false, false); if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['change field nullability (null)'] = $test; } @@ -460,10 +460,10 @@ class test extends XMLDBAction { $field = new XMLDBField('name'); $field->setAttributes(XMLDB_TYPE_CHAR, '30', null, null, null, null, null, null); - $test->sql = $table->getModifyDefaultSQL($CFG->dbtype, $CFG->prefix, $field, true); - $test->status = change_field_default($table, $field, false, false); + $test->sql = $gen->getModifyDefaultSQL($table, $field); + $test->status = $dbman->change_field_default($table, $field, false, false); if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['drop field default of NULL field'] = $test; } @@ -475,10 +475,10 @@ class test extends XMLDBAction { $field = new XMLDBField('name'); $field->setAttributes(XMLDB_TYPE_CHAR, '30', null, null, null, null, null, 'Moodle'); - $test->sql = $table->getModifyDefaultSQL($CFG->dbtype, $CFG->prefix, $field, true); - $test->status = change_field_default($table, $field, false, false); + $test->sql = $gen->getModifyDefaultSQL($table, $field); + $test->status = $dbman->change_field_default($table, $field, false, false); if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['add field default of NULL field'] = $test; } @@ -490,10 +490,10 @@ class test extends XMLDBAction { $field = new XMLDBField('secondname'); $field->setAttributes(XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null, null, 'Moodle2'); - $test->sql = $table->getModifyDefaultSQL($CFG->dbtype, $CFG->prefix, $field, true); - $test->status = change_field_default($table, $field, false, false); + $test->sql = $gen->getModifyDefaultSQL($table, $field); + $test->status = $dbman->change_field_default($table, $field, false, false); if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['add field default of NOT NULL field'] = $test; } @@ -506,10 +506,10 @@ class test extends XMLDBAction { $field = new XMLDBField('secondname'); $field->setAttributes(XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null, null, null); - $test->sql = $table->getModifyDefaultSQL($CFG->dbtype, $CFG->prefix, $field, true); - $test->status = change_field_default($table, $field, false, false); + $test->sql = $gen->getModifyDefaultSQL($table, $field); + $test->status = $dbman->change_field_default($table, $field, false, false); if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['drop field default of NOT NULL field'] = $test; } @@ -521,10 +521,10 @@ class test extends XMLDBAction { $index = new XMLDBIndex('secondname'); $index->setAttributes(XMLDB_INDEX_UNIQUE, array('name', 'secondname', 'grade')); - $test->sql = $table->getAddIndexSQL($CFG->dbtype, $CFG->prefix, $index, true); - $test->status = add_index($table, $index, false, false); + $test->sql = $gen->getAddIndexSQL($table, $index); + $test->status = $dbman->add_index($table, $index, false, false); if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['add unique index'] = $test; } @@ -536,10 +536,10 @@ class test extends XMLDBAction { $index = new XMLDBIndex('secondname'); $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('course', 'name')); - $test->sql = $table->getAddIndexSQL($CFG->dbtype, $CFG->prefix, $index, true); - $test->status = add_index($table, $index, false, false); + $test->sql = $gen->getAddIndexSQL($table, $index); + $test->status = $dbman->add_index($table, $index, false, false); if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['add not unique index'] = $test; } @@ -551,7 +551,7 @@ class test extends XMLDBAction { $index = new XMLDBIndex('secondname'); $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('name', 'course')); - if ($indexfound = find_index_name($table, $index)) { + if ($indexfound = $dbman->find_index_name($table, $index)) { $test->status = true; $test->sql = array(); } else { @@ -570,10 +570,10 @@ class test extends XMLDBAction { $index = new XMLDBIndex('name'); $index->setAttributes(XMLDB_INDEX_UNIQUE, array('name', 'grade', 'secondname')); - $test->sql = $table->getDropIndexSQL($CFG->dbtype, $CFG->prefix, $index, true); - $test->status = drop_index($table, $index, false, false); + $test->sql = $gen->getDropIndexSQL($table, $index); + $test->status = $dbman->drop_index($table, $index, false, false); if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['drop index'] = $test; } @@ -585,10 +585,10 @@ class test extends XMLDBAction { $key = new XMLDBKey('id-course-grade'); $key->setAttributes(XMLDB_KEY_UNIQUE, array('id', 'course', 'grade')); - $test->sql = $table->getAddKeySQL($CFG->dbtype, $CFG->prefix, $key, true); - $test->status = add_key($table, $key, false, false); + $test->sql = $gen->getAddKeySQL($table, $key); + $test->status = $dbman->add_key($table, $key, false, false); if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['add unique key'] = $test; } @@ -600,10 +600,10 @@ class test extends XMLDBAction { $key = new XMLDBKey('course'); $key->setAttributes(XMLDB_KEY_FOREIGN_UNIQUE, array('course'), 'anothertest', array('id')); - $test->sql = $table->getAddKeySQL($CFG->dbtype, $CFG->prefix, $key, true); - $test->status = add_key($table, $key, false, false); + $test->sql = $gen->getAddKeySQL($table, $key); + $test->status = $dbman->add_key($table, $key, false, false); if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['add foreign+unique key'] = $test; } @@ -615,10 +615,10 @@ class test extends XMLDBAction { $key = new XMLDBKey('course'); $key->setAttributes(XMLDB_KEY_FOREIGN_UNIQUE, array('course'), 'anothertest', array('id')); - $test->sql = $table->getDropKeySQL($CFG->dbtype, $CFG->prefix, $key, true); - $test->status = drop_key($table, $key, false, false); + $test->sql = $gen->getDropKeySQL($table, $key); + $test->status = $dbman->drop_key($table, $key, false, false); if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['drop foreign+unique key'] = $test; } @@ -630,10 +630,10 @@ class test extends XMLDBAction { $key = new XMLDBKey('course'); $key->setAttributes(XMLDB_KEY_FOREIGN, array('course'), 'anothertest', array('id')); - $test->sql = $table->getAddKeySQL($CFG->dbtype, $CFG->prefix, $key, true); - $test->status = add_key($table, $key, false, false); + $test->sql = $gen->getAddKeySQL($table, $key); + $test->status = $dbman->add_key($table, $key, false, false); if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['add foreign key'] = $test; } @@ -645,10 +645,10 @@ class test extends XMLDBAction { $key = new XMLDBKey('course'); $key->setAttributes(XMLDB_KEY_FOREIGN, array('course'), 'anothertest', array('id')); - $test->sql = $table->getDropKeySQL($CFG->dbtype, $CFG->prefix, $key, true); - $test->status = drop_key($table, $key, false, false); + $test->sql = $gen->getDropKeySQL($table, $key); + $test->status = $dbman->drop_key($table, $key, false, false); if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['drop foreign key'] = $test; } @@ -660,11 +660,12 @@ class test extends XMLDBAction { $field->setAttributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, XMLDB_ENUM, array('single', 'news', 'general', 'social', 'eachuser', 'teacher', 'qanda'), 'general', 'course'); /// Get SQL code and execute it $test = new stdClass; - $test->sql = $table->getAddFieldSQL($CFG->dbtype, $CFG->prefix, $field, true); - $test->status = add_field($table, $field, false, false); + $test->sql = $gen->getAddFieldSQL($table, $field); + $test->status = $dbman->add_field($table, $field, false, false); if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } + $tests['add field with enum'] = $test; } @@ -674,11 +675,10 @@ class test extends XMLDBAction { $test = new stdClass; $field = new XMLDBField('type'); $field->setAttributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, 'general', 'course'); - - $test->sql = $table->getModifyEnumSQL($CFG->dbtype, $CFG->prefix, $field, true); - $test->status = change_field_enum($table, $field, false, false); + $test->sql = $gen->getModifyEnumSQL($table, $field); + $test->status = $dbman->change_field_enum($table, $field, false, false); if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['delete enumlist from one field'] = $test; } @@ -689,10 +689,10 @@ class test extends XMLDBAction { $test = new stdClass; $field = new XMLDBField('type'); $field->setAttributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, XMLDB_ENUM, array('single', 'news', 'general', 'social', 'eachuser', 'teacher', 'qanda'), 'general', 'course'); - $test->sql = $table->getModifyEnumSQL($CFG->dbtype, $CFG->prefix, $field, true); - $test->status = change_field_enum($table, $field, false, false); + $test->sql = $gen->getModifyEnumSQL($table, $field); + $test->status = $dbman->change_field_enum($table, $field, false, false); if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['add enumlist to one field'] = $test; } @@ -703,13 +703,14 @@ class test extends XMLDBAction { $test = new stdClass; $index = new XMLDBIndex('anyname'); $index->setAttributes(XMLDB_INDEX_UNIQUE, array('name', 'course')); - - $test->sql = $table->getRenameIndexSQL($CFG->dbtype, $CFG->prefix, $index, 'newnamefortheindex', true); - $test->status = rename_index($table, $index, 'newnamefortheindex', false, false); + $test->sql = $gen->getRenameIndexSQL($table, $index, 'newnamefortheindex'); + $test->status = $dbman->rename_index($table, $index, 'newnamefortheindex', false, false); if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['rename index (experimental. DO NOT USE IT)'] = $test; + $test = new stdClass; + $test->status = true; // ignore errors here } /// 40th test. Renaming one key @@ -719,12 +720,19 @@ class test extends XMLDBAction { $key = new XMLDBKey('anyname'); $key->setAttributes(XMLDB_KEY_UNIQUE, array('id', 'course', 'grade')); - $test->sql = $table->getRenameKeySQL($CFG->dbtype, $CFG->prefix, $key, 'newnameforthekey', true); - $test->status = rename_key($table, $key, 'newnameforthekey', false, false); + $test->sql = $gen->getRenameKeySQL($table, $key, 'newnameforthekey', true); + $olddebug = $CFG->debug; + if ($olddebug > DEBUG_ALL) { + $CFG->debug = DEBUG_ALL; // do not show experimental debug warning + } + $test->status = $dbman->rename_key($table, $key, 'newnameforthekey', false, false); + $CFG->debug = $olddebug; if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['rename key (experimental. DO NOT USE IT)'] = $test; + $test = new stdClass; + $test->status = true; // ignore errors here } /// 41th test. Renaming one field @@ -734,10 +742,10 @@ class test extends XMLDBAction { $field = new XMLDBField('type'); $field->setAttributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, XMLDB_ENUM, array('single', 'news', 'general', 'social', 'eachuser', 'teacher', 'qanda'), 'general', 'course'); - $test->sql = $table->getRenameFieldSQL($CFG->dbtype, $CFG->prefix, $field, 'newnameforthefield', true); - $test->status = rename_field($table, $field, 'newnameforthefield', false, false); + $test->sql = $gen->getRenameFieldSQL($table, $field, 'newnameforthefield', true); + $test->status = $dbman->rename_field($table, $field, 'newnameforthefield', false, false); if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['rename field'] = $test; } @@ -747,10 +755,10 @@ class test extends XMLDBAction { /// Get SQL code and execute it $test = new stdClass; - $test->sql = $table->getRenameTableSQL($CFG->dbtype, $CFG->prefix, 'newnameforthetable', true); - $test->status = rename_table($table, 'newnameforthetable', false, false); + $test->sql = $gen->getRenameTableSQL($table, 'newnameforthetable', true); + $test->status = $dbman->rename_table($table, 'newnameforthetable', false, false); if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['rename table'] = $test; } @@ -763,16 +771,16 @@ class test extends XMLDBAction { $field->setAttributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, XMLDB_ENUM, array('single', 'news', 'general', 'social', 'eachuser', 'teacher', 'qanda'), 'general', 'course'); /// Get SQL code and execute it $test = new stdClass; - $test->sql = $table->getModifyEnumSQL($CFG->dbtype, $CFG->prefix, $field, true); - $test->status = change_field_enum($table, $field, false, false); + $test->sql = $gen->getModifyEnumSQL($table, $field); + $test->status = $dbman->change_field_enum($table, $field, false, false); /// Let's see if the constraint exists to alter results - if (check_constraint_exists($table, $field)) { + if ($dbman->check_constraint_exists($table, $field)) { $test->sql = array('Nothing executed. Enum already exists. Correct.'); } else { $test->status = false; } if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['add enum to field containing enum'] = $test; } @@ -785,10 +793,10 @@ class test extends XMLDBAction { $field->setAttributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, 'general', 'course'); /// Get SQL code and execute it $test = new stdClass; - $test->sql = $table->getModifyEnumSQL($CFG->dbtype, $CFG->prefix, $field, true); - $test->status = change_field_enum($table, $field, false, false); + $test->sql = $gen->getModifyEnumSQL($table, $field); + $test->status = $dbman->change_field_enum($table, $field, false, false); if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['drop enum from field containing enum'] = $test; } @@ -801,16 +809,16 @@ class test extends XMLDBAction { $field->setAttributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, 'general', 'course'); /// Get SQL code and execute it $test = new stdClass; - $test->sql = $table->getModifyEnumSQL($CFG->dbtype, $CFG->prefix, $field, true); - $test->status = change_field_enum($table, $field, false, false); + $test->sql = $gen->getModifyEnumSQL($table, $field); + $test->status = $dbman->change_field_enum($table, $field, false, false); /// Let's see if the constraint exists to alter results - if (!check_constraint_exists($table, $field)) { + if (!$dbman->check_constraint_exists($table, $field)) { $test->sql = array('Nothing executed. Enum does not exists. Correct.'); } else { $test->status = false; } if (!$test->status) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['drop enum from field not containing enum'] = $test; } @@ -818,10 +826,10 @@ class test extends XMLDBAction { /// 46th test. Getting the PK sequence name for one table if ($test->status) { $test = new stdClass; - $test->sql = array(find_sequence_name($table)); - $test->status = find_sequence_name($table); + $test->sql = array($dbman->find_sequence_name($table)); + $test->status = $dbman->find_sequence_name($table); if (!$test->status) { - if (!$test->error = $db->ErrorMsg()) { //If no db errors, result is ok. Just the driver doesn't support this + if (!$test->error = $DB->get_last_error()) { //If no db errors, result is ok. Just the driver doesn't support this $test->sql = array('Not needed for this DB. Correct.'); $test->status = true; } @@ -843,30 +851,29 @@ class test extends XMLDBAction { } /// Build the record to insert - $rec->intro = addslashes($fulltext); + $rec->intro = $fulltext; $rec->name = 'texttest'; /// Calculate its length $textlen = $textlib->strlen($fulltext); - if ($rec->id = insert_record('newnameforthetable', $rec)) { - if ($new = get_record('newnameforthetable', 'id', $rec->id)) { - delete_records('newnameforthetable', 'id', $new->id); + if ($rec->id = $DB->insert_record('newnameforthetable', $rec)) { + if ($new = $DB->get_record('newnameforthetable', array('id'=>$rec->id))) { + $DB->delete_records('newnameforthetable', array('id'=>$new->id)); $newtextlen = $textlib->strlen($new->intro); if ($fulltext === $new->intro) { $test->sql = array($newtextlen . ' cc. (text) sent and received ok'); $test->status = true; } else { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); $test->sql = array($newtextlen . ' cc. (text) transfer failed. Data changed!'); print_object($new); $test->status = false; } } else { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error().'xx'; } } else { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error().'yy'.var_export($rec->id, true); } - $tests['insert record '. $textlen . ' cc. (text)'] = $test; } /// 48th test. Inserting BINARY contents @@ -874,26 +881,26 @@ class test extends XMLDBAction { $test = new stdClass; $test->status = false; /// Build the record to insert - $rec->avatar = addslashes($fulltext); + $rec->avatar = $fulltext; $rec->name = 'binarytest'; /// Calculate its length $textlen = strlen($fulltext); - if ($rec->id = insert_record('newnameforthetable', $rec)) { - if ($new = get_record('newnameforthetable', 'id', $rec->id)) { + if ($rec->id = $DB->insert_record('newnameforthetable', $rec)) { + if ($new = $DB->get_record('newnameforthetable', array('id'=>$rec->id))) { $newtextlen = strlen($new->avatar); if ($fulltext === $new->avatar) { $test->sql = array($newtextlen . ' bytes (binary) sent and received ok'); $test->status = true; } else { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); $test->sql = array($newtextlen . ' bytes (binary) transfer failed. Data changed!'); $test->status = false; } } else { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } } else { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['insert record '. $textlen . ' bytes (binary)'] = $test; } @@ -904,14 +911,14 @@ class test extends XMLDBAction { $test->status = false; $test->sql = array(); /// Build the record to insert - $rec->intro = addslashes($basetext); - $rec->avatar = addslashes($basetext); + $rec->intro = $basetext; + $rec->avatar = $basetext; $rec->name = 'updatelobs'; /// Calculate its length $textlen = $textlib->strlen($basetext); $imglen = strlen($basetext); - if (update_record('newnameforthetable', $rec)) { - if ($new = get_record('newnameforthetable', 'id', $rec->id)) { + if ($DB->update_record('newnameforthetable', $rec)) { + if ($new = $DB->get_record('newnameforthetable', array('id'=>$rec->id))) { $newtextlen = $textlib->strlen($new->intro); $newimglen = strlen($new->avatar); if ($basetext === $new->avatar && $basetext === $new->intro) { @@ -920,20 +927,20 @@ class test extends XMLDBAction { $test->status = true; } else { if ($rec->avatar !== $new->avatar) { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); $test->sql = array($newimglen . ' bytes (binary) transfer failed. Data changed!'); $test->status = false; } else { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); $test->sql = array($newtextlen . ' cc. (text) transfer failed. Data changed!'); $test->status = false; } } } else { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } } else { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['update record '. $textlen . ' cc. (text) and ' . $imglen . ' bytes (binary)'] = $test; } @@ -944,26 +951,26 @@ class test extends XMLDBAction { $test->status = false; $test->sql = array(); /// Build the record to insert - $rec->intro = addslashes($fulltext); + $rec->intro = $fulltext; $rec->name = 'updatelobs'; /// Calculate its length $textlen = $textlib->strlen($fulltext); - if (set_field('newnameforthetable', 'intro', $rec->intro, 'name', $rec->name)) { - if ($new = get_record('newnameforthetable', 'id', $rec->id)) { + if ($DB->set_field('newnameforthetable', 'intro', $rec->intro, array('name'=>$rec->name))) { + if ($new = $DB->get_record('newnameforthetable', array('id'=>$rec->id))) { $newtextlen = $textlib->strlen($new->intro); if ($fulltext === $new->intro) { $test->sql = array($newtextlen . ' cc. (text) sent and received ok'); $test->status = true; } else { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); $test->sql = array($newtextlen . ' cc. (text) transfer failed. Data changed!'); $test->status = false; } } else { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } } else { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['set field '. $textlen . ' cc. (text)'] = $test; } @@ -974,31 +981,31 @@ class test extends XMLDBAction { $test->status = false; $test->sql = array(); /// Build the record to insert - $rec->avatar = addslashes($fulltext); + $rec->avatar = $fulltext; $rec->name = 'updatelobs'; /// Calculate its length $textlen = strlen($fulltext); - if (set_field('newnameforthetable', 'avatar', $rec->avatar, 'name', $rec->name)) { - if ($new = get_record('newnameforthetable', 'id', $rec->id)) { + if ($DB->set_field('newnameforthetable', 'avatar', $rec->avatar, array('name'=>$rec->name))) { + if ($new = $DB->get_record('newnameforthetable', array('id'=>$rec->id))) { $newtextlen = strlen($new->avatar); if ($fulltext === $new->avatar) { $test->sql = array($newtextlen . ' bytes (binary) sent and received ok'); $test->status = true; } else { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); $test->sql = array($newtextlen . ' bytes (binary) transfer failed. Data changed!'); $test->status = false; } } else { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } } else { - $test->error = $db->ErrorMsg(); + $test->error = $DB->get_last_error(); } $tests['set field '. $textlen . ' bytes (binary)'] = $test; } - /// TODO: Check here values of the inserted records to see that everything ha the correct value + /// TODO: Check here values of the inserted records to see that everything has the correct value /// Iterate over tests, showing information as needed diff --git a/admin/xmldb/actions/view_reserved_words/view_reserved_words.class.php b/admin/xmldb/actions/view_reserved_words/view_reserved_words.class.php index c24cce12bb..c29f2d573b 100644 --- a/admin/xmldb/actions/view_reserved_words/view_reserved_words.class.php +++ b/admin/xmldb/actions/view_reserved_words/view_reserved_words.class.php @@ -63,49 +63,27 @@ class view_reserved_words extends XMLDBAction { $this->does_generate = ACTION_GENERATE_HTML; /// These are always here - global $CFG, $XMLDB, $db; + global $CFG, $XMLDB, $DB; /// Calculate list of available SQL generators - $plugins = get_list_of_plugins('lib/xmldb/classes/generators'); - $reserved_words = array(); - $reserved_words_bydb = array(); - foreach($plugins as $plugin) { - $classname = 'XMLDB' . $plugin; - $generator = new $classname(); - $reserved_words = array_merge($reserved_words, $generator->getReservedWords()); - $reserved_words_bydb[$plugin] = $generator->getReservedWords(); - } - sort($reserved_words); - $reserved_words = array_unique($reserved_words); + require("$CFG->libdir/ddl/sql_generator.php"); + $reserved_words = sql_generator::getAllReservedWords(); /// Now, calculate, looking into current DB (with AdoDB Metadata), which fields are /// in the list of reserved words $wronguses = array(); - $dbtables = $db->MetaTables('TABLES'); + $dbtables = $DB->get_tables(); if ($dbtables) { - foreach ($dbtables as $dbtable) { - $table = str_replace($CFG->prefix, '', $dbtable); - if (in_array($table, $reserved_words)) { - $list_of_db = array(); - foreach ($reserved_words_bydb as $key=>$words) { - if (in_array($table, $words)) { - $list_of_db[] = $key; - } - } - $wronguses[] = $this->str['table'] . ' - ' . $table . ' (' . implode(', ',$list_of_db) . ')'; + foreach ($dbtables as $table) { + if (array_key_exists($table, $reserved_words)) { + $wronguses[] = $this->str['table'] . ' - ' . $table . ' (' . implode(', ',$reserved_words[$table]) . ')'; } - $dbfields = $db->MetaColumns($dbtable); + $dbfields = $DB->get_columns($table); if ($dbfields) { foreach ($dbfields as $dbfield) { - if (in_array($dbfield->name, $reserved_words)) { - $list_of_db = array(); - foreach ($reserved_words_bydb as $key=>$words) { - if (in_array($dbfield->name, $words)) { - $list_of_db[] = $key; - } - } - $wronguses[] = $this->str['field'] . ' - ' . $table . '->' . $dbfield->name . ' (' . implode(', ',$list_of_db) . ')'; + if (array_key_exists($dbfield->name, $reserved_words)) { + $wronguses[] = $this->str['field'] . ' - ' . $table . '->' . $dbfield->name . ' (' . implode(', ',$reserved_words[$dbfield->name]) . ')'; } } } @@ -135,7 +113,7 @@ class view_reserved_words extends XMLDBAction { $o.= '
    '; $o.= ' '; $o.= ' '; $o.= '
    ' . $this->str['listreservedwords'].'
    '; diff --git a/admin/xmldb/actions/view_structure_sql/view_structure_sql.class.php b/admin/xmldb/actions/view_structure_sql/view_structure_sql.class.php index 7165e5b50f..a49483abe2 100644 --- a/admin/xmldb/actions/view_structure_sql/view_structure_sql.class.php +++ b/admin/xmldb/actions/view_structure_sql/view_structure_sql.class.php @@ -58,7 +58,8 @@ class view_structure_sql extends XMLDBAction { $this->does_generate = ACTION_GENERATE_HTML; /// These are always here - global $CFG, $XMLDB; + global $CFG, $XMLDB, $DB; + $dbman = $DB->get_manager(); /// Do the job, setting result as needed /// Get the dir containing the file @@ -77,23 +78,6 @@ class view_structure_sql extends XMLDBAction { } /// ADD YOUR CODE HERE - /// Get parameters - $generatorparam = optional_param('generator', null, PARAM_ALPHANUM); - if (empty($generatorparam)) { - $generatorparam = $CFG->dbtype; - } - - /// Calculate list of available SQL generators - $plugins = get_list_of_plugins('lib/xmldb/classes/generators'); - $generators = array(); - foreach($plugins as $plugin) { - $generators[$plugin] = $plugin; - } - /// Check we have the selected generator - if (!in_array($generatorparam, $generators)) { - $generatorparam = reset($generators); - } - /// The back to edit table button $b = '

    '; $b .= '[' . $this->str['back'] . ']'; @@ -101,15 +85,10 @@ class view_structure_sql extends XMLDBAction { $o = $b; $o.= ' '; - $o.= ' '; $o.= '
    ' . $this->str['selectdb']; - - /// Show the popup of generators - $url = 'index.php?action=view_structure_sql&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&generator='; - $o.= popup_form($url, $generators, 'selectgenerator', $generatorparam, '', '', '' , true); - $o.= '