Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/resource/db/upgrade.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00047 defined('MOODLE_INTERNAL') || die;
00048 
00049 function xmldb_resource_upgrade($oldversion) {
00050     global $CFG, $DB;
00051     require_once("$CFG->dirroot/mod/resource/db/upgradelib.php");
00052 
00053     $dbman = $DB->get_manager();
00054 
00055 //===== 1.9.0 upgrade line ======//
00056 
00057     if ($oldversion < 2009041900) {
00058         resource_20_prepare_migration();
00059         // resource savepoint reached
00060         upgrade_mod_savepoint(true, 2009041900, 'resource');
00061     }
00062 
00063     if ($oldversion < 2009042000) {
00064        // Rename field summary on table resource to intro
00065         $table = new xmldb_table('resource');
00066         $field = new xmldb_field('summary', XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'reference');
00067 
00068         // Launch rename field summary
00069         $dbman->rename_field($table, $field, 'intro');
00070 
00071         // resource savepoint reached
00072         upgrade_mod_savepoint(true, 2009042000, 'resource');
00073     }
00074 
00075     if ($oldversion < 2009042001) {
00076         // Define field introformat to be added to resource
00077         $table = new xmldb_table('resource');
00078         $field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro');
00079 
00080         // Launch add field introformat
00081         if (!$dbman->field_exists($table, $field)) {
00082             $dbman->add_field($table, $field);
00083         }
00084 
00085         // conditionally migrate to html format in intro
00086         if ($CFG->texteditors !== 'textarea') {
00087             $rs = $DB->get_recordset('resource', array('introformat'=>FORMAT_MOODLE), '', 'id,intro,introformat');
00088             foreach ($rs as $r) {
00089                 $r->intro       = text_to_html($r->intro, false, false, true);
00090                 $r->introformat = FORMAT_HTML;
00091                 $DB->update_record('resource', $r);
00092                 upgrade_set_timeout();
00093             }
00094             $rs->close();
00095         }
00096 
00097         // resource savepoint reached
00098         upgrade_mod_savepoint(true, 2009042001, 'resource');
00099     }
00100 
00101     if ($oldversion < 2009062600) {
00102         $res_count = $DB->count_records('resource');
00103         $old_count = $DB->count_records('resource_old', array('migrated'=>0));
00104         if ($res_count != $old_count) {
00105             //we can not continue, something is very wrong!!
00106             upgrade_log(UPGRADE_LOG_ERROR, null, 'Resource migration failed.');
00107             upgrade_mod_savepoint(false, 2009062600, 'resource');
00108         }
00109 
00110         // Drop obsoleted fields from resource table
00111         $table = new xmldb_table('resource');
00112         $fields = array('type', 'reference', 'alltext', 'popup', 'options');
00113         foreach ($fields as $fname) {
00114             $field = new xmldb_field($fname);
00115             $dbman->drop_field($table, $field);
00116         }
00117 
00118         // resource savepoint reached
00119         upgrade_mod_savepoint(true, 2009062600, 'resource');
00120     }
00121 
00122     if ($oldversion < 2009062601) {
00123         $table = new xmldb_table('resource');
00124         // Define field tobemigrated to be added to resource
00125         $field = new xmldb_field('tobemigrated', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'introformat');
00126         // Conditionally launch add field tobemigrated
00127         if (!$dbman->field_exists($table, $field)) {
00128             $dbman->add_field($table, $field);
00129         }
00130         // Define field mainfile to be added to resource
00131         $field = new xmldb_field('mainfile', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'tobemigrated');
00132         // Conditionally launch add field mainfile
00133         if (!$dbman->field_exists($table, $field)) {
00134             $dbman->add_field($table, $field);
00135         }
00136         // Define field legacyfiles to be added to resource
00137         $field = new xmldb_field('legacyfiles', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'mainfile');
00138         // Conditionally launch add field legacyfiles
00139         if (!$dbman->field_exists($table, $field)) {
00140             $dbman->add_field($table, $field);
00141         }
00142         // Define field legacyfileslast to be added to resource
00143         $field = new xmldb_field('legacyfileslast', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'legacyfiles');
00144         // Conditionally launch add field legacyfileslast
00145         if (!$dbman->field_exists($table, $field)) {
00146             $dbman->add_field($table, $field);
00147         }
00148         // Define field display to be added to resource
00149         $field = new xmldb_field('display', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'legacyfileslast');
00150         // Conditionally launch add field display
00151         if (!$dbman->field_exists($table, $field)) {
00152             $dbman->add_field($table, $field);
00153         }
00154         // Define field displayoptions to be added to resource
00155         $field = new xmldb_field('displayoptions', XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'display');
00156         // Conditionally launch add field displayoptions
00157         if (!$dbman->field_exists($table, $field)) {
00158             $dbman->add_field($table, $field);
00159         }
00160         // Define field filterfiles to be added to resource
00161         $field = new xmldb_field('filterfiles', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'displayoptions');
00162         // Conditionally launch add field filterfiles
00163         if (!$dbman->field_exists($table, $field)) {
00164             $dbman->add_field($table, $field);
00165         }
00166         // Define field revision to be added to resource
00167         $field = new xmldb_field('revision', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'filterfiles');
00168         // Conditionally launch add field revision
00169         if (!$dbman->field_exists($table, $field)) {
00170             $dbman->add_field($table, $field);
00171         }
00172 
00173         //mark all records as awaiting migration
00174         $DB->set_field('resource', 'tobemigrated', 1, array());
00175 
00176         // resource savepoint reached
00177         upgrade_mod_savepoint(true, 2009062601, 'resource');
00178     }
00179 
00180     if ($oldversion < 2009062603) {
00181         resource_20_migrate();
00182         upgrade_mod_savepoint(true, 2009062603, 'resource');
00183     }
00184 
00185     if ($oldversion < 2009063000) {
00186         //migrate and prune old settings - admins need to review and set up all module settings anyway
00187         if (!empty($CFG->resource_framesize)) {
00188             set_config('framesize', $CFG->resource_framesize, 'resource');
00189         }
00190         if (!empty($CFG->resource_popupheight)) {
00191             set_config('popupheight', $CFG->resource_popupheight, 'resource');
00192         }
00193         if (!empty($CFG->resource_popupwidth)) {
00194             set_config('popupwidth', $CFG->resource_popupwidth, 'resource');
00195         }
00196 
00197         $cleanupsettings = array(
00198             // migrated settings
00199             'resource_framesize', 'resource_popupheight', 'resource_popupwidth', 'resource_popupmenubar',
00200 
00201             // obsoleted settings
00202             'resource_websearch', 'resource_defaulturl', 'resource_allowlocalfiles',
00203             'resource_popup', 'resource_popupresizable', 'resource_popupscrollbars',
00204             'resource_popupdirectories', 'resource_popuplocation',
00205             'resource_popuptoolbar', 'resource_popupstatus',
00206 
00207             //waiting for some other modules or plugins to pick these up
00208             /*
00209             'resource_secretphrase',
00210             */
00211         );
00212         foreach ($cleanupsettings as $setting) {
00213             unset_config($setting);
00214         }
00215 
00216         upgrade_mod_savepoint(true, 2009063000, 'resource');
00217     }
00218 
00219     if ($oldversion < 2009080501) {
00220         require_once("$CFG->libdir/filelib.php");
00221 
00222         $sql = "SELECT r.id,
00223                        r.mainfile,
00224                        cm.id AS cmid
00225                   FROM {resource} r
00226                   JOIN {modules} m ON m.name='resource'
00227                   JOIN {course_modules} cm ON (cm.module = m.id AND cm.instance = r.id)";
00228 
00229         $instances = $DB->get_recordset_sql($sql);
00230         foreach ($instances as $instance) {
00231             if (empty($instance->mainfile)) {
00232                 // weird
00233                 continue;
00234             }
00235             $context   = get_context_instance(CONTEXT_MODULE, $instance->cmid, MUST_EXIST);
00236             $parts     = explode('/', $instance->mainfile);
00237             $filename  = array_pop($parts);
00238             $filepath  = implode('/', $parts);
00239             file_set_sortorder($context->id, 'mod_resource', 'content', 0, $filepath, $filename, 1);
00240         }
00241         $instances->close();
00242 
00244         $table = new xmldb_table('resource');
00245         $field = new xmldb_field('mainfile');
00246         $dbman->drop_field($table, $field);
00247 
00249         upgrade_mod_savepoint(true, 2009080501, 'resource');
00250     }
00251 
00252     // MDL-10906. Removing resource_allowlocalfiles setting.
00253     if ($oldversion < 2010083000) {
00254         unset_config('resource_allowlocalfiles');
00255         upgrade_mod_savepoint(true, 2010083000, 'resource');
00256     }
00257 
00258     if ($oldversion < 2011022700) {
00259         // refresh resource links breakage caused by invalid sortorder
00260         require_once($CFG->dirroot . '/course/lib.php');
00261         rebuild_course_cache(0, true);
00262         upgrade_mod_savepoint(true, 2011022700, 'resource');
00263     }
00264 
00265     // Moodle v2.1.0 release upgrade line
00266     // Put any upgrade step following this
00267 
00268     // Moodle v2.2.0 release upgrade line
00269     // Put any upgrade step following this
00270 
00271     return true;
00272 }
 All Data Structures Namespaces Files Functions Variables Enumerations