Skip to content

Commit

Permalink
MDL-83080 message: handle core\url instance data as contexturl.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulholden committed Dec 17, 2024
1 parent ce0193f commit 8cc4988
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 24 deletions.
15 changes: 3 additions & 12 deletions lib/classes/message/message.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* New messaging class.
*
* @package core_message
* @since Moodle 2.9
* @copyright 2015 onwards Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace core\message;

defined('MOODLE_INTERNAL') || die();
use moodle_url;

/**
* New messaging class.
Expand All @@ -46,7 +37,7 @@
*
* Optional parameters of the $eventdata object:
* notification bool Should the message be considered as a notification rather than a personal message
* contexturl string If this is a notification then you can specify a url to view the event.
* contexturl string|moodle_url If this is a notification then you can specify a url to view the event.
* For example the forum post the user is being notified of.
* contexturlname string The display text for contexturl.
* replyto string An email address which can be used to send an reply.
Expand Down Expand Up @@ -102,7 +93,7 @@ class message {
/** @var int Is it a notification? */
private $notification;

/** @var string context url. */
/** @var string|moodle_url context url. */
private $contexturl;

/** @var string context name. */
Expand Down
26 changes: 14 additions & 12 deletions lib/messagelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

use moodle_url;

defined('MOODLE_INTERNAL') || die();

require_once(__DIR__ . '/../message/lib.php');
Expand All @@ -44,7 +46,8 @@
*
* Optional parameters of the $eventdata object:
* notification bool should the message be considered as a notification rather than a personal message
* contexturl string if this is a notification then you can specify a url to view the event. For example the forum post the user is being notified of.
* contexturl string|moodle_url if this is a notification then you can specify a url to view the event.
* For example the forum post the user is being notified of.
* contexturlname string the display text for contexturl
*
* Note: processor failure will not reported as false return value in all scenarios,
Expand Down Expand Up @@ -83,6 +86,14 @@ function message_send(\core\message\message $eventdata) {
return false;
}

// Cast context URL and name.
if (!empty($eventdata->contexturl)) {
$eventdata->contexturl = (string) $eventdata->contexturl;
}
if (!empty($eventdata->contexturlname)) {
$eventdata->contexturlname = (string) $eventdata->contexturlname;
}

// Legacy messages (FROM a single user TO a single user) must be converted into conversation messages.
// Then, these will be passed through the conversation messages code below.
if (!$eventdata->notification && !$eventdata->convid) {
Expand Down Expand Up @@ -256,17 +267,8 @@ function message_send(\core\message\message $eventdata) {
$tabledata->component = $eventdata->component;
$tabledata->timecreated = time();
$tabledata->customdata = $eventdata->customdata;
if (!empty($eventdata->contexturl)) {
$tabledata->contexturl = (string)$eventdata->contexturl;
} else {
$tabledata->contexturl = null;
}

if (!empty($eventdata->contexturlname)) {
$tabledata->contexturlname = (string)$eventdata->contexturlname;
} else {
$tabledata->contexturlname = null;
}
$tabledata->contexturl = $eventdata->contexturl ?? null;
$tabledata->contexturlname = $eventdata->contexturlname ?? null;

if ($messageid = message_handle_phpunit_redirection($eventdata, $table, $tabledata)) {
return $messageid;
Expand Down
4 changes: 4 additions & 0 deletions message/upgrade.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
This files describes API changes in /message/ messaging system,
information provided here is intended especially for developers.

=== 4.4.6 ===

* The `contexturl` property to `\core\message\message` instances can now contain `moodle_url` values in addition to plain strings

=== 4.2 ===

* The following methods, deprecated since 3.10, have been removed and can no longer be used:
Expand Down

0 comments on commit 8cc4988

Please sign in to comment.