mirror of
https://github.com/moodle/moodle.git
synced 2025-03-18 22:50:19 +01:00
MDL-45296 events: Fix objecttable and ids
Various events had them incorrectly set or missing: - submission_locked - submission_unlocked - subscription_created - subscription_deleted
This commit is contained in:
parent
f8fa440649
commit
9c94ca5843
@ -47,13 +47,13 @@ class submission_locked extends base {
|
||||
* @since Moodle 2.7
|
||||
*
|
||||
* @param \assign $assign
|
||||
* @param \stdClass $user
|
||||
* @param \stdClass $submission
|
||||
* @return submission_locked
|
||||
*/
|
||||
public static function create_from_user(\assign $assign, \stdClass $user) {
|
||||
public static function create_from_submission(\assign $assign, \stdClass $submission, \stdClass $user) {
|
||||
$data = array(
|
||||
'context' => $assign->get_context(),
|
||||
'objectid' => $assign->get_instance()->id,
|
||||
'objectid' => $submission->id,
|
||||
'relateduserid' => $user->id,
|
||||
);
|
||||
self::$preventcreatecall = false;
|
||||
@ -92,7 +92,7 @@ class submission_locked extends base {
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'u';
|
||||
$this->data['edulevel'] = self::LEVEL_TEACHING;
|
||||
$this->data['objecttable'] = 'assign';
|
||||
$this->data['objecttable'] = 'assign_submission';
|
||||
}
|
||||
|
||||
/**
|
||||
@ -114,7 +114,7 @@ class submission_locked extends base {
|
||||
*/
|
||||
protected function validate_data() {
|
||||
if (self::$preventcreatecall) {
|
||||
throw new \coding_exception('cannot call submission_locked::create() directly, use submission_locked::create_from_user() instead.');
|
||||
throw new \coding_exception('cannot call submission_locked::create() directly, use submission_locked::create_from_submission() instead.');
|
||||
}
|
||||
|
||||
parent::validate_data();
|
||||
|
@ -47,13 +47,13 @@ class submission_unlocked extends base {
|
||||
* @since Moodle 2.7
|
||||
*
|
||||
* @param \assign $assign
|
||||
* @param \stdClass $user
|
||||
* @param \stdClass $submission
|
||||
* @return submission_unlocked
|
||||
*/
|
||||
public static function create_from_user(\assign $assign, \stdClass $user) {
|
||||
public static function create_from_submission(\assign $assign, \stdClass $submission, \stdClass $user) {
|
||||
$data = array(
|
||||
'context' => $assign->get_context(),
|
||||
'objectid' => $assign->get_instance()->id,
|
||||
'objectid' => $submission->id,
|
||||
'relateduserid' => $user->id,
|
||||
);
|
||||
self::$preventcreatecall = false;
|
||||
@ -92,7 +92,7 @@ class submission_unlocked extends base {
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'u';
|
||||
$this->data['edulevel'] = self::LEVEL_TEACHING;
|
||||
$this->data['objecttable'] = 'assign';
|
||||
$this->data['objecttable'] = 'assign_submission';
|
||||
}
|
||||
|
||||
/**
|
||||
@ -114,7 +114,7 @@ class submission_unlocked extends base {
|
||||
*/
|
||||
protected function validate_data() {
|
||||
if (self::$preventcreatecall) {
|
||||
throw new \coding_exception('cannot call submission_unlocked::create() directly, use submission_unlocked::create_from_user() instead.');
|
||||
throw new \coding_exception('cannot call submission_unlocked::create() directly, use submission_unlocked::create_from_submission() instead.');
|
||||
}
|
||||
|
||||
parent::validate_data();
|
||||
|
@ -6103,7 +6103,7 @@ class assign {
|
||||
}
|
||||
|
||||
$user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
|
||||
\mod_assign\event\submission_locked::create_from_user($this, $user)->trigger();
|
||||
\mod_assign\event\submission_locked::create_from_submission($this, $submission, $user)->trigger();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -6228,7 +6228,7 @@ class assign {
|
||||
}
|
||||
|
||||
$user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
|
||||
\mod_assign\event\submission_unlocked::create_from_user($this, $user)->trigger();
|
||||
\mod_assign\event\submission_unlocked::create_from_submission($this, $submission, $user)->trigger();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ This files describes API changes in the assign code.
|
||||
* A new web service function mod_assign_save_grades has been added which allows multiple grades to be processed.
|
||||
* The event submission_updated() [mod/assign/classes/event/submission_updated.php] has been altered to now be an abstract class
|
||||
for submission events in the submission plug-ins.
|
||||
* The subscription_created and subscription_deleted event's objecttables have been changed from 'assign' to 'assign_submission'
|
||||
|
||||
=== 2.6.1 ===
|
||||
|
||||
|
@ -49,6 +49,7 @@ class subscription_created extends \core\event\base {
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'c';
|
||||
$this->data['edulevel'] = self::LEVEL_OTHER;
|
||||
$this->data['objecttable'] = 'forum_subscriptions';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -49,6 +49,7 @@ class subscription_deleted extends \core\event\base {
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'd';
|
||||
$this->data['edulevel'] = self::LEVEL_OTHER;
|
||||
$this->data['objecttable'] = 'forum_subscriptions';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4839,6 +4839,7 @@ function forum_subscribe($userid, $forumid) {
|
||||
$cm = get_coursemodule_from_instance('forum', $forumid);
|
||||
$params = array(
|
||||
'context' => context_module::instance($cm->id),
|
||||
'objectid' => $result,
|
||||
'relateduserid' => $userid,
|
||||
'other' => array('forumid' => $forumid),
|
||||
|
||||
@ -4860,17 +4861,22 @@ function forum_unsubscribe($userid, $forumid) {
|
||||
global $DB;
|
||||
|
||||
$DB->delete_records('forum_digests', array('userid' => $userid, 'forum' => $forumid));
|
||||
$DB->delete_records('forum_subscriptions', array('userid' => $userid, 'forum' => $forumid));
|
||||
|
||||
$cm = get_coursemodule_from_instance('forum', $forumid);
|
||||
$params = array(
|
||||
'context' => context_module::instance($cm->id),
|
||||
'relateduserid' => $userid,
|
||||
'other' => array('forumid' => $forumid),
|
||||
if ($forumsubscription = $DB->get_record('forum_subscriptions', array('userid' => $userid, 'forum' => $forumid))) {
|
||||
$DB->delete_records('forum_subscriptions', array('id' => $forumsubscription->id));
|
||||
|
||||
);
|
||||
$event = \mod_forum\event\subscription_deleted::create($params);
|
||||
$event->trigger();
|
||||
$cm = get_coursemodule_from_instance('forum', $forumid);
|
||||
$params = array(
|
||||
'context' => context_module::instance($cm->id),
|
||||
'objectid' => $forumsubscription->id,
|
||||
'relateduserid' => $userid,
|
||||
'other' => array('forumid' => $forumid),
|
||||
|
||||
);
|
||||
$event = \mod_forum\event\subscription_deleted::create($params);
|
||||
$event->add_record_snapshot('forum_subscriptions', $forumsubscription);
|
||||
$event->trigger();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user