Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/quiz/report/overview/db/upgrade.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00016 
00027 defined('MOODLE_INTERNAL') || die();
00028 
00029 
00034 function xmldb_quiz_overview_upgrade($oldversion) {
00035     global $CFG, $DB;
00036 
00037     $dbman = $DB->get_manager();
00038 
00039     //===== 1.9.0 upgrade line ======//
00040 
00041     if ($oldversion < 2009091400) {
00042 
00043         // Define table quiz_question_regrade to be created
00044         $table = new xmldb_table('quiz_question_regrade');
00045 
00046         // Adding fields to table quiz_question_regrade
00047         $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
00048                 XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
00049         $table->add_field('questionid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
00050                 XMLDB_NOTNULL, null, null);
00051         $table->add_field('attemptid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
00052                 XMLDB_NOTNULL, null, null);
00053         $table->add_field('newgrade', XMLDB_TYPE_NUMBER, '12, 7', null,
00054                 XMLDB_NOTNULL, null, null);
00055         $table->add_field('oldgrade', XMLDB_TYPE_NUMBER, '12, 7', null,
00056                 XMLDB_NOTNULL, null, null);
00057         $table->add_field('regraded', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED,
00058                 XMLDB_NOTNULL, null, null);
00059         $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
00060                 XMLDB_NOTNULL, null, null);
00061 
00062         // Adding keys to table quiz_question_regrade
00063         $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
00064 
00065         // Conditionally launch create table for quiz_question_regrade
00066         if (!$dbman->table_exists($table)) {
00067             $dbman->create_table($table);
00068         }
00069 
00070         // overview savepoint reached
00071         upgrade_plugin_savepoint(true, 2009091400, 'quiz', 'overview');
00072     }
00073 
00074     if ($oldversion < 2010040600) {
00075 
00076         // Wipe the quiz_question_regrade before we changes its structure. The data
00077         // It contains is not important long-term, and it is almost impossible to upgrade.
00078         $DB->delete_records('quiz_question_regrade');
00079 
00080         // overview savepoint reached
00081         upgrade_plugin_savepoint(true, 2010040600, 'quiz', 'overview');
00082     }
00083 
00084     if ($oldversion < 2010040601) {
00085 
00086         // Rename field attemptid on table quiz_question_regrade to questionusageid
00087         $table = new xmldb_table('quiz_question_regrade');
00088         $field = new xmldb_field('attemptid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
00089                 XMLDB_NOTNULL, null, null, 'id');
00090 
00091         // Launch rename field questionusageid
00092         $dbman->rename_field($table, $field, 'questionusageid');
00093 
00094         // overview savepoint reached
00095         upgrade_plugin_savepoint(true, 2010040601, 'quiz', 'overview');
00096     }
00097 
00098     if ($oldversion < 2010040602) {
00099 
00100         // Define field slot to be added to quiz_question_regrade
00101         $table = new xmldb_table('quiz_question_regrade');
00102         $field = new xmldb_field('slot', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
00103                 XMLDB_NOTNULL, null, null, 'questionusageid');
00104 
00105         // Conditionally launch add field slot
00106         if (!$dbman->field_exists($table, $field)) {
00107             $dbman->add_field($table, $field);
00108         }
00109 
00110         // overview savepoint reached
00111         upgrade_plugin_savepoint(true, 2010040602, 'quiz', 'overview');
00112     }
00113 
00114     if ($oldversion < 2010040603) {
00115 
00116         // Define field questionid to be dropped from quiz_question_regrade
00117         $table = new xmldb_table('quiz_question_regrade');
00118         $field = new xmldb_field('questionid');
00119 
00120         // Conditionally launch drop field questionusageid
00121         if ($dbman->field_exists($table, $field)) {
00122             $dbman->drop_field($table, $field);
00123         }
00124 
00125         // overview savepoint reached
00126         upgrade_plugin_savepoint(true, 2010040603, 'quiz', 'overview');
00127     }
00128 
00129     if ($oldversion < 2010040604) {
00130 
00131         // Rename field newgrade on table quiz_question_regrade to newfraction
00132         $table = new xmldb_table('quiz_question_regrade');
00133         $field = new xmldb_field('newgrade', XMLDB_TYPE_NUMBER, '12, 7', null,
00134                 null, null, null, 'slot');
00135 
00136         // Launch rename field newfraction
00137         $dbman->rename_field($table, $field, 'newfraction');
00138 
00139         // overview savepoint reached
00140         upgrade_plugin_savepoint(true, 2010040604, 'quiz', 'overview');
00141     }
00142 
00143     if ($oldversion < 2010040605) {
00144 
00145         // Rename field oldgrade on table quiz_question_regrade to oldfraction
00146         $table = new xmldb_table('quiz_question_regrade');
00147         $field = new xmldb_field('oldgrade', XMLDB_TYPE_NUMBER, '12, 7', null,
00148                 null, null, null, 'slot');
00149 
00150         // Launch rename field newfraction
00151         $dbman->rename_field($table, $field, 'oldfraction');
00152 
00153         // overview savepoint reached
00154         upgrade_plugin_savepoint(true, 2010040605, 'quiz', 'overview');
00155     }
00156 
00157     if ($oldversion < 2010040606) {
00158 
00159         // Changing precision of field newfraction on table quiz_question_regrade to (12, 7)
00160         $table = new xmldb_table('quiz_question_regrade');
00161         $field = new xmldb_field('newfraction', XMLDB_TYPE_NUMBER, '12, 7', null,
00162                 null, null, null, 'slot');
00163 
00164         // Launch change of precision for field newfraction
00165         $dbman->change_field_precision($table, $field);
00166 
00167         // overview savepoint reached
00168         upgrade_plugin_savepoint(true, 2010040606, 'quiz', 'overview');
00169     }
00170 
00171     if ($oldversion < 2010040607) {
00172 
00173         // Changing precision of field oldfraction on table quiz_question_regrade to (12, 7)
00174         $table = new xmldb_table('quiz_question_regrade');
00175         $field = new xmldb_field('oldfraction', XMLDB_TYPE_NUMBER, '12, 7', null,
00176                 null, null, null, 'slot');
00177 
00178         // Launch change of precision for field newfraction
00179         $dbman->change_field_precision($table, $field);
00180 
00181         // overview savepoint reached
00182         upgrade_plugin_savepoint(true, 2010040607, 'quiz', 'overview');
00183     }
00184 
00185     if ($oldversion < 2010082700) {
00186 
00187         // Changing nullability of field newfraction on table quiz_question_regrade to null
00188         $table = new xmldb_table('quiz_question_regrade');
00189         $field = new xmldb_field('newfraction', XMLDB_TYPE_NUMBER, '12, 7', null,
00190                 null, null, null, 'slot');
00191 
00192         // Launch change of nullability for field newfraction
00193         $dbman->change_field_notnull($table, $field);
00194 
00195         // overview savepoint reached
00196         upgrade_plugin_savepoint(true, 2010082700, 'quiz', 'overview');
00197     }
00198 
00199     if ($oldversion < 2010082701) {
00200 
00201         // Changing nullability of field oldfraction on table quiz_question_regrade to null
00202         $table = new xmldb_table('quiz_question_regrade');
00203         $field = new xmldb_field('oldfraction', XMLDB_TYPE_NUMBER, '12, 7', null,
00204                 null, null, null, 'slot');
00205 
00206         // Launch change of nullability for field newfraction
00207         $dbman->change_field_notnull($table, $field);
00208 
00209         // overview savepoint reached
00210         upgrade_plugin_savepoint(true, 2010082701, 'quiz', 'overview');
00211     }
00212 
00213     if ($oldversion < 2011021600) {
00214 
00215         // Define table quiz_question_regrade to be renamed to quiz_overview_regrades
00216         // so that it follows the Moodle coding guidelines.
00217         $table = new xmldb_table('quiz_question_regrade');
00218 
00219         // Launch rename table for quiz_question_regrade
00220         $dbman->rename_table($table, 'quiz_overview_regrades');
00221 
00222         // overview savepoint reached
00223         upgrade_plugin_savepoint(true, 2011021600, 'quiz', 'overview');
00224     }
00225 
00226     // Moodle v2.1.0 release upgrade line
00227     // Put any upgrade step following this
00228 
00229     // Moodle v2.2.0 release upgrade line
00230     // Put any upgrade step following this
00231 
00232     return true;
00233 }
 All Data Structures Namespaces Files Functions Variables Enumerations