MDL-33774 mod_label stores the content where it is supposed to
authorMarina Glancy <marina@moodle.com>
Fri, 18 Jan 2013 06:25:58 +0000 (17:25 +1100)
committerMarina Glancy <marina@moodle.com>
Thu, 14 Feb 2013 08:46:19 +0000 (19:46 +1100)
removed hardcoded checking for 'label' module type

changed label update script

lib/modinfolib.php
mod/label/db/upgrade.php
mod/label/lib.php
mod/label/version.php

index c40efc7..f575761 100644 (file)
@@ -785,11 +785,6 @@ class cm_info extends stdClass {
         if (empty($this->content)) {
             return '';
         }
-        if ($this->modname === 'label') {
-            // special case, label returns already formatted content, see cm_info::__construct()
-            // and label_get_coursemodule_info()
-            return $this->content;
-        }
         // Improve filter performance by preloading filter setttings for all
         // activities on the course (this does nothing if called multiple
         // times)
@@ -1094,13 +1089,6 @@ class cm_info extends stdClass {
         $this->showdescription  = isset($mod->showdescription) ? $mod->showdescription : 0;
         $this->state = self::STATE_BASIC;
 
-        // This special case handles old label data. Labels used to use the 'name' field for
-        // content
-        if ($this->modname === 'label' && $this->content === '') {
-            $this->content = $this->extra;
-            $this->extra = '';
-        }
-
         // Note: These fields from $cm were not present in cm_info in Moodle
         // 2.0.2 and prior. They may not be available if course cache hasn't
         // been rebuilt since then.
@@ -1491,8 +1479,8 @@ function rebuild_course_cache($courseid=0, $clearonly=false) {
  * Class that is the return value for the _get_coursemodule_info module API function.
  *
  * Note: For backward compatibility, you can also return a stdclass object from that function.
- * The difference is that the stdclass object may contain an 'extra' field (deprecated because
- * it was crazy, except for label which uses it differently). The stdclass object may not contain
+ * The difference is that the stdclass object may contain an 'extra' field (deprecated,
+ * use extraclasses and onclick instead). The stdclass object may not contain
  * the new fields defined here (content, extraclasses, customdata).
  */
 class cached_cm_info {
index ccaad7b..576cd99 100644 (file)
@@ -62,6 +62,22 @@ function xmldb_label_upgrade($oldversion) {
     // Moodle v2.4.0 release upgrade line
     // Put any upgrade step following this
 
+    if ($oldversion < 2013021400) {
+        // find all courses that contain labels and reset their cache
+        $modid = $DB->get_field_sql("SELECT id FROM {modules} WHERE name=?",
+                array('label'));
+        if ($modid) {
+            $courses = $DB->get_fieldset_sql('SELECT DISTINCT course '.
+                'FROM {course_modules} WHERE module=?', array($modid));
+            foreach ($courses as $courseid) {
+                $DB->execute('UPDATE {course} set modinfo = ?, sectioncache = ? '.
+                        'WHERE id = ?', array(null, null, $courseid));
+            }
+        }
+
+        // label savepoint reached
+        upgrade_mod_savepoint(true, 2013021400, 'label');
+    }
 
     return true;
 }
index 7ab153c..e265129 100644 (file)
@@ -129,9 +129,9 @@ function label_get_coursemodule_info($coursemodule) {
             $label->name = "label{$label->id}";
             $DB->set_field('label', 'name', $label->name, array('id'=>$label->id));
         }
-        $info = new stdClass();
+        $info = new cached_cm_info();
         // no filtering hre because this info is cached and filtered later
-        $info->extra = format_module_intro('label', $label, $coursemodule->id, false);
+        $info->content = format_module_intro('label', $label, $coursemodule->id, false);
         $info->name  = $label->name;
         return $info;
     } else {
index 7d1e67f..3c91dd2 100644 (file)
@@ -25,7 +25,7 @@
 
 defined('MOODLE_INTERNAL') || die();
 
-$module->version   = 2012112900;       // The current module version (Date: YYYYMMDDXX)
+$module->version   = 2013021400;       // The current module version (Date: YYYYMMDDXX)
 $module->requires  = 2012112900;    // Requires this Moodle version
 $module->component = 'mod_label'; // Full name of the plugin (used for diagnostics)
 $module->cron      = 0;