MDL-14956 DDL exceptions

This commit is contained in:
skodak 2008-06-22 16:51:55 +00:00
parent d90e0ef3d6
commit eee5d9bb85
21 changed files with 777 additions and 854 deletions

View File

@ -1,9 +1,9 @@
<?php
/**
* cliupgrade.php
* cliupgrade.php
* Command Line Installer and Upgrader for Moodle
* @author Dilan Anuruddha
*
*
*/
@ -16,19 +16,19 @@ if (!empty($_SERVER['GATEWAY_INTERFACE'])){
/**
* BEFORE YOU ADD/EDIT/DELETE ANYTHING IN THIS DOCUMENT PLEASE READ
*
* BEFORE YOU ADD/EDIT/DELETE ANYTHING IN THIS DOCUMENT PLEASE READ
*
* When you add some code that print something on to standard out always wrap it around if clause with $verbose
* argument check. If the $verbose is CLI_NO, you shouldn't print anything. If $verboser is CLI_SEMI it's ok to print a
* summarized version. If $verbose is CLI_FULL you can print anything you want.
*
* When you add a code that read input from the standard input you should wrap it with appropriate if clause, allowing
* argument check. If the $verbose is CLI_NO, you shouldn't print anything. If $verboser is CLI_SEMI it's ok to print a
* summarized version. If $verbose is CLI_FULL you can print anything you want.
*
* When you add a code that read input from the standard input you should wrap it with appropriate if clause, allowing
* required level of interaction. Also remember to add the same option as a command line argument list.
* In CLI_FULL interaction mode, whether you have set the argument in commandline or not you
* should prompt for user input. In CLI_SEMI interaction only the arguments which are not set are prompted for user input.
* No interaction mode doesn't prompt user for anyinput. If any argument is not specified then the default value should be assumed.
* should prompt for user input. In CLI_SEMI interaction only the arguments which are not set are prompted for user input.
* No interaction mode doesn't prompt user for anyinput. If any argument is not specified then the default value should be assumed.
* So do the appropriate thing considering this when you edit or delete this code
*
*
*/
//=============================================================================//
// Set values for initial structures
@ -558,20 +558,20 @@ if (!file_exists(dirname(dirname(__FILE__)) . '/config.php')) {
}
}
}
if ( $verbose > CLI_NO && !empty($downloadsuccess)) {
//print success message if language pack download is successful
console_write(STDOUT,'downloadsuccess');
print_newline();
}
$CONFFILE = array();
//==================================================================================//
//set INSTALL array values to CONFFILE array
foreach ($INSTALL as $key => $value) {
$CONFFILE[$key] = $value;
}
//==================================================================================//
//if any value is not set, set default values
@ -687,9 +687,9 @@ if ( file_exists(dirname(dirname(__FILE__)) . '/config.php')) {
require_once($CFG->libdir.'/adminlib.php'); // Contains various admin-only functions
/**
* @todo check upgrade status, if upgrader is running already, notify user and exit.
* @todo check upgrade status, if upgrader is running already, notify user and exit.
* existing thing might work for this with some modifications
*
*
*/
///check PHP Settings
@ -827,14 +827,13 @@ if ( file_exists(dirname(dirname(__FILE__)) . '/config.php')) {
}
}
$status = $DB->get_manager()->install_from_xmldb_file("$CFG->libdir/db/install.xml"); //New method
$DB->get_manager()->install_from_xmldb_file("$CFG->libdir/db/install.xml"); //New method
// all new installs are in unicode - keep for backwards compatibility and 1.8 upgrade checks
set_config('unicodedb', 1);
/// Continue with the instalation
if ($status) {
// Install the roles system.
moodle_install_roles();
@ -861,9 +860,6 @@ if ( file_exists(dirname(dirname(__FILE__)) . '/config.php')) {
notify($strdatabasesuccess, "green");
require_once $CFG->dirroot.'/mnet/lib.php';
} else {
console_write(STDERR,"Error: Main databases NOT set up successfully",'');
}
}
@ -1096,7 +1092,7 @@ if ( file_exists(dirname(dirname(__FILE__)) . '/config.php')) {
/// just make sure upgrade logging is properly terminated
upgrade_log_finish();
unset($_SESSION['installautopilot']);
unset($SESSION->installautopilot);
/// Set up the site
if (! $site = get_site()) {
@ -1160,7 +1156,7 @@ if ( file_exists(dirname(dirname(__FILE__)) . '/config.php')) {
$newsite->student = get_string("defaultcoursestudent");
$newsite->students = get_string("defaultcoursestudents");
$newsite->timemodified = time();
if ($newid = $DB->insert_record('course', $newsite)) {
// Site created, add blocks for it
$page = page_create_object(PAGE_COURSE_VIEW, $newid);

View File

@ -109,7 +109,7 @@
}
}
}
if (! $maintables) {
/// hide errors from headers in case debug enabled in config.php
$origdebug = $CFG->debug;
@ -166,43 +166,40 @@
}
}
$status = $DB->get_manager()->install_from_xmldb_file("$CFG->libdir/db/install.xml"); //New method
$DB->get_manager()->install_from_xmldb_file("$CFG->libdir/db/install.xml"); //New method
// all new installs are in unicode - keep for backwards compatibility and 1.8 upgrade checks
set_config('unicodedb', 1);
/// Continue with the instalation
$DB->set_debug(false);
if ($status) {
/// Groups install is now in core above.
/// Groups install is now in core above.
// Install the roles system.
moodle_install_roles();
// Install the roles system.
moodle_install_roles();
// install core event handlers
events_update_definition();
// install core event handlers
events_update_definition();
/// This is used to handle any settings that must exist in $CFG but which do not exist in
/// admin_get_root()/$ADMIN as admin_setting objects (there are some exceptions).
apply_default_exception_settings(array('auth' => 'email',
'auth_pop3mailbox' => 'INBOX',
'enrol' => 'manual',
'enrol_plugins_enabled' => 'manual',
'style' => 'default',
'template' => 'default',
'theme' => 'standardwhite',
'filter_multilang_converted' => 1));
/// This is used to handle any settings that must exist in $CFG but which do not exist in
/// admin_get_root()/$ADMIN as admin_setting objects (there are some exceptions).
apply_default_exception_settings(array('auth' => 'email',
'auth_pop3mailbox' => 'INBOX',
'enrol' => 'manual',
'enrol_plugins_enabled' => 'manual',
'style' => 'default',
'template' => 'default',
'theme' => 'standardwhite',
'filter_multilang_converted' => 1));
// Write default settings unconditionally (i.e. even if a setting is already set, overwrite it)
// (this should only have any effect during initial install).
admin_apply_default_settings(NULL, true);
// Write default settings unconditionally (i.e. even if a setting is already set, overwrite it)
// (this should only have any effect during initial install).
admin_apply_default_settings(NULL, true);
notify($strdatabasesuccess, "green");
require_once $CFG->dirroot.'/mnet/lib.php';
notify($strdatabasesuccess, "green");
require_once $CFG->dirroot.'/mnet/lib.php';
} else {
print_error('dbnotsetup', 'debug');
}
print_continue('index.php');
print_footer('none');
die;
@ -279,7 +276,7 @@
print_footer('none');
die;
} elseif (empty($confirmplugincheck)) {
} elseif (empty($confirmplugincheck)) {
$strplugincheck = get_string('plugincheck');
$navigation = build_navigation(array(array('name'=>$strplugincheck, 'link'=>null, 'type'=>'misc')));
print_header($strplugincheck, $strplugincheck, $navigation, "", "", false, "&nbsp;", "&nbsp;");
@ -302,7 +299,7 @@
echo '</form>';
print_footer('none');
die();
} else {
$strdatabasesuccess = get_string("databasesuccess");
$navigation = build_navigation(array(array('name'=>$strdatabasesuccess, 'link'=>null, 'type'=>'misc')));

View File

@ -75,15 +75,15 @@ class test extends XMLDBAction {
/// Silenty drop any previous test tables
$table = new xmldb_table('testtable');
if ($dbman->table_exists($table)) {
$status = $dbman->drop_table($table, true, false);
$dbman->drop_table($table);
}
$table = new xmldb_table ('anothertest');
if ($dbman->table_exists($table)) {
$status = $dbman->drop_table($table, true, false);
$dbman->drop_table($table);
}
$table = new xmldb_table ('newnameforthetable');
if ($dbman->table_exists($table)) {
$status = $dbman->drop_table($table, true, false);
$dbman->drop_table($table);
}
/// 1st test. Complete table creation.
@ -119,8 +119,11 @@ class test extends XMLDBAction {
/// Get SQL code and execute it
$test = new stdClass;
$test->sql = $gen->getCreateTableSQL($table);
$test->status = $dbman->create_table($table, false, false);
if (!$test->status) {
try {
$dbman->create_table($table);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
$test->error = $DB->get_last_error();
}
$tests['create table'] = $test;
@ -130,8 +133,11 @@ class test extends XMLDBAction {
/// Get SQL code and execute it
$test = new stdClass;
$test->sql = $gen->getDropTableSQL($table);
$test->status = $dbman->drop_table($table, false, false);
if (!$test->status) {
try {
$dbman->drop_table($table);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
$test->error = $DB->get_last_error();
}
$tests['drop table'] = $test;
@ -151,14 +157,18 @@ class test extends XMLDBAction {
/// Get SQL code and execute it
$test = new stdClass;
$test->sql = $gen->getCreateTableSQL($table);
$test->status = $dbman->create_table($table, false, false);
if (!$test->status) {
try {
$dbman->create_table($table);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
$test->error = $DB->get_last_error();
}
$tests['create table - 2'] = $test;
}
/// Insert two records to do the work with real data
$rec = new stdClass;
$rec->course = 1;
$rec->name = 'Martin';
$rec->secondname = 'Dougiamas';
@ -179,8 +189,11 @@ class test extends XMLDBAction {
/// Get SQL code and execute it
$test = new stdClass;
$test->sql = $gen->getAddFieldSQL($table, $field);
$test->status = $dbman->add_field($table, $field, false, false);
if (!$test->status) {
try {
$dbman->add_field($table, $field, false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
$test->error = $DB->get_last_error();
}
$tests['add enum field'] = $test;
@ -191,8 +204,11 @@ class test extends XMLDBAction {
/// Create a new field with complex specs (enums are good candidates)
$test = new stdClass;
$test->sql = $gen->getDropFieldSQL($table, $field);
$test->status = $dbman->drop_field($table, $field, false, false);
if (!$test->status) {
try {
$dbman->drop_field($table, $field, false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
$test->error = $DB->get_last_error();
}
$tests['drop enum field'] = $test;
@ -205,8 +221,11 @@ class test extends XMLDBAction {
/// Get SQL code and execute it
$test = new stdClass;
$test->sql = $gen->getAddFieldSQL($table, $field);
$test->status = $dbman->add_field($table, $field, false, false);
if (!$test->status) {
try {
$dbman->add_field($table, $field, false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
$test->error = $DB->get_last_error();
}
$tests['add enum field again'] = $test;
@ -219,8 +238,11 @@ class test extends XMLDBAction {
/// Get SQL code and execute it
$test = new stdClass;
$test->sql = $gen->getAddFieldSQL($table, $field);
$test->status = $dbman->add_field($table, $field, false, false);
if (!$test->status) {
try {
$dbman->add_field($table, $field, false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
$test->error = $DB->get_last_error();
}
$tests['add numeric field'] = $test;
@ -232,8 +254,11 @@ class test extends XMLDBAction {
$field = new xmldb_field('type');
$test = new stdClass;
$test->sql = $gen->getDropFieldSQL($table, $field);
$test->status = $dbman->drop_field($table, $field, false, false);
if (!$test->status) {
try {
$dbman->drop_field($table, $field, false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
$test->error = $DB->get_last_error();
}
$tests['drop enum field again'] = $test;
@ -246,8 +271,11 @@ class test extends XMLDBAction {
$field = new xmldb_field('course', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, '0');
$test->sql = $gen->getAlterFieldSQL($table, $field);
$test->status = $dbman->change_field_type($table, $field, false, false);
if (!$test->status) {
try {
$dbman->change_field_type($table, $field, false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
$test->error = $DB->get_last_error();
}
$tests['change field type (int2char)'] = $test;
@ -260,8 +288,11 @@ class test extends XMLDBAction {
$field = new xmldb_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$test->sql = $gen->getAlterFieldSQL($table, $field);
$test->status = $dbman->change_field_type($table, $field, false, false);
if (!$test->status) {
try {
$dbman->change_field_type($table, $field, false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
$test->error = $DB->get_last_error();
}
$tests['change field type (char2int)'] = $test;
@ -274,8 +305,11 @@ class test extends XMLDBAction {
$field = new xmldb_field('grade', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, "test'n drop");
$test->sql = $gen->getAlterFieldSQL($table, $field);
$test->status = $dbman->change_field_type($table, $field, false, false);
if (!$test->status) {
try {
$dbman->change_field_type($table, $field, false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
$test->error = $DB->get_last_error();
}
$tests['change field type (number2char)'] = $test;
@ -288,8 +322,11 @@ class test extends XMLDBAction {
$field = new xmldb_field('grade', XMLDB_TYPE_FLOAT, '20,10', XMLDB_UNSIGNED, null, null, null, null, null);
$test->sql = $gen->getAlterFieldSQL($table, $field);
$test->status = $dbman->change_field_type($table, $field, false, false);
if (!$test->status) {
try {
$dbman->change_field_type($table, $field, false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
$test->error = $DB->get_last_error();
}
$tests['change field type (char2float)'] = $test;
@ -302,8 +339,11 @@ class test extends XMLDBAction {
$field = new xmldb_field('grade', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, 'test');
$test->sql = $gen->getAlterFieldSQL($table, $field);
$test->status = $dbman->change_field_type($table, $field, false, false);
if (!$test->status) {
try {
$dbman->change_field_type($table, $field, false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
$test->error = $DB->get_last_error();
}
$tests['change field type (float2char)'] = $test;
@ -316,8 +356,11 @@ class test extends XMLDBAction {
$field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '20,10', XMLDB_UNSIGNED, null, null, null, null, null);
$test->sql = $gen->getAlterFieldSQL($table, $field);
$test->status = $dbman->change_field_type($table, $field, false, false);
if (!$test->status) {
try {
$dbman->change_field_type($table, $field, false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
$test->error = $DB->get_last_error();
}
$tests['change field type (char2number)'] = $test;
@ -332,8 +375,11 @@ class test extends XMLDBAction {
$field->set_attributes(XMLDB_TYPE_TEXT, 'big', null, XMLDB_NOTNULL, null, null, null, null);
$test->sql = $gen->getAlterFieldSQL($table, $field);
$test->status = $dbman->change_field_precision($table, $field, false, false);
if (!$test->status) {
try {
$dbman->change_field_precision($table, $field, false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
$test->error = $DB->get_last_error();
}
$tests['change field precision (text)'] = $test;
@ -347,8 +393,11 @@ class test extends XMLDBAction {
$field->set_attributes(XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null, null, null);
$test->sql = $gen->getAlterFieldSQL($table, $field);
$test->status = $dbman->change_field_precision($table, $field, false, false);
if (!$test->status) {
try {
$dbman->change_field_precision($table, $field, false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
$test->error = $DB->get_last_error();
}
$tests['change field precision (char)'] = $test;
@ -362,8 +411,11 @@ class test extends XMLDBAction {
$field->set_attributes(XMLDB_TYPE_NUMBER, '10,2', null, null, null, null, null, null);
$test->sql = $gen->getAlterFieldSQL($table, $field);
$test->status = $dbman->change_field_precision($table, $field, false, false);
if (!$test->status) {
try {
$dbman->change_field_precision($table, $field, false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
$test->error = $DB->get_last_error();
}
$tests['change field precision (number)'] = $test;
@ -377,8 +429,11 @@ class test extends XMLDBAction {
$field->set_attributes(XMLDB_TYPE_INTEGER, '5', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$test->sql = $gen->getAlterFieldSQL($table, $field);
$test->status = $dbman->change_field_precision($table, $field, false, false);
if (!$test->status) {
try {
$dbman->change_field_precision($table, $field, false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
$test->error = $DB->get_last_error();
}
$tests['change field precision (integer) to smaller one'] = $test;
@ -392,8 +447,11 @@ class test extends XMLDBAction {
$field->set_attributes(XMLDB_TYPE_NUMBER, '10,2', XMLDB_UNSIGNED, null, null, null, null, null);
$test->sql = $gen->getAlterFieldSQL($table, $field);
$test->status = $dbman->change_field_unsigned($table, $field, false, false);
if (!$test->status) {
try {
$dbman->change_field_unsigned($table, $field, false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
$test->error = $DB->get_last_error();
}
$tests['change field sign (unsigned)'] = $test;
@ -407,8 +465,11 @@ class test extends XMLDBAction {
$field->set_attributes(XMLDB_TYPE_NUMBER, '10,2', null, null, null, null, null, null);
$test->sql = $gen->getAlterFieldSQL($table, $field);
$test->status = $dbman->change_field_unsigned($table, $field, false, false);
if (!$test->status) {
try {
$dbman->change_field_unsigned($table, $field, false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
$test->error = $DB->get_last_error();
}
$tests['change field sign (signed)'] = $test;
@ -422,8 +483,11 @@ class test extends XMLDBAction {
$field->set_attributes(XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, 'Moodle');
$test->sql = $gen->getAlterFieldSQL($table, $field);
$test->status = $dbman->change_field_notnull($table, $field, false, false);
if (!$test->status) {
try {
$dbman->change_field_notnull($table, $field, false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
$test->error = $DB->get_last_error();
}
$tests['change field nullability (not null)'] = $test;
@ -437,8 +501,11 @@ class test extends XMLDBAction {
$field->set_attributes(XMLDB_TYPE_CHAR, '30', null, null, null, null, null, 'Moodle');
$test->sql = $gen->getAlterFieldSQL($table, $field);
$test->status = $dbman->change_field_notnull($table, $field, false, false);
if (!$test->status) {
try {
$dbman->change_field_notnull($table, $field, false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
$test->error = $DB->get_last_error();
}
$tests['change field nullability (null)'] = $test;
@ -452,8 +519,11 @@ class test extends XMLDBAction {
$field->set_attributes(XMLDB_TYPE_CHAR, '30', null, null, null, null, null, null);
$test->sql = $gen->getModifyDefaultSQL($table, $field);
$test->status = $dbman->change_field_default($table, $field, false, false);
if (!$test->status) {
try {
$dbman->change_field_default($table, $field, false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
$test->error = $DB->get_last_error();
}
$tests['drop field default of NULL field'] = $test;
@ -467,8 +537,11 @@ class test extends XMLDBAction {
$field->set_attributes(XMLDB_TYPE_CHAR, '30', null, null, null, null, null, 'Moodle');
$test->sql = $gen->getModifyDefaultSQL($table, $field);
$test->status = $dbman->change_field_default($table, $field, false, false);
if (!$test->status) {
try {
$dbman->change_field_default($table, $field, false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
$test->error = $DB->get_last_error();
}
$tests['add field default of NULL field'] = $test;
@ -482,8 +555,11 @@ class test extends XMLDBAction {
$field->set_attributes(XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null, null, 'Moodle2');
$test->sql = $gen->getModifyDefaultSQL($table, $field);
$test->status = $dbman->change_field_default($table, $field, false, false);
if (!$test->status) {
try {
$dbman->change_field_default($table, $field, false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
$test->error = $DB->get_last_error();
}
$tests['add field default of NOT NULL field'] = $test;
@ -498,8 +574,11 @@ class test extends XMLDBAction {
$field->set_attributes(XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null, null, null);
$test->sql = $gen->getModifyDefaultSQL($table, $field);
$test->status = $dbman->change_field_default($table, $field, false, false);
if (!$test->status) {
try {
$dbman->change_field_default($table, $field, false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
$test->error = $DB->get_last_error();
}
$tests['drop field default of NOT NULL field'] = $test;
@ -513,8 +592,11 @@ class test extends XMLDBAction {
$index->set_attributes(XMLDB_INDEX_UNIQUE, array('name', 'secondname', 'grade'));
$test->sql = $gen->getAddIndexSQL($table, $index);
$test->status = $dbman->add_index($table, $index, false, false);
if (!$test->status) {
try {
$dbman->add_index($table, $index, false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
$test->error = $DB->get_last_error();
}
$tests['add unique index'] = $test;
@ -528,8 +610,11 @@ class test extends XMLDBAction {
$index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('course', 'name'));
$test->sql = $gen->getAddIndexSQL($table, $index);
$test->status = $dbman->add_index($table, $index, false, false);
if (!$test->status) {
try {
$dbman->add_index($table, $index, false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
$test->error = $DB->get_last_error();
}
$tests['add not unique index'] = $test;
@ -562,8 +647,11 @@ class test extends XMLDBAction {
$index->set_attributes(XMLDB_INDEX_UNIQUE, array('name', 'grade', 'secondname'));
$test->sql = $gen->getDropIndexSQL($table, $index);
$test->status = $dbman->drop_index($table, $index, false, false);
if (!$test->status) {
try {
$dbman->drop_index($table, $index, false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
$test->error = $DB->get_last_error();
}
$tests['drop index'] = $test;
@ -577,8 +665,11 @@ class test extends XMLDBAction {
$key->set_attributes(XMLDB_KEY_UNIQUE, array('id', 'course', 'grade'));
$test->sql = $gen->getAddKeySQL($table, $key);
$test->status = $dbman->add_key($table, $key, false, false);
if (!$test->status) {
try {
$dbman->add_key($table, $key, false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
$test->error = $DB->get_last_error();
}
$tests['add unique key'] = $test;
@ -592,8 +683,11 @@ class test extends XMLDBAction {
$key->set_attributes(XMLDB_KEY_FOREIGN_UNIQUE, array('course'), 'anothertest', array('id'));
$test->sql = $gen->getAddKeySQL($table, $key);
$test->status = $dbman->add_key($table, $key, false, false);
if (!$test->status) {
try {
$dbman->add_key($table, $key, false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
$test->error = $DB->get_last_error();
}
$tests['add foreign+unique key'] = $test;
@ -607,8 +701,11 @@ class test extends XMLDBAction {
$key->set_attributes(XMLDB_KEY_FOREIGN_UNIQUE, array('course'), 'anothertest', array('id'));
$test->sql = $gen->getDropKeySQL($table, $key);
$test->status = $dbman->drop_key($table, $key, false, false);
if (!$test->status) {
try {
$dbman->drop_key($table, $key, false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
$test->error = $DB->get_last_error();
}
$tests['drop foreign+unique key'] = $test;
@ -622,8 +719,11 @@ class test extends XMLDBAction {
$key->set_attributes(XMLDB_KEY_FOREIGN, array('course'), 'anothertest', array('id'));
$test->sql = $gen->getAddKeySQL($table, $key);
$test->status = $dbman->add_key($table, $key, false, false);
if (!$test->status) {
try {
$dbman->add_key($table, $key, false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
$test->error = $DB->get_last_error();
}
$tests['add foreign key'] = $test;
@ -637,8 +737,11 @@ class test extends XMLDBAction {
$key->set_attributes(XMLDB_KEY_FOREIGN, array('course'), 'anothertest', array('id'));
$test->sql = $gen->getDropKeySQL($table, $key);
$test->status = $dbman->drop_key($table, $key, false, false);
if (!$test->status) {
try {
$dbman->drop_key($table, $key, false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
$test->error = $DB->get_last_error();
}
$tests['drop foreign key'] = $test;
@ -652,11 +755,13 @@ class test extends XMLDBAction {
/// Get SQL code and execute it
$test = new stdClass;
$test->sql = $gen->getAddFieldSQL($table, $field);
$test->status = $dbman->add_field($table, $field, false, false);
if (!$test->status) {
try {
$dbman->add_field($table, $field, false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
$test->error = $DB->get_last_error();
}
$tests['add field with enum'] = $test;
}
@ -667,8 +772,11 @@ class test extends XMLDBAction {
$field = new xmldb_field('type');
$field->set_attributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, 'general', 'course');
$test->sql = $gen->getModifyEnumSQL($table, $field);
$test->status = $dbman->change_field_enum($table, $field, false, false);
if (!$test->status) {
try {
$dbman->change_field_enum($table, $field, false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
$test->error = $DB->get_last_error();
}
$tests['delete enumlist from one field'] = $test;
@ -681,8 +789,11 @@ class test extends XMLDBAction {
$field = new xmldb_field('type');
$field->set_attributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, XMLDB_ENUM, array('single', 'news', 'general', 'social', 'eachuser', 'teacher', 'qanda'), 'general', 'course');
$test->sql = $gen->getModifyEnumSQL($table, $field);
$test->status = $dbman->change_field_enum($table, $field, false, false);
if (!$test->status) {
try {
$dbman->change_field_enum($table, $field, false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
$test->error = $DB->get_last_error();
}
$tests['add enumlist to one field'] = $test;
@ -695,8 +806,11 @@ class test extends XMLDBAction {
$index = new xmldb_index('anyname');
$index->set_attributes(XMLDB_INDEX_UNIQUE, array('name', 'course'));
$test->sql = $gen->getRenameIndexSQL($table, $index, 'newnamefortheindex');
$test->status = $dbman->rename_index($table, $index, 'newnamefortheindex', false, false);
if (!$test->status) {
try {
$dbman->rename_index($table, $index, 'newnamefortheindex', false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
$test->error = $DB->get_last_error();
}
$tests['rename index (experimental. DO NOT USE IT)'] = $test;
@ -716,11 +830,14 @@ class test extends XMLDBAction {
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) {
try {
$dbman->rename_key($table, $key, 'newnameforthekey', false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
$test->error = $DB->get_last_error();
}
$CFG->debug = $olddebug;
$tests['rename key (experimental. DO NOT USE IT)'] = $test;
$test = new stdClass;
$test->status = true; // ignore errors here
@ -734,8 +851,11 @@ class test extends XMLDBAction {
$field->set_attributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, XMLDB_ENUM, array('single', 'news', 'general', 'social', 'eachuser', 'teacher', 'qanda'), 'general', 'course');
$test->sql = $gen->getRenameFieldSQL($table, $field, 'newnameforthefield', true);
$test->status = $dbman->rename_field($table, $field, 'newnameforthefield', false, false);
if (!$test->status) {
try {
$dbman->rename_field($table, $field, 'newnameforthefield', false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
$test->error = $DB->get_last_error();
}
$tests['rename field'] = $test;
@ -747,8 +867,11 @@ class test extends XMLDBAction {
$test = new stdClass;
$test->sql = $gen->getRenameTableSQL($table, 'newnameforthetable', true);
$test->status = $dbman->rename_table($table, 'newnameforthetable', false, false);
if (!$test->status) {
try {
$dbman->rename_table($table, 'newnameforthetable');
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
$test->error = $DB->get_last_error();
}
$tests['rename table'] = $test;
@ -763,14 +886,16 @@ class test extends XMLDBAction {
/// Get SQL code and execute it
$test = new stdClass;
$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 ($dbman->check_constraint_exists($table, $field)) {
$test->sql = array('Nothing executed. Enum already exists. Correct.');
} else {
try {
$dbman->change_field_enum($table, $field, false, false);
if ($dbman->check_constraint_exists($table, $field)) {
$test->sql = array('Nothing executed. Enum already exists. Correct.');
$test->status = true;
} else {
$test->status = false;
}
} catch (moodle_exception $e) {
$test->status = false;
}
if (!$test->status) {
$test->error = $DB->get_last_error();
}
$tests['add enum to field containing enum'] = $test;
@ -785,8 +910,11 @@ class test extends XMLDBAction {
/// Get SQL code and execute it
$test = new stdClass;
$test->sql = $gen->getModifyEnumSQL($table, $field);
$test->status = $dbman->change_field_enum($table, $field, false, false);
if (!$test->status) {
try {
$dbman->change_field_enum($table, $field, false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
$test->error = $DB->get_last_error();
}
$tests['drop enum from field containing enum'] = $test;
@ -801,14 +929,11 @@ class test extends XMLDBAction {
/// Get SQL code and execute it
$test = new stdClass;
$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 (!$dbman->check_constraint_exists($table, $field)) {
$test->sql = array('Nothing executed. Enum does not exists. Correct.');
} else {
try {
$dbman->change_field_enum($table, $field, false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
}
if (!$test->status) {
$test->error = $DB->get_last_error();
}
$tests['drop enum from field not containing enum'] = $test;

View File

@ -341,10 +341,8 @@
/// Both old .sql files and new install.xml are supported
/// but we priorize install.xml (XMLDB) if present
$status = false;
if (file_exists($CFG->dirroot . '/backup/db/install.xml')) {
$status = $DB->get_manager()->install_from_xmldb_file($CFG->dirroot . '/backup/db/install.xml'); //New method
}
$DB->get_manager()->install_from_xmldb_file($CFG->dirroot . '/backup/db/install.xml'); //New method
$status = true;
if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
$DB->set_debug(false);
}

View File

@ -41,7 +41,7 @@ $string['cannotcreateuploaddir'] = 'Cannot create upload folder. The site admini
$string['cannotcreateuser'] = 'Error creating user record';
$string['cannotcreateorfindstructs'] = 'Error finding or creating section structures for this course';
$string['cannotcreatepopupwin'] = 'Undefined element - cannot create popup window.';
$string['cannotcustomizelocallang'] = 'You do not have permission to customize the strings translation. This permission is controlled by the capability "moodle/site:langeditlocal". Set this capability to allow you to edit local language packages in case you want to modify translations for your site.';
$string['cannotcustomizelocallang'] = 'You do not have permission to customize the strings translation. This permission is controlled by the capability \"moodle/site:langeditlocal\". Set this capability to allow you to edit local language packages in case you want to modify translations for your site.';
$string['cannotdeletelangcache'] = 'Language cache can not be deleted, please fix permissions in dataroot/cache/languages!';
$string['cannotdeletebackupids'] = 'Couldn\'t delete previous backup ids.';
$string['cannotdeletecap'] = 'Could not delete deprecated capability $a';
@ -58,7 +58,7 @@ $string['cannoteditcomment'] = 'Comment is not yours to edit!';
$stirng['cannoteditcommentexpired'] = 'You can\'t edit this. Time expired!';
$string['cannoteditsiteform'] = 'You cannot edit the site course using this form';
$string['cannoteditpostorblog'] = 'You can not post or edit blogs.';
$string['cannoteditmasterlang'] = 'You do not have permission to edit master language package. This permission is controlled by the capability "moodle/site:langeditmaster". Set this capability to allow you to edit master language packages in case you are the maintainer of a package.';
$string['cannoteditmasterlang'] = 'You do not have permission to edit master language package. This permission is controlled by the capability \"moodle/site:langeditmaster\". Set this capability to allow you to edit master language packages in case you are the maintainer of a package.';
$string['cannotedityourprofile'] = 'Can not edit own profile, sorry.';
$string['cannotfindcomponent'] = 'Cannot find component.';
$string['cannotfindcontext'] = 'Could not find context';
@ -172,7 +172,7 @@ $string['csvemptyfile'] = 'The CSV file is empty.';
$string['csvcolumnduplicates'] = 'Duplicate columns detected.';
$string['csvfewcolumns'] = 'Not enough columns, please verify the delimiter setting.';
$string['csvinvalidcolsnum'] = 'INVALID CSV FILE; Each line must include 49 or 70 fields';
$string['csvinvalidcols'] = '<b>INVALID CSV FILE:</b> First line must include "Header Fields" and the file must be type of <br />"Expanded Fields/Comma Separated"<br />or<br /> "Expanded Fields with CAVV Result Code/Comma Separated"';
$string['csvinvalidcols'] = '<b>INVALID CSV FILE:</b> First line must include \"Header Fields\" and the file must be type of <br />\"Expanded Fields/Comma Separated\"<br />or<br /> \"Expanded Fields with CAVV Result Code/Comma Separated\"';
$string['csvweirdcolumns'] = 'Invalid CSV file format - number of columns is not constant!';
$string['csvloaderror'] = 'Error occur during loading CSV file!';
$string['dbconnectionfailed'] = '<p>Error: Database connection failed.</p>
@ -181,6 +181,13 @@ $string['dbconnectionfailed'] = '<p>Error: Database connection failed.</p>
$string['dbdriverproblem'] = '<p>Error: database driver problem detected</p>
<p>The site administrator should verify server configuration</p><p>$a</p>';
$string['dbupdatefailed'] = 'Database update failed.';
$string['ddlexecuteerror'] = 'DDL sql execution error.';
$string['ddlfieldalreadyexists'] = 'Field \"$a\" does not exist.';
$string['ddlfieldnotexist'] = 'Field \"$a->fieldname\" does not exist in table \"$a->tablename\".';
$string['ddltablealreadyexists'] = 'Table \"$a\" already exists.';
$string['ddltablenotexist'] = 'Table \"$a\" does not exist.';
$string['ddlunknownerror'] = 'Unknown DDL library error.';
$string['ddlxmlfileerror'] = 'XML database file errors found';
$string['destinationcmnotexit'] = 'The destination course module does not exist';
$string['downloadedfilecheckfailed'] = 'Downloaded file check failed.';
$string['duplicateusername'] = 'Duplicate username - skiping record';

View File

@ -65,7 +65,7 @@ function drop_plugin_tables($name, $file, $feedback=true) {
global $CFG, $DB;
// first try normal delete
if ($DB->get_manager()->delete_tables_from_xmldb_file($file, $feedback)) {
if ($DB->get_manager()->delete_tables_from_xmldb_file($file)) {
return true;
}
@ -83,7 +83,7 @@ function drop_plugin_tables($name, $file, $feedback=true) {
// found orphan table --> delete it
if ($DB->get_manager()->table_exists($table)) {
$xmldb_table = new xmldb_table($table);
$DB->get_manager()->drop_table($xmldb_table, true, $feedback);
$DB->get_manager()->drop_table($xmldb_table);
}
}
@ -288,12 +288,10 @@ function upgrade_plugins($type, $dir, $return) {
if ($CFG->$pluginversion == 0) { // It's a new install of this plugin
/// Both old .sql files and new install.xml are supported
/// but we priorize install.xml (XMLDB) if present
$status = false;
if (file_exists($fullplug . '/db/install.xml')) {
$status = $DB->get_manager()->install_from_xmldb_file($fullplug . '/db/install.xml'); //New method
} else {
$status = true;
$DB->get_manager()->install_from_xmldb_file($fullplug . '/db/install.xml'); //New method
}
$status = true;
if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
$DB->set_debug(false);
}
@ -534,7 +532,8 @@ function upgrade_activity_modules($return) {
/// Both old .sql files and new install.xml are supported
/// but we priorize install.xml (XMLDB) if present
if (file_exists($fullmod . '/db/install.xml')) {
$status = $DB->get_manager()->install_from_xmldb_file($fullmod . '/db/install.xml'); //New method
$DB->get_manager()->install_from_xmldb_file($fullmod . '/db/install.xml'); //New method
$status = true;
}
if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
$DB->set_debug(false);

View File

@ -1069,10 +1069,8 @@ function upgrade_blocks_db($continueto) {
}
/// Both old .sql files and new install.xml are supported
/// but we priorize install.xml (XMLDB) if present
$status = false;
if (file_exists($CFG->dirroot . '/blocks/db/install.xml')) {
$status = $DB->get_manager()->install_from_xmldb_file($CFG->dirroot . '/blocks/db/install.xml'); //New method
}
$DB->get_manager()->install_from_xmldb_file($CFG->dirroot . '/blocks/db/install.xml'); //New method
$status = true;
if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
$DB->set_debug(false);
}
@ -1363,12 +1361,10 @@ function upgrade_blocks_plugins($continueto) {
/// Both old .sql files and new install.xml are supported
/// but we priorize install.xml (XMLDB) if present
$status = false;
if (file_exists($fullblock . '/db/install.xml')) {
$status = $DB->get_manager()->install_from_xmldb_file($fullblock . '/db/install.xml'); //New method
} else {
$status = true;
$DB->get_manager()->install_from_xmldb_file($fullblock . '/db/install.xml'); //New method
}
$status = true;
if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
$DB->set_debug(false);
}

View File

@ -18,7 +18,6 @@
function xmldb_main_upgrade($oldversion=0) {
global $CFG, $THEME, $USER, $DB;
$result = true;
@ -36,14 +35,14 @@ function xmldb_main_upgrade($oldversion=0) {
$index = new xmldb_index('contextid-lowerboundary', XMLDB_INDEX_NOTUNIQUE, array('contextid', 'lowerboundary'));
/// Launch drop index contextid-lowerboundary
$result = $result && $dbman->drop_index($table, $index);
$dbman->drop_index($table, $index);
/// Define index contextid-lowerboundary-letter (unique) to be added to grade_letters
$table = new xmldb_table('grade_letters');
$index = new xmldb_index('contextid-lowerboundary-letter', XMLDB_INDEX_UNIQUE, array('contextid', 'lowerboundary', 'letter'));
/// Launch add index contextid-lowerboundary-letter
$result = $result && $dbman->add_index($table, $index);
$dbman->add_index($table, $index);
/// Main savepoint reached
upgrade_main_savepoint($result, 2008030700);
@ -89,7 +88,7 @@ function xmldb_main_upgrade($oldversion=0) {
/// Under MySQL and Postgres... detect old NULL contents and change them by correct empty string. MDL-14859
if ($CFG->dbfamily == 'mysql' || $CFG->dbfamily == 'postgres') {
$DB->execute("UPDATE {user} SET idnumber = '' WHERE idnumber IS NULL", true);
$DB->execute("UPDATE {user} SET idnumber = '' WHERE idnumber IS NULL");
}
/// Define index idnumber (not unique) to be dropped form user
@ -98,7 +97,7 @@ function xmldb_main_upgrade($oldversion=0) {
/// Launch drop index idnumber
if ($dbman->index_exists($table, $index)) {
$result = $result && $dbman->drop_index($table, $index);
$dbman->drop_index($table, $index);
}
/// Changing precision of field idnumber on table user to (255)
@ -106,11 +105,11 @@ function xmldb_main_upgrade($oldversion=0) {
$field = new xmldb_field('idnumber', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null, 'password');
/// Launch change of precision for field idnumber
$result = $result && $dbman->change_field_precision($table, $field);
$dbman->change_field_precision($table, $field);
/// Launch add index idnumber again
$index = new xmldb_index('idnumber', XMLDB_INDEX_NOTUNIQUE, array('idnumber'));
$result = $result && $dbman->add_index($table, $index);
$dbman->add_index($table, $index);
/// Main savepoint reached
upgrade_main_savepoint($result, 2008051201);
@ -131,7 +130,7 @@ function xmldb_main_upgrade($oldversion=0) {
if ($result && $oldversion < 2008051203) {
$table = new xmldb_table('mnet_enrol_course');
$field = new xmldb_field('sortorder', XMLDB_TYPE_INTEGER, '10', true, true, null, false, false, 0);
$result = $dbman->change_field_precision($table, $field);
$dbman->change_field_precision($table, $field);
upgrade_main_savepoint($result, 2008051203);
}

File diff suppressed because it is too large Load Diff

View File

@ -84,14 +84,14 @@ class ddl_test extends UnitTestCase {
for ($i=0; $i<3; $i++) {
$table = new xmldb_table('test_table_cust'.$i);
if ($dbman->table_exists($table)) {
$dbman->drop_table($table, true, false);
$dbman->drop_table($table);
}
}
// drop default tables
foreach ($this->tables as $table) {
if ($dbman->table_exists($table)) {
$dbman->drop_table($table, true, false);
$dbman->drop_table($table);
}
}
}
@ -106,9 +106,9 @@ class ddl_test extends UnitTestCase {
$table = $this->tables[$tablename];
if ($dbman->table_exists($table)) {
$dbman->drop_table($table, true, false);
$dbman->drop_table($table);
}
$dbman->create_table($table, true, false);
$dbman->create_table($table);
return $table;
}
@ -128,7 +128,8 @@ class ddl_test extends UnitTestCase {
$this->assertFalse($dbman->table_exists($table));
// create table and test again
$this->assertTrue($dbman->create_table($table, true, false));
$dbman->create_table($table);
$this->assertTrue($DB->get_records('test_table0') !== false);
$this->assertTrue($dbman->table_exists('test_table0'));
$this->assertTrue($dbman->table_exists($table));
@ -142,17 +143,10 @@ class ddl_test extends UnitTestCase {
$DB = $this->tdb; // do not use global $DB!
$dbman = $this->tdb->get_manager();
// Give a wrong table param (expect a debugging message)
$table = 'string';
ob_start(); // hide debug warning
$result = $dbman->create_table($table);
ob_end_clean();
$this->assertFalse($result);
// create table and do basic column tests
$table = $this->tables['test_table1'];
$this->assertTrue($dbman->create_table($table));
$dbman->create_table($table);
$this->assertTrue($dbman->table_exists($table));
$columns = $DB->get_columns('test_table1');
@ -172,22 +166,8 @@ class ddl_test extends UnitTestCase {
$table = $this->create_deftable('test_table0');
$this->assertTrue($dbman->drop_table($table, true, false));
$dbman->drop_table($table);
$this->assertFalse($dbman->table_exists('test_table0'));
// Try dropping non-existent table
$table = new xmldb_table('nonexistenttable');
ob_start(); // hide debug warning
$result = $dbman->drop_table($table, true, false);
ob_end_clean();
$this->assertTrue($result);
// Give a wrong table param
$table = 'string';
ob_start(); // hide debug warning
$result = $dbman->drop_table($table, true, false);
ob_end_clean();
$this->assertFalse($result);
}
@ -199,19 +179,19 @@ class ddl_test extends UnitTestCase {
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$dbman->create_table($table, true, false);
$dbman->create_table($table);
$enums = array('single', 'news', 'general');
/// Create a new field with complex specs (enums are good candidates)
$field = new xmldb_field('type1');
$field->set_attributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, XMLDB_ENUM, $enums, 'general', 'course');
$this->assertTrue($dbman->add_field($table, $field));
$dbman->add_field($table, $field);
$this->assertTrue($dbman->field_exists($table, 'type1'));
$field = new xmldb_field('type2');
$field->set_attributes(XMLDB_TYPE_CHAR, '20', null, null, null, XMLDB_ENUM, $enums, 'general', 'course');
$this->assertTrue($dbman->add_field($table, $field));
$dbman->add_field($table, $field);
$this->assertTrue($dbman->field_exists($table, 'type2'));
/// try inserting a good record
@ -263,7 +243,7 @@ class ddl_test extends UnitTestCase {
/// Create a new field with complex specs (enums are good candidates)
$field = new xmldb_field('onenumber');
$field->set_attributes(XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, 0, 'type');
$this->assertTrue($dbman->add_field($table, $field));
$dbman->add_field($table, $field);
$this->assertTrue($dbman->field_exists($table, 'onenumber'));
$columns = $DB->get_columns('test_table0');
@ -281,7 +261,7 @@ class ddl_test extends UnitTestCase {
$this->assertTrue($dbman->field_exists($table, $field));
$this->assertTrue($dbman->field_exists($table, 'type'));
$this->assertTrue($dbman->drop_field($table, $field));
$dbman->drop_field($table, $field);
$this->assertFalse($dbman->field_exists($table, 'type'));
}
@ -294,7 +274,7 @@ class ddl_test extends UnitTestCase {
$table->add_field('id', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->add_field('onenumber', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$dbman->create_table($table, true, false);
$dbman->create_table($table);
$record = new object();
$recorf->course = 2;
@ -302,47 +282,47 @@ class ddl_test extends UnitTestCase {
$field = new xmldb_field('onenumber');
$field->set_attributes(XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, '0');
$this->assertTrue($dbman->change_field_type($table, $field));
$dbman->change_field_type($table, $field);
$columns = $DB->get_columns('test_table_cust0');
$this->assertEqual($columns['onenumber']->meta_type, 'C');
$field = new xmldb_field('onenumber');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$this->assertTrue($dbman->change_field_type($table, $field));
$dbman->change_field_type($table, $field);
$columns = $DB->get_columns('test_table_cust0');
$this->assertEqual($columns['onenumber']->meta_type, 'I');
$field = new xmldb_field('onenumber');
$field->set_attributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, "test'n drop");
$this->assertTrue($dbman->change_field_type($table, $field));
$dbman->change_field_type($table, $field);
$columns = $DB->get_columns('test_table_cust0');
$this->assertEqual($columns['onenumber']->meta_type, 'C');
$field = new xmldb_field('onenumber');
$field->set_attributes(XMLDB_TYPE_FLOAT, '20,10', XMLDB_UNSIGNED, null, null, null, null, null);
$this->assertTrue($dbman->change_field_type($table, $field));
$dbman->change_field_type($table, $field);
$columns = $DB->get_columns('test_table_cust0');
$this->assertEqual($columns['onenumber']->meta_type, 'N');
$field = new xmldb_field('onenumber');
$field->set_attributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, 'test');
$this->assertTrue($dbman->change_field_type($table, $field));
$dbman->change_field_type($table, $field);
$columns = $DB->get_columns('test_table_cust0');
$this->assertEqual($columns['onenumber']->meta_type, 'C');
$field = new xmldb_field('onenumber');
$field->set_attributes(XMLDB_TYPE_NUMBER, '20,10', XMLDB_UNSIGNED, null, null, null, null, null);
$this->assertTrue($dbman->change_field_type($table, $field));
$dbman->change_field_type($table, $field);
$columns = $DB->get_columns('test_table_cust0');
$this->assertEqual($columns['onenumber']->meta_type, 'N');
$dbman->drop_table($table, true, false);
$dbman->drop_table($table);
}
public function testChangeFieldPrecision() {
@ -352,19 +332,19 @@ class ddl_test extends UnitTestCase {
$table = $this->create_deftable('test_table1');
$field = new xmldb_field('intro');
$field->set_attributes(XMLDB_TYPE_TEXT, 'big', null, XMLDB_NOTNULL, null, null, null, null);
$this->assertTrue($dbman->change_field_precision($table, $field));
$dbman->change_field_precision($table, $field);
$field = new xmldb_field('secondname');
$field->set_attributes(XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null, null, null);
$this->assertTrue($dbman->change_field_precision($table, $field));
$dbman->change_field_precision($table, $field);
$field = new xmldb_field('grade');
$field->set_attributes(XMLDB_TYPE_NUMBER, '10,2', null, null, null, null, null, null);
$this->assertTrue($dbman->change_field_precision($table, $field));
$dbman->change_field_precision($table, $field);
$field = new xmldb_field('course');
$field->set_attributes(XMLDB_TYPE_INTEGER, '5', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$this->assertTrue($dbman->change_field_precision($table, $field));
$dbman->change_field_precision($table, $field);
}
@ -375,11 +355,11 @@ class ddl_test extends UnitTestCase {
$table = $this->create_deftable('test_table1');
$field = new xmldb_field('grade');
$field->set_attributes(XMLDB_TYPE_NUMBER, '10,2', XMLDB_UNSIGNED, null, null, null, null, null);
$this->assertTrue($dbman->change_field_unsigned($table, $field));
$dbman->change_field_unsigned($table, $field);
$field = new xmldb_field('grade');
$field->set_attributes(XMLDB_TYPE_NUMBER, '10,2', null, null, null, null, null, null);
$this->assertTrue($dbman->change_field_unsigned($table, $field));
$dbman->change_field_unsigned($table, $field);
}
public function testChangeFieldNullability() {
@ -390,7 +370,7 @@ class ddl_test extends UnitTestCase {
$table->add_field('id', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->add_field('name', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, null);
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$dbman->create_table($table, true, false);
$dbman->create_table($table);
$record = new object();
$record->name = NULL;
@ -402,7 +382,7 @@ class ddl_test extends UnitTestCase {
$field = new xmldb_field('name');
$field->set_attributes(XMLDB_TYPE_CHAR, '30', null, null, null, null, null, null);
$this->assertTrue($dbman->change_field_notnull($table, $field));
$dbman->change_field_notnull($table, $field);
$this->assertTrue($DB->insert_record('test_table_cust0', $record, false));
@ -411,14 +391,14 @@ class ddl_test extends UnitTestCase {
$field = new xmldb_field('name');
$field->set_attributes(XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, null);
$this->assertTrue($dbman->change_field_notnull($table, $field));
$dbman->change_field_notnull($table, $field);
ob_start(); // hide debug warning
$result = $DB->insert_record('test_table_cust0', $record, false);
ob_end_clean();
$this->assertFalse($result);
$dbman->drop_table($table, true, false);
$dbman->drop_table($table);
}
public function testChangeFieldDefault() {
@ -430,11 +410,11 @@ class ddl_test extends UnitTestCase {
$table->add_field('number', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$table->add_field('name', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, 'Moodle');
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$dbman->create_table($table, true, false);
$dbman->create_table($table);
$field = new xmldb_field('name');
$field->set_attributes(XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, 'Moodle2');
$this->assertTrue($dbman->change_field_default($table, $field));
$dbman->change_field_default($table, $field);
$record = new object();
$record->number = 666;
@ -446,7 +426,7 @@ class ddl_test extends UnitTestCase {
$field = new xmldb_field('number');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, 666);
$this->assertTrue($dbman->change_field_default($table, $field));
$dbman->change_field_default($table, $field);
$record = new object();
$record->name = 'something';
@ -455,7 +435,7 @@ class ddl_test extends UnitTestCase {
$record = $DB->get_record('test_table_cust0', array('id'=>$id));
$this->assertEqual($record->number, '666');
$dbman->drop_table($table, true, false);
$dbman->drop_table($table);
}
public function testAddUniqueIndex() {
@ -467,7 +447,7 @@ class ddl_test extends UnitTestCase {
$table->add_field('number', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$table->add_field('name', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, 'Moodle');
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$dbman->create_table($table, true, false);
$dbman->create_table($table);
$record = new object();
$record->number = 666;
@ -476,14 +456,14 @@ class ddl_test extends UnitTestCase {
$index = new xmldb_index('number-name');
$index->set_attributes(XMLDB_INDEX_UNIQUE, array('number', 'name'));
$this->assertTrue($dbman->add_index($table, $index));
$dbman->add_index($table, $index);
ob_start(); // hide debug warning
$result = $DB->insert_record('test_table_cust0', $record, false);
ob_end_clean();
$this->assertFalse($result);
$dbman->drop_table($table, true, false);
$dbman->drop_table($table);
}
public function testAddNonUniqueIndex() {
@ -492,7 +472,7 @@ class ddl_test extends UnitTestCase {
$table = $this->create_deftable('test_table1');
$index = new xmldb_index('secondname');
$index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('course', 'name'));
$this->assertTrue($dbman->add_index($table, $index));
$dbman->add_index($table, $index);
}
public function testFindIndexName() {
@ -520,7 +500,7 @@ class ddl_test extends UnitTestCase {
$index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('course', 'name'));
$dbman->add_index($table, $index);
$this->assertTrue($dbman->drop_index($table, $index));
$dbman->drop_index($table, $index);
$this->assertFalse($dbman->find_index_name($table, $index));
}
@ -530,7 +510,7 @@ class ddl_test extends UnitTestCase {
$table = $this->create_deftable('test_table1');
$key = new xmldb_key('id-course-grade');
$key->set_attributes(XMLDB_KEY_UNIQUE, array('id', 'course', 'grade'));
$this->assertTrue($dbman->add_key($table, $key));
$dbman->add_key($table, $key);
}
public function testAddForeignUniqueKey() {
@ -541,7 +521,7 @@ class ddl_test extends UnitTestCase {
$key = new xmldb_key('course');
$key->set_attributes(XMLDB_KEY_FOREIGN_UNIQUE, array('course'), 'test_table0', array('id'));
$this->assertTrue($dbman->add_key($table, $key));
$dbman->add_key($table, $key);
}
public function testDropKey() {
@ -554,7 +534,7 @@ class ddl_test extends UnitTestCase {
$key->set_attributes(XMLDB_KEY_FOREIGN_UNIQUE, array('course'), 'test_table0', array('id'));
$dbman->add_key($table, $key);
$this->assertTrue($dbman->drop_key($table, $key));
$dbman->drop_key($table, $key);
}
public function testAddForeignKey() {
@ -565,7 +545,7 @@ class ddl_test extends UnitTestCase {
$key = new xmldb_key('course');
$key->set_attributes(XMLDB_KEY_FOREIGN, array('course'), 'test_table0', array('id'));
$this->assertTrue($dbman->add_key($table, $key));
$dbman->add_key($table, $key);
}
public function testDropForeignKey() {
@ -578,7 +558,7 @@ class ddl_test extends UnitTestCase {
$key->set_attributes(XMLDB_KEY_FOREIGN, array('course'), 'test_table0', array('id'));
$dbman->add_key($table, $key);
$this->assertTrue($dbman->drop_key($table, $key));
$dbman->drop_key($table, $key);
}
public function testChangeFieldEnum() {
@ -590,12 +570,12 @@ class ddl_test extends UnitTestCase {
$table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$table->add_field('type', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, XMLDB_ENUM, array('single', 'news', 'general'), 'general');
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$dbman->create_table($table, true, false);
$dbman->create_table($table);
// Removing an enum value
$field = new xmldb_field('type');
$field->set_attributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null);
$this->assertTrue($dbman->change_field_enum($table, $field));
$dbman->change_field_enum($table, $field);
$record = new object();
$record->course = 666;
@ -605,7 +585,7 @@ class ddl_test extends UnitTestCase {
// Adding an enum value
$field = new xmldb_field('type');
$field->set_attributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, XMLDB_ENUM, array('single', 'news', 'general', 'social', 'eachuser', 'teacher', 'qanda'), 'general', 'course');
$this->assertTrue($dbman->change_field_enum($table, $field));
$dbman->change_field_enum($table, $field);
$record = new object();
$record->course = 666;
@ -616,7 +596,7 @@ class ddl_test extends UnitTestCase {
ob_end_clean();
$this->assertFalse($result);
$dbman->drop_table($table, true, false);
$dbman->drop_table($table);
}
public function testRenameField() {
@ -628,7 +608,7 @@ class ddl_test extends UnitTestCase {
$field->set_attributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, XMLDB_ENUM,
array('single', 'news', 'general', 'social', 'eachuser', 'teacher', 'qanda'), 'general', 'course');
$this->assertTrue($dbman->rename_field($table, $field, 'newfieldname'));
$dbman->rename_field($table, $field, 'newfieldname');
$columns = $DB->get_columns('test_table0');
@ -642,7 +622,7 @@ class ddl_test extends UnitTestCase {
$table = $this->create_deftable('test_table0');
$this->assertFalse($dbman->table_exists('test_table_cust0'));
$this->assertTrue($dbman->rename_table($table, 'test_table_cust0'));
$dbman->rename_table($table, 'test_table_cust0');
$this->assertTrue($dbman->table_exists('test_table_cust0'));
$table->setName('test_table_cust0');
@ -655,7 +635,12 @@ class ddl_test extends UnitTestCase {
$table = $this->create_deftable('test_table0');
// String params
// Give a nonexistent table as first param
$this->assertFalse($dbman->field_exists('nonexistenttable', 'id'));
try {
$dbman->field_exists('nonexistenttable', 'id');
$this->assertTrue(false);
} catch (Exception $e) {
$this->assertTrue($e instanceof moodle_exception);
}
// Give a nonexistent field as second param
$this->assertFalse($dbman->field_exists('test_table0', 'nonexistentfield'));
@ -668,7 +653,12 @@ class ddl_test extends UnitTestCase {
// Give a nonexistent table as first param
$nonexistenttable = new xmldb_table('nonexistenttable');
$this->assertFalse($dbman->field_exists($nonexistenttable, $realfield));
try {
$dbman->field_exists($nonexistenttable, $realfield);
$this->assertTrue(false);
} catch (Exception $e) {
$this->assertTrue($e instanceof moodle_exception);
}
// Give a nonexistent field as second param
$nonexistentfield = new xmldb_field('nonexistentfield');
@ -704,12 +694,6 @@ class ddl_test extends UnitTestCase {
$table = $this->create_deftable('test_table0');
$key = $table->getKey('primary');
$invalid_key = 'invalid_key';
ob_start(); // hide debug warning
$result = $dbman->find_key_name($table, $invalid_key);
ob_end_clean();
$this->assertFalse($result);
// With Mysql, the return value is actually "mdl_test_id_pk"
$result = $dbman->find_key_name($table, $key);
@ -719,19 +703,14 @@ class ddl_test extends UnitTestCase {
public function testFindSequenceName() {
$dbman = $this->tdb->get_manager();
// give invalid table param
$table = 'invalid_table';
ob_start(); // hide debug warning
$result = $dbman->find_sequence_name($table);
ob_end_clean();
$this->assertFalse($result);
// give nonexistent table param
$table = new xmldb_table("nonexistenttable");
ob_start(); // hide debug warning
$result = $dbman->find_sequence_name($table);
ob_end_clean();
$this->assertFalse($result);
try {
$dbman->find_sequence_name($table);
$this->assertTrue(false);
} catch (Exception $e) {
$this->assertTrue($e instanceof moodle_exception);
}
// Give existing and valid table param
$table = $this->create_deftable('test_table0');
@ -749,22 +728,32 @@ class ddl_test extends UnitTestCase {
$this->assertTrue($dbman->table_exists('test_table1'));
// feed nonexistent file
ob_start(); // hide debug warning
$result = $dbman->delete_tables_from_xmldb_file('fpsoiudfposui', false);
ob_end_clean();
$this->assertFalse($result);
try {
ob_start(); // hide debug warning
$dbman->delete_tables_from_xmldb_file('fpsoiudfposui');
ob_end_clean();
$this->assertTrue(false);
} catch (Exception $e) {
ob_end_clean();
$this->assertTrue($e instanceof moodle_exception);
}
// Real file but invalid xml file
ob_start(); // hide debug warning
$result = $dbman->delete_tables_from_xmldb_file($CFG->libdir . '/ddl/simpletest/fixtures/invalid.xml', false);
ob_end_clean();
$this->assertFalse($result);
try {
ob_start(); // hide debug warning
$dbman->delete_tables_from_xmldb_file($CFG->libdir . '/ddl/simpletest/fixtures/invalid.xml');
$this->assertTrue(false);
ob_end_clean();
} catch (Exception $e) {
ob_end_clean();
$this->assertTrue($e instanceof moodle_exception);
}
// Check that the table has not been deleted from DB
$this->assertTrue($dbman->table_exists('test_table1'));
// Real and valid xml file
$this->assertTrue($dbman->delete_tables_from_xmldb_file($CFG->libdir . '/ddl/simpletest/fixtures/xmldb_table.xml', false));
$dbman->delete_tables_from_xmldb_file($CFG->libdir . '/ddl/simpletest/fixtures/xmldb_table.xml');
// Check that the table has been deleted from DB
$this->assertFalse($dbman->table_exists('test_table1'));
@ -775,42 +764,46 @@ class ddl_test extends UnitTestCase {
$dbman = $this->tdb->get_manager();
// feed nonexistent file
ob_start(); // hide debug warning
$result = $dbman->install_from_xmldb_file('fpsoiudfposui', false);
ob_end_clean();
$this->assertFalse($result);
try {
ob_start(); // hide debug warning
$dbman->install_from_xmldb_file('fpsoiudfposui');
ob_end_clean();
$this->assertTrue(false);
} catch (Exception $e) {
ob_end_clean();
$this->assertTrue($e instanceof moodle_exception);
}
// Real but invalid xml file
ob_start(); // hide debug warning
$result = $dbman->install_from_xmldb_file($CFG->libdir.'/ddl/simpletest/fixtures/invalid.xml', false);
ob_end_clean();
$this->assertFalse($result);
try {
ob_start(); // hide debug warning
$dbman->install_from_xmldb_file($CFG->libdir.'/ddl/simpletest/fixtures/invalid.xml');
ob_end_clean();
$this->assertTrue(false);
} catch (Exception $e) {
ob_end_clean();
$this->assertTrue($e instanceof moodle_exception);
}
// Check that the table has not yet been created in DB
$this->assertFalse($dbman->table_exists('test_table1'));
// Real and valid xml file
$this->assertTrue($dbman->install_from_xmldb_file($CFG->libdir.'/ddl/simpletest/fixtures/xmldb_table.xml', false));
$dbman->install_from_xmldb_file($CFG->libdir.'/ddl/simpletest/fixtures/xmldb_table.xml');
$this->assertTrue($dbman->table_exists('test_table1'));
}
public function testCreateTempTable() {
$dbman = $this->tdb->get_manager();
// Feed incorrect table param
ob_start(); // hide debug warning
$result = $dbman->create_temp_table('test_table1');
ob_end_clean();
$this->assertFalse($result);
$table = $this->tables['test_table1'];
// New table
$this->assertTrue($dbman->create_temp_table($table));
$dbman->create_temp_table($table);
$this->assertTrue($dbman->table_exists('test_table1', true));
// Delete
$this->assertTrue($dbman->drop_temp_table($table));
$dbman->drop_temp_table($table);
$this->assertFalse($dbman->table_exists('test_table1', true));
}

View File

@ -442,7 +442,7 @@ function error($message, $link='') {
throw new moodle_exception('notlocalisederrormessage', 'error', $link, $message);
}
_print_normal_error('notlocalisederrormessage', 'error', $message, $link, debug_backtrace(), true); // show debug warning
_print_normal_error('notlocalisederrormessage', 'error', $message, $link, debug_backtrace(), null, true); // show debug warning
}
@ -496,124 +496,144 @@ function find_sequence_name($table) {
return $DB->get_manager()->find_sequence_name($table);
}
function drop_table($table, $continue=true, $feedback=true) {
function drop_table($table) {
global $DB;
debugging('Deprecated ddllib function used!');
return $DB->get_manager()->drop_table($table, $continue, $feedback);
$DB->get_manager()->drop_table($table);
return true;
}
function install_from_xmldb_file($file) {
global $DB;
debugging('Deprecated ddllib function used!');
return $DB->get_manager()->install_from_xmldb_file($file);
$DB->get_manager()->install_from_xmldb_file($file);
return true;
}
function create_table($table, $continue=true, $feedback=true) {
function create_table($table) {
global $DB;
debugging('Deprecated ddllib function used!');
return $DB->get_manager()->create_table($table, $continue, $feedback);
$DB->get_manager()->create_table($table);
return true;
}
function create_temp_table($table, $continue=true, $feedback=true) {
function create_temp_table($table) {
global $DB;
debugging('Deprecated ddllib function used!');
return $DB->get_manager()->create_temp_table($table, $continue, $feedback);
$DB->get_manager()->create_temp_table($table);
return true;
}
function rename_table($table, $newname, $continue=true, $feedback=true) {
function rename_table($table, $newname) {
global $DB;
debugging('Deprecated ddllib function used!');
return $DB->get_manager()->rename_table($table, $newname, $continue, $feedback);
$DB->get_manager()->rename_table($table, $newname);
return true;
}
function add_field($table, $field, $continue=true, $feedback=true) {
function add_field($table, $field) {
global $DB;
debugging('Deprecated ddllib function used!');
return $DB->get_manager()->add_field($table, $field, $continue, $feedback);
$DB->get_manager()->add_field($table, $field);
return true;
}
function drop_field($table, $field, $continue=true, $feedback=true) {
function drop_field($table, $field) {
global $DB;
debugging('Deprecated ddllib function used!');
return $DB->get_manager()->drop_field($table, $field, $continue, $feedback);
$DB->get_manager()->drop_field($table, $field);
return true;
}
function change_field_type($table, $field, $continue=true, $feedback=true) {
function change_field_type($table, $field) {
global $DB;
debugging('Deprecated ddllib function used!');
return $DB->get_manager()->change_field_type($table, $field, $continue, $feedback);
$DB->get_manager()->change_field_type($table, $field);
return true;
}
function change_field_precision($table, $field, $continue=true, $feedback=true) {
function change_field_precision($table, $field) {
global $DB;
debugging('Deprecated ddllib function used!');
return $DB->get_manager()->change_field_precision($table, $field, $continue, $feedback);
$DB->get_manager()->change_field_precision($table, $field);
return true;
}
function change_field_unsigned($table, $field, $continue=true, $feedback=true) {
function change_field_unsigned($table, $field) {
global $DB;
debugging('Deprecated ddllib function used!');
return $DB->get_manager()->change_field_unsigned($table, $field, $continue, $feedback);
$DB->get_manager()->change_field_unsigned($table, $field);
return true;
}
function change_field_notnull($table, $field, $continue=true, $feedback=true) {
function change_field_notnull($table, $field) {
global $DB;
debugging('Deprecated ddllib function used!');
return $DB->get_manager()->change_field_notnull($table, $field, $continue, $feedback);
$DB->get_manager()->change_field_notnull($table, $field);
return true;
}
function change_field_enum($table, $field, $continue=true, $feedback=true) {
function change_field_enum($table, $field) {
global $DB;
debugging('Deprecated ddllib function used!');
return $DB->get_manager()->change_field_enum($table, $field, $continue, $feedback);
$DB->get_manager()->change_field_enum($table, $field);
return true;
}
function change_field_default($table, $field, $continue=true, $feedback=true) {
function change_field_default($table, $field) {
global $DB;
debugging('Deprecated ddllib function used!');
return $DB->get_manager()->change_field_default($table, $field, $continue, $feedback);
$DB->get_manager()->change_field_default($table, $field);
return true;
}
function rename_field($table, $field, $newname, $continue=true, $feedback=true) {
function rename_field($table, $field, $newname) {
global $DB;
debugging('Deprecated ddllib function used!');
return $DB->get_manager()->rename_field($table, $field, $continue, $feedback);
$DB->get_manager()->rename_field($table, $field);
return true;
}
function add_key($table, $key, $continue=true, $feedback=true) {
function add_key($table, $key) {
global $DB;
debugging('Deprecated ddllib function used!');
return $DB->get_manager()->add_key($table, $key, $continue, $feedback);
$DB->get_manager()->add_key($table, $key);
return true;
}
function drop_key($table, $key, $continue=true, $feedback=true) {
function drop_key($table, $key) {
global $DB;
debugging('Deprecated ddllib function used!');
return $DB->get_manager()->drop_key($table, $key, $continue, $feedback);
$DB->get_manager()->drop_key($table, $key);
return true;
}
function rename_key($table, $key, $newname, $continue=true, $feedback=true) {
function rename_key($table, $key, $newname) {
global $DB;
debugging('Deprecated ddllib function used!');
return $DB->get_manager()->rename_key($table, $key, $newname, $continue, $feedback);
$DB->get_manager()->rename_key($table, $key, $newname);
return true;
}
function add_index($table, $index, $continue=true, $feedback=true) {
function add_index($table, $index) {
global $DB;
debugging('Deprecated ddllib function used!');
return $DB->get_manager()->add_index($table, $index, $continue, $feedback);
$DB->get_manager()->add_index($table, $index);
return true;
}
function drop_index($table, $index, $continue=true, $feedback=true) {
function drop_index($table, $index) {
global $DB;
debugging('Deprecated ddllib function used!');
return $DB->get_manager()->drop_index($table, $index, $continue, $feedback);
$DB->get_manager()->drop_index($table, $index);
return true;
}
function rename_index($table, $index, $newname, $continue=true, $feedback=true) {
function rename_index($table, $index, $newname) {
global $DB;
debugging('Deprecated ddllib function used!');
return $DB->get_manager()->rename_index($table, $index, $newname, $continue, $feedback);
$DB->get_manager()->rename_index($table, $index, $newname);
return true;
}

View File

@ -163,7 +163,7 @@ abstract class adodb_moodle_database extends moodle_database {
$column->enums[$key] = substr($value, 1, strlen($value)-2);
}
}
}
}
$this->columns[$table][$column->name] = new database_column_info($column);
}
@ -179,7 +179,9 @@ abstract class adodb_moodle_database extends moodle_database {
* @param bool $state
*/
public function set_debug($state) {
$this->adodb->debug = $state;
if ($this->adodb) {
$this->adodb->debug = $state;
}
}
/**

View File

@ -29,7 +29,7 @@ class dml_test extends UnitTestCase {
foreach ($this->tables as $table) {
if ($dbman->table_exists($table)) {
$dbman->drop_table($table, true, false);
$dbman->drop_table($table);
}
}
$this->tables = array();

View File

@ -96,8 +96,8 @@
var checkWarnings = function() {
// look for div tags with the class name notifyproblem
warnings = filterNodesByClassName(document.getElementsByTagName('div'), /(^|\b)notifyproblem(\b|$)/);
// look for div tags with the class name notifyproblem or error box
warnings = filterNodesByClassName(document.getElementsByTagName('div'), /((^|\b)notifyproblem(\b|$))|errorbox/);
// and find the continue button
continueBtn = filterNodesByClassName(document.getElementsByTagName('div'), /(^|\b)continuebutton(\b|$)/, true);

View File

@ -17,6 +17,7 @@ class moodle_exception extends Exception {
public $module;
public $a;
public $link;
public $debuginfo;
/**
* Constructor
@ -24,8 +25,9 @@ class moodle_exception extends Exception {
* @param string $module name of module
* @param string $link The url where the user will be prompted to continue. If no url is provided the user will be directed to the site index page.
* @param object $a Extra words and phrases that might be required in the error string
* @param string $debuginfo optional debugging information
*/
function __construct($errorcode, $module='', $link='', $a=NULL) {
function __construct($errorcode, $module='', $link='', $a=NULL, $debuginfo=null) {
if (empty($module) || $module == 'moodle' || $module == 'core') {
$module = 'error';
}
@ -34,6 +36,7 @@ class moodle_exception extends Exception {
$this->module = $module;
$this->link = $link;
$this->a = $a;
$this->debuginfo = $debuginfo;
$message = get_string($errorcode, $module, $a);
@ -45,12 +48,19 @@ class moodle_exception extends Exception {
* Default exception handler, uncought exceptions are equivalent to using print_error()
*/
function default_exception_handler($ex) {
global $DB;
if ($DB) {
//if you enable db debugging and exception is thrown, the print footer prints a lot of rubbish
$DB->set_debug(0);
}
$backtrace = $ex->getTrace();
$place = array('file'=>$ex->getFile(), 'line'=>$ex->getLine(), 'exception'=>get_class($ex));
array_unshift($backtrace, $place);
if ($ex instanceof moodle_exception) {
_print_normal_error($ex->errorcode, $ex->module, $ex->a, $ex->link, $backtrace);
_print_normal_error($ex->errorcode, $ex->module, $ex->a, $ex->link, $backtrace, $ex->debuginfo);
} else {
_print_normal_error('generalexceptionmessage', 'error', $ex->getMessage(), '', $backtrace);
}

View File

@ -151,9 +151,9 @@ class grade_test extends UnitTestCase {
$table->add_index('idnumber-course', XMLDB_INDEX_NOTUNIQUE, array('idnumber', 'course'));
/// Launch create table for course_modules
$result = $result && $this->dbmanager->create_table($table, true, false);
$this->dbmanager->create_table($table);
} else {
$DB->delete_records($table->name, array());
$DB->delete_records($table->name, null);
}
/// Define table modules to be created
@ -177,9 +177,9 @@ class grade_test extends UnitTestCase {
$table->add_index('name', XMLDB_INDEX_NOTUNIQUE, array('name'));
/// Launch create table for modules
$result = $result && $this->dbmanager->create_table($table, true, false);
$this->dbmanager->create_table($table);
} else {
$DB->delete_records($table->name, array());
$DB->delete_records($table->name, null);
}
/// Define table grade_items to be created
@ -223,10 +223,10 @@ class grade_test extends UnitTestCase {
$table->add_key('outcomeid', XMLDB_KEY_FOREIGN, array('outcomeid'), 'grade_outcomes', array('id'));
/// Launch create table for grade_items
$result = $result && $this->dbmanager->create_table($table, true, false);
$this->dbmanager->create_table($table);
} else {
$DB->delete_records($table->name, array());
$DB->delete_records($table->name, null);
}
@ -255,10 +255,10 @@ class grade_test extends UnitTestCase {
$table->add_key('parent', XMLDB_KEY_FOREIGN, array('parent'), 'grade_categories', array('id'));
/// Launch create table for grade_categories
$result = $result && $this->dbmanager->create_table($table, true, false);
$this->dbmanager->create_table($table);
} else {
$DB->delete_records($table->name, array());
$DB->delete_records($table->name, null);
}
@ -296,10 +296,10 @@ class grade_test extends UnitTestCase {
$table->add_key('usermodified', XMLDB_KEY_FOREIGN, array('usermodified'), 'user', array('id'));
/// Launch create table for grade_grades
$result = $result && $this->dbmanager->create_table($table, true, false);
$this->dbmanager->create_table($table);
} else {
$DB->delete_records($table->name, array());
$DB->delete_records($table->name, null);
}
@ -325,10 +325,10 @@ class grade_test extends UnitTestCase {
$table->add_key('usermodified', XMLDB_KEY_FOREIGN, array('usermodified'), 'user', array('id'));
/// Launch create table for grade_outcomes
$result = $result && $this->dbmanager->create_table($table, true, false);
$this->dbmanager->create_table($table);
} else {
$DB->delete_records($table->name, array());
$DB->delete_records($table->name, null);
}
@ -348,10 +348,10 @@ class grade_test extends UnitTestCase {
$table->add_index('courseid', XMLDB_INDEX_NOTUNIQUE, array('courseid'));
/// Launch create table for scale
$result = $result && $this->dbmanager->create_table($table, true, false);
$this->dbmanager->create_table($table);
} else {
$DB->delete_records($table->name, array());
$DB->delete_records($table->name, null);
}
/// Define table quiz to be created
@ -394,9 +394,9 @@ class grade_test extends UnitTestCase {
$table->add_index('course', XMLDB_INDEX_NOTUNIQUE, array('course'));
/// Launch create table for quiz
$result = $result && $this->dbmanager->create_table($table, true, false);
$this->dbmanager->create_table($table);
} else {
$DB->delete_records($table->name, array());
$DB->delete_records($table->name, null);
}
return $result;
@ -457,10 +457,10 @@ class grade_test extends UnitTestCase {
$table->add_index('action', XMLDB_INDEX_NOTUNIQUE, array('action'));
/// Launch create table for grade_items_history
$result = $result && $this->dbmanager->create_table($table, true, false);
$this->dbmanager->create_table($table);
} else {
$DB->delete_records($table->name, array());
$DB->delete_records($table->name, null);
}
/// Define table grade_categories to be created
@ -498,10 +498,10 @@ class grade_test extends UnitTestCase {
$table->add_index('action', XMLDB_INDEX_NOTUNIQUE, array('action'));
/// Launch create table for grade_categories_history
$result = $result && $this->dbmanager->create_table($table, true, false);
$this->dbmanager->create_table($table);
} else {
$DB->delete_records($table->name, array());
$DB->delete_records($table->name, null);
}
@ -549,10 +549,10 @@ class grade_test extends UnitTestCase {
$table->add_index('action', XMLDB_INDEX_NOTUNIQUE, array('action'));
/// Launch create table for grade_grades_history
$result = $result && $this->dbmanager->create_table($table, true, false);
$this->dbmanager->create_table($table);
} else {
$DB->delete_records($table->name, array());
$DB->delete_records($table->name, null);
}
@ -584,10 +584,10 @@ class grade_test extends UnitTestCase {
$table->add_index('action', XMLDB_INDEX_NOTUNIQUE, array('action'));
/// Launch create table for grade_outcomes_history
$result = $result && $this->dbmanager->create_table($table, true, false);
$this->dbmanager->create_table($table);
} else {
$DB->delete_records($table->name, array());
$DB->delete_records($table->name, null);
}
/// Define table scale to be created
@ -618,10 +618,10 @@ class grade_test extends UnitTestCase {
$table->add_index('action', XMLDB_INDEX_NOTUNIQUE, array('action'));
/// Launch create table for scale_history
$result = $result && $this->dbmanager->create_table($table, true, false);
$this->dbmanager->create_table($table);
} else {
$DB->delete_records($table->name, array());
$DB->delete_records($table->name, null);
}
return $result;

View File

@ -1042,7 +1042,7 @@ function print_textfield ($name, $value, $alt = '',$size=50,$maxlength=0, $retur
function popup_form($common, $options, $formid, $selected='', $nothing='choose', $help='', $helptext='', $return=false,
$targetwindow='self', $selectlabel='', $optionsextra=NULL) {
global $CFG;
global $CFG, $SESSION;
static $go, $choose; /// Locally cached, in case there's lots on a page
if (empty($options)) {
@ -1127,7 +1127,7 @@ $targetwindow='self', $selectlabel='', $optionsextra=NULL) {
} else {
if (!empty($CFG->usesid) && !isset($_COOKIE[session_name()]))
{
$url=sid_process_url( $common . $value );
$url = $SESSION->sid_process_url( $common . $value );
} else
{
$url=$common . $value;
@ -5650,7 +5650,7 @@ function print_error($errorcode, $module='', $link='', $a=NULL) {
/**
* Internal function - do not use directly!!
*/
function _print_normal_error($errorcode, $module, $a, $link, $backtrace, $showerrordebugwarning=false) {
function _print_normal_error($errorcode, $module, $a, $link, $backtrace, $debuginfo=null, $showerrordebugwarning=false) {
global $CFG, $SESSION, $THEME;
if ($module == 'error') {
@ -5706,7 +5706,11 @@ function _print_normal_error($errorcode, $module, $a, $link, $backtrace, $shower
} else {
if (debugging('', DEBUG_DEVELOPER)) {
notify('Stack trace:'.print_backtrace($backtrace, true), 'notifytiny');
if ($debuginfo) {
debugging($debuginfo, DEBUG_DEVELOPER, $backtrace);
} else {
notify('Stack trace:'.print_backtrace($backtrace, true), 'notifytiny');
}
}
}
@ -6040,11 +6044,10 @@ function notice_yesno ($message, $linkyes, $linkno, $optionsyes=NULL, $optionsno
* echo "<script type='text/javascript'>alert('Redirect $url');</script>";
*/
function redirect($url, $message='', $delay=-1) {
global $CFG, $THEME;
global $CFG, $THEME, $SESSION;
if (!empty($CFG->usesid) && !isset($_COOKIE[session_name()])) {
$url = sid_process_url($url);
$url = $SESSION->sid_process_url($url);
}
$message = clean_text($message);
@ -6879,9 +6882,10 @@ function doc_link($path='', $text='', $iconpath='') {
*
* @param string $message a message to print
* @param int $level the level at which this debugging statement should show
* @param array $backtrace use different backtrace
* @return bool
*/
function debugging($message='', $level=DEBUG_NORMAL) {
function debugging($message='', $level=DEBUG_NORMAL, $backtrace=null) {
global $CFG;
@ -6891,8 +6895,10 @@ function debugging($message='', $level=DEBUG_NORMAL) {
if ($CFG->debug >= $level) {
if ($message) {
$callers = debug_backtrace();
$from = print_backtrace($callers, true);
if (!$backtrace) {
$backtrace = debug_backtrace();
}
$from = print_backtrace($backtrace, true);
if (!isset($CFG->debugdisplay)) {
$CFG->debugdisplay = ini_get('display_errors');
}

View File

@ -34,7 +34,7 @@ function xmldb_data_upgrade($oldversion=0) {
$field = new xmldb_field('asearchtemplate', XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, 'jstemplate');
if (!$dbman->field_exists($table, $field)) {
$result = $result && $dbman->add_field($table, $field);
$dbman->add_field($table, $field);
}
}
@ -47,9 +47,9 @@ function xmldb_data_upgrade($oldversion=0) {
$table = new xmldb_table('data');
$field = new xmldb_field('notification', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'editany');
// First step, Set NOT NULL
$result = $result && $dbman->change_field_notnull($table, $field);
$dbman->change_field_notnull($table, $field);
// Second step, Set default to 0
$result = $result && $dbman->change_field_default($table, $field);
$dbman->change_field_default($table, $field);
}
return $result;

View File

@ -58,7 +58,7 @@ function xmldb_feedback_upgrade($oldversion=0) {
$key->set_attributes(XMLDB_KEY_FOREIGN, array('feedback'), 'feedback', 'id');
$table->addKey($key);
$result = $result && $dbman->create_table($table);
$dbman->create_table($table);
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
//create a new table feedback_valuetmp and the field-definition
@ -96,7 +96,7 @@ function xmldb_feedback_upgrade($oldversion=0) {
$key->set_attributes(XMLDB_KEY_FOREIGN, array('item'), 'feedback_item', 'id');
$table->addKey($key);
$result = $result && $dbman->create_table($table);
$dbman->create_table($table);
////////////////////////////////////////////////////////////
}
@ -106,25 +106,25 @@ function xmldb_feedback_upgrade($oldversion=0) {
$table = new xmldb_table('feedback_completed');
$field = new xmldb_field('random_response', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
/// Launch add field1
$result = $result && $dbman->add_field($table, $field);
$dbman->add_field($table, $field);
/// Define field anonymous_response to be added to feedback_completed
$table = new xmldb_table('feedback_completed');
$field = new xmldb_field('anonymous_response', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '1', null);
/// Launch add field2
$result = $result && $dbman->add_field($table, $field);
$dbman->add_field($table, $field);
/// Define field random_response to be added to feedback_completed
$table = new xmldb_table('feedback_completedtmp');
$field = new xmldb_field('random_response', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
/// Launch add field1
$result = $result && $dbman->add_field($table, $field);
$dbman->add_field($table, $field);
/// Define field anonymous_response to be added to feedback_completed
$table = new xmldb_table('feedback_completedtmp');
$field = new xmldb_field('anonymous_response', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '1', null);
/// Launch add field2
$result = $result && $dbman->add_field($table, $field);
$dbman->add_field($table, $field);
////////////////////////////////////////////////////////////
}
@ -135,7 +135,7 @@ function xmldb_feedback_upgrade($oldversion=0) {
$table = new xmldb_table('feedback_template');
$field = new xmldb_field('ispublic', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '1', null);
if (!$dbman->field_exists($table, $field)) {
$result = $result && $dbman->add_field($table, $field);
$dbman->add_field($table, $field);
}
}
@ -202,7 +202,7 @@ function xmldb_feedback_upgrade($oldversion=0) {
$table = new xmldb_table('feedback');
$field = new xmldb_field('autonumbering', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '1', 'multiple_submit');
/// Launch add field2
$result = $result && $dbman->add_field($table, $field);
$dbman->add_field($table, $field);
}
if ($result && $oldversion < 2008050104) {
@ -210,14 +210,14 @@ function xmldb_feedback_upgrade($oldversion=0) {
$table = new xmldb_table('feedback');
$field = new xmldb_field('site_after_submit', XMLDB_TYPE_CHAR, '255', null, null, false, null, null, '', 'autonumbering');
/// Launch add field2
$result = $result && $dbman->add_field($table, $field);
$dbman->add_field($table, $field);
}
if ($result && $oldversion < 2008050105) {
//field count is not more needed
$table = new xmldb_table('feedback_tracking');
$field = new xmldb_field('count');
$result = $result && $dbman->drop_field($table, $field);
$dbman->drop_field($table, $field);
}
return $result;
}

View File

@ -38,7 +38,7 @@ function xmldb_lesson_upgrade($oldversion=0) {
/// Set field specs
$field->set_attributes(XMLDB_TYPE_INTEGER, '3', null, XMLDB_NOTNULL, null, null, null, '0', 'ongoing');
/// Launch rename field usegrademax to usemaxgrade
$result = $result && $dbman->rename_field($table, $field, 'usemaxgrade');
$dbman->rename_field($table, $field, 'usemaxgrade');
}
}

View File

@ -42,7 +42,7 @@ function xmldb_quiz_upgrade($oldversion=0) {
/// Conditionally launch create table for quiz_report
if (!$dbman->table_exists($table)) {
$result = $result && $dbman->create_table($table);
$dbman->create_table($table);
}
}