Skip to content

Commit

Permalink
MDL-15343 mod upgrade savepoints implemented (the xmldb generator is …
Browse files Browse the repository at this point in the history
…not updated yet)
  • Loading branch information
skodak committed Jun 22, 2008
1 parent 16a5642 commit 04264ae
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 10 deletions.
19 changes: 17 additions & 2 deletions lib/adminlib.php
Expand Up @@ -39,8 +39,23 @@ function upgrade_main_savepoint($result, $version) {
}
}

function upgrade_mod_savepoint($result, $version, $type) {
//TODO
function upgrade_mod_savepoint($result, $version, $modname) {
global $DB;

if (!$module = $DB->get_record('modules', array('name'=>$modname))) {
print_error('modulenotexist', 'debug', '', $modname);
}

if ($result) {
if ($module->version >= $version) {
// something really wrong is going on in upgrade script
print_error('cannotdowngrade', 'debug', '', array($module->version, $version));
}
$module->verions = $version;
$DB->update_record('modules', $module);
} else {
notify ("Upgrade savepoint: Error during mod upgrade to version $version");
}
}

function upgrade_plugin_savepoint($result, $version, $type, $dir) {
Expand Down
7 changes: 0 additions & 7 deletions lib/setuplib.php
Expand Up @@ -48,13 +48,6 @@ function __construct($errorcode, $module='', $link='', $a=NULL, $debuginfo=null)
* 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);
Expand Down
7 changes: 6 additions & 1 deletion lib/weblib.php
Expand Up @@ -5651,7 +5651,12 @@ function print_error($errorcode, $module='', $link='', $a=NULL) {
* Internal function - do not use directly!!
*/
function _print_normal_error($errorcode, $module, $a, $link, $backtrace, $debuginfo=null, $showerrordebugwarning=false) {
global $CFG, $SESSION, $THEME;
global $CFG, $SESSION, $THEME, $DB;

if ($DB) {
//if you enable db debugging and exception is thrown, the print footer prints a lot of rubbish
$DB->set_debug(0);
}

if ($module == 'error') {
$modulelink = 'moodle';
Expand Down
1 change: 1 addition & 0 deletions mod/assignment/db/upgrade.php
Expand Up @@ -33,6 +33,7 @@ function xmldb_assignment_upgrade($oldversion=0) {
$DB->set_debug(false);
assignment_update_grades();
$DB->set_debug(true);
upgrade_mod_savepoint($result, 2007101511, 'assignment');
}

return $result;
Expand Down
2 changes: 2 additions & 0 deletions mod/data/db/upgrade.php
Expand Up @@ -36,6 +36,7 @@ function xmldb_data_upgrade($oldversion=0) {
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
upgrade_mod_savepoint($result, 2007101512, 'data');
}

if ($result && $oldversion < 2007101513) {
Expand All @@ -50,6 +51,7 @@ function xmldb_data_upgrade($oldversion=0) {
$dbman->change_field_notnull($table, $field);
// Second step, Set default to 0
$dbman->change_field_default($table, $field);
upgrade_mod_savepoint($result, 2007101513, 'data');
}

return $result;
Expand Down
14 changes: 14 additions & 0 deletions mod/feedback/db/upgrade.php
Expand Up @@ -98,6 +98,7 @@ function xmldb_feedback_upgrade($oldversion=0) {

$dbman->create_table($table);
////////////////////////////////////////////////////////////
upgrade_mod_savepoint($result, 2007012310, 'feedback');
}

if ($result && $oldversion < 2007050504) {
Expand Down Expand Up @@ -127,6 +128,7 @@ function xmldb_feedback_upgrade($oldversion=0) {
$dbman->add_field($table, $field);

////////////////////////////////////////////////////////////
upgrade_mod_savepoint($result, 2007050504, 'feedback');
}

if ($result && $oldversion < 2007102600) {
Expand All @@ -137,6 +139,7 @@ function xmldb_feedback_upgrade($oldversion=0) {
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
upgrade_mod_savepoint($result, 2007102600, 'feedback');
}

if ($result && $oldversion < 2008042400) { //New version in version.php
Expand All @@ -146,6 +149,7 @@ function xmldb_feedback_upgrade($oldversion=0) {
$result = $result && $DB->execute($update_sql.$fb->id);
}
}
upgrade_mod_savepoint($result, 2008042400, 'feedback');
}

if ($result && $oldversion < 2008042401) { //New version in version.php
Expand All @@ -168,6 +172,7 @@ function xmldb_feedback_upgrade($oldversion=0) {
$result = $result && $DB->execute($update_sql1);
$result = $result && $DB->execute($update_sql2);
}
upgrade_mod_savepoint($result, 2008042401, 'feedback');
}

if ($result && $oldversion < 2008042801) {
Expand Down Expand Up @@ -195,6 +200,8 @@ function xmldb_feedback_upgrade($oldversion=0) {
$new_log_display->mtable = 'course';
$new_log_display->field = 'shortname';
$result = $result && $DB->insert_record('log_display', $new_log_display);

upgrade_mod_savepoint($result, 2008042801, 'feedback');
}

if ($result && $oldversion < 2008042900) {
Expand All @@ -203,6 +210,8 @@ function xmldb_feedback_upgrade($oldversion=0) {
$field = new xmldb_field('autonumbering', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '1', 'multiple_submit');
/// Launch add field2
$dbman->add_field($table, $field);

upgrade_mod_savepoint($result, 2008042900, 'feedback');
}

if ($result && $oldversion < 2008050104) {
Expand All @@ -211,14 +220,19 @@ function xmldb_feedback_upgrade($oldversion=0) {
$field = new xmldb_field('site_after_submit', XMLDB_TYPE_CHAR, '255', null, null, false, null, null, '', 'autonumbering');
/// Launch add field2
$dbman->add_field($table, $field);

upgrade_mod_savepoint($result, 2008050104, 'feedback');
}

if ($result && $oldversion < 2008050105) {
//field count is not more needed
$table = new xmldb_table('feedback_tracking');
$field = new xmldb_field('count');
$dbman->drop_field($table, $field);

upgrade_mod_savepoint($result, 2008050105, 'feedback');
}

return $result;
}

Expand Down
4 changes: 4 additions & 0 deletions mod/forum/db/upgrade.php
Expand Up @@ -42,6 +42,8 @@ function xmldb_forum_upgrade($oldversion=0) {
$DB->set_debug(false);
forum_update_grades();
$DB->set_debug(true);

upgrade_mod_savepoint($result, 2007101511, 'forum');
}

if ($result && $oldversion < 2007101512) {
Expand Down Expand Up @@ -70,6 +72,8 @@ function xmldb_forum_upgrade($oldversion=0) {
$DB->set_debug(true);
$rs-close();
}

upgrade_mod_savepoint($result, 2007101512, 'forum');
}


Expand Down
2 changes: 2 additions & 0 deletions mod/lesson/db/upgrade.php
Expand Up @@ -40,6 +40,8 @@ function xmldb_lesson_upgrade($oldversion=0) {
/// Launch rename field usegrademax to usemaxgrade
$dbman->rename_field($table, $field, 'usemaxgrade');
}

upgrade_mod_savepoint($result, 2007072201, 'lesson');
}

return $result;
Expand Down
4 changes: 4 additions & 0 deletions mod/quiz/db/upgrade.php
Expand Up @@ -45,7 +45,9 @@ function xmldb_quiz_upgrade($oldversion=0) {
$dbman->create_table($table);
}

upgrade_mod_savepoint($result, 2008062000, 'quiz');
}

if ($result && $oldversion < 2008062001) {
$reporttoinsert = new object();
$reporttoinsert->name = 'overview';
Expand All @@ -71,6 +73,8 @@ function xmldb_quiz_upgrade($oldversion=0) {
$reporttoinsert->name = 'grading';
$reporttoinsert->displayorder = 6000;
$result = $result && $DB->insert_record('quiz_report', $reporttoinsert);

upgrade_mod_savepoint($result, 2008062001, 'quiz');
}


Expand Down

0 comments on commit 04264ae

Please sign in to comment.