Skip to content

Commit

Permalink
MDL-25660 recreate all workshop calendar events
Browse files Browse the repository at this point in the history
Due to complex workshop upgrade path from 1.9 and missing calendar events
support in 2.x, the only safe way to get rid of potentially invalid
calendar events (such as those reported in MDL-26687) is to remove all
current workshop events and recreate them from scratch.
  • Loading branch information
mudrd8mz committed Apr 13, 2012
1 parent 6c60424 commit 4494053
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
37 changes: 37 additions & 0 deletions mod/workshop/db/upgrade.php
Expand Up @@ -322,5 +322,42 @@ function xmldb_workshop_upgrade($oldversion) {
// Moodle v2.2.0 release upgrade line // Moodle v2.2.0 release upgrade line
// Put any upgrade step following this // Put any upgrade step following this


/**
* Remove all workshop calendar events
*/
if ($oldversion < 2011112901) {
require_once($CFG->dirroot . '/calendar/lib.php');
$events = $DB->get_records('event', array('modulename' => 'workshop'));
foreach ($events as $event) {
$event = calendar_event::load($event);
$event->delete();
}
upgrade_mod_savepoint(true, 2011112901, 'workshop');
}

/**
* Recreate all workshop calendar events
*/
if ($oldversion < 2011112902) {
require_once(dirname(dirname(__FILE__)) . '/lib.php');

$sql = "SELECT w.id, w.course, w.name, w.intro, w.introformat, w.submissionstart,
w.submissionend, w.assessmentstart, w.assessmentend,
cm.id AS cmid
FROM {workshop} w
JOIN {modules} m ON m.name = 'workshop'
JOIN {course_modules} cm ON (cm.module = m.id AND cm.course = w.course AND cm.instance = w.id)";

$rs = $DB->get_recordset_sql($sql);

foreach ($rs as $workshop) {
$cmid = $workshop->cmid;
unset($workshop->cmid);
workshop_calendar_update($workshop, $cmid);
}
$rs->close();
upgrade_mod_savepoint(true, 2011112902, 'workshop');
}

return true; return true;
} }
2 changes: 1 addition & 1 deletion mod/workshop/version.php
Expand Up @@ -25,7 +25,7 @@


defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();


$module->version = 2011112900; // The current module version (Date: YYYYMMDDXX) $module->version = 2011112902; // The current module version (Date: YYYYMMDDXX)
$module->requires = 2011112900; // Requires this Moodle version $module->requires = 2011112900; // Requires this Moodle version
$module->component = 'mod_workshop'; // Full name of the plugin (used for diagnostics) $module->component = 'mod_workshop'; // Full name of the plugin (used for diagnostics)
$module->cron = 0; $module->cron = 0;

0 comments on commit 4494053

Please sign in to comment.