From 02854eac9ef95f7a4dffe780c0b14e95df610bd5 Mon Sep 17 00:00:00 2001 From: Cameron Ball Date: Wed, 22 Mar 2017 19:23:05 +0800 Subject: [PATCH] MDL-58087 core_calendar: Don't pass non action events through our plumbing The event factory should simply instantiate an event for non action events and pass only action events through the plumbing. This way modules implementing the callbacks can be sure that what is passed in to the callback is actually supposed to be an action event. Part of MDL-55611 epic. --- .../factories/event_abstract_factory.php | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/calendar/classes/local/event/factories/event_abstract_factory.php b/calendar/classes/local/event/factories/event_abstract_factory.php index 477ca303ce2..9482819b900 100644 --- a/calendar/classes/local/event/factories/event_abstract_factory.php +++ b/calendar/classes/local/event/factories/event_abstract_factory.php @@ -156,7 +156,7 @@ abstract class event_abstract_factory implements event_factory_interface { function($modulename, $instance) { return \core_calendar\api::get_module_cached( $this->modulecachereference, - $dbrow->modulename, + $modulename, $instance ); } @@ -169,28 +169,28 @@ abstract class event_abstract_factory implements event_factory_interface { }); } - return $this->expose_event( - $this->apply_component_action( - new event( - $dbrow->id, - $dbrow->name, - new event_description($dbrow->description, $dbrow->format), - $course, - $group, - $user, - new repeat_event_collection($dbrow->id, $dbrow->repeatid, $this), - $module, - $dbrow->eventtype, - new event_times( - (new \DateTimeImmutable())->setTimestamp($dbrow->timestart), - (new \DateTimeImmutable())->setTimestamp($dbrow->timestart + $dbrow->timeduration), - (new \DateTimeImmutable())->setTimestamp($dbrow->timesort ? $dbrow->timesort : $dbrow->timestart), - (new \DateTimeImmutable())->setTimestamp($dbrow->timemodified) - ), - !empty($dbrow->visible), - $subscription - ) - ) + $event = new event( + $dbrow->id, + $dbrow->name, + new event_description($dbrow->description, $dbrow->format), + $course, + $group, + $user, + new repeat_event_collection($dbrow->id, $dbrow->repeatid, $this), + $module, + $dbrow->eventtype, + new event_times( + (new \DateTimeImmutable())->setTimestamp($dbrow->timestart), + (new \DateTimeImmutable())->setTimestamp($dbrow->timestart + $dbrow->timeduration), + (new \DateTimeImmutable())->setTimestamp($dbrow->timesort ? $dbrow->timesort : $dbrow->timestart), + (new \DateTimeImmutable())->setTimestamp($dbrow->timemodified) + ), + !empty($dbrow->visible), + $subscription ); + + $isactionevent = !empty($dbrow->type) && $dbrow->type == CALENDAR_EVENT_TYPE_ACTION; + + return $isactionevent ? $this->expose_event($this->apply_component_action($event)) : $event; } }