<?php
/**
- * cliupgrade.php
+ * cliupgrade.php
* Command Line Installer and Upgrader for Moodle
* @author Dilan Anuruddha
- *
+ *
*/
/**
- * 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
}
}
}
-
+
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
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
}
}
- $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();
notify($strdatabasesuccess, "green");
require_once $CFG->dirroot.'/mnet/lib.php';
- } else {
- console_write(STDERR,"Error: Main databases NOT set up successfully",'');
- }
}
/// 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()) {
$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);
}
}
}
-
+
if (! $maintables) {
/// hide errors from headers in case debug enabled in config.php
$origdebug = $CFG->debug;
}
}
- $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.
-
- // Install the roles system.
- moodle_install_roles();
-
- // 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));
-
- // 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';
- } else {
- print_error('dbnotsetup', 'debug');
- }
+
+ /// Groups install is now in core above.
+
+ // Install the roles system.
+ moodle_install_roles();
+
+ // 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));
+
+ // 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';
+
print_continue('index.php');
print_footer('none');
die;
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, " ", " ");
echo '</form>';
print_footer('none');
die();
-
+
} else {
$strdatabasesuccess = get_string("databasesuccess");
$navigation = build_navigation(array(array('name'=>$strdatabasesuccess, 'link'=>null, 'type'=>'misc')));
/// 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.
/// 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;
/// 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;
/// 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';
/// 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;
/// 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;
/// 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;
/// 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;
$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;
$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;
$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;
$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;
$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;
$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;
$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;
$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;
$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;
$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;
$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;
$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;
$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;
$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;
$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;
$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;
$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;
$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;
$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;
$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;
$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;
$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;
$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;
$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;
$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;
$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;
$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;
/// 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;
}
$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;
$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;
$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;
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
$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;
$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;
/// 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;
/// 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;
/// 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;
/// 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);
}
$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';
$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';
$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>
$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';
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;
}
// 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);
}
}
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);
}
/// 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);
}
/// 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);
}
/// 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);
}
function xmldb_main_upgrade($oldversion=0) {
-
global $CFG, $THEME, $USER, $DB;
$result = true;
$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);
/// 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
/// 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)
$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);
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);
}
$this->generator->dispose();
$this->generator = null;
}
- $this->mdb = null;
+ $this->mdb = null;
}
/**
- * This function will execute an array of SQL commands, returning
- * true/false if any error is found and stopping/continue as desired.
+ * This function will execute an array of SQL commands.
+ *
+ * @exception ddl_exception if error found
*
* @param array $sqlarr array of sql statements to execute
- * @param boolean $continue to specify if must continue on error (true) or stop (false)
- * @param boolean $feedback to specify to show status info (true) or not (false)
- * @return boolean true if everything was ok, false if some error was found
+ * @return void
*/
- protected function execute_sql_arr(array $sqlarr, $continue, $feedback=true) {
- $result = true;
+ protected function execute_sql_arr(array $sqlarr) {
foreach ($sqlarr as $sql) {
- $result = $this->execute_sql($sql, $feedback) && $result;
- if (!$continue and !$result) {
- break;
- }
+ $this->execute_sql($sql);
}
-
- return $result;
}
/**
- * Execute a given sql command string - used in upgrades
+ * Execute a given sql command string
*
- * Completely general function - it just runs some SQL and reports success.
+ * @exception ddl_exception if error found
*
* @param string $command The sql string you wish to be executed.
- * @param bool $feedback Set this argument to true if the results generated should be printed. Default is true.
- * @return bool success
+ * @return vaoid
*/
- protected function execute_sql($sql, $feedback=true) {
- $result = $this->mdb->change_database_structure($sql);
-
- if ($feedback and !$result) {
- notify('<strong>' . get_string('error') . '</strong>');
+ protected function execute_sql($sql) {
+ if (!$this->mdb->change_database_structure($sql)) {
+ throw new ddl_exception('ddlexecuteerror', NULL, $this->mdb->get_last_error());
}
-
- return $result;
}
/**
* @return boolean true/false
*/
public function table_exists($table, $temptable=false) {
+ if (!is_string($table) and !($table instanceof xmldb_table)) {
+ throw new ddl_exception('ddlunknownerror', NULL, 'incorrect table parameter!');
+ }
return $this->generator->table_exists($table, $temptable);
}
* @return boolean true/false
*/
public function field_exists($table, $field) {
- $exists = true;
+ /// Calculate the name of the table
+ if (is_string($table)) {
+ $tablename = $table;
+ } else {
+ $tablename = $table->getName();
+ }
/// Check the table exists
if (!$this->table_exists($table)) {
- return false;
+ throw new ddl_table_missing_exception($tablename);
}
/// Do this function silenty (to avoid output in install/upgrade process)
$olddbdebug = $this->mdb->get_debug();
$this->mdb->set_debug(false);
- if (is_string($table)) {
- $tablename = $table;
- } else {
- /// Calculate the name of the table
- $tablename = $table->getName();
- }
-
if (is_string($field)) {
$fieldname = $field;
} else {
}
/**
- * Given one xmldb_index, the function returns the name of the index in DB (if exists)
+ * Given one xmldb_index, the function returns the name of the index in DB
* of false if it doesn't exist
*
- * @param mixed the table to be searched (string name or xmldb_table instance)
- * @param xmldb_index the index to be searched
+ * @param object $xmldb_table table to be searched
+ * @param object $xmldb_index the index to be searched
* @return string index name of false
*/
- public function find_index_name($table, $xmldb_index) {
+ public function find_index_name(xmldb_table $xmldb_table, xmldb_index $xmldb_index) {
+ /// Calculate the name of the table
+ $tablename = $xmldb_table->getName();
+
/// Check the table exists
- if (!$this->table_exists($table)) {
- return false;
+ if (!$this->table_exists($xmldb_table)) {
+ throw new ddl_table_missing_exception($tablename);
}
/// Do this function silenty (to avoid output in install/upgrade process)
/// Extract index columns
$indcolumns = $xmldb_index->getFields();
- if (is_string($table)) {
- $tablename = $table;
- } else {
- /// Calculate the name of the table
- $tablename = $table->getName();
- }
-
/// Get list of indexes in table
$indexes = $this->mdb->get_indexes($tablename);
/**
* Given one xmldb_index, check if it exists in DB (true/false)
*
- * @param mixed the table to be searched (string name or xmldb_table instance)
- * @param xmldb_index the index to be searched for
+ * @param object $xmldb_table the table to be searched
+ * @param object $xmldb_index the index to be searched for
* @return boolean true/false
*/
- public function index_exists($table, $xmldb_index) {
- return ($this->find_index_name($table, $xmldb_index) !== false);
+ public function index_exists(xmldb_table $xmldb_table, xmldb_index $xmldb_index) {
+ if (!$this->table_exists($xmldb_table)) {
+ return false;
+ }
+ return ($this->find_index_name($xmldb_table, $xmldb_index) !== false);
}
/**
* @param xmldb_field the field to be searched
* @return string check constraint name or false
*/
- public function find_check_constraint_name($xmldb_table, $xmldb_field) {
+ public function find_check_constraint_name(xmldb_table $xmldb_table, xmldb_field $xmldb_field) {
/// Check the table exists
if (!$this->table_exists($xmldb_table)) {
- return false;
+ throw new ddl_table_missing_exception($xmldb_table->getName());
}
/// Check the field exists
if (!$this->field_exists($xmldb_table, $xmldb_field)) {
- return false;
+ throw new ddl_field_missing_exception($xmldb_field->getName(), $xmldb_table->getName());
}
/// Do this function silenty (to avoid output in install/upgrade process)
* @param xmldb_field the field to be searched for any existing constraint
* @return boolean true/false
*/
- public function check_constraint_exists($xmldb_table, $xmldb_field) {
+ public function check_constraint_exists(xmldb_table $xmldb_table, xmldb_field $xmldb_field) {
return ($this->find_check_constraint_name($xmldb_table, $xmldb_field) !== false);
}
* @param xmldb_key the key to be searched
* @return string key name of false
*/
- public function find_key_name($xmldb_table, $xmldb_key) {
-
- /// Extract key columns
- if (!($xmldb_key instanceof xmldb_key)) {
- debugging("Wrong type for second parameter to database_manager::find_key_name. Should be xmldb_key, got " . gettype($xmldb_key));
- return false;
- }
+ public function find_key_name(xmldb_table $xmldb_table, xmldb_key $xmldb_key) {
+if (!is_object($xmldb_key)) {
+ var_dump($xmldb_table);
+ debugging('grrr');
+}
$keycolumns = $xmldb_key->getFields();
/// Get list of keys in table
/**
- * Given one xmldb_table, the function returns the name of its sequence in DB (if exists)
- * of false if it doesn't exist
+ * Given one xmldb_table, the function returns the name of its sequence in DB
*
* @param xmldb_table the table to be searched
* @return string sequence name of false
*/
- public function find_sequence_name($xmldb_table) {
- if (!($xmldb_table instanceof xmldb_table)) {
- debugging('Incorrect find_sequence_name() $xmldb_table parameter');
- return false;
- }
-
+ public function find_sequence_name(xmldb_table $xmldb_table) {
if (!$this->table_exists($xmldb_table)) {
- debugging('Table ' . $xmldb_table->getName() .
- ' does not exist. Sequence not found', DEBUG_DEVELOPER);
- return false; //Table doesn't exist, nothing to do
-
+ throw new ddl_table_missing_exception($xmldb_table->getName());
}
$sequencename = false;
* This function will delete all tables found in XMLDB file from db
*
* @param $file full path to the XML file to be used
- * @param $feedback
- * @return boolean (true on success, false on error)
+ * @return void
*/
- public function delete_tables_from_xmldb_file($file, $feedback=true ) {
+ public function delete_tables_from_xmldb_file($file) {
$xmldb_file = new xmldb_file($file);
if (!$xmldb_file->fileExists()) {
- return false;
+ throw new ddl_exception('ddlxmlfileerror', null, 'File does not exist');
}
$loaded = $xmldb_file->loadXMLStructure();
if (!$loaded || !$xmldb_file->isLoaded()) {
/// Show info about the error if we can find it
- if ($feedback and $structure) {
+ if ($structure) {
if ($errors = $structure->getAllErrors()) {
- notify('Errors found in XMLDB file: '. implode (', ', $errors));
+ throw new ddl_exception('ddlxmlfileerror', null, 'Errors found in XMLDB file: '. implode (', ', $errors));
}
}
- return false;
+ throw new ddl_exception('ddlxmlfileerror', null, 'not loaded??');
}
if ($xmldb_tables = $structure->getTables()) {
foreach($xmldb_tables as $table) {
if ($this->table_exists($table)) {
- $this->drop_table($table, true, $feedback);
+ $this->drop_table($table);
}
}
}
-
- return true;
}
/**
* will be dropped too.
*
* @param xmldb_table table object (just the name is mandatory)
- * @param boolean continue to specify if must continue on error (true) or stop (false)
- * @param boolean feedback to specify to show status info (true) or not (false)
- * @return boolean true on success, false on error
- * @TODO I don't think returning TRUE when trying to drop a non-existing table is a good idea.
- * the point is, the method name is drop_table, and if it doesn't drop a table,
- * it should be obvious to the code calling this method, and not rely on the visual
- * feedback of debugging(). Exception handling may solve this.
+ * @return void
*/
- public function drop_table($xmldb_table, $continue=true, $feedback=true) {
- if (!($xmldb_table instanceof xmldb_table)) {
- debugging('Incorrect drop_table() $xmldb_table parameter');
- return false;
- }
-
+ public function drop_table(xmldb_table $xmldb_table) {
/// Check table exists
if (!$this->table_exists($xmldb_table)) {
- debugging('Table ' . $xmldb_table->getName() .
- ' does not exist. Delete skipped', DEBUG_DEVELOPER);
- return true; //Table don't exist, nothing to do
+ throw new ddl_table_missing_exception($xmldb_table->getName());
}
if (!$sqlarr = $this->generator->getDropTableSQL($xmldb_table)) {
- return true; //Empty array = nothing to do = no error
+ throw new ddl_exception('ddlunknownerror', null, 'table drop sql not generated');
}
- return $this->execute_sql_arr($sqlarr, $continue, $feedback);
+ $this->execute_sql_arr($sqlarr);
}
/**
* will execute all those statements against the DB.
*
* @param $file full path to the XML file to be used
- * @return boolean (true on success, false on error)
+ * @return void
*/
- public function install_from_xmldb_file($file, $continue=true, $feedback=true) {
+ public function install_from_xmldb_file($file) {
$xmldb_file = new xmldb_file($file);
if (!$xmldb_file->fileExists()) {
- return false;
+ throw new ddl_exception('ddlxmlfileerror', null, 'File does not exist');
}
$loaded = $xmldb_file->loadXMLStructure();
/// Show info about the error if we can find it
if ($structure =& $xmldb_file->getStructure()) {
if ($errors = $structure->getAllErrors()) {
- notify('Errors found in XMLDB file: '. implode (', ', $errors));
+ throw new ddl_exception('ddlxmlfileerror', null, 'Errors found in XMLDB file: '. implode (', ', $errors));
}
}
- return false;
+ throw new ddl_exception('ddlxmlfileerror', null, 'not loaded??');
}
$xmldb_structure = $xmldb_file->getStructure();
$this->mdb->set_debug(false);
if (!$sqlarr = $this->generator->getCreateStructureSQL($xmldb_structure)) {
- return true; //Empty array = nothing to do = no error
+ return; // nothing to do
}
$this->mdb->set_debug($olddbdebug);
- $result = $this->execute_sql_arr($sqlarr, $continue, $feedback);
-
- return $result;
+ $this->execute_sql_arr($sqlarr);
}
/**
* fields/keys/indexes/sequences, everything based in the XMLDB object
*
* @param xmldb_table table object (full specs are required)
- * @param boolean continue to specify if must continue on error (true) or stop (false)
- * @param boolean feedback to specify to show status info (true) or not (false)
- * @return boolean true on success, false on error
- * @TODO I don't think returning TRUE when trying to create an existing table is a good idea.
- * the point is, the method name is create_table, and if it doesn't create a table,
- * it should be obvious to the code calling this method, and not rely on the visual
- * feedback of debugging(). Exception handling may solve this.
+ * @return void
*/
- public function create_table($xmldb_table, $continue=true, $feedback=true) {
- if (!($xmldb_table instanceof xmldb_table)) {
- debugging('Incorrect create_table() $xmldb_table parameter');
- return false;
- }
-
+ public function create_table(xmldb_table $xmldb_table) {
/// Check table doesn't exist
if ($this->table_exists($xmldb_table)) {
- debugging('Table ' . $xmldb_table->getName() .
- ' already exists. Create skipped', DEBUG_DEVELOPER);
- return true; //Table exists, nothing to do
+ throw new ddl_exception('ddltablealreadyexists', $xmldb_table->getName());
}
if (!$sqlarr = $this->generator->getCreateTableSQL($xmldb_table)) {
- return true; //Empty array = nothing to do = no error
+ throw new ddl_exception('ddlunknownerror', null, 'table create sql not generated');
}
- return $this->execute_sql_arr($sqlarr, $continue, $feedback);
+ $this->execute_sql_arr($sqlarr);
}
/**
* the table name does not collide with existing normal table!
*
* @param xmldb_table table object (full specs are required)
- * @param boolean continue to specify if must continue on error (true) or stop (false)
- * @param boolean feedback to specify to show status info (true) or not (false)
- * @return string tablename on success, false on error
+ * @return void
*/
- public function create_temp_table($xmldb_table, $continue=true, $feedback=true) {
- if (!($xmldb_table instanceof xmldb_table)) {
- debugging('Incorrect create_table() $xmldb_table parameter');
- return false;
- }
-
+ public function create_temp_table(xmldb_table $xmldb_table) {
/// hack for mssql - it requires names to start with #
$xmldb_table = $this->generator->tweakTempTable($xmldb_table);
/// Check table doesn't exist
if ($this->table_exists($xmldb_table, true)) {
- debugging('Temporary table ' . $xmldb_table->getName() .
- ' already exists, dropping and recreating it.', DEBUG_DEVELOPER);
- if (!$this->drop_temp_table($xmldb_table, $continue, $feedback)) {
- return false;
- }
+ $this->drop_temp_table($xmldb_table);
}
if (!$sqlarr = $this->generator->getCreateTempTableSQL($xmldb_table)) {
- return $xmldb_table->getName(); //Empty array = nothing to do = no error
+ throw new ddl_exception('ddlunknownerror', null, 'temp table create sql not generated');
}
- if ($this->execute_sql_arr($sqlarr, $continue, $feedback)) {
- return $xmldb_table->getName();
- } else {
- return false;
- }
+ $this->execute_sql_arr($sqlarr);
}
/**
* It is recommended to drop temp table when not used anymore.
*
* @param xmldb_table table object
- * @param boolean continue to specify if must continue on error (true) or stop (false)
- * @param boolean feedback to specify to show status info (true) or not (false)
- * @return string tablename on success, false on error
+ * @return void
*/
- public function drop_temp_table($xmldb_table, $continue=true, $feedback=true) {
- if (!($xmldb_table instanceof xmldb_table)) {
- debugging('Incorrect create_table() $xmldb_table parameter');
- return false;
- }
-
+ public function drop_temp_table(xmldb_table $xmldb_table) {
/// mssql requires names to start with #
$xmldb_table = $this->generator->tweakTempTable($xmldb_table);
/// Check table doesn't exist
if (!$this->table_exists($xmldb_table, true)) {
- return true;
+ throw new ddl_table_missing_exception($xmldb_table->getName());
}
if (!$sqlarr = $this->generator->getDropTempTableSQL($xmldb_table)) {
- return false; // error
+ throw new ddl_exception('ddlunknownerror', null, 'temp table drop sql not generated');
}
- return $this->execute_sql_arr($sqlarr, $continue, $feedback);
+ $this->execute_sql_arr($sqlarr);
}
/**
*
* @param xmldb_table table object (just the name is mandatory)
* @param string new name of the index
- * @param boolean continue to specify if must continue on error (true) or stop (false)
- * @param boolean feedback to specify to show status info (true) or not (false)
- * @return boolean true on success, false on error
+ * @return void
*/
- public function rename_table($xmldb_table, $newname, $continue=true, $feedback=true) {
- if (!($xmldb_table instanceof xmldb_table)) {
- debugging('Incorrect rename_table() $xmldb_table parameter');
- return false;
- }
-
+ public function rename_table(xmldb_table $xmldb_table, $newname) {
/// Check newname isn't empty
if (!$newname) {
- debugging('Error: new name for table ' . $xmldb_table->getName() .
- ' is empty!');
- return false; //error!
+ throw new ddl_exception('ddlunknownerror', null, 'newname can not be empty');
}
$check = new xmldb_table($newname);
/// Check table already renamed
- if (!$this->table_exists($xmldb_table) and $this->table_exists($check)) {
- debugging('Table ' . $xmldb_table->getName() .
- ' already renamed. Rename skipped', DEBUG_DEVELOPER);
- return true; //ok fine
- }
-
- /// Check table exists
if (!$this->table_exists($xmldb_table)) {
- debugging('Table ' . $xmldb_table->getName() .
- ' does not exist. Rename skipped');
- return false; //error!
+ if ($this->table_exists($check)) {
+ throw new ddl_exception('ddlunknownerror', null, 'table probably already renamed');
+ } else {
+ throw new ddl_table_missing_exception($xmldb_table->getName());
+ }
}
/// Check new table doesn't exist
if ($this->table_exists($check)) {
- debugging('Table ' . $check->getName() .
- ' already exists. Rename skipped');
- return false; //error!
+ throw new ddl_exception('ddltablealreadyexists', $xmldb_table->getName(), 'can not rename table');
}
if (!$sqlarr = $this->generator->getRenameTableSQL($xmldb_table, $newname)) {
- return true; //Empty array = nothing to do = no error (this is weird!)
+ throw new ddl_exception('ddlunknownerror', null, 'table rename sql not generated');
}
- return $this->execute_sql_arr($sqlarr, $continue, $feedback);
+ $this->execute_sql_arr($sqlarr);
}
*
* @param xmldb_table table object (just the name is mandatory)
* @param xmldb_field field object (full specs are required)
- * @param boolean continue to specify if must continue on error (true) or stop (false)
- * @param boolean feedback to specify to show status info (true) or not (false)
- * @return boolean true on success, false on error
+ * @return void
*/
- public function add_field($xmldb_table, $xmldb_field, $continue=true, $feedback=true) {
- if (!($xmldb_table instanceof xmldb_table)) {
- debugging('Incorrect add_field() $xmldb_table parameter');
- return false;
- }
-
- if (!($xmldb_field instanceof xmldb_field)) {
- debugging('Incorrect add_field() $xmldb_field parameter');
- return false;
- }
+ public function add_field(xmldb_table $xmldb_table, xmldb_field $xmldb_field) {
/// Check the field doesn't exist
if ($this->field_exists($xmldb_table, $xmldb_field)) {
- debugging('Field ' . $xmldb_table->getName() . '->' . $xmldb_field->getName() .
- ' already exists. Create skipped', DEBUG_DEVELOPER);
- return true;
+ throw new ddl_exception('ddlfieldalreadyexists', $xmldb_field->getName());
}
/// If NOT NULL and no default given (we ask the generator about the
/// *real* default that will be used) check the table is empty
if ($xmldb_field->getNotNull() && $this->generator->getDefaultValue($xmldb_field) === NULL && $this->mdb->count_records($xmldb_table->getName())) {
- debugging('Field ' . $xmldb_table->getName() . '->' . $xmldb_field->getName() .
- ' cannot be added. Not null fields added to non empty tables require default value. Create skipped', DEBUG_DEVELOPER);
- return false; //error!!
+ throw new ddl_exception('ddlunknownerror', null, 'Field ' . $xmldb_table->getName() . '->' . $xmldb_field->getName() .
+ ' cannot be added. Not null fields added to non empty tables require default value. Create skipped');
}
if (!$sqlarr = $this->generator->getAddFieldSQL($xmldb_table, $xmldb_field)) {
- debugging('Error: No sql code for field adding found');
- return false;
+ throw new ddl_exception('ddlunknownerror', null, 'addfield sql not generated');
}
- return $this->execute_sql_arr($sqlarr, $continue, $feedback);
+ $this->execute_sql_arr($sqlarr);
}
/**
*
* @param xmldb_table table object (just the name is mandatory)
* @param xmldb_field field object (just the name is mandatory)
- * @param boolean continue to specify if must continue on error (true) or stop (false)
- * @param boolean feedback to specify to show status info (true) or not (false)
- * @return boolean true on success, false on error
+ * @return void
*/
- public function drop_field($xmldb_table, $xmldb_field, $continue=true, $feedback=true) {
- if (!($xmldb_table instanceof xmldb_table)) {
- debugging('Incorrect drop_field() $xmldb_table parameter');
- return false;
- }
-
- if (!($xmldb_field instanceof xmldb_field)) {
- debugging('Incorrect drop_field() $xmldb_field parameter');
- return false;
+ public function drop_field(xmldb_table $xmldb_table, xmldb_field $xmldb_field) {
+ if (!$this->table_exists($xmldb_table)) {
+ throw new ddl_table_missing_exception($xmldb_table->getName());
}
-
/// Check the field exists
if (!$this->field_exists($xmldb_table, $xmldb_field)) {
- debugging('Field ' . $xmldb_table->getName() . '->' . $xmldb_field->getName() .
- ' does not exist. Delete skipped', DEBUG_DEVELOPER);
- return true;
+ throw new ddl_field_missing_exception($xmldb_field->getName(), $xmldb_table->getName());
}
if (!$sqlarr = $this->generator->getDropFieldSQL($xmldb_table, $xmldb_field)) {
- return true; //Empty array = nothing to do = no error
+ throw new ddl_exception('ddlunknownerror', null, 'drop_field sql not generated');
}
- return $this->execute_sql_arr($sqlarr, $continue, $feedback);
+ $this->execute_sql_arr($sqlarr);
}
/**
*
* @param xmldb_table table object (just the name is mandatory)
* @param xmldb_field field object (full specs are required)
- * @param boolean continue to specify if must continue on error (true) or stop (false)
- * @param boolean feedback to specify to show status info (true) or not (false)
- * @return boolean true on success, false on error
+ * @return void
*/
- public function change_field_type($xmldb_table, $xmldb_field, $continue=true, $feedback=true) {
- if (!($xmldb_table instanceof xmldb_table)) {
- debugging('Incorrect change_field_type() $xmldb_table parameter');
- return false;
- }
-
- if (!($xmldb_field instanceof xmldb_field)) {
- debugging('Incorrect change_field_type() $xmldb_field parameter');
- return false;
+ public function change_field_type(xmldb_table $xmldb_table, xmldb_field $xmldb_field) {
+ if (!$this->table_exists($xmldb_table)) {
+ throw new ddl_table_missing_exception($xmldb_table->getName());
}
-
/// Check the field exists
if (!$this->field_exists($xmldb_table, $xmldb_field)) {
- debugging('Field ' . $xmldb_table->getName() . '->' . $xmldb_field->getName() .
- ' does not exist. Change type skipped');
- return false;
+ throw new ddl_field_missing_exception($xmldb_field->getName(), $xmldb_table->getName());
}
if (!$sqlarr = $this->generator->getAlterFieldSQL($xmldb_table, $xmldb_field)) {
- return true; //Empty array = nothing to do = no error
+ return; // probably nothing to do
}
- return $this->execute_sql_arr($sqlarr, $continue, $feedback);
+ $this->execute_sql_arr($sqlarr);
}
/**
*
* @param xmldb_table table object (just the name is mandatory)
* @param xmldb_field field object (full specs are required)
- * @param boolean continue to specify if must continue on error (true) or stop (false)
- * @param boolean feedback to specify to show status info (true) or not (false)
- * @return boolean true on success, false on error
+ * @return void
*/
- public function change_field_precision($xmldb_table, $xmldb_field, $continue=true, $feedback=true) {
-
+ public function change_field_precision(xmldb_table $xmldb_table, xmldb_field $xmldb_field) {
/// Just a wrapper over change_field_type. Does exactly the same processing
- return $this->change_field_type($xmldb_table, $xmldb_field, $continue, $feedback);
+ $this->change_field_type($xmldb_table, $xmldb_field);
}
/**
*
* @param xmldb_table table object (just the name is mandatory)
* @param xmldb_field field object (full specs are required)
- * @param boolean continue to specify if must continue on error (true) or stop (false)
- * @param boolean feedback to specify to show status info (true) or not (false)
- * @return boolean true on success, false on error
+ * @return void
*/
- public function change_field_unsigned($xmldb_table, $xmldb_field, $continue=true, $feedback=true) {
-
+ public function change_field_unsigned(xmldb_table $xmldb_table, xmldb_field $xmldb_field) {
/// Just a wrapper over change_field_type. Does exactly the same processing
- return $this->change_field_type($xmldb_table, $xmldb_field, $continue, $feedback);
+ $this->change_field_type($xmldb_table, $xmldb_field);
}
/**
*
* @param xmldb_table table object (just the name is mandatory)
* @param xmldb_field field object (full specs are required)
- * @param boolean continue to specify if must continue on error (true) or stop (false)
- * @param boolean feedback to specify to show status info (true) or not (false)
- * @return boolean true on success, false on error
+ * @return void
*/
- public function change_field_notnull($xmldb_table, $xmldb_field, $continue=true, $feedback=true) {
-
+ public function change_field_notnull(xmldb_table $xmldb_table, xmldb_field $xmldb_field) {
/// Just a wrapper over change_field_type. Does exactly the same processing
- return $this->change_field_type($xmldb_table, $xmldb_field, $continue, $feedback);
+ $this->change_field_type($xmldb_table, $xmldb_field);
}
/**
*
* @param xmldb_table table object (just the name is mandatory)
* @param xmldb_field field object (full specs are required)
- * @param boolean continue to specify if must continue on error (true) or stop (false)
- * @param boolean feedback to specify to show status info (true) or not (false)
- * @return boolean true on success, false on error
+ * @return void
*/
- public function change_field_enum($xmldb_table, $xmldb_field, $continue=true, $feedback=true) {
- if (!($xmldb_table instanceof xmldb_table)) {
- debugging('Incorrect change_field_enum() $xmldb_table parameter');
- return false;
- }
-
- if (!($xmldb_field instanceof xmldb_field)) {
- debugging('Incorrect change_field_enum() $xmldb_field parameter');
- return false;
+ public function change_field_enum(xmldb_table $xmldb_table, xmldb_field $xmldb_field) {
+ if (!$this->table_exists($xmldb_table)) {
+ throw new ddl_table_missing_exception($xmldb_table->getName());
}
-
/// Check the field exists
if (!$this->field_exists($xmldb_table, $xmldb_field)) {
- debugging('Field ' . $xmldb_table->getName() . '->' . $xmldb_field->getName() .
- ' does not exist. Change type skipped');
- return false;
+ throw new ddl_field_missing_exception($xmldb_field->getName(), $xmldb_table->getName());
}
/// If enum is defined, we're going to create it, check it doesn't exist.
if ($this->check_constraint_exists($xmldb_table, $xmldb_field)) {
debugging('Enum for ' . $xmldb_table->getName() . '->' . $xmldb_field->getName() .
' already exists. Create skipped', DEBUG_DEVELOPER);
- return true; //Enum exists, nothing to do
+ return; //Enum exists, nothing to do
}
} else { /// Else, we're going to drop it, check it exists
if (!$this->check_constraint_exists($xmldb_table, $xmldb_field)) {
debugging('Enum for ' . $xmldb_table->getName() . '->' . $xmldb_field->getName() .
' does not exist. Delete skipped', DEBUG_DEVELOPER);
- return true; //Enum does not exist, nothing to delete
+ return; //Enum does not exist, nothing to delete
}
}
if (!$sqlarr = $this->generator->getModifyEnumSQL($xmldb_table, $xmldb_field)) {
- return true; //Empty array = nothing to do = no error
+ return; //Empty array = nothing to do = no error
}
- return $this->execute_sql_arr($sqlarr, $continue, $feedback);
+ $this->execute_sql_arr($sqlarr);
}
/**
*
* @param xmldb_table table object (just the name is mandatory)
* @param xmldb_field field object (full specs are required)
- * @param boolean continue to specify if must continue on error (true) or stop (false)
- * @param boolean feedback to specify to show status info (true) or not (false)
- * @return boolean true on success, false on error
+ * @return void
*/
- public function change_field_default($xmldb_table, $xmldb_field, $continue=true, $feedback=true) {
- if (!($xmldb_table instanceof xmldb_table)) {
- debugging('Incorrect change_field_default() $xmldb_table parameter');
- return false;
- }
-
- if (!($xmldb_field instanceof xmldb_field)) {
- debugging('Incorrect change_field_default() $xmldb_field parameter');
- return false;
+ public function change_field_default(xmldb_table $xmldb_table, xmldb_field $xmldb_field) {
+ if (!$this->table_exists($xmldb_table)) {
+ throw new ddl_table_missing_exception($xmldb_table->getName());
}
-
/// Check the field exists
if (!$this->field_exists($xmldb_table, $xmldb_field)) {
- debugging('Field ' . $xmldb_table->getName() . '->' . $xmldb_field->getName() .
- ' does not exist. Change type skipped');
- return false;
+ throw new ddl_field_missing_exception($xmldb_field->getName(), $xmldb_table->getName());
}
if (!$sqlarr = $this->generator->getModifyDefaultSQL($xmldb_table, $xmldb_field)) {
- return true; //Empty array = nothing to do = no error
+ return; //Empty array = nothing to do = no error
}
- return $this->execute_sql_arr($sqlarr, $continue, $feedback);
+ $this->execute_sql_arr($sqlarr);
}
/**
* @param xmldb_table table object (just the name is mandatory)
* @param xmldb_field index object (full specs are required)
* @param string new name of the field
- * @param boolean continue to specify if must continue on error (true) or stop (false)
- * @param boolean feedback to specify to show status info (true) or not (false)
- * @return boolean true on success, false on error
+ * @return void
*/
- public function rename_field($xmldb_table, $xmldb_field, $newname, $continue=true, $feedback=true) {
- if (!($xmldb_table instanceof xmldb_table)) {
- debugging('Incorrect rename_field() $xmldb_table parameter');
- return false;
- }
-
- if (!($xmldb_field instanceof xmldb_field)) {
- debugging('Incorrect rename_field() $xmldb_field parameter');
- return false;
+ public function rename_field(xmldb_table $xmldb_table, xmldb_field $xmldb_field, $newname) {
+ if (empty($newname)) {
+ throw new ddl_exception('ddlunknownerror', null, 'newname can not be empty');
}
- if (empty($newname)) {
- debugging('New name for field ' . $xmldb_table->getName() . '->' . $xmldb_field->getName() .
- ' is empty! Rename skipped', DEBUG_DEVELOPER);
- return false; //error
+ if (!$this->table_exists($xmldb_table)) {
+ throw new ddl_table_missing_exception($xmldb_table->getName());
}
/// Check the field exists
if (!$this->field_exists($xmldb_table, $xmldb_field)) {
- debugging('Field ' . $xmldb_table->getName() . '->' . $xmldb_field->getName() .
- ' does not exist. Change type skipped');
- return false;
+ throw new ddl_field_missing_exception($xmldb_field->getName(), $xmldb_table->getName());
}
/// Check we have included full field specs
if (!$xmldb_field->getType()) {
- debugging('Field ' . $xmldb_table->getName() . '->' . $xmldb_field->getName() .
- ' must contain full specs. Rename skipped', DEBUG_DEVELOPER);
- return false;
+ throw new ddl_exception('ddlunknownerror', null,
+ 'Field ' . $xmldb_table->getName() . '->' . $xmldb_field->getName() .
+ ' must contain full specs. Rename skipped');
}
/// Check field isn't id. Renaming over that field is not allowed
if ($xmldb_field->getName() == 'id') {
- debugging('Field ' . $xmldb_table->getName() . '->' . $xmldb_field->getName() .
- ' cannot be renamed. Rename skipped', DEBUG_DEVELOPER);
- return false; //Field is "id", nothing to do
- }
-
- /// Check field exists
- if (!$this->field_exists($xmldb_table, $xmldb_field)) {
- debugging('Field ' . $xmldb_table->getName() . '->' . $xmldb_field->getName() .
- ' does not exist. Rename skipped', DEBUG_DEVELOPER);
- $newfield = clone($xmldb_field);
- $newfield->setName($newname);
- if ($this->field_exists($xmldb_table, $newfield)) {
- return true; //ok
- } else {
- return false; //error
- }
+ throw new ddl_exception('ddlunknownerror', null,
+ 'Field ' . $xmldb_table->getName() . '->' . $xmldb_field->getName() .
+ ' cannot be renamed. Rename skipped');
}
if (!$sqlarr = $this->generator->getRenameFieldSQL($xmldb_table, $xmldb_field, $newname)) {
- return true; //Empty array = nothing to do = no error
+ return; //Empty array = nothing to do = no error
}
- return $this->execute_sql_arr($sqlarr, $continue, $feedback);
+ $this->execute_sql_arr($sqlarr);
}
/**
*
* @param xmldb_table table object (just the name is mandatory)
* @param xmldb_key index object (full specs are required)
- * @param boolean continue to specify if must continue on error (true) or stop (false)
- * @param boolean feedback to specify to show status info (true) or not (false)
- * @return boolean true on success, false on error
+ * @return void
*/
- public function add_key($xmldb_table, $xmldb_key, $continue=true, $feedback=true) {
- if (!($xmldb_table instanceof xmldb_table)) {
- debugging('Incorrect add_key() $xmldb_table parameter');
- return false;
- }
-
- if (!($xmldb_key instanceof xmldb_key)) {
- debugging('Incorrect add_key() $xmldb_key parameter');
- return false;
- }
+ public function add_key(xmldb_table $xmldb_table, xmldb_key $xmldb_key) {
if ($xmldb_key->getType() == XMLDB_KEY_PRIMARY) { // Prevent PRIMARY to be added (only in create table, being serious :-P)
- debugging('Primary Keys can be added at table create time only', DEBUG_DEVELOPER);
- return true;
+ throw new ddl_exception('ddlunknownerror', null, 'Primary Keys can be added at table create time only');
}
if (!$sqlarr = $this->generator->getAddKeySQL($xmldb_table, $xmldb_key)) {
- return true; //Empty array = nothing to do = no error
+ return; //Empty array = nothing to do = no error
}
- return $this->execute_sql_arr($sqlarr, $continue, $feedback);
+ $this->execute_sql_arr($sqlarr);
}
/**
*
* @param xmldb_table table object (just the name is mandatory)
* @param xmldb_key key object (full specs are required)
- * @param boolean continue to specify if must continue on error (true) or stop (false)
- * @param boolean feedback to specify to show status info (true) or not (false)
- * @return boolean true on success, false on error
+ * @return void
*/
- public function drop_key($xmldb_table, $xmldb_key, $continue=true, $feedback=true) {
- if (!($xmldb_table instanceof xmldb_table)) {
- debugging('Incorrect drop_key() $xmldb_table parameter');
- return false;
- }
-
- if (!($xmldb_key instanceof xmldb_key)) {
- debugging('Incorrect drop_key() $xmldb_key parameter');
- return false;
- }
-
+ public function drop_key(xmldb_table $xmldb_table, xmldb_key $xmldb_key) {
if ($xmldb_key->getType() == XMLDB_KEY_PRIMARY) { // Prevent PRIMARY to be dropped (only in drop table, being serious :-P)
- debugging('Primary Keys can be deleted at table drop time only', DEBUG_DEVELOPER);
- return true;
+ throw new ddl_exception('ddlunknownerror', null, 'Primary Keys can be deleted at table drop time only');
}
- if(!$sqlarr = $this->generator->getDropKeySQL($xmldb_table, $xmldb_key)) {
- return true; //Empty array = nothing to do = no error
+ if (!$sqlarr = $this->generator->getDropKeySQL($xmldb_table, $xmldb_key)) {
+ return; //Empty array = nothing to do = no error
}
- return $this->execute_sql_arr($sqlarr, $continue, $feedback);
+ $this->execute_sql_arr($sqlarr);
}
/**
* @param xmldb_table table object (just the name is mandatory)
* @param xmldb_key key object (full specs are required)
* @param string new name of the key
- * @param boolean continue to specify if must continue on error (true) or stop (false)
- * @param boolean feedback to specify to show status info (true) or not (false)
- * @return boolean true on success, false on error
+ * @return void
*/
- public function rename_key($xmldb_table, $xmldb_key, $newname, $continue=true, $feedback=true) {
+ public function rename_key(xmldb_table $xmldb_table, xmldb_key $xmldb_key, $newname) {
debugging('rename_key() is one experimental feature. You must not use it in production!', DEBUG_DEVELOPER);
- if (!($xmldb_table instanceof xmldb_table)) {
- debugging('Incorrect rename_key() $xmldb_table parameter');
- return false;
- }
-
- if (!($xmldb_key instanceof xmldb_key)) {
- debugging('Incorrect rename_key() $xmldb_key parameter');
- return false;
- }
-
/// Check newname isn't empty
if (!$newname) {
- debugging('New name for key ' . $xmldb_table->getName() . '->' . $xmldb_key->getName() .
- ' is empty! Rename skipped', DEBUG_DEVELOPER);
- return true; //Key doesn't exist, nothing to do
+ throw new ddl_exception('ddlunknownerror', null, 'newname can not be empty');
}
if (!$sqlarr = $this->generator->getRenameKeySQL($xmldb_table, $xmldb_key, $newname)) {
- debugging('Some DBs do not support key renaming (MySQL, PostgreSQL, MsSQL). Rename skipped', DEBUG_DEVELOPER);
- return true; //Empty array = nothing to do = no error
+ throw new ddl_exception('ddlunknownerror', null, 'Some DBs do not support key renaming (MySQL, PostgreSQL, MsSQL). Rename skipped');
}
- return $this->execute_sql_arr($sqlarr, $continue, $feedback);
+ $this->execute_sql_arr($sqlarr);
}
/**
*
* @param xmldb_table table object (just the name is mandatory)
* @param xmldb_index index object (full specs are required)
- * @param boolean continue to specify if must continue on error (true) or stop (false)
- * @param boolean feedback to specify to show status info (true) or not (false)
- * @return boolean true on success, false on error
+ * @return void
*/
- public function add_index($xmldb_table, $xmldb_intex, $continue=true, $feedback=true) {
- if (!($xmldb_table instanceof xmldb_table)) {
- debugging('Incorrect add_index() $xmldb_table parameter');
- return false;
- }
-
- if (!($xmldb_intex instanceof xmldb_index)) {
- debugging('Incorrect add_index() $xmldb_index parameter');
- return false;
+ public function add_index($xmldb_table, $xmldb_intex) {
+ if (!$this->table_exists($xmldb_table)) {
+ throw new ddl_table_missing_exception($xmldb_table->getName());
}
/// Check index doesn't exist
if ($this->index_exists($xmldb_table, $xmldb_intex)) {
- debugging('Index ' . $xmldb_table->getName() . '->' . $xmldb_intex->getName() .
- ' already exists. Create skipped', DEBUG_DEVELOPER);
- return true; //Index exists, nothing to do
+ throw new ddl_exception('ddlunknownerror', null,
+ 'Index ' . $xmldb_table->getName() . '->' . $xmldb_intex->getName() .
+ ' already exists. Create skipped');
}
if (!$sqlarr = $this->generator->getAddIndexSQL($xmldb_table, $xmldb_intex)) {
- return true; //Empty array = nothing to do = no error
+ throw new ddl_exception('ddlunknownerror', null, 'add_index sql not generated');
}
- return $this->execute_sql_arr($sqlarr, $continue, $feedback);
+ $this->execute_sql_arr($sqlarr);
}
/**
*
* @param xmldb_table table object (just the name is mandatory)
* @param xmldb_index index object (full specs are required)
- * @param boolean continue to specify if must continue on error (true) or stop (false)
- * @param boolean feedback to specify to show status info (true) or not (false)
- * @return boolean true on success, false on error
+ * @return void
*/
- public function drop_index($xmldb_table, $xmldb_intex, $continue=true, $feedback=true) {
- if (!($xmldb_table instanceof xmldb_table)) {
- debugging('Incorrect add_index() $xmldb_table parameter');
- return false;
- }
-
- if (!($xmldb_intex instanceof xmldb_index)) {
- debugging('Incorrect add_index() $xmldb_index parameter');
- return false;
+ public function drop_index($xmldb_table, $xmldb_intex) {
+ if (!$this->table_exists($xmldb_table)) {
+ throw new ddl_table_missing_exception($xmldb_table->getName());
}
/// Check index exists
if (!$this->index_exists($xmldb_table, $xmldb_intex)) {
- debugging('Index ' . $xmldb_table->getName() . '->' . $xmldb_intex->getName() .
- ' does not exist. Delete skipped', DEBUG_DEVELOPER);
- return true; //Index doesn't exist, nothing to do
+ throw new ddl_exception('ddlunknownerror', null,
+ 'Index ' . $xmldb_table->getName() . '->' . $xmldb_intex->getName() .
+ ' does not exist. Delete skipped');
}
if (!$sqlarr = $this->generator->getDropIndexSQL($xmldb_table, $xmldb_intex)) {
- return true; //Empty array = nothing to do = no error
+ throw new ddl_exception('ddlunknownerror', null, 'drop_index sql not generated');
}
- return $this->execute_sql_arr($sqlarr, $continue, $feedback);
+ $this->execute_sql_arr($sqlarr);
}
/**
* @param xmldb_table table object (just the name is mandatory)
* @param xmldb_index index object (full specs are required)
* @param string new name of the index
- * @param boolean continue to specify if must continue on error (true) or stop (false)
- * @param boolean feedback to specify to show status info (true) or not (false)
- * @return boolean true on success, false on error
+ * @return void
*/
- public function rename_index($xmldb_table, $xmldb_intex, $newname, $continue=true, $feedback=true) {
+ public function rename_index($xmldb_table, $xmldb_intex, $newname) {
debugging('rename_index() is one experimental feature. You must not use it in production!', DEBUG_DEVELOPER);
- if (!($xmldb_table instanceof xmldb_table)) {
- debugging('Incorrect add_index() $xmldb_table parameter');
- return false;
- }
-
- if (!($xmldb_intex instanceof xmldb_index)) {
- debugging('Incorrect add_index() $xmldb_index parameter');
- return false;
- }
-
/// Check newname isn't empty
if (!$newname) {
- debugging('New name for index ' . $xmldb_table->getName() . '->' . $xmldb_intex->getName() .
- ' is empty! Rename skipped', DEBUG_DEVELOPER);
- return true; //Index doesn't exist, nothing to do
+ throw new ddl_exception('ddlunknownerror', null, 'newname can not be empty');
}
/// Check index exists
if (!$this->index_exists($xmldb_table, $xmldb_intex)) {
- debugging('Index ' . $xmldb_table->getName() . '->' . $xmldb_intex->getName() .
- ' does not exist. Rename skipped', DEBUG_DEVELOPER);
- return true; //Index doesn't exist, nothing to do
+ throw new ddl_exception('ddlunknownerror', null,
+ 'Index ' . $xmldb_table->getName() . '->' . $xmldb_intex->getName() .
+ ' does not exist. Rename skipped');
}
if (!$sqlarr = $this->generator->getRenameIndexSQL($xmldb_table, $xmldb_intex, $newname)) {
- debugging('Some DBs do not support index renaming (MySQL). Rename skipped', DEBUG_DEVELOPER);
- return false; // Error - index not renamed
+ throw new ddl_exception('ddlunknownerror', null, 'Some DBs do not support index renaming (MySQL). Rename skipped');
}
- return $this->execute_sql_arr($sqlarr, $continue, $feedback);
+ $this->execute_sql_arr($sqlarr);
+ }
+}
+
+
+/**
+ * DDL exception class, use instead of error() and "return false;" in ddl code.
+ */
+class ddl_exception extends moodle_exception {
+ function __construct($errorcode, $a=NULL, $debuginfo=null) {
+ parent::__construct($errorcode, '', '', $a, $debuginfo);
+ }
+}
+
+/**
+ * Table does not exist problem exception
+ */
+class ddl_table_missing_exception extends ddl_exception {
+ function __construct($tablename, $debuginfo=null) {
+ parent::__construct('ddltablenotexist', $tablename, $debuginfo);
+ }
+}
+
+/**
+ * Table does not exist problem exception
+ */
+class ddl_field_missing_exception extends ddl_exception {
+ function __construct($fieldname, $tablename, $debuginfo=null) {
+ $a = new object();
+ $a->fieldname = $fieldname;
+ $a->tablename = $tablename;
+ parent::__construct('ddlfieldnotexist', $a, $debuginfo);
}
}
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);
}
}
}
$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;
}
$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));
$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');
$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);
}
$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
/// 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');
$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'));
}
$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;
$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() {
$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);
}
$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() {
$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;
$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));
$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() {
$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;
$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';
$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() {
$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;
$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() {
$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() {
$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));
}
$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() {
$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() {
$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() {
$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() {
$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() {
$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;
// 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;
ob_end_clean();
$this->assertFalse($result);
- $dbman->drop_table($table, true, false);
+ $dbman->drop_table($table);
}
public function testRenameField() {
$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');
$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');
$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'));
// 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');
$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);
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');
$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'));
$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));
}
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
}
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;
}
$column->enums[$key] = substr($value, 1, strlen($value)-2);
}
}
- }
+ }
$this->columns[$table][$column->name] = new database_column_info($column);
}
* @param bool $state
*/
public function set_debug($state) {
- $this->adodb->debug = $state;
+ if ($this->adodb) {
+ $this->adodb->debug = $state;
+ }
}
/**
foreach ($this->tables as $table) {
if ($dbman->table_exists($table)) {
- $dbman->drop_table($table, true, false);
+ $dbman->drop_table($table);
}
}
$this->tables = array();
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);
public $module;
public $a;
public $link;
+ public $debuginfo;
/**
* Constructor
* @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';
}
$this->module = $module;
$this->link = $link;
$this->a = $a;
+ $this->debuginfo = $debuginfo;
$message = get_string($errorcode, $module, $a);
* 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);
}
$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
$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
$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);
}
$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);
}
$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);
}
$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);
}
$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
$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;
$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
$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);
}
$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);
}
$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
$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;
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)) {
} 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;
/**
* 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') {
} 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');
+ }
}
}
* 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);
*
* @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;
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');
}
$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);
}
}
$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;
$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
$key->set_attributes(XMLDB_KEY_FOREIGN, array('item'), 'feedback_item', 'id');
$table->addKey($key);
- $result = $result && $dbman->create_table($table);
+ $dbman->create_table($table);
////////////////////////////////////////////////////////////
}
$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);
////////////////////////////////////////////////////////////
}
$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);
}
}
$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) {
$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;
}
/// 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');
}
}
/// Conditionally launch create table for quiz_report
if (!$dbman->table_exists($table)) {
- $result = $result && $dbman->create_table($table);
+ $dbman->create_table($table);
}
}