Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/feedback/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 
00017 // This file keeps track of upgrades to
00018 // the feedback module
00019 //
00020 // Sometimes, changes between versions involve
00021 // alterations to database structures and other
00022 // major things that may break installations.
00023 //
00024 // The upgrade function in this file will attempt
00025 // to perform all the necessary actions to upgrade
00026 // your older installation to the current version.
00027 //
00028 // If there's something it cannot do itself, it
00029 // will tell you what you need to do.
00030 //
00031 // The commands in here will all be database-neutral,
00032 // using the methods of database_manager class
00033 //
00034 // Please do not forget to use upgrade_set_timeout()
00035 // before any action that may take longer time to finish.
00036 
00037 function xmldb_feedback_upgrade($oldversion) {
00038     global $CFG, $DB;
00039 
00040     $dbman = $DB->get_manager();
00041 
00042     if ($oldversion < 2007012310) {
00043 
00044         //create a new table feedback_completedtmp and the field-definition
00045         $table = new xmldb_table('feedback_completedtmp');
00046 
00047         $field = new xmldb_field('id');
00048         $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
00049                                 XMLDB_NOTNULL, true, null, null);
00050         $table->addField($field);
00051 
00052         $field = new xmldb_field('feedback');
00053         $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
00054                                 XMLDB_NOTNULL, false, '0', null);
00055         $table->addField($field);
00056 
00057         $field = new xmldb_field('userid');
00058         $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
00059                                 XMLDB_NOTNULL, false, '0', null);
00060         $table->addField($field);
00061 
00062         $field = new xmldb_field('guestid');
00063         $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, null, false, '', null);
00064         $table->addField($field);
00065 
00066         $field = new xmldb_field('timemodified');
00067         $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
00068                                 XMLDB_NOTNULL, false, '0', null);
00069         $table->addField($field);
00070 
00071         $key = new xmldb_key('PRIMARY');
00072         $key->set_attributes(XMLDB_KEY_PRIMARY, array('id'));
00073         $table->addKey($key);
00074 
00075         $key = new xmldb_key('feedback');
00076         $key->set_attributes(XMLDB_KEY_FOREIGN, array('feedback'), 'feedback', 'id');
00077         $table->addKey($key);
00078 
00079         $dbman->create_table($table);
00082         //create a new table feedback_valuetmp and the field-definition
00083         $table = new xmldb_table('feedback_valuetmp');
00084 
00085         $field = new xmldb_field('id');
00086         $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
00087                                 XMLDB_NOTNULL, true, null, null);
00088         $table->addField($field);
00089 
00090         $field = new xmldb_field('course_id');
00091         $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
00092                                 XMLDB_NOTNULL, false, '0', null);
00093         $table->addField($field);
00094 
00095         $field = new xmldb_field('item');
00096         $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
00097                                 XMLDB_NOTNULL, false, '0', null);
00098         $table->addField($field);
00099 
00100         $field = new xmldb_field('completed');
00101         $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
00102                                 XMLDB_NOTNULL, false, '0', null);
00103         $table->addField($field);
00104 
00105         $field = new xmldb_field('tmp_completed');
00106         $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
00107                                 XMLDB_NOTNULL, false, '0', null);
00108         $table->addField($field);
00109 
00110         $field = new xmldb_field('value');
00111         $field->set_attributes(XMLDB_TYPE_TEXT, null, null, null, false, '', null);
00112         $table->addField($field);
00113 
00114         $key = new xmldb_key('PRIMARY');
00115         $key->set_attributes(XMLDB_KEY_PRIMARY, array('id'));
00116         $table->addKey($key);
00117 
00118         $key = new xmldb_key('feedback');
00119         $key->set_attributes(XMLDB_KEY_FOREIGN, array('item'), 'feedback_item', 'id');
00120         $table->addKey($key);
00121 
00122         $dbman->create_table($table);
00124         upgrade_mod_savepoint(true, 2007012310, 'feedback');
00125     }
00126 
00127     if ($oldversion < 2007050504) {
00128 
00130         $table = new xmldb_table('feedback_completed');
00131         $field = new xmldb_field('random_response', XMLDB_TYPE_INTEGER, '10',
00132                                     XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
00134         $dbman->add_field($table, $field);
00135 
00137         $table = new xmldb_table('feedback_completed');
00138         $field = new xmldb_field('anonymous_response', XMLDB_TYPE_INTEGER, '1',
00139                                     XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '1', null);
00141         $dbman->add_field($table, $field);
00142 
00144         $table = new xmldb_table('feedback_completedtmp');
00145         $field = new xmldb_field('random_response', XMLDB_TYPE_INTEGER, '10',
00146                                     XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
00148         $dbman->add_field($table, $field);
00149 
00151         $table = new xmldb_table('feedback_completedtmp');
00152         $field = new xmldb_field('anonymous_response', XMLDB_TYPE_INTEGER, '1',
00153                                     XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '1', null);
00155         $dbman->add_field($table, $field);
00156 
00158         upgrade_mod_savepoint(true, 2007050504, 'feedback');
00159     }
00160 
00161     if ($oldversion < 2007102600) {
00162         // public is a reserved word on Oracle
00163 
00164         $table = new xmldb_table('feedback_template');
00165         $field = new xmldb_field('ispublic', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED,
00166                                     XMLDB_NOTNULL, false, '1', null);
00167         if (!$dbman->field_exists($table, $field)) {
00168             $dbman->add_field($table, $field);
00169         }
00170         upgrade_mod_savepoint(true, 2007102600, 'feedback');
00171     }
00172 
00173     if ($oldversion < 2008042400) { //New version in version.php
00174         if ($all_nonanonymous_feedbacks = $DB->get_records('feedback', array('anonymous'=>2))) {
00175             $update_sql = 'UPDATE {feedback_completed}
00176                             SET anonymous_response = 2
00177                             WHERE feedback = ';
00178             foreach ($all_nonanonymous_feedbacks as $fb) {
00179                 $DB->execute($update_sql.$fb->id);
00180             }
00181         }
00182         upgrade_mod_savepoint(true, 2008042400, 'feedback');
00183     }
00184 
00185     if ($oldversion < 2008042401) { //New version in version.php
00186         $concat_radio    = $DB->sql_concat("'r>>>>>'", 'presentation');
00187         $concat_check    = $DB->sql_concat("'c>>>>>'", 'presentation');
00188         $concat_dropdown = $DB->sql_concat("'d>>>>>'", 'presentation');
00189 
00190         $update_sql1 = "UPDATE {feedback_item}
00191                         SET presentation = ".$concat_radio."
00192                         WHERE typ IN('radio','radiorated')";
00193 
00194         $update_sql2 = "UPDATE {feedback_item}
00195                         SET presentation = ".$concat_dropdown."
00196                         WHERE typ IN('dropdown','dropdownrated')";
00197 
00198         $update_sql3 = "UPDATE {feedback_item}
00199                         SET presentation = ".$concat_check."
00200                         WHERE typ = 'check'";
00201 
00202         $DB->execute($update_sql1);
00203         $DB->execute($update_sql2);
00204         $DB->execute($update_sql3);
00205 
00206         $update_sql1 = "UPDATE {feedback_item}
00207                         SET typ = 'multichoice'
00208                         WHERE typ IN('radio','check','dropdown')";
00209 
00210         $update_sql2 = "UPDATE {feedback_item}
00211                         SET typ = 'multichoicerated'
00212                         WHERE typ IN('radiorated','dropdownrated')";
00213 
00214         $DB->execute($update_sql1);
00215         $DB->execute($update_sql2);
00216 
00217         upgrade_mod_savepoint(true, 2008042401, 'feedback');
00218     }
00219 
00220     if ($oldversion < 2008042900) {
00222         $table = new xmldb_table('feedback');
00223         $field = new xmldb_field('autonumbering', XMLDB_TYPE_INTEGER, '1',
00224                                     XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', 'multiple_submit');
00226         $dbman->add_field($table, $field);
00227 
00228         upgrade_mod_savepoint(true, 2008042900, 'feedback');
00229     }
00230 
00231     if ($oldversion < 2008050104) {
00233         $table = new xmldb_table('feedback');
00234         $field = new xmldb_field('site_after_submit', XMLDB_TYPE_CHAR, '255',
00235                                     null, null, false, '', 'autonumbering');
00237         $dbman->add_field($table, $field);
00238 
00239         upgrade_mod_savepoint(true, 2008050104, 'feedback');
00240     }
00241 
00242     if ($oldversion < 2008050105) {
00243         //field count is not more needed
00244         $table = new xmldb_table('feedback_tracking');
00245         $field = new xmldb_field('count');
00246         $dbman->drop_field($table, $field);
00247 
00248         upgrade_mod_savepoint(true, 2008050105, 'feedback');
00249     }
00250 
00251     if ($oldversion < 2008073002) {
00252         $update_sql = "UPDATE {feedback_item}
00253                         SET presentation = '-|-'
00254                         WHERE " . $DB->sql_compare_text('presentation') . " = '0|0' AND
00255                             typ = 'numeric'";
00256 
00257         $DB->execute($update_sql);
00258 
00259         upgrade_mod_savepoint(true, 2008073002, 'feedback');
00260     }
00261 
00262     if ($oldversion < 2009031301) {
00264         $table = new xmldb_table('feedback_item');
00265         $field = new xmldb_field('label', XMLDB_TYPE_CHAR, '255', null, null, false, '', 'name');
00267         $dbman->add_field($table, $field);
00268 
00269         upgrade_mod_savepoint(true, 2009031301, 'feedback');
00270     }
00271 
00272     if ($oldversion < 2009042000) {
00273 
00275         $table = new xmldb_table('feedback');
00276         $field = new xmldb_field('summary', XMLDB_TYPE_TEXT, 'small', null,
00277                                     XMLDB_NOTNULL, null, null, 'name');
00278 
00280         $dbman->rename_field($table, $field, 'intro');
00281 
00283         upgrade_mod_savepoint(true, 2009042000, 'feedback');
00284     }
00285 
00286     if ($oldversion < 2009042001) {
00287 
00289         $table = new xmldb_table('feedback');
00290         $field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4',
00291                                     XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro');
00292 
00294         $dbman->add_field($table, $field);
00295 
00297         upgrade_mod_savepoint(true, 2009042001, 'feedback');
00298     }
00299 
00300     if ($oldversion < 2009112000) {
00302         $table = new xmldb_table('feedback');
00303         $field = new xmldb_field('page_after_submitformat', XMLDB_TYPE_INTEGER, '2',
00304                                     XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'page_after_submit');
00305 
00306         if (!$dbman->field_exists($table, $field)) {
00307             // Launch add field page_after_submitformat
00308             $dbman->add_field($table, $field);
00309         }
00310 
00311         // feedback savepoint reached
00312         upgrade_mod_savepoint(true, 2009112000, 'feedback');
00313     }
00314 
00315     if ($oldversion < 2010051101) {
00317         $table = new xmldb_table('feedback_item');
00318         $field = new xmldb_field('options', XMLDB_TYPE_CHAR, '255',
00319                                     null, null, false, '', 'required');
00321         $dbman->add_field($table, $field);
00322 
00323         upgrade_mod_savepoint(true, 2010051101, 'feedback');
00324     }
00325 
00326     if ($oldversion < 2010051600) {
00328         $table = new xmldb_table('feedback_item');
00329         $field = new xmldb_field('dependitem', XMLDB_TYPE_INTEGER, '10',
00330                                     XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'required');
00332         $dbman->add_field($table, $field);
00333 
00334         upgrade_mod_savepoint(true, 2010051600, 'feedback');
00335     }
00336 
00337     if ($oldversion < 2010051601) {
00339         $table = new xmldb_table('feedback_item');
00340         $field = new xmldb_field('dependvalue', XMLDB_TYPE_CHAR, '255',
00341                                     null, null, false, '', 'dependitem');
00343         $dbman->add_field($table, $field);
00344 
00345         upgrade_mod_savepoint(true, 2010051601, 'feedback');
00346     }
00347 
00348     if ($oldversion < 2010102300) {
00349 
00350         // Define field completionsubmit to be added to feedback
00351         $table = new xmldb_table('feedback');
00352         $field = new xmldb_field('completionsubmit', XMLDB_TYPE_INTEGER, '1',
00353                                     null, XMLDB_NOTNULL, null, '0', 'timemodified');
00354 
00355         // Conditionally launch add field completionsubmit
00356         if (!$dbman->field_exists($table, $field)) {
00357             $dbman->add_field($table, $field);
00358         }
00359 
00360         // feedback savepoint reached
00361         upgrade_mod_savepoint(true, 2010102300, 'feedback');
00362     }
00363 
00364     // Moodle v2.1.0 release upgrade line
00365     // Put any upgrade step following this
00366 
00367     // Moodle v2.2.0 release upgrade line
00368     // Put any upgrade step following this
00369 
00370     return true;
00371 }
00372 
00373 
 All Data Structures Namespaces Files Functions Variables Enumerations