MDL-80947 communication_customlink: Check before customlink update
This commit is contained in:
@@ -113,13 +113,17 @@ class communication_feature implements
|
||||
}
|
||||
|
||||
public function save_form_data(\stdClass $instance): void {
|
||||
if (empty($instance->customlinkurl)) {
|
||||
return;
|
||||
}
|
||||
|
||||
global $DB;
|
||||
|
||||
$commid = $this->communication->get_id();
|
||||
$cachekey = "link_url_{$commid}";
|
||||
|
||||
$newrecord = new \stdClass();
|
||||
$newrecord->url = $instance->customlinkurl ?? null;
|
||||
$newrecord->url = $instance->customlinkurl;
|
||||
|
||||
$existingrecord = $DB->get_record(
|
||||
self::CUSTOMLINK_TABLE,
|
||||
@@ -131,7 +135,7 @@ class communication_feature implements
|
||||
// Create the record if it does not exist.
|
||||
$newrecord->commid = $commid;
|
||||
$DB->insert_record(self::CUSTOMLINK_TABLE, $newrecord);
|
||||
} else if ($newrecord->url !== $existingrecord->url) {
|
||||
} else if ($instance->customlinkurl !== $existingrecord->url) {
|
||||
// Update record if the URL has changed.
|
||||
$newrecord->id = $existingrecord->id;
|
||||
$DB->update_record(self::CUSTOMLINK_TABLE, $newrecord);
|
||||
|
||||
@@ -88,6 +88,22 @@ class communication_feature_test extends \advanced_testcase {
|
||||
$communicationprocessor->get_form_provider()->save_form_data($formdatainstance);
|
||||
$fetchedurl = $communicationprocessor->get_room_provider()->get_chat_room_url();
|
||||
$this->assertEquals($customlinkurl, $fetchedurl);
|
||||
|
||||
// Test with empty customlinkurl.
|
||||
$customlinkurlempty = '';
|
||||
$formdatainstance = (object) ['customlinkurl' => $customlinkurlempty];
|
||||
$communicationprocessor->get_form_provider()->save_form_data($formdatainstance);
|
||||
$fetchedurl = $communicationprocessor->get_room_provider()->get_chat_room_url();
|
||||
// It should not update the url to an empty one.
|
||||
$this->assertEquals($customlinkurl, $fetchedurl);
|
||||
|
||||
// Test with null customlinkurl.
|
||||
$customlinkurlempty = null;
|
||||
$formdatainstance = (object) ['customlinkurl' => $customlinkurlempty];
|
||||
$communicationprocessor->get_form_provider()->save_form_data($formdatainstance);
|
||||
$fetchedurl = $communicationprocessor->get_room_provider()->get_chat_room_url();
|
||||
// It should not update the url to a null one.
|
||||
$this->assertEquals($customlinkurl, $fetchedurl);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -476,6 +476,8 @@ class api_test extends \advanced_testcase {
|
||||
// Now delete all the ad-hoc tasks.
|
||||
$DB->delete_records('task_adhoc');
|
||||
|
||||
$course->customlinkurl = $course->customlinkurl ?? 'https://moodle.org';
|
||||
|
||||
// Now change the provider to another one.
|
||||
$communication->configure_room_and_membership_by_provider(
|
||||
provider: 'communication_customlink',
|
||||
|
||||
Reference in New Issue
Block a user