From 1a219fb6c934566b8b82ddf54fd027e0ebed7beb Mon Sep 17 00:00:00 2001 From: Adrian Greeve Date: Wed, 2 Apr 2014 11:46:16 +0800 Subject: [PATCH] MDL-44340 mod_workshop: Added an event call to phase switched page. This event was missed in the previous workshop add_to_log change over. The switch phase event has been moved into the workshop::switch_phase() method. Also workshop::log() has been deprecated. Developers should use the event classes to log events. --- mod/workshop/locallib.php | 11 +++++++++++ mod/workshop/switchphase.php | 1 - mod/workshop/tests/events_test.php | 14 ++++++-------- mod/workshop/upgrade.txt | 7 +++++++ mod/workshop/view.php | 3 --- 5 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 mod/workshop/upgrade.txt diff --git a/mod/workshop/locallib.php b/mod/workshop/locallib.php index 8934f2afd31..8afb25a4585 100644 --- a/mod/workshop/locallib.php +++ b/mod/workshop/locallib.php @@ -1505,6 +1505,7 @@ class workshop { /** * Workshop wrapper around {@see add_to_log()} + * @deprecated since 2.7 Please use the provided event classes for logging actions. * * @param string $action to be logged * @param moodle_url $url absolute url as returned by {@see workshop::submission_url()} and friends @@ -1513,6 +1514,7 @@ class workshop { * @return void|array array of arguments for add_to_log if $return is true */ public function log($action, moodle_url $url = null, $info = null, $return = false) { + debugging('The log method is now deprecated, please use event classes instead', DEBUG_DEVELOPER); if (is_null($url)) { $url = $this->view_url(); @@ -1690,6 +1692,15 @@ class workshop { $DB->set_field('workshop', 'phase', $newphase, array('id' => $this->id)); $this->phase = $newphase; + $eventdata = array( + 'objectid' => $this->id, + 'context' => $this->context, + 'other' => array( + 'workshopphase' => $this->phase + ) + ); + $event = \mod_workshop\event\phase_switched::create($eventdata); + $event->trigger(); return true; } diff --git a/mod/workshop/switchphase.php b/mod/workshop/switchphase.php index aa1a380baa9..0c58cef8937 100644 --- a/mod/workshop/switchphase.php +++ b/mod/workshop/switchphase.php @@ -47,7 +47,6 @@ if ($confirm) { if (!$workshop->switch_phase($phase)) { print_error('errorswitchingphase', 'workshop', $workshop->view_url()); } - $workshop->log('update switch phase', $workshop->view_url(), $workshop->phase); redirect($workshop->view_url()); } diff --git a/mod/workshop/tests/events_test.php b/mod/workshop/tests/events_test.php index db0384936dc..99ae64b23fd 100644 --- a/mod/workshop/tests/events_test.php +++ b/mod/workshop/tests/events_test.php @@ -80,22 +80,20 @@ class mod_workshop_events_testcase extends advanced_testcase { $this->workshop->phaseswitchassessment = 1; $this->workshop->submissionend = time() - 1; - $event = \mod_workshop\event\phase_switched::create(array( - 'objectid' => $this->workshop->id, - 'context' => $this->context, - 'courseid' => $this->course->id, - 'other' => array('workshopphase' => $this->workshop->phase) - )); + $cm = get_coursemodule_from_instance('workshop', $this->workshop->id, $this->course->id, false, MUST_EXIST); + $workshop = new testable_workshop($this->workshop, $cm, $this->course); + // The phase that we are switching to. + $newphase = 30; // Trigger and capture the event. $sink = $this->redirectEvents(); - $event->trigger(); + $workshop->switch_phase($newphase); $events = $sink->get_events(); $event = reset($events); // Check that the legacy log data is valid. $expected = array($this->course->id, 'workshop', 'update switch phase', 'view.php?id=' . $this->workshop->id, - $this->workshop->phase, $this->cm->id); + $newphase, $this->cm->id); $this->assertEventLegacyLogData($expected, $event); $this->assertEventContextNotUsed($event); diff --git a/mod/workshop/upgrade.txt b/mod/workshop/upgrade.txt new file mode 100644 index 00000000000..7a76f64956d --- /dev/null +++ b/mod/workshop/upgrade.txt @@ -0,0 +1,7 @@ +This files describes API changes in /mod/workshop - activity modules, +information provided here is intended especially for developers. + +=== 2.7 === + +* The method workshop::log() has been deprecated in the workshop module. Please use the event classes instead + (mod/workshop/classes/event). \ No newline at end of file diff --git a/mod/workshop/view.php b/mod/workshop/view.php index de989f25b83..10a26d8849e 100644 --- a/mod/workshop/view.php +++ b/mod/workshop/view.php @@ -74,9 +74,6 @@ $event->trigger(); if ($workshop->phase == workshop::PHASE_SUBMISSION and $workshop->phaseswitchassessment and $workshop->submissionend > 0 and $workshop->submissionend < time()) { $workshop->switch_phase(workshop::PHASE_ASSESSMENT); - $eventdata['other']['workshopphase'] = $workshop->phase; - $event = \mod_workshop\event\phase_switched::create($eventdata); - $event->trigger(); // Disable the automatic switching now so that it is not executed again by accident // if the teacher changes the phase back to the submission one. $DB->set_field('workshop', 'phaseswitchassessment', 0, array('id' => $workshop->id));