MDL-33774 mod_label stores the content where it is supposed to

removed hardcoded checking for 'label' module type

changed label update script
This commit is contained in:
Marina Glancy 2013-01-18 17:25:58 +11:00
parent 1dd6835d8c
commit 3008f86c3f
4 changed files with 21 additions and 17 deletions

View 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 {

View 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;
}

View 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 {

View 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;