mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 12:40:01 +01:00
MDL-36941 core: alter events to use new table structure
This commit is contained in:
parent
ee14412e21
commit
4cd439887a
@ -32,7 +32,6 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @property-read array $other {
|
||||
* Extra information about event.
|
||||
*
|
||||
* - string $messagetable: the table we marked the message as deleted from (message/message_read).
|
||||
* - int messageid: the id of the message.
|
||||
* - int useridfrom: the id of the user who received the message.
|
||||
* - int useridto: the id of the user who sent the message.
|
||||
@ -51,11 +50,11 @@ class message_deleted extends base {
|
||||
* @param int $userfromid the user who the message was from.
|
||||
* @param int $usertoid the user who the message was sent to.
|
||||
* @param int $userdeleted the user who deleted it.
|
||||
* @param string $messagetable the table we are marking the message as deleted in.
|
||||
* @param int $messageid the id of the message that was deleted.
|
||||
* @param int $muaid The id in the message_user_actions table
|
||||
* @return message_deleted
|
||||
*/
|
||||
public static function create_from_ids($userfromid, $usertoid, $userdeleted, $messagetable, $messageid) {
|
||||
public static function create_from_ids($userfromid, $usertoid, $userdeleted, $messageid, $muaid) {
|
||||
// Check who was deleting the message.
|
||||
if ($userdeleted == $userfromid) {
|
||||
$relateduserid = $usertoid;
|
||||
@ -66,11 +65,11 @@ class message_deleted extends base {
|
||||
// We set the userid to the user who deleted the message, nothing to do
|
||||
// with whether or not they sent or received the message.
|
||||
$event = self::create(array(
|
||||
'objectid' => $muaid,
|
||||
'userid' => $userdeleted,
|
||||
'context' => \context_system::instance(),
|
||||
'relateduserid' => $relateduserid,
|
||||
'other' => array(
|
||||
'messagetable' => $messagetable,
|
||||
'messageid' => $messageid,
|
||||
'useridfrom' => $userfromid,
|
||||
'useridto' => $usertoid
|
||||
@ -84,7 +83,8 @@ class message_deleted extends base {
|
||||
* Init method.
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'u';
|
||||
$this->data['objecttable'] = 'message_user_actions';
|
||||
$this->data['crud'] = 'c';
|
||||
$this->data['edulevel'] = self::LEVEL_OTHER;
|
||||
}
|
||||
|
||||
@ -126,10 +126,6 @@ class message_deleted extends base {
|
||||
throw new \coding_exception('The \'relateduserid\' must be set.');
|
||||
}
|
||||
|
||||
if (!isset($this->other['messagetable'])) {
|
||||
throw new \coding_exception('The \'messagetable\' value must be set in other.');
|
||||
}
|
||||
|
||||
if (!isset($this->other['messageid'])) {
|
||||
throw new \coding_exception('The \'messageid\' value must be set in other.');
|
||||
}
|
||||
@ -143,11 +139,13 @@ class message_deleted extends base {
|
||||
}
|
||||
}
|
||||
|
||||
public static function get_objectid_mapping() {
|
||||
return array('db' => 'message_user_actions', 'restore' => base::NOT_MAPPED);
|
||||
}
|
||||
|
||||
public static function get_other_mapping() {
|
||||
// Messages are not backed up, so no need to map them on restore.
|
||||
$othermapped = array();
|
||||
// The messageid table varies so it cannot be mapped.
|
||||
$othermapped['messageid'] = array('db' => base::NOT_MAPPED, 'restore' => base::NOT_MAPPED);
|
||||
$othermapped['useridfrom'] = array('db' => 'user', 'restore' => base::NOT_MAPPED);
|
||||
$othermapped['useridto'] = array('db' => 'user', 'restore' => base::NOT_MAPPED);
|
||||
return $othermapped;
|
||||
|
@ -32,7 +32,6 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @property-read array $other {
|
||||
* Extra information about event.
|
||||
*
|
||||
* - int messageid: the id of the message.
|
||||
* - int courseid: the id of the related course.
|
||||
* }
|
||||
*
|
||||
@ -69,14 +68,11 @@ class message_sent extends base {
|
||||
}
|
||||
|
||||
$event = self::create(array(
|
||||
'objectid' => $messageid,
|
||||
'userid' => $userfromid,
|
||||
'context' => \context_system::instance(),
|
||||
'relateduserid' => $usertoid,
|
||||
'other' => array(
|
||||
// In earlier versions it can either be the id in the 'message_read' or 'message' table.
|
||||
// Now it is always the id from 'message' table. Please note that the record is still moved
|
||||
// to the 'message_read' table later when message marked as read.
|
||||
'messageid' => $messageid,
|
||||
'courseid' => $courseid
|
||||
)
|
||||
));
|
||||
@ -88,6 +84,7 @@ class message_sent extends base {
|
||||
* Init method.
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['objecttable'] = 'messages';
|
||||
$this->data['crud'] = 'c';
|
||||
$this->data['edulevel'] = self::LEVEL_OTHER;
|
||||
}
|
||||
@ -133,8 +130,9 @@ class message_sent extends base {
|
||||
// The add_to_log function was only ever called when we sent a message from one user to another. We do not want
|
||||
// to return the legacy log data if we are sending a system message, so check that the userid is valid.
|
||||
if (\core_user::is_real_user($this->userid)) {
|
||||
$messageid = $this->other['messageid'] ?? $this->objectid; // For BC we may have 'messageid' in other.
|
||||
return array(SITEID, 'message', 'write', 'index.php?user=' . $this->userid . '&id=' . $this->relateduserid .
|
||||
'&history=1#m' . $this->other['messageid'], $this->userid);
|
||||
'&history=1#m' . $messageid, $this->userid);
|
||||
}
|
||||
|
||||
return null;
|
||||
@ -153,26 +151,18 @@ class message_sent extends base {
|
||||
throw new \coding_exception('The \'relateduserid\' must be set.');
|
||||
}
|
||||
|
||||
if (!isset($this->other['messageid'])) {
|
||||
throw new \coding_exception('The \'messageid\' value must be set in other.');
|
||||
}
|
||||
|
||||
if (!isset($this->other['courseid'])) {
|
||||
throw new \coding_exception('The \'courseid\' value must be set in other.');
|
||||
}
|
||||
}
|
||||
|
||||
public static function get_objectid_mapping() {
|
||||
// Messages are not backed up, so no need to map them.
|
||||
return false;
|
||||
return array('db' => 'messages', 'restore' => base::NOT_MAPPED);
|
||||
}
|
||||
|
||||
public static function get_other_mapping() {
|
||||
// Messages are not backed up, so no need to map them on restore.
|
||||
$othermapped = array();
|
||||
// The messages table could vary for older events - so cannot be mapped.
|
||||
$othermapped['messageid'] = array('db' => base::NOT_MAPPED, 'restore' => base::NOT_MAPPED);
|
||||
$othermapped['courseid'] = array('db' => base::NOT_MAPPED, 'restore' => base::NOT_MAPPED);
|
||||
$othermapped['courseid'] = array('db' => 'course', 'restore' => base::NOT_MAPPED);
|
||||
return $othermapped;
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ class message_viewed extends base {
|
||||
* Init method.
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['objecttable'] = 'message_read';
|
||||
$this->data['objecttable'] = 'message_user_actions';
|
||||
$this->data['crud'] = 'c';
|
||||
$this->data['edulevel'] = self::LEVEL_OTHER;
|
||||
}
|
||||
@ -97,15 +97,13 @@ class message_viewed extends base {
|
||||
}
|
||||
|
||||
public static function get_objectid_mapping() {
|
||||
// Messages are not backed up, so no need to map them.
|
||||
return array('db' => 'message_read', 'restore' => base::NOT_MAPPED);
|
||||
return array('db' => 'message_user_actions', 'restore' => base::NOT_MAPPED);
|
||||
}
|
||||
|
||||
public static function get_other_mapping() {
|
||||
// Messages are not backed up, so no need to map them on restore.
|
||||
$othermapped = array();
|
||||
// The messages table could vary for older events - so cannot be mapped.
|
||||
$othermapped['messageid'] = array('db' => base::NOT_MAPPED, 'restore' => base::NOT_MAPPED);
|
||||
$othermapped['messageid'] = array('db' => 'messages', 'restore' => base::NOT_MAPPED);
|
||||
return $othermapped;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user