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.
This commit is contained in:
Cameron Ball 2017-03-22 19:23:05 +08:00 committed by Dan Poltawski
parent f8a3e28b16
commit 02854eac9e

View File

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