From: moodler Date: Sun, 16 Apr 2006 16:50:55 +0000 (+0000) Subject: Fixed the upgrade_plugins function so that it automatically X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=d87a9d733833f633adc3918b7381b2ee35a0f8c9;p=moodle.git Fixed the upgrade_plugins function so that it automatically handles the .sql file for first installation (just like activities) --- diff --git a/admin/index.php b/admin/index.php index 6c896455a9..c1c836103f 100644 --- a/admin/index.php +++ b/admin/index.php @@ -179,11 +179,7 @@ print_header($strcurrentversion, $stradministration, $strcurrentversion, "", "", false, " ", " "); - if (set_config("version", $version)) { - print_heading("Moodle $release ($version)"); - print_continue("index.php"); - die; - } else { + if (!set_config("version", $version)) { $db->debug=true; if (main_upgrade(0)) { print_continue("index.php"); diff --git a/enrol/authorize/db/mysql.php b/enrol/authorize/db/mysql.php index 7736c9d249..d6e88ea8e2 100755 --- a/enrol/authorize/db/mysql.php +++ b/enrol/authorize/db/mysql.php @@ -8,17 +8,6 @@ function enrol_authorize_upgrade($oldversion=0) { $result = true; - if (!$tables = $db->MetaColumns($CFG->prefix . 'enrol_authorize')) { - $installfirst = true; - } - - if ($oldversion == 0 || !empty($installfirst)) { // First time install - $result = modify_database("$CFG->dirroot/enrol/authorize/db/mysql.sql"); - return $result; // RETURN, sql file contains last upgrades. - } - - // Authorize module was installed before. Upgrades must be applied to SQL file. - if ($oldversion < 2005071600) { // Be sure, only last 4 digit is inserted. table_column('enrol_authorize', 'cclastfour', 'cclastfour', 'integer', '4', 'unsigned', '0', 'not null'); diff --git a/enrol/authorize/db/postgres7.php b/enrol/authorize/db/postgres7.php index 1e006f98d7..ec7878eb45 100644 --- a/enrol/authorize/db/postgres7.php +++ b/enrol/authorize/db/postgres7.php @@ -8,17 +8,6 @@ function enrol_authorize_upgrade($oldversion=0) { $result = true; - if (!$tables = $db->MetaColumns($CFG->prefix . 'enrol_authorize')) { - $installfirst = true; - } - - if ($oldversion == 0 || !empty($installfirst)) { // First time install - $result = modify_database("$CFG->dirroot/enrol/authorize/db/postgres7.sql"); - return $result; // RETURN, sql file contains last upgrades. - } - - // Authorize module was installed before. Upgrades must be applied to SQL file. - if ($oldversion < 2005071602) { notify("If you are using the authorize.net enrolment plugin for credit card handling, please ensure that you have turned loginhttps ON in Admin >> Variables >> Security."); diff --git a/enrol/paypal/db/mysql.php b/enrol/paypal/db/mysql.php index cb2b94dbd2..9f6abc5db9 100644 --- a/enrol/paypal/db/mysql.php +++ b/enrol/paypal/db/mysql.php @@ -8,10 +8,6 @@ function enrol_paypal_upgrade($oldversion=0) { $result = true; - if ($oldversion == 0) { - modify_database("$CFG->dirroot/enrol/paypal/db/mysql.sql"); - } - return $result; } diff --git a/enrol/paypal/db/postgres7.php b/enrol/paypal/db/postgres7.php index 7ac6b989ab..132a8fac9c 100644 --- a/enrol/paypal/db/postgres7.php +++ b/enrol/paypal/db/postgres7.php @@ -8,10 +8,6 @@ function enrol_paypal_upgrade($oldversion=0) { $result = true; - if ($oldversion == 0) { - modify_database("$CFG->dirroot/enrol/paypal/db/postgres7.sql"); - } - return $result; } diff --git a/lib/adminlib.php b/lib/adminlib.php index 6d8e69062b..cd6b27b6d0 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -76,21 +76,41 @@ function upgrade_plugins($type, $dir, $return) { print_header($strpluginsetup, $strpluginsetup, $strpluginsetup, '', '', false, ' ', ' '); } print_heading($plugin->name .' plugin needs upgrading'); - $upgrade_function = $type.'_'.$plugin->name .'_upgrade'; - if (function_exists($upgrade_function)) { - $db->debug=true; - if ($upgrade_function($CFG->$pluginversion)) { - $db->debug=false; - // OK so far, now update the plugins record + + if ($CFG->$pluginversion == 0) { // It's a new install of this plugin + if (file_exists($fullplug .'/db/'. $CFG->dbtype .'.sql')) { + $db->debug = true; + @set_time_limit(0); // To allow slow databases to complete the long SQL + if (modify_database($fullplug .'/db/'. $CFG->dbtype .'.sql')) { + // OK so far, now update the plugins record + set_config($pluginversion, $plugin->version); + notify(get_string('modulesuccess', '', $plugin->name), 'notifysuccess'); + } else { + notify('Installing '. $plugin->name .' FAILED!'); + } + $db->debug = false; + } else { // We'll assume no tables are necessary set_config($pluginversion, $plugin->version); notify(get_string('modulesuccess', '', $plugin->name), 'notifysuccess'); - echo '
'; - } else { - $db->debug=false; - notify('Upgrading '. $plugin->name .' from '. $CFG->$pluginversion .' to '. $plugin->version .' FAILED!'); + } + } else { // Upgrade existing install + $upgrade_function = $type.'_'.$plugin->name .'_upgrade'; + if (function_exists($upgrade_function)) { + $db->debug=true; + if ($upgrade_function($CFG->$pluginversion)) { + $db->debug=false; + // OK so far, now update the plugins record + set_config($pluginversion, $plugin->version); + notify(get_string('modulesuccess', '', $plugin->name), 'notifysuccess'); + } else { + $db->debug=false; + notify('Upgrading '. $plugin->name .' from '. $CFG->$pluginversion .' to '. $plugin->version .' FAILED!'); + } } } + echo '
'; $updated_plugins = true; + } else { error('Version mismatch: '. $plugin->name .' can\'t downgrade '. $CFG->$pluginversion .' -> '. $plugin->version .' !'); } diff --git a/question/type/calculated/db/mysql.php b/question/type/calculated/db/mysql.php index 1f0612135f..7f29bf5de9 100644 --- a/question/type/calculated/db/mysql.php +++ b/question/type/calculated/db/mysql.php @@ -5,18 +5,6 @@ function qtype_calculated_upgrade($oldversion=0) { global $CFG; - - if ($oldversion == 0) { // First time install - $result = modify_database("$CFG->dirroot/question/type/calculated/db/mysql.sql"); - return $result; - } - - // Question type was installed before. Upgrades must be applied - -// if ($oldversion < 2005071600) { -// -// } - return true; } diff --git a/question/type/calculated/db/postgres7.php b/question/type/calculated/db/postgres7.php index 561fa1c1ec..cd7049901c 100644 --- a/question/type/calculated/db/postgres7.php +++ b/question/type/calculated/db/postgres7.php @@ -4,18 +4,6 @@ function qtype_calculated_upgrade($oldversion=0) { global $CFG; - require_once("$CFG->libdir/questionlib.php"); - - if ($oldversion == 0) { // First time install - $result = modify_database("$CFG->dirroot/question/type/calculated/db/postgres7.sql"); - return $result; - } - - // Question type was installed before. Upgrades must be applied - -// if ($oldversion < 2005071600) { -// -// } return true; } diff --git a/question/type/essay/db/mysql.php b/question/type/essay/db/mysql.php index f6e1986a10..547dbe39ac 100644 --- a/question/type/essay/db/mysql.php +++ b/question/type/essay/db/mysql.php @@ -5,18 +5,6 @@ function qtype_essay_upgrade($oldversion=0) { global $CFG; - - if ($oldversion == 0) { // First time install - $result = modify_database("$CFG->dirroot/question/type/essay/db/mysql.sql"); - return $result; - } - - // Question type was installed before. Upgrades must be applied - -// if ($oldversion < 2005071600) { -// -// } - return true; } diff --git a/question/type/essay/db/postgres7.php b/question/type/essay/db/postgres7.php index c990635f36..331ae0093b 100644 --- a/question/type/essay/db/postgres7.php +++ b/question/type/essay/db/postgres7.php @@ -5,18 +5,6 @@ function qtype_essay_upgrade($oldversion=0) { global $CFG; - - if ($oldversion == 0) { // First time install - $result = modify_database("$CFG->dirroot/question/type/essay/db/postgres7.sql"); - return $result; - } - - // Question type was installed before. Upgrades must be applied - -// if ($oldversion < 2005071600) { -// -// } - return true; } diff --git a/question/type/match/db/mysql.php b/question/type/match/db/mysql.php index 9327a9ae46..fbb28ffc37 100644 --- a/question/type/match/db/mysql.php +++ b/question/type/match/db/mysql.php @@ -5,18 +5,6 @@ function qtype_match_upgrade($oldversion=0) { global $CFG; - - if ($oldversion == 0) { // First time install - $result = modify_database("$CFG->dirroot/question/type/match/db/mysql.sql"); - return $result; - } - - // Question type was installed before. Upgrades must be applied - -// if ($oldversion < 2005071600) { -// -// } - return true; } diff --git a/question/type/match/db/postgres7.php b/question/type/match/db/postgres7.php index 70e1b447c6..1599878e36 100644 --- a/question/type/match/db/postgres7.php +++ b/question/type/match/db/postgres7.php @@ -5,18 +5,6 @@ function qtype_match_upgrade($oldversion=0) { global $CFG; - - if ($oldversion == 0) { // First time install - $result = modify_database("$CFG->dirroot/question/type/match/db/postgres7.sql"); - return $result; - } - - // Question type was installed before. Upgrades must be applied - -// if ($oldversion < 2005071600) { -// -// } - return true; } diff --git a/question/type/multianswer/db/mysql.php b/question/type/multianswer/db/mysql.php index d87ecde271..fded4f41af 100644 --- a/question/type/multianswer/db/mysql.php +++ b/question/type/multianswer/db/mysql.php @@ -5,18 +5,6 @@ function qtype_multianswer_upgrade($oldversion=0) { global $CFG; - - if ($oldversion == 0) { // First time install - $result = modify_database("$CFG->dirroot/question/type/multianswer/db/mysql.sql"); - return $result; - } - - // Question type was installed before. Upgrades must be applied - -// if ($oldversion < 2005071600) { -// -// } - return true; } diff --git a/question/type/multianswer/db/postgres7.php b/question/type/multianswer/db/postgres7.php index 87d8a27c77..59a5534dd2 100644 --- a/question/type/multianswer/db/postgres7.php +++ b/question/type/multianswer/db/postgres7.php @@ -5,18 +5,6 @@ function qtype_multianswer_upgrade($oldversion=0) { global $CFG; - - if ($oldversion == 0) { // First time install - $result = modify_database("$CFG->dirroot/question/type/multianswer/db/postgres7.sql"); - return $result; - } - - // Question type was installed before. Upgrades must be applied - -// if ($oldversion < 2005071600) { -// -// } - return true; } diff --git a/question/type/multichoice/db/mysql.php b/question/type/multichoice/db/mysql.php index 1ad38a0e8b..c95cd21f73 100644 --- a/question/type/multichoice/db/mysql.php +++ b/question/type/multichoice/db/mysql.php @@ -5,18 +5,6 @@ function qtype_multichoice_upgrade($oldversion=0) { global $CFG; - - if ($oldversion == 0) { // First time install - $result = modify_database("$CFG->dirroot/question/type/multichoice/db/mysql.sql"); - return $result; - } - - // Question type was installed before. Upgrades must be applied - -// if ($oldversion < 2005071600) { -// -// } - return true; } diff --git a/question/type/multichoice/db/postgres7.php b/question/type/multichoice/db/postgres7.php index f14c1de734..b811bfe8cb 100644 --- a/question/type/multichoice/db/postgres7.php +++ b/question/type/multichoice/db/postgres7.php @@ -5,18 +5,6 @@ function qtype_multichoice_upgrade($oldversion=0) { global $CFG; - - if ($oldversion == 0) { // First time install - $result = modify_database("$CFG->dirroot/question/type/multichoice/db/postgres7.sql"); - return $result; - } - - // Question type was installed before. Upgrades must be applied - -// if ($oldversion < 2005071600) { -// -// } - return true; } diff --git a/question/type/numerical/db/mysql.php b/question/type/numerical/db/mysql.php index 8a455cea70..7572d100df 100644 --- a/question/type/numerical/db/mysql.php +++ b/question/type/numerical/db/mysql.php @@ -5,18 +5,6 @@ function qtype_numerical_upgrade($oldversion=0) { global $CFG; - - if ($oldversion == 0) { // First time install - $result = modify_database("$CFG->dirroot/question/type/numerical/db/mysql.sql"); - return $result; - } - - // Question type was installed before. Upgrades must be applied - -// if ($oldversion < 2005071600) { -// -// } - return true; } diff --git a/question/type/numerical/db/postgres7.php b/question/type/numerical/db/postgres7.php index bc377842cb..7be7fbed8d 100644 --- a/question/type/numerical/db/postgres7.php +++ b/question/type/numerical/db/postgres7.php @@ -5,18 +5,6 @@ function qtype_numerical_upgrade($oldversion=0) { global $CFG; - - if ($oldversion == 0) { // First time install - $result = modify_database("$CFG->dirroot/question/type/numerical/db/postgres7.sql"); - return $result; - } - - // Question type was installed before. Upgrades must be applied - -// if ($oldversion < 2005071600) { -// -// } - return true; } diff --git a/question/type/randomsamatch/db/mysql.php b/question/type/randomsamatch/db/mysql.php index 6057208902..86a8c00aaa 100644 --- a/question/type/randomsamatch/db/mysql.php +++ b/question/type/randomsamatch/db/mysql.php @@ -5,18 +5,6 @@ function qtype_randomsamatch_upgrade($oldversion=0) { global $CFG; - - if ($oldversion == 0) { // First time install - $result = modify_database("$CFG->dirroot/question/type/randomsamatch/db/mysql.sql"); - return $result; - } - - // Question type was installed before. Upgrades must be applied - -// if ($oldversion < 2005071600) { -// -// } - return true; } diff --git a/question/type/randomsamatch/db/postgres7.php b/question/type/randomsamatch/db/postgres7.php index 92ef559779..fe37c48afa 100644 --- a/question/type/randomsamatch/db/postgres7.php +++ b/question/type/randomsamatch/db/postgres7.php @@ -5,18 +5,6 @@ function qtype_randomsamatch_upgrade($oldversion=0) { global $CFG; - - if ($oldversion == 0) { // First time install - $result = modify_database("$CFG->dirroot/question/type/randomsamatch/db/postgres7.sql"); - return $result; - } - - // Question type was installed before. Upgrades must be applied - -// if ($oldversion < 2005071600) { -// -// } - return true; } diff --git a/question/type/rqp/db/mysql.php b/question/type/rqp/db/mysql.php index 49046cadcd..4fec5aa3b4 100644 --- a/question/type/rqp/db/mysql.php +++ b/question/type/rqp/db/mysql.php @@ -5,18 +5,6 @@ function qtype_rqp_upgrade($oldversion=0) { global $CFG; - - if ($oldversion == 0) { // First time install - $result = modify_database("$CFG->dirroot/question/type/rqp/db/mysql.sql"); - return $result; - } - - // Question type was installed before. Upgrades must be applied - -// if ($oldversion < 2005071600) { -// -// } - return true; } diff --git a/question/type/rqp/db/postgres7.php b/question/type/rqp/db/postgres7.php index 3b680051f7..bac7a52349 100644 --- a/question/type/rqp/db/postgres7.php +++ b/question/type/rqp/db/postgres7.php @@ -5,18 +5,6 @@ function qtype_rqp_upgrade($oldversion=0) { global $CFG; - - if ($oldversion == 0) { // First time install - $result = modify_database("$CFG->dirroot/question/type/rqp/db/postgres7.sql"); - return $result; - } - - // Question type was installed before. Upgrades must be applied - -// if ($oldversion < 2005071600) { -// -// } - return true; } diff --git a/question/type/shortanswer/db/mysql.php b/question/type/shortanswer/db/mysql.php index c8fe4afc13..57164b8ae0 100644 --- a/question/type/shortanswer/db/mysql.php +++ b/question/type/shortanswer/db/mysql.php @@ -5,18 +5,6 @@ function qtype_shortanswer_upgrade($oldversion=0) { global $CFG; - - if ($oldversion == 0) { // First time install - $result = modify_database("$CFG->dirroot/question/type/shortanswer/db/mysql.sql"); - return $result; - } - - // Question type was installed before. Upgrades must be applied - -// if ($oldversion < 2005071600) { -// -// } - return true; } diff --git a/question/type/shortanswer/db/postgres7.php b/question/type/shortanswer/db/postgres7.php index fc35a8c62c..e6096355a5 100644 --- a/question/type/shortanswer/db/postgres7.php +++ b/question/type/shortanswer/db/postgres7.php @@ -5,18 +5,6 @@ function qtype_shortanswer_upgrade($oldversion=0) { global $CFG; - - if ($oldversion == 0) { // First time install - $result = modify_database("$CFG->dirroot/question/type/shortanswer/db/postgres7.sql"); - return $result; - } - - // Question type was installed before. Upgrades must be applied - -// if ($oldversion < 2005071600) { -// -// } - return true; } diff --git a/question/type/truefalse/db/mysql.php b/question/type/truefalse/db/mysql.php index 4c182576c8..649b86d25c 100644 --- a/question/type/truefalse/db/mysql.php +++ b/question/type/truefalse/db/mysql.php @@ -5,18 +5,6 @@ function qtype_truefalse_upgrade($oldversion=0) { global $CFG; - - if ($oldversion == 0) { // First time install - $result = modify_database("$CFG->dirroot/question/type/truefalse/db/mysql.sql"); - return $result; - } - - // Question type was installed before. Upgrades must be applied - -// if ($oldversion < 2005071600) { -// -// } - return true; } diff --git a/question/type/truefalse/db/postgres7.php b/question/type/truefalse/db/postgres7.php index 12564e71a7..18d585d732 100644 --- a/question/type/truefalse/db/postgres7.php +++ b/question/type/truefalse/db/postgres7.php @@ -5,18 +5,6 @@ function qtype_truefalse_upgrade($oldversion=0) { global $CFG; - - if ($oldversion == 0) { // First time install - $result = modify_database("$CFG->dirroot/question/type/truefalse/db/postgres7.sql"); - return $result; - } - - // Question type was installed before. Upgrades must be applied - -// if ($oldversion < 2005071600) { -// -// } - return true; }