From cb48a42adaeeb9b62dacd26f94dcd0c1df4af6c7 Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Fri, 13 Apr 2012 04:40:29 +0200 Subject: [PATCH] MDL-25660 recreate all workshop calendar events 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. --- mod/workshop/db/upgrade.php | 37 +++++++++++++++++++++++++++++++++++++ mod/workshop/version.php | 2 +- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/mod/workshop/db/upgrade.php b/mod/workshop/db/upgrade.php index dd9fb9e514c..af5ebab17c5 100644 --- a/mod/workshop/db/upgrade.php +++ b/mod/workshop/db/upgrade.php @@ -42,5 +42,42 @@ function xmldb_workshop_upgrade($oldversion) { // Moodle v2.2.0 release upgrade line // 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; } diff --git a/mod/workshop/version.php b/mod/workshop/version.php index 28505d53b0a..9f2b2537af1 100644 --- a/mod/workshop/version.php +++ b/mod/workshop/version.php @@ -25,7 +25,7 @@ defined('MOODLE_INTERNAL') || die(); -$module->version = 2012030700; // The current module version (Date: YYYYMMDDXX) +$module->version = 2012041300; // The current module version (Date: YYYYMMDDXX) $module->requires = 2012030100.04; // Requires this Moodle version $module->component = 'mod_workshop'; // Full name of the plugin (used for diagnostics) $module->cron = 0;