mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
Merge branch 'MDL-62709_master' of git://github.com/markn86/moodle
This commit is contained in:
commit
d2b1d001bb
2 changed files with 64 additions and 7 deletions
|
@ -90,10 +90,10 @@ class migrate_message_data extends \core\task\adhoc_task {
|
||||||
$this->migrate_data($userid, $otheruserid);
|
$this->migrate_data($userid, $otheruserid);
|
||||||
$transaction->allow_commit();
|
$transaction->allow_commit();
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
$updatepreference = false;
|
throw $e;
|
||||||
|
} finally {
|
||||||
|
$lock->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
$lock->release();
|
|
||||||
} else {
|
} else {
|
||||||
// Couldn't get a lock, move on to next user but make sure we don't update user preference so
|
// Couldn't get a lock, move on to next user but make sure we don't update user preference so
|
||||||
// we still try again.
|
// we still try again.
|
||||||
|
@ -172,7 +172,7 @@ class migrate_message_data extends \core\task\adhoc_task {
|
||||||
$tabledata->useridto = $notification->useridto;
|
$tabledata->useridto = $notification->useridto;
|
||||||
$tabledata->subject = $notification->subject;
|
$tabledata->subject = $notification->subject;
|
||||||
$tabledata->fullmessage = $notification->fullmessage;
|
$tabledata->fullmessage = $notification->fullmessage;
|
||||||
$tabledata->fullmessageformat = $notification->fullmessageformat;
|
$tabledata->fullmessageformat = $notification->fullmessageformat ?? FORMAT_MOODLE;
|
||||||
$tabledata->fullmessagehtml = $notification->fullmessagehtml;
|
$tabledata->fullmessagehtml = $notification->fullmessagehtml;
|
||||||
$tabledata->smallmessage = $notification->smallmessage;
|
$tabledata->smallmessage = $notification->smallmessage;
|
||||||
$tabledata->component = $notification->component;
|
$tabledata->component = $notification->component;
|
||||||
|
@ -210,7 +210,7 @@ class migrate_message_data extends \core\task\adhoc_task {
|
||||||
$tabledata->conversationid = $conversationid;
|
$tabledata->conversationid = $conversationid;
|
||||||
$tabledata->subject = $message->subject;
|
$tabledata->subject = $message->subject;
|
||||||
$tabledata->fullmessage = $message->fullmessage;
|
$tabledata->fullmessage = $message->fullmessage;
|
||||||
$tabledata->fullmessageformat = $message->fullmessageformat;
|
$tabledata->fullmessageformat = $message->fullmessageformat ?? FORMAT_MOODLE;
|
||||||
$tabledata->fullmessagehtml = $message->fullmessagehtml;
|
$tabledata->fullmessagehtml = $message->fullmessagehtml;
|
||||||
$tabledata->smallmessage = $message->smallmessage;
|
$tabledata->smallmessage = $message->smallmessage;
|
||||||
$tabledata->timecreated = $message->timecreated;
|
$tabledata->timecreated = $message->timecreated;
|
||||||
|
|
|
@ -268,6 +268,62 @@ class core_message_migrate_message_data_task_testcase extends advanced_testcase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test migrating a legacy message that contains null as the format.
|
||||||
|
*/
|
||||||
|
public function test_migrating_message_null_format() {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
// Create users to test with.
|
||||||
|
$user1 = $this->getDataGenerator()->create_user();
|
||||||
|
$user2 = $this->getDataGenerator()->create_user();
|
||||||
|
|
||||||
|
$this->create_legacy_message_or_notification($user1->id, $user2->id, null, false, null, null);
|
||||||
|
|
||||||
|
// Now, let's execute the task for user 1.
|
||||||
|
$task = new \core_message\task\migrate_message_data();
|
||||||
|
$task->set_custom_data(
|
||||||
|
[
|
||||||
|
'userid' => $user1->id
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$task->execute();
|
||||||
|
|
||||||
|
$messages = $DB->get_records('messages');
|
||||||
|
$this->assertCount(1, $messages);
|
||||||
|
|
||||||
|
$message = reset($messages);
|
||||||
|
$this->assertEquals(FORMAT_MOODLE, $message->fullmessageformat);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test migrating a legacy notification that contains null as the format.
|
||||||
|
*/
|
||||||
|
public function test_migrating_notification_null_format() {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
// Create users to test with.
|
||||||
|
$user1 = $this->getDataGenerator()->create_user();
|
||||||
|
$user2 = $this->getDataGenerator()->create_user();
|
||||||
|
|
||||||
|
$this->create_legacy_message_or_notification($user1->id, $user2->id, null, true, null, null);
|
||||||
|
|
||||||
|
// Now, let's execute the task for user 1.
|
||||||
|
$task = new \core_message\task\migrate_message_data();
|
||||||
|
$task->set_custom_data(
|
||||||
|
[
|
||||||
|
'userid' => $user1->id
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$task->execute();
|
||||||
|
|
||||||
|
$notifications = $DB->get_records('notifications');
|
||||||
|
$this->assertCount(1, $notifications);
|
||||||
|
|
||||||
|
$notification = reset($notifications);
|
||||||
|
$this->assertEquals(FORMAT_MOODLE, $notification->fullmessageformat);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a legacy message or notification to be used for testing.
|
* Creates a legacy message or notification to be used for testing.
|
||||||
*
|
*
|
||||||
|
@ -276,11 +332,12 @@ class core_message_migrate_message_data_task_testcase extends advanced_testcase
|
||||||
* @param int $timecreated
|
* @param int $timecreated
|
||||||
* @param bool $notification
|
* @param bool $notification
|
||||||
* @param int|null $timeread The time the message/notification was read, null if it hasn't been.
|
* @param int|null $timeread The time the message/notification was read, null if it hasn't been.
|
||||||
|
* @param string|int|null $format The format of the message.
|
||||||
* @return int The id of the message (in either the message or message_read table)
|
* @return int The id of the message (in either the message or message_read table)
|
||||||
* @throws dml_exception
|
* @throws dml_exception
|
||||||
*/
|
*/
|
||||||
private function create_legacy_message_or_notification($useridfrom, $useridto, $timecreated = null,
|
private function create_legacy_message_or_notification($useridfrom, $useridto, $timecreated = null,
|
||||||
$notification = false, $timeread = null) {
|
$notification = false, $timeread = null, $format = FORMAT_PLAIN) {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
$tabledata = new \stdClass();
|
$tabledata = new \stdClass();
|
||||||
|
@ -312,7 +369,7 @@ class core_message_migrate_message_data_task_testcase extends advanced_testcase
|
||||||
$tabledata->useridto = $useridto;
|
$tabledata->useridto = $useridto;
|
||||||
$tabledata->subject = 'Subject ' . $timecreated;
|
$tabledata->subject = 'Subject ' . $timecreated;
|
||||||
$tabledata->fullmessage = 'Full message ' . $timecreated;
|
$tabledata->fullmessage = 'Full message ' . $timecreated;
|
||||||
$tabledata->fullmessageformat = FORMAT_PLAIN;
|
$tabledata->fullmessageformat = $format;
|
||||||
$tabledata->fullmessagehtml = 'Full message HTML ' . $timecreated;
|
$tabledata->fullmessagehtml = 'Full message HTML ' . $timecreated;
|
||||||
$tabledata->smallmessage = 'Small message ' . $timecreated;
|
$tabledata->smallmessage = 'Small message ' . $timecreated;
|
||||||
$tabledata->timecreated = $timecreated;
|
$tabledata->timecreated = $timecreated;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue