]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-14956 DDL exceptions
authorskodak <skodak>
Sun, 22 Jun 2008 16:51:55 +0000 (16:51 +0000)
committerskodak <skodak>
Sun, 22 Jun 2008 16:51:55 +0000 (16:51 +0000)
21 files changed:
admin/cliupgrade.php
admin/index.php
admin/xmldb/actions/test/test.class.php
backup/lib.php
lang/en_utf8/error.php
lib/adminlib.php
lib/blocklib.php
lib/db/upgrade.php
lib/ddl/database_manager.php
lib/ddl/simpletest/testddl.php
lib/deprecatedlib.php
lib/dml/adodb_moodle_database.php
lib/dml/simpletest/testdml.php
lib/scroll_to_errors.js
lib/setuplib.php
lib/simpletest/fixtures/gradetest.php
lib/weblib.php
mod/data/db/upgrade.php
mod/feedback/db/upgrade.php
mod/lesson/db/upgrade.php
mod/quiz/db/upgrade.php

index 44d86dc6604566f30c473a7623202eb64287b041..94b8a21b80fbca8b893f6150468ebe41ec3975f9 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /**
- * cliupgrade.php 
+ * cliupgrade.php
  * Command Line Installer and Upgrader for Moodle
  * @author Dilan Anuruddha
- * 
+ *
  */
 
 
@@ -16,19 +16,19 @@ if (!empty($_SERVER['GATEWAY_INTERFACE'])){
 
 
 /**
- * BEFORE YOU ADD/EDIT/DELETE ANYTHING IN THIS DOCUMENT PLEASE READ 
- * 
+ * BEFORE YOU ADD/EDIT/DELETE ANYTHING IN THIS DOCUMENT PLEASE READ
+ *
  * When you add some code that print something on to standard out always wrap it around if clause with $verbose
- * argument check. If the $verbose is CLI_NO, you shouldn't print anything. If $verboser is CLI_SEMI it's ok to print a 
- * summarized version. If $verbose is CLI_FULL you can print anything you want. 
- * 
- * When you add a code that read input from the standard input you should wrap  it with appropriate if clause, allowing 
+ * argument check. If the $verbose is CLI_NO, you shouldn't print anything. If $verboser is CLI_SEMI it's ok to print a
+ * summarized version. If $verbose is CLI_FULL you can print anything you want.
+ *
+ * When you add a code that read input from the standard input you should wrap  it with appropriate if clause, allowing
  * required level of interaction. Also remember to add the same option as a command line argument list.
  * In CLI_FULL interaction mode, whether you have set the argument in commandline or not you
- * should prompt for user input. In CLI_SEMI interaction only the arguments which are not set are prompted for user input. 
- * No interaction mode doesn't prompt user for anyinput. If any argument is not specified then the default value should be assumed. 
+ * should prompt for user input. In CLI_SEMI interaction only the arguments which are not set are prompted for user input.
+ * No interaction mode doesn't prompt user for anyinput. If any argument is not specified then the default value should be assumed.
  * So do the appropriate thing considering this when you edit or delete this code
- * 
+ *
  */
 //=============================================================================//
 // Set values for initial structures
@@ -558,20 +558,20 @@ if (!file_exists(dirname(dirname(__FILE__)) . '/config.php')) {
             }
         }
     }
-    
+
     if ( $verbose > CLI_NO && !empty($downloadsuccess)) {
         //print success message if language pack download is successful
         console_write(STDOUT,'downloadsuccess');
         print_newline();
     }
-    
+
     $CONFFILE = array();
     //==================================================================================//
     //set INSTALL array values to CONFFILE array
     foreach ($INSTALL as $key => $value) {
         $CONFFILE[$key] = $value;
     }
-    
+
     //==================================================================================//
     //if any value is not set, set default values
 
@@ -687,9 +687,9 @@ if ( file_exists(dirname(dirname(__FILE__)) . '/config.php')) {
     require_once($CFG->libdir.'/adminlib.php');  // Contains various admin-only functions
 
     /**
-     * @todo check upgrade status, if upgrader is running already, notify user and exit. 
+     * @todo check upgrade status, if upgrader is running already, notify user and exit.
      * existing thing might work for this with some modifications
-     * 
+     *
      */
 
     ///check PHP Settings
@@ -827,14 +827,13 @@ if ( file_exists(dirname(dirname(__FILE__)) . '/config.php')) {
             }
         }
 
-        $status = $DB->get_manager()->install_from_xmldb_file("$CFG->libdir/db/install.xml"); //New method
+        $DB->get_manager()->install_from_xmldb_file("$CFG->libdir/db/install.xml"); //New method
 
         // all new installs are in unicode - keep for backwards compatibility and 1.8 upgrade checks
         set_config('unicodedb', 1);
 
         /// Continue with the instalation
 
-        if ($status) {
             // Install the roles system.
             moodle_install_roles();
 
@@ -861,9 +860,6 @@ if ( file_exists(dirname(dirname(__FILE__)) . '/config.php')) {
 
             notify($strdatabasesuccess, "green");
             require_once $CFG->dirroot.'/mnet/lib.php';
-        } else {
-            console_write(STDERR,"Error: Main databases NOT set up successfully",'');
-        }
 
     }
 
@@ -1096,7 +1092,7 @@ if ( file_exists(dirname(dirname(__FILE__)) . '/config.php')) {
     /// just make sure upgrade logging is properly terminated
     upgrade_log_finish();
 
-    unset($_SESSION['installautopilot']);
+    unset($SESSION->installautopilot);
 
     /// Set up the site
     if (! $site = get_site()) {
@@ -1160,7 +1156,7 @@ if ( file_exists(dirname(dirname(__FILE__)) . '/config.php')) {
         $newsite->student = get_string("defaultcoursestudent");
         $newsite->students = get_string("defaultcoursestudents");
         $newsite->timemodified = time();
-        
+
         if ($newid = $DB->insert_record('course', $newsite)) {
             // Site created, add blocks for it
             $page = page_create_object(PAGE_COURSE_VIEW, $newid);
index 11bfe093f26150322b4369c6cff2dd78943a7836..7efab26e6b6c024340f318e1a1c84867b7da7cf9 100644 (file)
             }
         }
     }
-    
+
     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, "&nbsp;", "&nbsp;");
                 echo '</form>';
                 print_footer('none');
                 die();
-    
+
             } else {
                 $strdatabasesuccess  = get_string("databasesuccess");
                 $navigation = build_navigation(array(array('name'=>$strdatabasesuccess, 'link'=>null, 'type'=>'misc')));
index b65c141cd273595b88ac61af662a514eb11d7858..156081764b24e0cd3e40994365194e2eaf4adf15 100644 (file)
@@ -75,15 +75,15 @@ class test extends XMLDBAction {
     /// Silenty drop any previous test tables
         $table = new xmldb_table('testtable');
         if ($dbman->table_exists($table)) {
-            $status = $dbman->drop_table($table, true, false);
+            $dbman->drop_table($table);
         }
         $table = new xmldb_table ('anothertest');
         if ($dbman->table_exists($table)) {
-            $status = $dbman->drop_table($table, true, false);
+            $dbman->drop_table($table);
         }
         $table = new xmldb_table ('newnameforthetable');
         if ($dbman->table_exists($table)) {
-            $status = $dbman->drop_table($table, true, false);
+            $dbman->drop_table($table);
         }
 
     /// 1st test. Complete table creation.
@@ -119,8 +119,11 @@ class test extends XMLDBAction {
     /// Get SQL code and execute it
         $test = new stdClass;
         $test->sql = $gen->getCreateTableSQL($table);
-        $test->status = $dbman->create_table($table, false, false);
-        if (!$test->status) {
+        try {
+            $dbman->create_table($table);
+            $test->status = true;
+        } catch (moodle_exception $e) {
+            $test->status = false;
             $test->error = $DB->get_last_error();
         }
         $tests['create table'] = $test;
@@ -130,8 +133,11 @@ class test extends XMLDBAction {
         /// Get SQL code and execute it
             $test = new stdClass;
             $test->sql = $gen->getDropTableSQL($table);
-            $test->status = $dbman->drop_table($table, false, false);
-            if (!$test->status) {
+            try {
+                $dbman->drop_table($table);
+                $test->status = true;
+            } catch (moodle_exception $e) {
+                $test->status = false;
                 $test->error = $DB->get_last_error();
             }
             $tests['drop table'] = $test;
@@ -151,14 +157,18 @@ class test extends XMLDBAction {
         /// Get SQL code and execute it
             $test = new stdClass;
             $test->sql = $gen->getCreateTableSQL($table);
-            $test->status = $dbman->create_table($table, false, false);
-            if (!$test->status) {
+            try {
+                $dbman->create_table($table);
+                $test->status = true;
+            } catch (moodle_exception $e) {
+                $test->status = false;
                 $test->error = $DB->get_last_error();
             }
             $tests['create table - 2'] = $test;
         }
 
     /// Insert two records to do the work with real data
+        $rec = new stdClass;
         $rec->course = 1;
         $rec->name = 'Martin';
         $rec->secondname = 'Dougiamas';
@@ -179,8 +189,11 @@ class test extends XMLDBAction {
         /// Get SQL code and execute it
             $test = new stdClass;
             $test->sql = $gen->getAddFieldSQL($table, $field);
-            $test->status = $dbman->add_field($table, $field, false, false);
-            if (!$test->status) {
+            try {
+                $dbman->add_field($table, $field, false, false);
+                $test->status = true;
+            } catch (moodle_exception $e) {
+                $test->status = false;
                 $test->error = $DB->get_last_error();
             }
             $tests['add enum field'] = $test;
@@ -191,8 +204,11 @@ class test extends XMLDBAction {
         /// Create a new field with complex specs (enums are good candidates)
             $test = new stdClass;
             $test->sql = $gen->getDropFieldSQL($table, $field);
-            $test->status = $dbman->drop_field($table, $field, false, false);
-            if (!$test->status) {
+            try {
+                $dbman->drop_field($table, $field, false, false);
+                $test->status = true;
+            } catch (moodle_exception $e) {
+                $test->status = false;
                 $test->error = $DB->get_last_error();
             }
             $tests['drop enum field'] = $test;
@@ -205,8 +221,11 @@ class test extends XMLDBAction {
         /// Get SQL code and execute it
             $test = new stdClass;
             $test->sql = $gen->getAddFieldSQL($table, $field);
-            $test->status = $dbman->add_field($table, $field, false, false);
-            if (!$test->status) {
+            try {
+                $dbman->add_field($table, $field, false, false);
+                $test->status = true;
+            } catch (moodle_exception $e) {
+                $test->status = false;
                 $test->error = $DB->get_last_error();
             }
             $tests['add enum field again'] = $test;
@@ -219,8 +238,11 @@ class test extends XMLDBAction {
         /// Get SQL code and execute it
             $test = new stdClass;
             $test->sql = $gen->getAddFieldSQL($table, $field);
-            $test->status = $dbman->add_field($table, $field, false, false);
-            if (!$test->status) {
+            try {
+                $dbman->add_field($table, $field, false, false);
+                $test->status = true;
+            } catch (moodle_exception $e) {
+                $test->status = false;
                 $test->error = $DB->get_last_error();
             }
             $tests['add numeric field'] = $test;
@@ -232,8 +254,11 @@ class test extends XMLDBAction {
             $field = new xmldb_field('type');
             $test = new stdClass;
             $test->sql = $gen->getDropFieldSQL($table, $field);
-            $test->status = $dbman->drop_field($table, $field, false, false);
-            if (!$test->status) {
+            try {
+                $dbman->drop_field($table, $field, false, false);
+                $test->status = true;
+            } catch (moodle_exception $e) {
+                $test->status = false;
                 $test->error = $DB->get_last_error();
             }
             $tests['drop enum field again'] = $test;
@@ -246,8 +271,11 @@ class test extends XMLDBAction {
             $field = new xmldb_field('course', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, '0');
 
             $test->sql = $gen->getAlterFieldSQL($table, $field);
-            $test->status = $dbman->change_field_type($table, $field, false, false);
-            if (!$test->status) {
+            try {
+                $dbman->change_field_type($table, $field, false, false);
+                $test->status = true;
+            } catch (moodle_exception $e) {
+                $test->status = false;
                 $test->error = $DB->get_last_error();
             }
             $tests['change field type (int2char)'] = $test;
@@ -260,8 +288,11 @@ class test extends XMLDBAction {
             $field = new xmldb_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
 
             $test->sql = $gen->getAlterFieldSQL($table, $field);
-            $test->status = $dbman->change_field_type($table, $field, false, false);
-            if (!$test->status) {
+            try {
+                $dbman->change_field_type($table, $field, false, false);
+                $test->status = true;
+            } catch (moodle_exception $e) {
+                $test->status = false;
                 $test->error = $DB->get_last_error();
             }
             $tests['change field type (char2int)'] = $test;
@@ -274,8 +305,11 @@ class test extends XMLDBAction {
             $field = new xmldb_field('grade', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, "test'n drop");
 
             $test->sql = $gen->getAlterFieldSQL($table, $field);
-            $test->status = $dbman->change_field_type($table, $field, false, false);
-            if (!$test->status) {
+            try {
+                $dbman->change_field_type($table, $field, false, false);
+                $test->status = true;
+            } catch (moodle_exception $e) {
+                $test->status = false;
                 $test->error = $DB->get_last_error();
             }
             $tests['change field type (number2char)'] = $test;
@@ -288,8 +322,11 @@ class test extends XMLDBAction {
             $field = new xmldb_field('grade', XMLDB_TYPE_FLOAT, '20,10', XMLDB_UNSIGNED, null, null, null, null, null);
 
             $test->sql = $gen->getAlterFieldSQL($table, $field);
-            $test->status = $dbman->change_field_type($table, $field, false, false);
-            if (!$test->status) {
+            try {
+                $dbman->change_field_type($table, $field, false, false);
+                $test->status = true;
+            } catch (moodle_exception $e) {
+                $test->status = false;
                 $test->error = $DB->get_last_error();
             }
             $tests['change field type (char2float)'] = $test;
@@ -302,8 +339,11 @@ class test extends XMLDBAction {
             $field = new xmldb_field('grade', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, 'test');
 
             $test->sql = $gen->getAlterFieldSQL($table, $field);
-            $test->status = $dbman->change_field_type($table, $field, false, false);
-            if (!$test->status) {
+            try {
+                $dbman->change_field_type($table, $field, false, false);
+                $test->status = true;
+            } catch (moodle_exception $e) {
+                $test->status = false;
                 $test->error = $DB->get_last_error();
             }
             $tests['change field type (float2char)'] = $test;
@@ -316,8 +356,11 @@ class test extends XMLDBAction {
             $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '20,10', XMLDB_UNSIGNED, null, null, null, null, null);
 
             $test->sql = $gen->getAlterFieldSQL($table, $field);
-            $test->status = $dbman->change_field_type($table, $field, false, false);
-            if (!$test->status) {
+            try {
+                $dbman->change_field_type($table, $field, false, false);
+                $test->status = true;
+            } catch (moodle_exception $e) {
+                $test->status = false;
                 $test->error = $DB->get_last_error();
             }
             $tests['change field type (char2number)'] = $test;
@@ -332,8 +375,11 @@ class test extends XMLDBAction {
             $field->set_attributes(XMLDB_TYPE_TEXT, 'big', null, XMLDB_NOTNULL, null, null, null, null);
 
             $test->sql = $gen->getAlterFieldSQL($table, $field);
-            $test->status = $dbman->change_field_precision($table, $field, false, false);
-            if (!$test->status) {
+            try {
+                $dbman->change_field_precision($table, $field, false, false);
+                $test->status = true;
+            } catch (moodle_exception $e) {
+                $test->status = false;
                 $test->error = $DB->get_last_error();
             }
             $tests['change field precision (text)'] = $test;
@@ -347,8 +393,11 @@ class test extends XMLDBAction {
             $field->set_attributes(XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null, null, null);
 
             $test->sql = $gen->getAlterFieldSQL($table, $field);
-            $test->status = $dbman->change_field_precision($table, $field, false, false);
-            if (!$test->status) {
+            try {
+                $dbman->change_field_precision($table, $field, false, false);
+                $test->status = true;
+            } catch (moodle_exception $e) {
+                $test->status = false;
                 $test->error = $DB->get_last_error();
             }
             $tests['change field precision (char)'] = $test;
@@ -362,8 +411,11 @@ class test extends XMLDBAction {
             $field->set_attributes(XMLDB_TYPE_NUMBER, '10,2', null, null, null, null, null, null);
 
             $test->sql = $gen->getAlterFieldSQL($table, $field);
-            $test->status = $dbman->change_field_precision($table, $field, false, false);
-            if (!$test->status) {
+            try {
+                $dbman->change_field_precision($table, $field, false, false);
+                $test->status = true;
+            } catch (moodle_exception $e) {
+                $test->status = false;
                 $test->error = $DB->get_last_error();
             }
             $tests['change field precision (number)'] = $test;
@@ -377,8 +429,11 @@ class test extends XMLDBAction {
             $field->set_attributes(XMLDB_TYPE_INTEGER, '5', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
 
             $test->sql = $gen->getAlterFieldSQL($table, $field);
-            $test->status = $dbman->change_field_precision($table, $field, false, false);
-            if (!$test->status) {
+            try {
+                $dbman->change_field_precision($table, $field, false, false);
+                $test->status = true;
+            } catch (moodle_exception $e) {
+                $test->status = false;
                 $test->error = $DB->get_last_error();
             }
             $tests['change field precision (integer) to smaller one'] = $test;
@@ -392,8 +447,11 @@ class test extends XMLDBAction {
             $field->set_attributes(XMLDB_TYPE_NUMBER, '10,2', XMLDB_UNSIGNED, null, null, null, null, null);
 
             $test->sql = $gen->getAlterFieldSQL($table, $field);
-            $test->status = $dbman->change_field_unsigned($table, $field, false, false);
-            if (!$test->status) {
+            try {
+                $dbman->change_field_unsigned($table, $field, false, false);
+                $test->status = true;
+            } catch (moodle_exception $e) {
+                $test->status = false;
                 $test->error = $DB->get_last_error();
             }
             $tests['change field sign (unsigned)'] = $test;
@@ -407,8 +465,11 @@ class test extends XMLDBAction {
             $field->set_attributes(XMLDB_TYPE_NUMBER, '10,2', null, null, null, null, null, null);
 
             $test->sql = $gen->getAlterFieldSQL($table, $field);
-            $test->status = $dbman->change_field_unsigned($table, $field, false, false);
-            if (!$test->status) {
+            try {
+                $dbman->change_field_unsigned($table, $field, false, false);
+                $test->status = true;
+            } catch (moodle_exception $e) {
+                $test->status = false;
                 $test->error = $DB->get_last_error();
             }
             $tests['change field sign (signed)'] = $test;
@@ -422,8 +483,11 @@ class test extends XMLDBAction {
             $field->set_attributes(XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, 'Moodle');
 
             $test->sql = $gen->getAlterFieldSQL($table, $field);
-            $test->status = $dbman->change_field_notnull($table, $field, false, false);
-            if (!$test->status) {
+            try {
+                $dbman->change_field_notnull($table, $field, false, false);
+                $test->status = true;
+            } catch (moodle_exception $e) {
+                $test->status = false;
                 $test->error = $DB->get_last_error();
             }
             $tests['change field nullability (not null)'] = $test;
@@ -437,8 +501,11 @@ class test extends XMLDBAction {
             $field->set_attributes(XMLDB_TYPE_CHAR, '30', null, null, null, null, null, 'Moodle');
 
             $test->sql = $gen->getAlterFieldSQL($table, $field);
-            $test->status = $dbman->change_field_notnull($table, $field, false, false);
-            if (!$test->status) {
+            try {
+                $dbman->change_field_notnull($table, $field, false, false);
+                $test->status = true;
+            } catch (moodle_exception $e) {
+                $test->status = false;
                 $test->error = $DB->get_last_error();
             }
             $tests['change field nullability (null)'] = $test;
@@ -452,8 +519,11 @@ class test extends XMLDBAction {
             $field->set_attributes(XMLDB_TYPE_CHAR, '30', null, null, null, null, null, null);
 
             $test->sql = $gen->getModifyDefaultSQL($table, $field);
-            $test->status = $dbman->change_field_default($table, $field, false, false);
-            if (!$test->status) {
+            try {
+                $dbman->change_field_default($table, $field, false, false);
+                $test->status = true;
+            } catch (moodle_exception $e) {
+                $test->status = false;
                 $test->error = $DB->get_last_error();
             }
             $tests['drop field default of NULL field'] = $test;
@@ -467,8 +537,11 @@ class test extends XMLDBAction {
             $field->set_attributes(XMLDB_TYPE_CHAR, '30', null, null, null, null, null, 'Moodle');
 
             $test->sql = $gen->getModifyDefaultSQL($table, $field);
-            $test->status = $dbman->change_field_default($table, $field, false, false);
-            if (!$test->status) {
+            try {
+                $dbman->change_field_default($table, $field, false, false);
+                $test->status = true;
+            } catch (moodle_exception $e) {
+                $test->status = false;
                 $test->error = $DB->get_last_error();
             }
             $tests['add field default of NULL field'] = $test;
@@ -482,8 +555,11 @@ class test extends XMLDBAction {
             $field->set_attributes(XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null, null, 'Moodle2');
 
             $test->sql = $gen->getModifyDefaultSQL($table, $field);
-            $test->status = $dbman->change_field_default($table, $field, false, false);
-            if (!$test->status) {
+            try {
+                $dbman->change_field_default($table, $field, false, false);
+                $test->status = true;
+            } catch (moodle_exception $e) {
+                $test->status = false;
                 $test->error = $DB->get_last_error();
             }
             $tests['add field default of NOT NULL field'] = $test;
@@ -498,8 +574,11 @@ class test extends XMLDBAction {
             $field->set_attributes(XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null, null, null);
 
             $test->sql = $gen->getModifyDefaultSQL($table, $field);
-            $test->status = $dbman->change_field_default($table, $field, false, false);
-            if (!$test->status) {
+            try {
+                $dbman->change_field_default($table, $field, false, false);
+                $test->status = true;
+            } catch (moodle_exception $e) {
+                $test->status = false;
                 $test->error = $DB->get_last_error();
             }
             $tests['drop field default of NOT NULL field'] = $test;
@@ -513,8 +592,11 @@ class test extends XMLDBAction {
             $index->set_attributes(XMLDB_INDEX_UNIQUE, array('name', 'secondname', 'grade'));
 
             $test->sql = $gen->getAddIndexSQL($table, $index);
-            $test->status = $dbman->add_index($table, $index, false, false);
-            if (!$test->status) {
+            try {
+                $dbman->add_index($table, $index, false, false);
+                $test->status = true;
+            } catch (moodle_exception $e) {
+                $test->status = false;
                 $test->error = $DB->get_last_error();
             }
             $tests['add unique index'] = $test;
@@ -528,8 +610,11 @@ class test extends XMLDBAction {
             $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('course', 'name'));
 
             $test->sql = $gen->getAddIndexSQL($table, $index);
-            $test->status = $dbman->add_index($table, $index, false, false);
-            if (!$test->status) {
+            try {
+                $dbman->add_index($table, $index, false, false);
+                $test->status = true;
+            } catch (moodle_exception $e) {
+                $test->status = false;
                 $test->error = $DB->get_last_error();
             }
             $tests['add not unique index'] = $test;
@@ -562,8 +647,11 @@ class test extends XMLDBAction {
             $index->set_attributes(XMLDB_INDEX_UNIQUE, array('name', 'grade', 'secondname'));
 
             $test->sql = $gen->getDropIndexSQL($table, $index);
-            $test->status = $dbman->drop_index($table, $index, false, false);
-            if (!$test->status) {
+            try {
+                $dbman->drop_index($table, $index, false, false);
+                $test->status = true;
+            } catch (moodle_exception $e) {
+                $test->status = false;
                 $test->error = $DB->get_last_error();
             }
             $tests['drop index'] = $test;
@@ -577,8 +665,11 @@ class test extends XMLDBAction {
             $key->set_attributes(XMLDB_KEY_UNIQUE, array('id', 'course', 'grade'));
 
             $test->sql = $gen->getAddKeySQL($table, $key);
-            $test->status = $dbman->add_key($table, $key, false, false);
-            if (!$test->status) {
+            try {
+                $dbman->add_key($table, $key, false, false);
+                $test->status = true;
+            } catch (moodle_exception $e) {
+                $test->status = false;
                 $test->error = $DB->get_last_error();
             }
             $tests['add unique key'] = $test;
@@ -592,8 +683,11 @@ class test extends XMLDBAction {
             $key->set_attributes(XMLDB_KEY_FOREIGN_UNIQUE, array('course'), 'anothertest', array('id'));
 
             $test->sql = $gen->getAddKeySQL($table, $key);
-            $test->status = $dbman->add_key($table, $key, false, false);
-            if (!$test->status) {
+            try {
+                $dbman->add_key($table, $key, false, false);
+                $test->status = true;
+            } catch (moodle_exception $e) {
+                $test->status = false;
                 $test->error = $DB->get_last_error();
             }
             $tests['add foreign+unique key'] = $test;
@@ -607,8 +701,11 @@ class test extends XMLDBAction {
             $key->set_attributes(XMLDB_KEY_FOREIGN_UNIQUE, array('course'), 'anothertest', array('id'));
 
             $test->sql = $gen->getDropKeySQL($table, $key);
-            $test->status = $dbman->drop_key($table, $key, false, false);
-            if (!$test->status) {
+            try {
+                $dbman->drop_key($table, $key, false, false);
+                $test->status = true;
+            } catch (moodle_exception $e) {
+                $test->status = false;
                 $test->error = $DB->get_last_error();
             }
             $tests['drop foreign+unique key'] = $test;
@@ -622,8 +719,11 @@ class test extends XMLDBAction {
             $key->set_attributes(XMLDB_KEY_FOREIGN, array('course'), 'anothertest', array('id'));
 
             $test->sql = $gen->getAddKeySQL($table, $key);
-            $test->status = $dbman->add_key($table, $key, false, false);
-            if (!$test->status) {
+            try {
+                $dbman->add_key($table, $key, false, false);
+                $test->status = true;
+            } catch (moodle_exception $e) {
+                $test->status = false;
                 $test->error = $DB->get_last_error();
             }
             $tests['add foreign key'] = $test;
@@ -637,8 +737,11 @@ class test extends XMLDBAction {
             $key->set_attributes(XMLDB_KEY_FOREIGN, array('course'), 'anothertest', array('id'));
 
             $test->sql = $gen->getDropKeySQL($table, $key);
-            $test->status = $dbman->drop_key($table, $key, false, false);
-            if (!$test->status) {
+            try {
+                $dbman->drop_key($table, $key, false, false);
+                $test->status = true;
+            } catch (moodle_exception $e) {
+                $test->status = false;
                 $test->error = $DB->get_last_error();
             }
             $tests['drop foreign key'] = $test;
@@ -652,11 +755,13 @@ class test extends XMLDBAction {
         /// Get SQL code and execute it
             $test = new stdClass;
             $test->sql = $gen->getAddFieldSQL($table, $field);
-            $test->status = $dbman->add_field($table, $field, false, false);
-            if (!$test->status) {
+            try {
+                $dbman->add_field($table, $field, false, false);
+                $test->status = true;
+            } catch (moodle_exception $e) {
+                $test->status = false;
                 $test->error = $DB->get_last_error();
             }
-
             $tests['add field with enum'] = $test;
         }
 
@@ -667,8 +772,11 @@ class test extends XMLDBAction {
             $field = new xmldb_field('type');
             $field->set_attributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, 'general', 'course');
             $test->sql = $gen->getModifyEnumSQL($table, $field);
-            $test->status = $dbman->change_field_enum($table, $field, false, false);
-            if (!$test->status) {
+            try {
+                $dbman->change_field_enum($table, $field, false, false);
+                $test->status = true;
+            } catch (moodle_exception $e) {
+                $test->status = false;
                 $test->error = $DB->get_last_error();
             }
             $tests['delete enumlist from one field'] = $test;
@@ -681,8 +789,11 @@ class test extends XMLDBAction {
             $field = new xmldb_field('type');
             $field->set_attributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, XMLDB_ENUM, array('single', 'news', 'general', 'social', 'eachuser', 'teacher', 'qanda'), 'general', 'course');
             $test->sql = $gen->getModifyEnumSQL($table, $field);
-            $test->status = $dbman->change_field_enum($table, $field, false, false);
-            if (!$test->status) {
+            try {
+                $dbman->change_field_enum($table, $field, false, false);
+                $test->status = true;
+            } catch (moodle_exception $e) {
+                $test->status = false;
                 $test->error = $DB->get_last_error();
             }
             $tests['add enumlist to one field'] = $test;
@@ -695,8 +806,11 @@ class test extends XMLDBAction {
             $index = new xmldb_index('anyname');
             $index->set_attributes(XMLDB_INDEX_UNIQUE, array('name', 'course'));
             $test->sql = $gen->getRenameIndexSQL($table, $index, 'newnamefortheindex');
-            $test->status = $dbman->rename_index($table, $index, 'newnamefortheindex', false, false);
-            if (!$test->status) {
+            try {
+                $dbman->rename_index($table, $index, 'newnamefortheindex', false, false);
+                $test->status = true;
+            } catch (moodle_exception $e) {
+                $test->status = false;
                 $test->error = $DB->get_last_error();
             }
             $tests['rename index (experimental. DO NOT USE IT)'] = $test;
@@ -716,11 +830,14 @@ class test extends XMLDBAction {
             if ($olddebug > DEBUG_ALL) {
                 $CFG->debug = DEBUG_ALL; // do not show experimental debug warning
             }
-            $test->status = $dbman->rename_key($table, $key, 'newnameforthekey', false, false);
-            $CFG->debug = $olddebug;
-            if (!$test->status) {
+            try {
+                $dbman->rename_key($table, $key, 'newnameforthekey', false, false);
+                $test->status = true;
+            } catch (moodle_exception $e) {
+                $test->status = false;
                 $test->error = $DB->get_last_error();
             }
+            $CFG->debug = $olddebug;
             $tests['rename key (experimental. DO NOT USE IT)'] = $test;
             $test = new stdClass;
             $test->status = true; // ignore errors here
@@ -734,8 +851,11 @@ class test extends XMLDBAction {
             $field->set_attributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, XMLDB_ENUM, array('single', 'news', 'general', 'social', 'eachuser', 'teacher', 'qanda'), 'general', 'course');
 
             $test->sql = $gen->getRenameFieldSQL($table, $field, 'newnameforthefield', true);
-            $test->status = $dbman->rename_field($table, $field, 'newnameforthefield', false, false);
-            if (!$test->status) {
+            try {
+                $dbman->rename_field($table, $field, 'newnameforthefield', false, false);
+                $test->status = true;
+            } catch (moodle_exception $e) {
+                $test->status = false;
                 $test->error = $DB->get_last_error();
             }
             $tests['rename field'] = $test;
@@ -747,8 +867,11 @@ class test extends XMLDBAction {
             $test = new stdClass;
 
             $test->sql = $gen->getRenameTableSQL($table, 'newnameforthetable', true);
-            $test->status = $dbman->rename_table($table, 'newnameforthetable', false, false);
-            if (!$test->status) {
+            try {
+                $dbman->rename_table($table, 'newnameforthetable');
+                $test->status = true;
+            } catch (moodle_exception $e) {
+                $test->status = false;
                 $test->error = $DB->get_last_error();
             }
             $tests['rename table'] = $test;
@@ -763,14 +886,16 @@ class test extends XMLDBAction {
         /// Get SQL code and execute it
             $test = new stdClass;
             $test->sql = $gen->getModifyEnumSQL($table, $field);
-            $test->status = $dbman->change_field_enum($table, $field, false, false);
-        /// Let's see if the constraint exists to alter results
-            if ($dbman->check_constraint_exists($table, $field)) {
-                $test->sql = array('Nothing executed. Enum already exists. Correct.');
-            } else {
+            try {
+                $dbman->change_field_enum($table, $field, false, false);
+                if ($dbman->check_constraint_exists($table, $field)) {
+                    $test->sql = array('Nothing executed. Enum already exists. Correct.');
+                    $test->status = true;
+                } else {
+                    $test->status = false;
+                }
+            } catch (moodle_exception $e) {
                 $test->status = false;
-            }
-            if (!$test->status) {
                 $test->error = $DB->get_last_error();
             }
             $tests['add enum to field containing enum'] = $test;
@@ -785,8 +910,11 @@ class test extends XMLDBAction {
         /// Get SQL code and execute it
             $test = new stdClass;
             $test->sql = $gen->getModifyEnumSQL($table, $field);
-            $test->status = $dbman->change_field_enum($table, $field, false, false);
-            if (!$test->status) {
+            try {
+                $dbman->change_field_enum($table, $field, false, false);
+                $test->status = true;
+            } catch (moodle_exception $e) {
+                $test->status = false;
                 $test->error = $DB->get_last_error();
             }
             $tests['drop enum from field containing enum'] = $test;
@@ -801,14 +929,11 @@ class test extends XMLDBAction {
         /// Get SQL code and execute it
             $test = new stdClass;
             $test->sql = $gen->getModifyEnumSQL($table, $field);
-            $test->status = $dbman->change_field_enum($table, $field, false, false);
-        /// Let's see if the constraint exists to alter results
-            if (!$dbman->check_constraint_exists($table, $field)) {
-                $test->sql = array('Nothing executed. Enum does not exists. Correct.');
-            } else {
+            try {
+                $dbman->change_field_enum($table, $field, false, false);
+                $test->status = true;
+            } catch (moodle_exception $e) {
                 $test->status = false;
-            }
-            if (!$test->status) {
                 $test->error = $DB->get_last_error();
             }
             $tests['drop enum from field not containing enum'] = $test;
index bb81a0a5e95e7940c3002e2bdc494cf96655e478..f8cc143570c5c636abd95b431a34e791cefefdc9 100644 (file)
 
         /// 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);
         }
index ff5b3fd52e1926712f7bfe22312369516f1bc295..29539dfe52e57d0898e4060e80a26335a81cfc5d 100644 (file)
@@ -41,7 +41,7 @@ $string['cannotcreateuploaddir'] = 'Cannot create upload folder. The site admini
 $string['cannotcreateuser'] = 'Error creating user record';
 $string['cannotcreateorfindstructs'] = 'Error finding or creating section structures for this course';
 $string['cannotcreatepopupwin'] = 'Undefined element - cannot create popup window.';
-$string['cannotcustomizelocallang'] = 'You do not have permission to customize the strings translation.  This permission is controlled by the capability "moodle/site:langeditlocal". Set this capability to allow you to edit local language packages in case you want to modify translations for your site.';
+$string['cannotcustomizelocallang'] = 'You do not have permission to customize the strings translation.  This permission is controlled by the capability \"moodle/site:langeditlocal\". Set this capability to allow you to edit local language packages in case you want to modify translations for your site.';
 $string['cannotdeletelangcache'] = 'Language cache can not be deleted, please fix permissions in dataroot/cache/languages!';
 $string['cannotdeletebackupids'] = 'Couldn\'t delete previous backup ids.';
 $string['cannotdeletecap'] = 'Could not delete deprecated capability $a';
@@ -58,7 +58,7 @@ $string['cannoteditcomment'] = 'Comment is not yours to edit!';
 $stirng['cannoteditcommentexpired'] = 'You can\'t edit this. Time expired!';
 $string['cannoteditsiteform'] = 'You cannot edit the site course using this form';
 $string['cannoteditpostorblog'] = 'You can not post or edit blogs.';
-$string['cannoteditmasterlang'] = 'You do not have permission to edit master language package. This permission is controlled by the capability "moodle/site:langeditmaster". Set this capability to allow you to edit master language packages in case you are the maintainer of a package.';
+$string['cannoteditmasterlang'] = 'You do not have permission to edit master language package. This permission is controlled by the capability \"moodle/site:langeditmaster\". Set this capability to allow you to edit master language packages in case you are the maintainer of a package.';
 $string['cannotedityourprofile'] = 'Can not edit own profile, sorry.';
 $string['cannotfindcomponent'] = 'Cannot find component.';
 $string['cannotfindcontext'] = 'Could not find context';
@@ -172,7 +172,7 @@ $string['csvemptyfile'] = 'The CSV file is empty.';
 $string['csvcolumnduplicates'] = 'Duplicate columns detected.';
 $string['csvfewcolumns'] = 'Not enough columns, please verify the delimiter setting.';
 $string['csvinvalidcolsnum'] = 'INVALID CSV FILE; Each line must include 49 or 70 fields';
-$string['csvinvalidcols'] = '<b>INVALID CSV FILE:</b> First line must include "Header Fields" and the file must be type of <br />"Expanded Fields/Comma Separated"<br />or<br /> "Expanded Fields with CAVV Result Code/Comma Separated"';
+$string['csvinvalidcols'] = '<b>INVALID CSV FILE:</b> First line must include \"Header Fields\" and the file must be type of <br />\"Expanded Fields/Comma Separated\"<br />or<br /> \"Expanded Fields with CAVV Result Code/Comma Separated\"';
 $string['csvweirdcolumns'] = 'Invalid CSV file format - number of columns is not constant!';
 $string['csvloaderror'] = 'Error occur during loading CSV file!';
 $string['dbconnectionfailed'] = '<p>Error: Database connection failed.</p>
@@ -181,6 +181,13 @@ $string['dbconnectionfailed'] = '<p>Error: Database connection failed.</p>
 $string['dbdriverproblem'] = '<p>Error: database driver problem detected</p>
 <p>The site administrator should verify server configuration</p><p>$a</p>';
 $string['dbupdatefailed'] = 'Database update failed.';
+$string['ddlexecuteerror'] = 'DDL sql execution error.';
+$string['ddlfieldalreadyexists'] = 'Field \"$a\" does not exist.';
+$string['ddlfieldnotexist'] = 'Field \"$a->fieldname\" does not exist in table \"$a->tablename\".';
+$string['ddltablealreadyexists'] = 'Table \"$a\" already exists.';
+$string['ddltablenotexist'] = 'Table \"$a\" does not exist.';
+$string['ddlunknownerror'] = 'Unknown DDL library error.';
+$string['ddlxmlfileerror'] = 'XML database file errors found';
 $string['destinationcmnotexit'] = 'The destination course module does not exist';
 $string['downloadedfilecheckfailed'] = 'Downloaded file check failed.';
 $string['duplicateusername'] = 'Duplicate username - skiping record';
index f815171b418203d118df5e5ef0715d788240d92a..ee18e82592d3c101e7ed98952f9fb81defe4da7e 100644 (file)
@@ -65,7 +65,7 @@ function drop_plugin_tables($name, $file, $feedback=true) {
     global $CFG, $DB;
 
     // first try normal delete
-    if ($DB->get_manager()->delete_tables_from_xmldb_file($file, $feedback)) {
+    if ($DB->get_manager()->delete_tables_from_xmldb_file($file)) {
         return true;
     }
 
@@ -83,7 +83,7 @@ function drop_plugin_tables($name, $file, $feedback=true) {
         // found orphan table --> delete it
         if ($DB->get_manager()->table_exists($table)) {
             $xmldb_table = new xmldb_table($table);
-            $DB->get_manager()->drop_table($xmldb_table, true, $feedback);
+            $DB->get_manager()->drop_table($xmldb_table);
         }
     }
 
@@ -288,12 +288,10 @@ function upgrade_plugins($type, $dir, $return) {
             if ($CFG->$pluginversion == 0) {    // It's a new install of this plugin
             /// Both old .sql files and new install.xml are supported
             /// but we priorize install.xml (XMLDB) if present
-                $status = false;
                 if (file_exists($fullplug . '/db/install.xml')) {
-                    $status = $DB->get_manager()->install_from_xmldb_file($fullplug . '/db/install.xml'); //New method
-                } else {
-                    $status = true;
+                    $DB->get_manager()->install_from_xmldb_file($fullplug . '/db/install.xml'); //New method
                 }
+                $status = true;
                 if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
                     $DB->set_debug(false);
                 }
@@ -534,7 +532,8 @@ function upgrade_activity_modules($return) {
         /// Both old .sql files and new install.xml are supported
         /// but we priorize install.xml (XMLDB) if present
             if (file_exists($fullmod . '/db/install.xml')) {
-                $status = $DB->get_manager()->install_from_xmldb_file($fullmod . '/db/install.xml'); //New method
+                $DB->get_manager()->install_from_xmldb_file($fullmod . '/db/install.xml'); //New method
+                $status = true;
             }
             if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
                 $DB->set_debug(false);
index 0853a9f293c60351384b0f65958972f1e654ae3d..2ad26395e853534c594757ee6d17c05fe7165d56 100644 (file)
@@ -1069,10 +1069,8 @@ function upgrade_blocks_db($continueto) {
         }
     /// Both old .sql files and new install.xml are supported
     /// but we priorize install.xml (XMLDB) if present
-        $status = false;
-        if (file_exists($CFG->dirroot . '/blocks/db/install.xml')) {
-            $status = $DB->get_manager()->install_from_xmldb_file($CFG->dirroot . '/blocks/db/install.xml'); //New method
-        }
+        $DB->get_manager()->install_from_xmldb_file($CFG->dirroot . '/blocks/db/install.xml'); //New method
+        $status = true;
         if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
         $DB->set_debug(false);
         }
@@ -1363,12 +1361,10 @@ function upgrade_blocks_plugins($continueto) {
 
         /// Both old .sql files and new install.xml are supported
         /// but we priorize install.xml (XMLDB) if present
-            $status = false;
             if (file_exists($fullblock . '/db/install.xml')) {
-                $status = $DB->get_manager()->install_from_xmldb_file($fullblock . '/db/install.xml'); //New method
-            } else {
-                $status = true;
+                $DB->get_manager()->install_from_xmldb_file($fullblock . '/db/install.xml'); //New method
             }
+            $status = true;
             if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
                 $DB->set_debug(false);
             }
index c5c584ba7875eea6cf3c1acda353e911036c86ca..b7255b4b5dc7a6946fdd2968443767e822947cce 100644 (file)
@@ -18,7 +18,6 @@
 
 
 function xmldb_main_upgrade($oldversion=0) {
-
     global $CFG, $THEME, $USER, $DB;
 
     $result = true;
@@ -36,14 +35,14 @@ function xmldb_main_upgrade($oldversion=0) {
         $index = new xmldb_index('contextid-lowerboundary', XMLDB_INDEX_NOTUNIQUE, array('contextid', 'lowerboundary'));
 
     /// Launch drop index contextid-lowerboundary
-        $result = $result && $dbman->drop_index($table, $index);
+        $dbman->drop_index($table, $index);
 
     /// Define index contextid-lowerboundary-letter (unique) to be added to grade_letters
         $table = new xmldb_table('grade_letters');
         $index = new xmldb_index('contextid-lowerboundary-letter', XMLDB_INDEX_UNIQUE, array('contextid', 'lowerboundary', 'letter'));
 
     /// Launch add index contextid-lowerboundary-letter
-        $result = $result && $dbman->add_index($table, $index);
+        $dbman->add_index($table, $index);
 
     /// Main savepoint reached
         upgrade_main_savepoint($result, 2008030700);
@@ -89,7 +88,7 @@ function xmldb_main_upgrade($oldversion=0) {
 
     /// Under MySQL and Postgres... detect old NULL contents and change them by correct empty string. MDL-14859
         if ($CFG->dbfamily == 'mysql' || $CFG->dbfamily == 'postgres') {
-            $DB->execute("UPDATE {user} SET idnumber = '' WHERE idnumber IS NULL", true);
+            $DB->execute("UPDATE {user} SET idnumber = '' WHERE idnumber IS NULL");
         }
 
     /// Define index idnumber (not unique) to be dropped form user
@@ -98,7 +97,7 @@ function xmldb_main_upgrade($oldversion=0) {
 
     /// Launch drop index idnumber
         if ($dbman->index_exists($table, $index)) {
-            $result = $result && $dbman->drop_index($table, $index);
+            $dbman->drop_index($table, $index);
         }
 
     /// Changing precision of field idnumber on table user to (255)
@@ -106,11 +105,11 @@ function xmldb_main_upgrade($oldversion=0) {
         $field = new xmldb_field('idnumber', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null, 'password');
 
     /// Launch change of precision for field idnumber
-        $result = $result && $dbman->change_field_precision($table, $field);
+        $dbman->change_field_precision($table, $field);
 
     /// Launch add index idnumber again
         $index = new xmldb_index('idnumber', XMLDB_INDEX_NOTUNIQUE, array('idnumber'));
-        $result = $result && $dbman->add_index($table, $index);
+        $dbman->add_index($table, $index);
 
     /// Main savepoint reached
         upgrade_main_savepoint($result, 2008051201);
@@ -131,7 +130,7 @@ function xmldb_main_upgrade($oldversion=0) {
     if ($result && $oldversion < 2008051203) {
         $table = new xmldb_table('mnet_enrol_course');
         $field = new xmldb_field('sortorder', XMLDB_TYPE_INTEGER, '10', true, true, null, false, false, 0);
-        $result = $dbman->change_field_precision($table, $field);
+        $dbman->change_field_precision($table, $field);
         upgrade_main_savepoint($result, 2008051203);
     }
 
index a4a631a0a8487aa6807f4a3f423c335b72c823ae..823facbf94252ad85950db32aa018a1983a911a9 100644 (file)
@@ -54,47 +54,35 @@ class database_manager {
             $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;
     }
 
     /**
@@ -105,6 +93,9 @@ class database_manager {
      * @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);
     }
 
@@ -116,24 +107,22 @@ class database_manager {
      * @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 {
@@ -153,17 +142,20 @@ class database_manager {
     }
 
     /**
-     * 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)
@@ -173,13 +165,6 @@ class database_manager {
     /// 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);
 
@@ -203,12 +188,15 @@ class database_manager {
     /**
      * 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);
     }
 
     /**
@@ -221,16 +209,16 @@ class database_manager {
      * @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)
@@ -259,7 +247,7 @@ class database_manager {
      * @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);
     }
 
@@ -274,14 +262,12 @@ class database_manager {
      * @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
@@ -320,23 +306,14 @@ class database_manager {
 
 
     /**
-     * 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;
@@ -355,15 +332,14 @@ class database_manager {
      * 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();
@@ -371,23 +347,21 @@ class database_manager {
 
         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;
     }
 
     /**
@@ -396,32 +370,19 @@ class database_manager {
      * 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);
     }
 
     /**
@@ -430,13 +391,13 @@ class database_manager {
      * 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();
@@ -444,10 +405,10 @@ class database_manager {
         /// 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();
@@ -457,14 +418,12 @@ class database_manager {
         $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);
     }
 
     /**
@@ -472,31 +431,18 @@ class database_manager {
      * 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);
     }
 
     /**
@@ -507,37 +453,22 @@ class database_manager {
      * 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);
     }
 
     /**
@@ -547,29 +478,22 @@ class database_manager {
      * 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);
     }
 
     /**
@@ -578,51 +502,35 @@ class database_manager {
      *
      * @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);
     }
 
 
@@ -631,40 +539,25 @@ class database_manager {
      *
      * @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);
     }
 
     /**
@@ -672,33 +565,22 @@ class database_manager {
      *
      * @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);
     }
 
     /**
@@ -706,33 +588,22 @@ class database_manager {
      *
      * @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);
     }
 
     /**
@@ -740,14 +611,11 @@ class database_manager {
      *
      * @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);
     }
 
     /**
@@ -755,14 +623,11 @@ class database_manager {
      *
      * @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);
     }
 
     /**
@@ -770,14 +635,11 @@ class database_manager {
      *
      * @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);
     }
 
     /**
@@ -785,26 +647,15 @@ class database_manager {
      *
      * @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.
@@ -812,21 +663,21 @@ class database_manager {
             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);
     }
 
     /**
@@ -835,33 +686,22 @@ class database_manager {
      *
      * @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);
     }
 
     /**
@@ -871,66 +711,41 @@ class database_manager {
      * @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);
     }
 
     /**
@@ -938,31 +753,19 @@ class database_manager {
      *
      * @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);
     }
 
     /**
@@ -970,31 +773,18 @@ class database_manager {
      *
      * @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);
     }
 
     /**
@@ -1004,36 +794,21 @@ class database_manager {
      * @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);
     }
 
     /**
@@ -1042,33 +817,25 @@ class database_manager {
      *
      * @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);
     }
 
     /**
@@ -1077,33 +844,25 @@ class database_manager {
      *
      * @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);
     }
 
     /**
@@ -1114,43 +873,59 @@ class database_manager {
      * @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);
     }
 }
 
index 99cde3dd0e0444fb81547701ab4ff192be143906..462379c81fc84fe64a5cff78c00463641f9dee30 100755 (executable)
@@ -84,14 +84,14 @@ class ddl_test extends UnitTestCase {
         for ($i=0; $i<3; $i++) {
             $table = new xmldb_table('test_table_cust'.$i);
             if ($dbman->table_exists($table)) {
-                $dbman->drop_table($table, true, false);
+                $dbman->drop_table($table);
             }
         }
 
         // drop default tables
         foreach ($this->tables as $table) {
             if ($dbman->table_exists($table)) {
-                $dbman->drop_table($table, true, false);
+                $dbman->drop_table($table);
             }
         }
     }
@@ -106,9 +106,9 @@ class ddl_test extends UnitTestCase {
         $table = $this->tables[$tablename];
 
         if ($dbman->table_exists($table)) {
-            $dbman->drop_table($table, true, false);
+            $dbman->drop_table($table);
         }
-        $dbman->create_table($table, true, false);
+        $dbman->create_table($table);
 
         return $table;
     }
@@ -128,7 +128,8 @@ class ddl_test extends UnitTestCase {
         $this->assertFalse($dbman->table_exists($table));
 
         // create table and test again
-        $this->assertTrue($dbman->create_table($table, true, false));
+        $dbman->create_table($table);
+
         $this->assertTrue($DB->get_records('test_table0') !== false);
         $this->assertTrue($dbman->table_exists('test_table0'));
         $this->assertTrue($dbman->table_exists($table));
@@ -142,17 +143,10 @@ class ddl_test extends UnitTestCase {
         $DB = $this->tdb; // do not use global $DB!
         $dbman = $this->tdb->get_manager();
 
-        // Give a wrong table param (expect a debugging message)
-        $table = 'string';
-        ob_start(); // hide debug warning
-        $result = $dbman->create_table($table);
-        ob_end_clean();
-        $this->assertFalse($result);
-
         // create table and do basic column tests
         $table = $this->tables['test_table1'];
 
-        $this->assertTrue($dbman->create_table($table));
+        $dbman->create_table($table);
         $this->assertTrue($dbman->table_exists($table));
 
         $columns = $DB->get_columns('test_table1');
@@ -172,22 +166,8 @@ class ddl_test extends UnitTestCase {
 
         $table = $this->create_deftable('test_table0');
 
-        $this->assertTrue($dbman->drop_table($table, true, false));
+        $dbman->drop_table($table);
         $this->assertFalse($dbman->table_exists('test_table0'));
-
-        // Try dropping non-existent table
-        $table = new xmldb_table('nonexistenttable');
-        ob_start(); // hide debug warning
-        $result = $dbman->drop_table($table, true, false);
-        ob_end_clean();
-        $this->assertTrue($result);
-
-        // Give a wrong table param
-        $table = 'string';
-        ob_start(); // hide debug warning
-        $result = $dbman->drop_table($table, true, false);
-        ob_end_clean();
-        $this->assertFalse($result);
     }
 
 
@@ -199,19 +179,19 @@ class ddl_test extends UnitTestCase {
         $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
         $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
         $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
-        $dbman->create_table($table, true, false);
+        $dbman->create_table($table);
 
         $enums = array('single', 'news', 'general');
 
         /// Create a new field with complex specs (enums are good candidates)
         $field = new xmldb_field('type1');
         $field->set_attributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, XMLDB_ENUM, $enums, 'general', 'course');
-        $this->assertTrue($dbman->add_field($table, $field));
+        $dbman->add_field($table, $field);
         $this->assertTrue($dbman->field_exists($table, 'type1'));
 
         $field = new xmldb_field('type2');
         $field->set_attributes(XMLDB_TYPE_CHAR, '20', null, null, null, XMLDB_ENUM, $enums, 'general', 'course');
-        $this->assertTrue($dbman->add_field($table, $field));
+        $dbman->add_field($table, $field);
         $this->assertTrue($dbman->field_exists($table, 'type2'));
 
         /// try inserting a good record
@@ -263,7 +243,7 @@ class ddl_test extends UnitTestCase {
         /// Create a new field with complex specs (enums are good candidates)
         $field = new xmldb_field('onenumber');
         $field->set_attributes(XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, 0, 'type');
-        $this->assertTrue($dbman->add_field($table, $field));
+        $dbman->add_field($table, $field);
         $this->assertTrue($dbman->field_exists($table, 'onenumber'));
 
         $columns = $DB->get_columns('test_table0');
@@ -281,7 +261,7 @@ class ddl_test extends UnitTestCase {
         $this->assertTrue($dbman->field_exists($table, $field));
         $this->assertTrue($dbman->field_exists($table, 'type'));
 
-        $this->assertTrue($dbman->drop_field($table, $field));
+        $dbman->drop_field($table, $field);
 
         $this->assertFalse($dbman->field_exists($table, 'type'));
     }
@@ -294,7 +274,7 @@ class ddl_test extends UnitTestCase {
         $table->add_field('id', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
         $table->add_field('onenumber', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
         $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
-        $dbman->create_table($table, true, false);
+        $dbman->create_table($table);
 
         $record = new object();
         $recorf->course = 2;
@@ -302,47 +282,47 @@ class ddl_test extends UnitTestCase {
 
         $field = new xmldb_field('onenumber');
         $field->set_attributes(XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, '0');
-        $this->assertTrue($dbman->change_field_type($table, $field));
+        $dbman->change_field_type($table, $field);
 
         $columns = $DB->get_columns('test_table_cust0');
         $this->assertEqual($columns['onenumber']->meta_type, 'C');
 
         $field = new xmldb_field('onenumber');
         $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
-        $this->assertTrue($dbman->change_field_type($table, $field));
+        $dbman->change_field_type($table, $field);
 
         $columns = $DB->get_columns('test_table_cust0');
         $this->assertEqual($columns['onenumber']->meta_type, 'I');
 
         $field = new xmldb_field('onenumber');
         $field->set_attributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, "test'n drop");
-        $this->assertTrue($dbman->change_field_type($table, $field));
+        $dbman->change_field_type($table, $field);
 
         $columns = $DB->get_columns('test_table_cust0');
         $this->assertEqual($columns['onenumber']->meta_type, 'C');
 
         $field = new xmldb_field('onenumber');
         $field->set_attributes(XMLDB_TYPE_FLOAT, '20,10', XMLDB_UNSIGNED, null, null, null, null, null);
-        $this->assertTrue($dbman->change_field_type($table, $field));
+        $dbman->change_field_type($table, $field);
 
         $columns = $DB->get_columns('test_table_cust0');
         $this->assertEqual($columns['onenumber']->meta_type, 'N');
 
         $field = new xmldb_field('onenumber');
         $field->set_attributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, 'test');
-        $this->assertTrue($dbman->change_field_type($table, $field));
+        $dbman->change_field_type($table, $field);
 
         $columns = $DB->get_columns('test_table_cust0');
         $this->assertEqual($columns['onenumber']->meta_type, 'C');
 
         $field = new xmldb_field('onenumber');
         $field->set_attributes(XMLDB_TYPE_NUMBER, '20,10', XMLDB_UNSIGNED, null, null, null, null, null);
-        $this->assertTrue($dbman->change_field_type($table, $field));
+        $dbman->change_field_type($table, $field);
 
         $columns = $DB->get_columns('test_table_cust0');
         $this->assertEqual($columns['onenumber']->meta_type, 'N');
 
-        $dbman->drop_table($table, true, false);
+        $dbman->drop_table($table);
     }
 
     public function testChangeFieldPrecision() {
@@ -352,19 +332,19 @@ class ddl_test extends UnitTestCase {
         $table = $this->create_deftable('test_table1');
         $field = new xmldb_field('intro');
         $field->set_attributes(XMLDB_TYPE_TEXT, 'big', null, XMLDB_NOTNULL, null, null, null, null);
-        $this->assertTrue($dbman->change_field_precision($table, $field));
+        $dbman->change_field_precision($table, $field);
 
         $field = new xmldb_field('secondname');
         $field->set_attributes(XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null, null, null);
-        $this->assertTrue($dbman->change_field_precision($table, $field));
+        $dbman->change_field_precision($table, $field);
 
         $field = new xmldb_field('grade');
         $field->set_attributes(XMLDB_TYPE_NUMBER, '10,2', null, null, null, null, null, null);
-        $this->assertTrue($dbman->change_field_precision($table, $field));
+        $dbman->change_field_precision($table, $field);
 
         $field = new xmldb_field('course');
         $field->set_attributes(XMLDB_TYPE_INTEGER, '5', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
-        $this->assertTrue($dbman->change_field_precision($table, $field));
+        $dbman->change_field_precision($table, $field);
 
     }
 
@@ -375,11 +355,11 @@ class ddl_test extends UnitTestCase {
         $table = $this->create_deftable('test_table1');
         $field = new xmldb_field('grade');
         $field->set_attributes(XMLDB_TYPE_NUMBER, '10,2', XMLDB_UNSIGNED, null, null, null, null, null);
-        $this->assertTrue($dbman->change_field_unsigned($table, $field));
+        $dbman->change_field_unsigned($table, $field);
 
         $field = new xmldb_field('grade');
         $field->set_attributes(XMLDB_TYPE_NUMBER, '10,2', null, null, null, null, null, null);
-        $this->assertTrue($dbman->change_field_unsigned($table, $field));
+        $dbman->change_field_unsigned($table, $field);
     }
 
     public function testChangeFieldNullability() {
@@ -390,7 +370,7 @@ class ddl_test extends UnitTestCase {
         $table->add_field('id', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
         $table->add_field('name', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, null);
         $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
-        $dbman->create_table($table, true, false);
+        $dbman->create_table($table);
 
         $record = new object();
         $record->name = NULL;
@@ -402,7 +382,7 @@ class ddl_test extends UnitTestCase {
 
         $field = new xmldb_field('name');
         $field->set_attributes(XMLDB_TYPE_CHAR, '30', null, null, null, null, null, null);
-        $this->assertTrue($dbman->change_field_notnull($table, $field));
+        $dbman->change_field_notnull($table, $field);
 
         $this->assertTrue($DB->insert_record('test_table_cust0', $record, false));
 
@@ -411,14 +391,14 @@ class ddl_test extends UnitTestCase {
 
         $field = new xmldb_field('name');
         $field->set_attributes(XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, null);
-        $this->assertTrue($dbman->change_field_notnull($table, $field));
+        $dbman->change_field_notnull($table, $field);
 
         ob_start(); // hide debug warning
         $result = $DB->insert_record('test_table_cust0', $record, false);
         ob_end_clean();
         $this->assertFalse($result);
 
-        $dbman->drop_table($table, true, false);
+        $dbman->drop_table($table);
     }
 
     public function testChangeFieldDefault() {
@@ -430,11 +410,11 @@ class ddl_test extends UnitTestCase {
         $table->add_field('number', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
         $table->add_field('name', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, 'Moodle');
         $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
-        $dbman->create_table($table, true, false);
+        $dbman->create_table($table);
 
         $field = new xmldb_field('name');
         $field->set_attributes(XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, 'Moodle2');
-        $this->assertTrue($dbman->change_field_default($table, $field));
+        $dbman->change_field_default($table, $field);
 
         $record = new object();
         $record->number = 666;
@@ -446,7 +426,7 @@ class ddl_test extends UnitTestCase {
 
         $field = new xmldb_field('number');
         $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, 666);
-        $this->assertTrue($dbman->change_field_default($table, $field));
+        $dbman->change_field_default($table, $field);
 
         $record = new object();
         $record->name = 'something';
@@ -455,7 +435,7 @@ class ddl_test extends UnitTestCase {
         $record = $DB->get_record('test_table_cust0', array('id'=>$id));
         $this->assertEqual($record->number, '666');
 
-        $dbman->drop_table($table, true, false);
+        $dbman->drop_table($table);
     }
 
     public function testAddUniqueIndex() {
@@ -467,7 +447,7 @@ class ddl_test extends UnitTestCase {
         $table->add_field('number', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
         $table->add_field('name', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, 'Moodle');
         $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
-        $dbman->create_table($table, true, false);
+        $dbman->create_table($table);
 
         $record = new object();
         $record->number = 666;
@@ -476,14 +456,14 @@ class ddl_test extends UnitTestCase {
 
         $index = new xmldb_index('number-name');
         $index->set_attributes(XMLDB_INDEX_UNIQUE, array('number', 'name'));
-        $this->assertTrue($dbman->add_index($table, $index));
+        $dbman->add_index($table, $index);
 
         ob_start(); // hide debug warning
         $result = $DB->insert_record('test_table_cust0', $record, false);
         ob_end_clean();
         $this->assertFalse($result);
 
-        $dbman->drop_table($table, true, false);
+        $dbman->drop_table($table);
     }
 
     public function testAddNonUniqueIndex() {
@@ -492,7 +472,7 @@ class ddl_test extends UnitTestCase {
         $table = $this->create_deftable('test_table1');
         $index = new xmldb_index('secondname');
         $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('course', 'name'));
-        $this->assertTrue($dbman->add_index($table, $index));
+        $dbman->add_index($table, $index);
     }
 
     public function testFindIndexName() {
@@ -520,7 +500,7 @@ class ddl_test extends UnitTestCase {
         $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('course', 'name'));
         $dbman->add_index($table, $index);
 
-        $this->assertTrue($dbman->drop_index($table, $index));
+        $dbman->drop_index($table, $index);
         $this->assertFalse($dbman->find_index_name($table, $index));
     }
 
@@ -530,7 +510,7 @@ class ddl_test extends UnitTestCase {
         $table = $this->create_deftable('test_table1');
         $key = new xmldb_key('id-course-grade');
         $key->set_attributes(XMLDB_KEY_UNIQUE, array('id', 'course', 'grade'));
-        $this->assertTrue($dbman->add_key($table, $key));
+        $dbman->add_key($table, $key);
     }
 
     public function testAddForeignUniqueKey() {
@@ -541,7 +521,7 @@ class ddl_test extends UnitTestCase {
 
         $key = new xmldb_key('course');
         $key->set_attributes(XMLDB_KEY_FOREIGN_UNIQUE, array('course'), 'test_table0', array('id'));
-        $this->assertTrue($dbman->add_key($table, $key));
+        $dbman->add_key($table, $key);
     }
 
     public function testDropKey() {
@@ -554,7 +534,7 @@ class ddl_test extends UnitTestCase {
         $key->set_attributes(XMLDB_KEY_FOREIGN_UNIQUE, array('course'), 'test_table0', array('id'));
         $dbman->add_key($table, $key);
 
-        $this->assertTrue($dbman->drop_key($table, $key));
+        $dbman->drop_key($table, $key);
     }
 
     public function testAddForeignKey() {
@@ -565,7 +545,7 @@ class ddl_test extends UnitTestCase {
 
         $key = new xmldb_key('course');
         $key->set_attributes(XMLDB_KEY_FOREIGN, array('course'), 'test_table0', array('id'));
-        $this->assertTrue($dbman->add_key($table, $key));
+        $dbman->add_key($table, $key);
     }
 
     public function testDropForeignKey() {
@@ -578,7 +558,7 @@ class ddl_test extends UnitTestCase {
         $key->set_attributes(XMLDB_KEY_FOREIGN, array('course'), 'test_table0', array('id'));
         $dbman->add_key($table, $key);
 
-        $this->assertTrue($dbman->drop_key($table, $key));
+        $dbman->drop_key($table, $key);
     }
 
     public function testChangeFieldEnum() {
@@ -590,12 +570,12 @@ class ddl_test extends UnitTestCase {
         $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
         $table->add_field('type', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, XMLDB_ENUM, array('single', 'news', 'general'), 'general');
         $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
-        $dbman->create_table($table, true, false);
+        $dbman->create_table($table);
 
         // Removing an enum value
         $field = new xmldb_field('type');
         $field->set_attributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null);
-        $this->assertTrue($dbman->change_field_enum($table, $field));
+        $dbman->change_field_enum($table, $field);
 
         $record = new object();
         $record->course = 666;
@@ -605,7 +585,7 @@ class ddl_test extends UnitTestCase {
         // Adding an enum value
         $field = new xmldb_field('type');
         $field->set_attributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, XMLDB_ENUM, array('single', 'news', 'general', 'social', 'eachuser', 'teacher', 'qanda'), 'general', 'course');
-        $this->assertTrue($dbman->change_field_enum($table, $field));
+        $dbman->change_field_enum($table, $field);
 
         $record = new object();
         $record->course = 666;
@@ -616,7 +596,7 @@ class ddl_test extends UnitTestCase {
         ob_end_clean();
         $this->assertFalse($result);
 
-        $dbman->drop_table($table, true, false);
+        $dbman->drop_table($table);
     }
 
     public function testRenameField() {
@@ -628,7 +608,7 @@ class ddl_test extends UnitTestCase {
         $field->set_attributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, XMLDB_ENUM,
                 array('single', 'news', 'general', 'social', 'eachuser', 'teacher', 'qanda'), 'general', 'course');
 
-        $this->assertTrue($dbman->rename_field($table, $field, 'newfieldname'));
+        $dbman->rename_field($table, $field, 'newfieldname');
 
         $columns = $DB->get_columns('test_table0');
 
@@ -642,7 +622,7 @@ class ddl_test extends UnitTestCase {
         $table = $this->create_deftable('test_table0');
 
         $this->assertFalse($dbman->table_exists('test_table_cust0'));
-        $this->assertTrue($dbman->rename_table($table, 'test_table_cust0'));
+        $dbman->rename_table($table, 'test_table_cust0');
         $this->assertTrue($dbman->table_exists('test_table_cust0'));
 
         $table->setName('test_table_cust0');
@@ -655,7 +635,12 @@ class ddl_test extends UnitTestCase {
         $table = $this->create_deftable('test_table0');
         // String params
         // Give a nonexistent table as first param
-        $this->assertFalse($dbman->field_exists('nonexistenttable', 'id'));
+        try {
+            $dbman->field_exists('nonexistenttable', 'id');
+            $this->assertTrue(false);
+        } catch (Exception $e) {
+            $this->assertTrue($e instanceof moodle_exception);
+        }
 
         // Give a nonexistent field as second param
         $this->assertFalse($dbman->field_exists('test_table0', 'nonexistentfield'));
@@ -668,7 +653,12 @@ class ddl_test extends UnitTestCase {
 
         // Give a nonexistent table as first param
         $nonexistenttable = new xmldb_table('nonexistenttable');
-        $this->assertFalse($dbman->field_exists($nonexistenttable, $realfield));
+        try {
+            $dbman->field_exists($nonexistenttable, $realfield);
+            $this->assertTrue(false);
+        } catch (Exception $e) {
+            $this->assertTrue($e instanceof moodle_exception);
+        }
 
         // Give a nonexistent field as second param
         $nonexistentfield = new xmldb_field('nonexistentfield');
@@ -704,12 +694,6 @@ class ddl_test extends UnitTestCase {
 
         $table = $this->create_deftable('test_table0');
         $key = $table->getKey('primary');
-        $invalid_key = 'invalid_key';
-
-        ob_start(); // hide debug warning
-        $result = $dbman->find_key_name($table, $invalid_key);
-        ob_end_clean();
-        $this->assertFalse($result);
 
         // With Mysql, the return value is actually "mdl_test_id_pk"
         $result = $dbman->find_key_name($table, $key);
@@ -719,19 +703,14 @@ class ddl_test extends UnitTestCase {
     public function testFindSequenceName() {
         $dbman = $this->tdb->get_manager();
 
-        // give invalid table param
-        $table = 'invalid_table';
-        ob_start(); // hide debug warning
-        $result = $dbman->find_sequence_name($table);
-        ob_end_clean();
-        $this->assertFalse($result);
-
         // give nonexistent table param
         $table = new xmldb_table("nonexistenttable");
-        ob_start(); // hide debug warning
-        $result = $dbman->find_sequence_name($table);
-        ob_end_clean();
-        $this->assertFalse($result);
+        try {
+            $dbman->find_sequence_name($table);
+            $this->assertTrue(false);
+        } catch (Exception $e) {
+            $this->assertTrue($e instanceof moodle_exception);
+        }
 
         // Give existing and valid table param
         $table = $this->create_deftable('test_table0');
@@ -749,22 +728,32 @@ class ddl_test extends UnitTestCase {
         $this->assertTrue($dbman->table_exists('test_table1'));
 
         // feed nonexistent file
-        ob_start(); // hide debug warning
-        $result = $dbman->delete_tables_from_xmldb_file('fpsoiudfposui', false);
-        ob_end_clean();
-        $this->assertFalse($result);
+        try {
+            ob_start(); // hide debug warning
+            $dbman->delete_tables_from_xmldb_file('fpsoiudfposui');
+            ob_end_clean();
+            $this->assertTrue(false);
+        } catch (Exception $e) {
+            ob_end_clean();
+            $this->assertTrue($e instanceof moodle_exception);
+        }
 
         // Real file but invalid xml file
-        ob_start(); // hide debug warning
-        $result = $dbman->delete_tables_from_xmldb_file($CFG->libdir . '/ddl/simpletest/fixtures/invalid.xml', false);
-        ob_end_clean();
-        $this->assertFalse($result);
+        try {
+            ob_start(); // hide debug warning
+            $dbman->delete_tables_from_xmldb_file($CFG->libdir . '/ddl/simpletest/fixtures/invalid.xml');
+            $this->assertTrue(false);
+            ob_end_clean();
+        } catch (Exception $e) {
+            ob_end_clean();
+            $this->assertTrue($e instanceof moodle_exception);
+        }
 
         // Check that the table has not been deleted from DB
         $this->assertTrue($dbman->table_exists('test_table1'));
 
         // Real and valid xml file
-        $this->assertTrue($dbman->delete_tables_from_xmldb_file($CFG->libdir . '/ddl/simpletest/fixtures/xmldb_table.xml', false));
+        $dbman->delete_tables_from_xmldb_file($CFG->libdir . '/ddl/simpletest/fixtures/xmldb_table.xml');
 
         // Check that the table has been deleted from DB
         $this->assertFalse($dbman->table_exists('test_table1'));
@@ -775,42 +764,46 @@ class ddl_test extends UnitTestCase {
         $dbman = $this->tdb->get_manager();
 
         // feed nonexistent file
-        ob_start(); // hide debug warning
-        $result = $dbman->install_from_xmldb_file('fpsoiudfposui', false);
-        ob_end_clean();
-        $this->assertFalse($result);
+        try {
+            ob_start(); // hide debug warning
+            $dbman->install_from_xmldb_file('fpsoiudfposui');
+            ob_end_clean();
+            $this->assertTrue(false);
+        } catch (Exception $e) {
+            ob_end_clean();
+            $this->assertTrue($e instanceof moodle_exception);
+        }
 
         // Real but invalid xml file
-        ob_start(); // hide debug warning
-        $result = $dbman->install_from_xmldb_file($CFG->libdir.'/ddl/simpletest/fixtures/invalid.xml', false);
-        ob_end_clean();
-        $this->assertFalse($result);
+        try {
+            ob_start(); // hide debug warning
+            $dbman->install_from_xmldb_file($CFG->libdir.'/ddl/simpletest/fixtures/invalid.xml');
+            ob_end_clean();
+            $this->assertTrue(false);
+        } catch (Exception $e) {
+            ob_end_clean();
+            $this->assertTrue($e instanceof moodle_exception);
+        }
 
         // Check that the table has not yet been created in DB
         $this->assertFalse($dbman->table_exists('test_table1'));
 
         // Real and valid xml file
-        $this->assertTrue($dbman->install_from_xmldb_file($CFG->libdir.'/ddl/simpletest/fixtures/xmldb_table.xml', false));
+        $dbman->install_from_xmldb_file($CFG->libdir.'/ddl/simpletest/fixtures/xmldb_table.xml');
         $this->assertTrue($dbman->table_exists('test_table1'));
     }
 
     public function testCreateTempTable() {
         $dbman = $this->tdb->get_manager();
 
-        // Feed incorrect table param
-        ob_start(); // hide debug warning
-        $result = $dbman->create_temp_table('test_table1');
-        ob_end_clean();
-        $this->assertFalse($result);
-
         $table = $this->tables['test_table1'];
 
         // New table
-        $this->assertTrue($dbman->create_temp_table($table));
+        $dbman->create_temp_table($table);
         $this->assertTrue($dbman->table_exists('test_table1', true));
 
         // Delete
-        $this->assertTrue($dbman->drop_temp_table($table));
+        $dbman->drop_temp_table($table);
         $this->assertFalse($dbman->table_exists('test_table1', true));
     }
 
index 787944384a1c52c100ea9ddb2bc80f368d7aa304..fdc76f9568b7a15e0d04e1d082c1342576d31896 100644 (file)
@@ -442,7 +442,7 @@ function error($message, $link='') {
         throw new moodle_exception('notlocalisederrormessage', 'error', $link, $message);
     }
 
-    _print_normal_error('notlocalisederrormessage', 'error', $message, $link, debug_backtrace(), true); // show debug warning
+    _print_normal_error('notlocalisederrormessage', 'error', $message, $link, debug_backtrace(), null, true); // show debug warning
 }
 
 
@@ -496,124 +496,144 @@ function find_sequence_name($table) {
     return $DB->get_manager()->find_sequence_name($table);
 }
 
-function drop_table($table, $continue=true, $feedback=true) {
+function drop_table($table) {
     global $DB;
     debugging('Deprecated ddllib function used!');
-    return $DB->get_manager()->drop_table($table, $continue, $feedback);
+    $DB->get_manager()->drop_table($table);
+    return true;
 }
 
 function install_from_xmldb_file($file) {
     global $DB;
     debugging('Deprecated ddllib function used!');
-    return $DB->get_manager()->install_from_xmldb_file($file);
+    $DB->get_manager()->install_from_xmldb_file($file);
+    return true;
 }
 
-function create_table($table, $continue=true, $feedback=true) {
+function create_table($table) {
     global $DB;
     debugging('Deprecated ddllib function used!');
-    return $DB->get_manager()->create_table($table, $continue, $feedback);
+    $DB->get_manager()->create_table($table);
+    return true;
 }
 
-function create_temp_table($table, $continue=true, $feedback=true) {
+function create_temp_table($table) {
     global $DB;
     debugging('Deprecated ddllib function used!');
-    return $DB->get_manager()->create_temp_table($table, $continue, $feedback);
+    $DB->get_manager()->create_temp_table($table);
+    return true;
 }
 
-function rename_table($table, $newname, $continue=true, $feedback=true) {
+function rename_table($table, $newname) {
     global $DB;
     debugging('Deprecated ddllib function used!');
-    return $DB->get_manager()->rename_table($table, $newname, $continue, $feedback);
+    $DB->get_manager()->rename_table($table, $newname);
+    return true;
 }
 
-function add_field($table, $field, $continue=true, $feedback=true) {
+function add_field($table, $field) {
     global $DB;
     debugging('Deprecated ddllib function used!');
-    return $DB->get_manager()->add_field($table, $field, $continue, $feedback);
+    $DB->get_manager()->add_field($table, $field);
+    return true;
 }
 
-function drop_field($table, $field, $continue=true, $feedback=true) {
+function drop_field($table, $field) {
     global $DB;
     debugging('Deprecated ddllib function used!');
-    return $DB->get_manager()->drop_field($table, $field, $continue, $feedback);
+    $DB->get_manager()->drop_field($table, $field);
+    return true;
 }
 
-function change_field_type($table, $field, $continue=true, $feedback=true) {
+function change_field_type($table, $field) {
     global $DB;
     debugging('Deprecated ddllib function used!');
-    return $DB->get_manager()->change_field_type($table, $field, $continue, $feedback);
+    $DB->get_manager()->change_field_type($table, $field);
+    return true;
 }
 
-function change_field_precision($table, $field, $continue=true, $feedback=true) {
+function change_field_precision($table, $field) {
     global $DB;
     debugging('Deprecated ddllib function used!');
-    return $DB->get_manager()->change_field_precision($table, $field, $continue, $feedback);
+    $DB->get_manager()->change_field_precision($table, $field);
+    return true;
 }
 
-function change_field_unsigned($table, $field, $continue=true, $feedback=true) {
+function change_field_unsigned($table, $field) {
     global $DB;
     debugging('Deprecated ddllib function used!');
-    return $DB->get_manager()->change_field_unsigned($table, $field, $continue, $feedback);
+    $DB->get_manager()->change_field_unsigned($table, $field);
+    return true;
 }
 
-function change_field_notnull($table, $field, $continue=true, $feedback=true) {
+function change_field_notnull($table, $field) {
     global $DB;
     debugging('Deprecated ddllib function used!');
-    return $DB->get_manager()->change_field_notnull($table, $field, $continue, $feedback);
+    $DB->get_manager()->change_field_notnull($table, $field);
+    return true;
 }
 
-function change_field_enum($table, $field, $continue=true, $feedback=true) {
+function change_field_enum($table, $field) {
     global $DB;
     debugging('Deprecated ddllib function used!');
-    return $DB->get_manager()->change_field_enum($table, $field, $continue, $feedback);
+    $DB->get_manager()->change_field_enum($table, $field);
+    return true;
 }
 
-function change_field_default($table, $field, $continue=true, $feedback=true) {
+function change_field_default($table, $field) {
     global $DB;
     debugging('Deprecated ddllib function used!');
-    return $DB->get_manager()->change_field_default($table, $field, $continue, $feedback);
+    $DB->get_manager()->change_field_default($table, $field);
+    return true;
 }
 
-function rename_field($table, $field, $newname, $continue=true, $feedback=true) {
+function rename_field($table, $field, $newname) {
     global $DB;
     debugging('Deprecated ddllib function used!');
-    return $DB->get_manager()->rename_field($table, $field, $continue, $feedback);
+    $DB->get_manager()->rename_field($table, $field);
+    return true;
 }
 
-function add_key($table, $key, $continue=true, $feedback=true) {
+function add_key($table, $key) {
     global $DB;
     debugging('Deprecated ddllib function used!');
-    return $DB->get_manager()->add_key($table, $key, $continue, $feedback);
+    $DB->get_manager()->add_key($table, $key);
+    return true;
 }
 
-function drop_key($table, $key, $continue=true, $feedback=true) {
+function drop_key($table, $key) {
     global $DB;
     debugging('Deprecated ddllib function used!');
-    return $DB->get_manager()->drop_key($table, $key, $continue, $feedback);
+    $DB->get_manager()->drop_key($table, $key);
+    return true;
 }
 
-function rename_key($table, $key, $newname, $continue=true, $feedback=true) {
+function rename_key($table, $key, $newname) {
     global $DB;
     debugging('Deprecated ddllib function used!');
-    return $DB->get_manager()->rename_key($table, $key, $newname, $continue, $feedback);
+    $DB->get_manager()->rename_key($table, $key, $newname);
+    return true;
 }
 
-function add_index($table, $index, $continue=true, $feedback=true) {
+function add_index($table, $index) {
     global $DB;
     debugging('Deprecated ddllib function used!');
-    return $DB->get_manager()->add_index($table, $index, $continue, $feedback);
+    $DB->get_manager()->add_index($table, $index);
+    return true;
 }
 
-function drop_index($table, $index, $continue=true, $feedback=true) {
+function drop_index($table, $index) {
     global $DB;
     debugging('Deprecated ddllib function used!');
-    return $DB->get_manager()->drop_index($table, $index, $continue, $feedback);
+    $DB->get_manager()->drop_index($table, $index);
+    return true;
 }
 
-function rename_index($table, $index, $newname, $continue=true, $feedback=true) {
+function rename_index($table, $index, $newname) {
     global $DB;
     debugging('Deprecated ddllib function used!');
-    return $DB->get_manager()->rename_index($table, $index, $newname, $continue, $feedback);
+    $DB->get_manager()->rename_index($table, $index, $newname);
+    return true;
 }
 
 
index 19fca53ec82baded60b5550c833090d66b1ee30c..c8b4042c0a0d68ee1c9841ea700954899af83e13 100644 (file)
@@ -163,7 +163,7 @@ abstract class adodb_moodle_database extends moodle_database {
                         $column->enums[$key] = substr($value, 1, strlen($value)-2);
                     }
                 }
-            } 
+            }
             $this->columns[$table][$column->name] = new database_column_info($column);
         }
 
@@ -179,7 +179,9 @@ abstract class adodb_moodle_database extends moodle_database {
      * @param bool $state
      */
     public function set_debug($state) {
-        $this->adodb->debug = $state;
+        if ($this->adodb) {
+            $this->adodb->debug = $state;
+        }
     }
 
     /**
index 118480028440e8e1e367b6a06f507db7ca1d8f08..0ccbadd59eb7bf46e13afd9aa6356ded8d90fbcc 100755 (executable)
@@ -29,7 +29,7 @@ class dml_test extends UnitTestCase {
 
         foreach ($this->tables as $table) {
             if ($dbman->table_exists($table)) {
-                $dbman->drop_table($table, true, false);
+                $dbman->drop_table($table);
             }
         }
         $this->tables = array();
index 928f9487ea2335e3dd9f938ea8209aa107e0f79e..7e2e0f0ccc909b32d48948e77ad4168d1ff385b7 100644 (file)
@@ -96,8 +96,8 @@
    
 
     var checkWarnings = function() {
-        // look for div tags with the class name notifyproblem
-        warnings = filterNodesByClassName(document.getElementsByTagName('div'), /(^|\b)notifyproblem(\b|$)/);
+        // look for div tags with the class name notifyproblem or error box
+        warnings = filterNodesByClassName(document.getElementsByTagName('div'), /((^|\b)notifyproblem(\b|$))|errorbox/);
         // and find the continue button
         continueBtn = filterNodesByClassName(document.getElementsByTagName('div'), /(^|\b)continuebutton(\b|$)/, true);
                 
index b4bd86dc29de04a46de133bcd5f74e727963a461..61a5220f8e06250a2162b69794232466c3ecd3c9 100644 (file)
@@ -17,6 +17,7 @@ class moodle_exception extends Exception {
     public $module;
     public $a;
     public $link;
+    public $debuginfo;
 
     /**
      * Constructor
@@ -24,8 +25,9 @@ class moodle_exception extends Exception {
      * @param string $module name of module
      * @param string $link The url where the user will be prompted to continue. If no url is provided the user will be directed to the site index page.
      * @param object $a Extra words and phrases that might be required in the error string
+     * @param string $debuginfo optional debugging information
      */
-    function __construct($errorcode, $module='', $link='', $a=NULL) {
+    function __construct($errorcode, $module='', $link='', $a=NULL, $debuginfo=null) {
         if (empty($module) || $module == 'moodle' || $module == 'core') {
             $module = 'error';
         }
@@ -34,6 +36,7 @@ class moodle_exception extends Exception {
         $this->module    = $module;
         $this->link      = $link;
         $this->a         = $a;
+        $this->debuginfo = $debuginfo;
 
         $message = get_string($errorcode, $module, $a);
 
@@ -45,12 +48,19 @@ class moodle_exception extends Exception {
  * Default exception handler, uncought exceptions are equivalent to using print_error()
  */
 function default_exception_handler($ex) {
+    global $DB;
+
+    if ($DB) {
+        //if you enable db debugging and exception is thrown, the print footer prints a lot of rubbish
+        $DB->set_debug(0);
+    }
+
     $backtrace = $ex->getTrace();
     $place = array('file'=>$ex->getFile(), 'line'=>$ex->getLine(), 'exception'=>get_class($ex));
     array_unshift($backtrace, $place);
 
     if ($ex instanceof moodle_exception) {
-        _print_normal_error($ex->errorcode, $ex->module, $ex->a, $ex->link, $backtrace);
+        _print_normal_error($ex->errorcode, $ex->module, $ex->a, $ex->link, $backtrace, $ex->debuginfo);
     } else {
         _print_normal_error('generalexceptionmessage', 'error', $ex->getMessage(), '', $backtrace);
     }
index b0645054b39f3f3babd9c90f37032a1429769807..a7fed55103988a7a02e4a9417e0c9698bc705872 100644 (file)
@@ -151,9 +151,9 @@ class grade_test extends UnitTestCase {
             $table->add_index('idnumber-course', XMLDB_INDEX_NOTUNIQUE, array('idnumber', 'course'));
 
             /// Launch create table for course_modules
-            $result = $result && $this->dbmanager->create_table($table, true, false);
+            $this->dbmanager->create_table($table);
         } else {
-            $DB->delete_records($table->name, array());
+            $DB->delete_records($table->name, null);
         }
 
         /// Define table modules to be created
@@ -177,9 +177,9 @@ class grade_test extends UnitTestCase {
             $table->add_index('name', XMLDB_INDEX_NOTUNIQUE, array('name'));
 
             /// Launch create table for modules
-            $result = $result && $this->dbmanager->create_table($table, true, false);
+            $this->dbmanager->create_table($table);
         } else {
-            $DB->delete_records($table->name, array());
+            $DB->delete_records($table->name, null);
         }
 
         /// Define table grade_items to be created
@@ -223,10 +223,10 @@ class grade_test extends UnitTestCase {
             $table->add_key('outcomeid', XMLDB_KEY_FOREIGN, array('outcomeid'), 'grade_outcomes', array('id'));
 
             /// Launch create table for grade_items
-            $result = $result && $this->dbmanager->create_table($table, true, false);
+            $this->dbmanager->create_table($table);
 
         } else {
-            $DB->delete_records($table->name, array());
+            $DB->delete_records($table->name, null);
         }
 
 
@@ -255,10 +255,10 @@ class grade_test extends UnitTestCase {
             $table->add_key('parent', XMLDB_KEY_FOREIGN, array('parent'), 'grade_categories', array('id'));
 
             /// Launch create table for grade_categories
-            $result = $result && $this->dbmanager->create_table($table, true, false);
+            $this->dbmanager->create_table($table);
 
         } else {
-            $DB->delete_records($table->name, array());
+            $DB->delete_records($table->name, null);
         }
 
 
@@ -296,10 +296,10 @@ class grade_test extends UnitTestCase {
             $table->add_key('usermodified', XMLDB_KEY_FOREIGN, array('usermodified'), 'user', array('id'));
 
             /// Launch create table for grade_grades
-            $result = $result && $this->dbmanager->create_table($table, true, false);
+            $this->dbmanager->create_table($table);
 
         } else {
-            $DB->delete_records($table->name, array());
+            $DB->delete_records($table->name, null);
         }
 
 
@@ -325,10 +325,10 @@ class grade_test extends UnitTestCase {
             $table->add_key('usermodified', XMLDB_KEY_FOREIGN, array('usermodified'), 'user', array('id'));
 
             /// Launch create table for grade_outcomes
-            $result = $result && $this->dbmanager->create_table($table, true, false);
+            $this->dbmanager->create_table($table);
 
         } else {
-            $DB->delete_records($table->name, array());
+            $DB->delete_records($table->name, null);
         }
 
 
@@ -348,10 +348,10 @@ class grade_test extends UnitTestCase {
             $table->add_index('courseid', XMLDB_INDEX_NOTUNIQUE, array('courseid'));
 
             /// Launch create table for scale
-            $result = $result && $this->dbmanager->create_table($table, true, false);
+            $this->dbmanager->create_table($table);
 
         } else {
-            $DB->delete_records($table->name, array());
+            $DB->delete_records($table->name, null);
         }
 
         /// Define table quiz to be created
@@ -394,9 +394,9 @@ class grade_test extends UnitTestCase {
             $table->add_index('course', XMLDB_INDEX_NOTUNIQUE, array('course'));
 
             /// Launch create table for quiz
-            $result = $result && $this->dbmanager->create_table($table, true, false);
+            $this->dbmanager->create_table($table);
         } else {
-            $DB->delete_records($table->name, array());
+            $DB->delete_records($table->name, null);
         }
 
         return $result;
@@ -457,10 +457,10 @@ class grade_test extends UnitTestCase {
             $table->add_index('action', XMLDB_INDEX_NOTUNIQUE, array('action'));
 
         /// Launch create table for grade_items_history
-            $result = $result && $this->dbmanager->create_table($table, true, false);
+            $this->dbmanager->create_table($table);
 
         } else {
-            $DB->delete_records($table->name, array());
+            $DB->delete_records($table->name, null);
         }
 
         /// Define table grade_categories to be created
@@ -498,10 +498,10 @@ class grade_test extends UnitTestCase {
             $table->add_index('action', XMLDB_INDEX_NOTUNIQUE, array('action'));
 
         /// Launch create table for grade_categories_history
-            $result = $result && $this->dbmanager->create_table($table, true, false);
+            $this->dbmanager->create_table($table);
 
         } else {
-            $DB->delete_records($table->name, array());
+            $DB->delete_records($table->name, null);
         }
 
 
@@ -549,10 +549,10 @@ class grade_test extends UnitTestCase {
             $table->add_index('action', XMLDB_INDEX_NOTUNIQUE, array('action'));
 
         /// Launch create table for grade_grades_history
-            $result = $result && $this->dbmanager->create_table($table, true, false);
+            $this->dbmanager->create_table($table);
 
         } else {
-            $DB->delete_records($table->name, array());
+            $DB->delete_records($table->name, null);
         }
 
 
@@ -584,10 +584,10 @@ class grade_test extends UnitTestCase {
             $table->add_index('action', XMLDB_INDEX_NOTUNIQUE, array('action'));
 
         /// Launch create table for grade_outcomes_history
-            $result = $result && $this->dbmanager->create_table($table, true, false);
+            $this->dbmanager->create_table($table);
 
         } else {
-            $DB->delete_records($table->name, array());
+            $DB->delete_records($table->name, null);
         }
 
         /// Define table scale to be created
@@ -618,10 +618,10 @@ class grade_test extends UnitTestCase {
             $table->add_index('action', XMLDB_INDEX_NOTUNIQUE, array('action'));
 
         /// Launch create table for scale_history
-            $result = $result && $this->dbmanager->create_table($table, true, false);
+            $this->dbmanager->create_table($table);
 
         } else {
-            $DB->delete_records($table->name, array());
+            $DB->delete_records($table->name, null);
         }
 
         return $result;
index e2fcaa0f1b6978411776ffb9f2736d67e118956c..cc53ab82d5366e0f8d2e80845a24204cbd1b9be4 100644 (file)
@@ -1042,7 +1042,7 @@ function print_textfield ($name, $value, $alt = '',$size=50,$maxlength=0, $retur
 function popup_form($common, $options, $formid, $selected='', $nothing='choose', $help='', $helptext='', $return=false,
 $targetwindow='self', $selectlabel='', $optionsextra=NULL) {
 
-    global $CFG;
+    global $CFG, $SESSION;
     static $go, $choose;   /// Locally cached, in case there's lots on a page
 
     if (empty($options)) {
@@ -1127,7 +1127,7 @@ $targetwindow='self', $selectlabel='', $optionsextra=NULL) {
         } else {
            if (!empty($CFG->usesid) && !isset($_COOKIE[session_name()]))
             {
-                $url=sid_process_url( $common . $value );
+                $url = $SESSION->sid_process_url( $common . $value );
             } else
             {
                 $url=$common . $value;
@@ -5650,7 +5650,7 @@ function print_error($errorcode, $module='', $link='', $a=NULL) {
 /**
  * Internal function - do not use directly!!
  */
-function _print_normal_error($errorcode, $module, $a, $link, $backtrace, $showerrordebugwarning=false) {
+function _print_normal_error($errorcode, $module, $a, $link, $backtrace, $debuginfo=null, $showerrordebugwarning=false) {
     global $CFG, $SESSION, $THEME;
 
     if ($module == 'error') {
@@ -5706,7 +5706,11 @@ function _print_normal_error($errorcode, $module, $a, $link, $backtrace, $shower
 
     } else {
         if (debugging('', DEBUG_DEVELOPER)) {
-            notify('Stack trace:'.print_backtrace($backtrace, true), 'notifytiny');
+            if ($debuginfo) {
+                debugging($debuginfo, DEBUG_DEVELOPER, $backtrace);
+            } else {
+                notify('Stack trace:'.print_backtrace($backtrace, true), 'notifytiny');
+            }
         }
     }
 
@@ -6040,11 +6044,10 @@ function notice_yesno ($message, $linkyes, $linkno, $optionsyes=NULL, $optionsno
  *      echo "<script type='text/javascript'>alert('Redirect $url');</script>";
  */
 function redirect($url, $message='', $delay=-1) {
-
-    global $CFG, $THEME;
+    global $CFG, $THEME, $SESSION;
 
     if (!empty($CFG->usesid) && !isset($_COOKIE[session_name()])) {
-       $url = sid_process_url($url);
+       $url = $SESSION->sid_process_url($url);
     }
 
     $message = clean_text($message);
@@ -6879,9 +6882,10 @@ function doc_link($path='', $text='', $iconpath='') {
  *
  * @param string $message a message to print
  * @param int $level the level at which this debugging statement should show
+ * @param array $backtrace use different backtrace
  * @return bool
  */
-function debugging($message='', $level=DEBUG_NORMAL) {
+function debugging($message='', $level=DEBUG_NORMAL, $backtrace=null) {
 
     global $CFG;
 
@@ -6891,8 +6895,10 @@ function debugging($message='', $level=DEBUG_NORMAL) {
 
     if ($CFG->debug >= $level) {
         if ($message) {
-            $callers = debug_backtrace();
-            $from = print_backtrace($callers, true);
+            if (!$backtrace) {
+                $backtrace = debug_backtrace();
+            }
+            $from = print_backtrace($backtrace, true);
             if (!isset($CFG->debugdisplay)) {
                 $CFG->debugdisplay = ini_get('display_errors');
             }
index 94627617a16039bd746d4a2fffa1db13957e1040..69d7b7ef1ae9408d92cfd4200fc7adb25b0f45f4 100644 (file)
@@ -34,7 +34,7 @@ function xmldb_data_upgrade($oldversion=0) {
         $field = new xmldb_field('asearchtemplate', XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, 'jstemplate');
 
         if (!$dbman->field_exists($table, $field)) {
-            $result = $result && $dbman->add_field($table, $field);
+            $dbman->add_field($table, $field);
         }
     }
 
@@ -47,9 +47,9 @@ function xmldb_data_upgrade($oldversion=0) {
         $table = new xmldb_table('data');
         $field = new xmldb_field('notification', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'editany');
         // First step, Set NOT NULL
-        $result = $result && $dbman->change_field_notnull($table, $field);
+        $dbman->change_field_notnull($table, $field);
         // Second step, Set default to 0
-        $result = $result && $dbman->change_field_default($table, $field);
+        $dbman->change_field_default($table, $field);
     }
 
     return $result;
index 4f0e254f203769b525af5d6f78acc3df2995767a..4fd94503dd369f232d658094fa4857093909093b 100644 (file)
@@ -58,7 +58,7 @@ function xmldb_feedback_upgrade($oldversion=0) {
         $key->set_attributes(XMLDB_KEY_FOREIGN, array('feedback'), 'feedback', 'id');
         $table->addKey($key);
 
-        $result = $result && $dbman->create_table($table);
+        $dbman->create_table($table);
         ////////////////////////////////////////////////////////////
         ////////////////////////////////////////////////////////////
         //create a new table feedback_valuetmp and the field-definition
@@ -96,7 +96,7 @@ function xmldb_feedback_upgrade($oldversion=0) {
         $key->set_attributes(XMLDB_KEY_FOREIGN, array('item'), 'feedback_item', 'id');
         $table->addKey($key);
 
-        $result = $result && $dbman->create_table($table);
+        $dbman->create_table($table);
         ////////////////////////////////////////////////////////////
     }
 
@@ -106,25 +106,25 @@ function xmldb_feedback_upgrade($oldversion=0) {
         $table = new xmldb_table('feedback_completed');
         $field = new xmldb_field('random_response', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
         /// Launch add field1
-        $result = $result && $dbman->add_field($table, $field);
+        $dbman->add_field($table, $field);
 
         /// Define field anonymous_response to be added to feedback_completed
         $table = new xmldb_table('feedback_completed');
         $field = new xmldb_field('anonymous_response', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '1', null);
         /// Launch add field2
-        $result = $result && $dbman->add_field($table, $field);
+        $dbman->add_field($table, $field);
 
         /// Define field random_response to be added to feedback_completed
         $table = new xmldb_table('feedback_completedtmp');
         $field = new xmldb_field('random_response', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
         /// Launch add field1
-        $result = $result && $dbman->add_field($table, $field);
+        $dbman->add_field($table, $field);
 
         /// Define field anonymous_response to be added to feedback_completed
         $table = new xmldb_table('feedback_completedtmp');
         $field = new xmldb_field('anonymous_response', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '1', null);
         /// Launch add field2
-        $result = $result && $dbman->add_field($table, $field);
+        $dbman->add_field($table, $field);
 
         ////////////////////////////////////////////////////////////
     }
@@ -135,7 +135,7 @@ function xmldb_feedback_upgrade($oldversion=0) {
         $table = new xmldb_table('feedback_template');
         $field = new xmldb_field('ispublic', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '1', null);
         if (!$dbman->field_exists($table, $field)) {
-            $result = $result && $dbman->add_field($table, $field);
+            $dbman->add_field($table, $field);
         }
     }
 
@@ -202,7 +202,7 @@ function xmldb_feedback_upgrade($oldversion=0) {
         $table = new xmldb_table('feedback');
         $field = new xmldb_field('autonumbering', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '1', 'multiple_submit');
         /// Launch add field2
-        $result = $result && $dbman->add_field($table, $field);
+        $dbman->add_field($table, $field);
     }
 
     if ($result && $oldversion < 2008050104) {
@@ -210,14 +210,14 @@ function xmldb_feedback_upgrade($oldversion=0) {
         $table = new xmldb_table('feedback');
         $field = new xmldb_field('site_after_submit', XMLDB_TYPE_CHAR, '255', null, null, false, null, null, '', 'autonumbering');
         /// Launch add field2
-        $result = $result && $dbman->add_field($table, $field);
+        $dbman->add_field($table, $field);
     }
     
     if ($result && $oldversion < 2008050105) {
         //field count is not more needed
         $table = new xmldb_table('feedback_tracking');
         $field = new xmldb_field('count');
-        $result = $result && $dbman->drop_field($table, $field);
+        $dbman->drop_field($table, $field);
     }
     return $result;
 }
index 365e22509310658287900152907dbe0973fa31e8..98a3331e47798df899579dea430a7390a1ea0bbd 100644 (file)
@@ -38,7 +38,7 @@ function xmldb_lesson_upgrade($oldversion=0) {
         /// Set field specs
             $field->set_attributes(XMLDB_TYPE_INTEGER, '3', null, XMLDB_NOTNULL, null, null, null, '0', 'ongoing');
         /// Launch rename field usegrademax to usemaxgrade
-            $result = $result && $dbman->rename_field($table, $field, 'usemaxgrade');
+            $dbman->rename_field($table, $field, 'usemaxgrade');
         }
     }
 
index 6283f7392d23be0629a22591e845de889b0d725f..796713864a8ff736336be29e8f143e2d5ce5dbc8 100644 (file)
@@ -42,7 +42,7 @@ function xmldb_quiz_upgrade($oldversion=0) {
 
     /// Conditionally launch create table for quiz_report
         if (!$dbman->table_exists($table)) {
-            $result = $result && $dbman->create_table($table);
+            $dbman->create_table($table);
         }
 
     }