]> git.mjollnir.org Git - moodle.git/commitdiff
Fixed the upgrade_plugins function so that it automatically
authormoodler <moodler>
Sun, 16 Apr 2006 16:50:55 +0000 (16:50 +0000)
committermoodler <moodler>
Sun, 16 Apr 2006 16:50:55 +0000 (16:50 +0000)
handles the .sql file for first installation (just like activities)

26 files changed:
admin/index.php
enrol/authorize/db/mysql.php
enrol/authorize/db/postgres7.php
enrol/paypal/db/mysql.php
enrol/paypal/db/postgres7.php
lib/adminlib.php
question/type/calculated/db/mysql.php
question/type/calculated/db/postgres7.php
question/type/essay/db/mysql.php
question/type/essay/db/postgres7.php
question/type/match/db/mysql.php
question/type/match/db/postgres7.php
question/type/multianswer/db/mysql.php
question/type/multianswer/db/postgres7.php
question/type/multichoice/db/mysql.php
question/type/multichoice/db/postgres7.php
question/type/numerical/db/mysql.php
question/type/numerical/db/postgres7.php
question/type/randomsamatch/db/mysql.php
question/type/randomsamatch/db/postgres7.php
question/type/rqp/db/mysql.php
question/type/rqp/db/postgres7.php
question/type/shortanswer/db/mysql.php
question/type/shortanswer/db/postgres7.php
question/type/truefalse/db/mysql.php
question/type/truefalse/db/postgres7.php

index 6c896455a9a9061e8a36ebc8444aea269a4974df..c1c836103f6d2d31827f970832ae450d0a099a9b 100644 (file)
         print_header($strcurrentversion, $stradministration, $strcurrentversion,
                      "", "", false, "&nbsp;", "&nbsp;");
 
-        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");
index 7736c9d249e1b16c65572bf11bced1a4e4b68622..d6e88ea8e294f59002492ffcb5ee81b9f5054745 100755 (executable)
@@ -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');
index 1e006f98d78f132b31ea3b76557aaf2ee7b6ff1f..ec7878eb453b7c441c5dbd4f580017402782cbc8 100644 (file)
@@ -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.");
index cb2b94dbd2dae55220b263d109eb14cbd7af9e15..9f6abc5db9d4263d360894736d7fb52949b884ac 100644 (file)
@@ -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;
 
 }
index 7ac6b989ab8ab1d086542f4144d23271d7e81a80..132a8fac9ccfd160a2010bd65baf47c010e4c4e7 100644 (file)
@@ -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;
 
 }
index 6d8e69062bb34136a9a32d486b745fbafd379849..cd6b27b6d07073d71f8d902b4e233c7524401ec5 100644 (file)
@@ -76,21 +76,41 @@ function upgrade_plugins($type, $dir, $return) {
                 print_header($strpluginsetup, $strpluginsetup, $strpluginsetup, '', '', false, '&nbsp;', '&nbsp;');
             }
             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 '<hr />';
-                } 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 '<hr />';
             $updated_plugins = true;
+
         } else {
             error('Version mismatch: '. $plugin->name .' can\'t downgrade '. $CFG->$pluginversion .' -> '. $plugin->version .' !');
         }
index 1f0612135f5f7bd990553be282ec600a340ee7b8..7f29bf5de971f4a8d689c88b41c1b99bcbde4978 100644 (file)
@@ -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;
 }
 
index 561fa1c1ecaf4c92a9a5d5247a7b6116d2c009a7..cd7049901cd589cdaa1ae966bf3446cc4e50aa74 100644 (file)
@@ -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;
 }
index f6e1986a10a6a4a4ab82588f86bac851314b2982..547dbe39acc8aacd6614bedbbcb1bd18037de9ba 100644 (file)
@@ -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;
 }
 
index c990635f362f17f7c207b21704161ce3f68ec4a8..331ae0093bb209272de1024ba35bd883599da953 100644 (file)
@@ -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;
 }
 
index 9327a9ae466510f1f02d09ad4bed2ad0a03f8eb9..fbb28ffc37b55f52219025fb612867d63e611362 100644 (file)
@@ -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;
 }
 
index 70e1b447c612664aa03dcfcda6de474e4894d17f..1599878e36c5690a4d776223cf0fe572e37f88ad 100644 (file)
@@ -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;
 }
 
index d87ecde271071d784040ff0ce2bd01cec160796d..fded4f41af25659cfdf26bd1400b65686ef5d888 100644 (file)
@@ -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;
 }
 
index 87d8a27c77474dd5749b47c4d3128037b6652fa6..59a5534dd2aa58c5e03d7ea153b35160aefc1ffd 100644 (file)
@@ -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;
 }
 
index 1ad38a0e8b6e8edf2e2d82d05056e387f77de2f9..c95cd21f732792dfaccfd5f3b388e1481e3c7b92 100644 (file)
@@ -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;
 }
 
index f14c1de73435e41f85ce92efb2e20671bd1e2fb7..b811bfe8cbfc781f2c841640b53b07f466179d57 100644 (file)
@@ -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;
 }
 
index 8a455cea7094cb75881250799dba621b26809ad8..7572d100df205755938eb921859f0f850ae1c0e3 100644 (file)
@@ -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;
 }
 
index bc377842cb63d3ebf2cd62126021fef70b7c070a..7be7fbed8d762c2f676884b2691e18bb8c50a76c 100644 (file)
@@ -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;
 }
 
index 605720890234a46714157619a76754f9c6ff62dc..86a8c00aaad43e1fcc9cbaeb5b1e46e9c1974d46 100644 (file)
@@ -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;
 }
 
index 92ef55977953e15e26349aab1cb5fdc5f69141a7..fe37c48afa21da7dc19d0f65535a8f0c5fff088e 100644 (file)
@@ -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;
 }
 
index 49046cadcd01ea528e98618fc8a597faa9e9a0e9..4fec5aa3b488ad0fa322b7752e15f60529f806de 100644 (file)
@@ -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;
 }
 
index 3b680051f7f74d5ff3d5785cd687bd47ec4f5b96..bac7a523493f6202fc12b61c34b47d354b131d35 100644 (file)
@@ -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;
 }
 
index c8fe4afc131d980f75a6c12e2cc32a57c085be5c..57164b8ae026733d05b20b61c821b208b686a5ef 100644 (file)
@@ -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;
 }
 
index fc35a8c62c7d7abf4c815961cc8ca38e4dc72ea5..e6096355a5e199bf6bf4b4bf189c41c33150533b 100644 (file)
@@ -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;
 }
 
index 4c182576c869955de0632fde33b411cf51f626c9..649b86d25c91df9323095cec77ac69ec6b1dc4d7 100644 (file)
@@ -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;
 }
 
index 12564e71a71a856dd3054f8755978ee87a4c5206..18d585d73240fee58db577e18713cf0f93d7e68e 100644 (file)
@@ -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;
 }