Skip to content

Commit

Permalink
Merge branch 'MDL_59834-Indexing_of_personal_messages' of https://git…
Browse files Browse the repository at this point in the history
  • Loading branch information
danpoltawski authored and David Monllao committed Sep 7, 2017
2 parents f827adb + bc60052 commit 0426cc9
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
8 changes: 8 additions & 0 deletions message/classes/search/base_message.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ abstract class base_message extends \core_search\base {
* @return \core_search\document
*/
public function get_document($record, $options = array()) {

// Check if user still exists, before proceeding.
$user = \core_user::get_user($options['user1id'], 'deleted');
if ($user->deleted == 1) {
return false;
}

// Get user context.
try {
$usercontext = \context_user::instance($options['user1id']);
} catch (\moodle_exception $ex) {
Expand Down
45 changes: 45 additions & 0 deletions message/tests/search_test_received.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,49 @@ public function test_message_received_access() {
$this->assertEquals(\core_search\manager::ACCESS_DELETED, $searcharea->check_access($messageid));

}

/**
* Test received deleted user.
* Tests the case where a received message for a deleted user
* is attempted to be added to the index.
*
* @return void
*/
public function test_message_received_deleted_user() {

// Returns the instance as long as the area is supported.
$searcharea = \core_search\manager::get_search_area($this->messagereceivedareaid);
$this->assertInstanceOf('\core_message\search\message_received', $searcharea);

$user1 = self::getDataGenerator()->create_user();
$user2 = self::getDataGenerator()->create_user();

$this->preventResetByRollback();
$sink = $this->redirectMessages();

$message = new \core\message\message();
$message->courseid = SITEID;
$message->userfrom = $user1;
$message->userto = $user2;
$message->subject = "Test Subject";
$message->smallmessage = "Test small messsage";
$message->fullmessage = "Test full messsage";
$message->fullmessageformat = 0;
$message->fullmessagehtml = null;
$message->notification = 0;
$message->component = "moodle";
$message->name = "instantmessage";

message_send($message);

$messages = $sink->get_messages();
$message = $messages[0];

// Delete user.
delete_user($user2);

$doc = $searcharea->get_document($message);

$this->assertFalse($doc);
}
}
46 changes: 46 additions & 0 deletions message/tests/search_test_sent.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,50 @@ public function test_message_sent_access() {
$this->assertEquals(\core_search\manager::ACCESS_DELETED, $searcharea->check_access($messageid));

}

/**
* Test sent deleted user.
* Tests the case where a sent message for a deleted user
* is attempted to be added to the index.
*
* @return void
*/
public function test_message_sent_deleted_user() {

// Returns the instance as long as the area is supported.
$searcharea = \core_search\manager::get_search_area($this->messagesentareaid);
$this->assertInstanceOf('\core_message\search\message_sent', $searcharea);

$user1 = self::getDataGenerator()->create_user();
$user2 = self::getDataGenerator()->create_user();

$this->preventResetByRollback();
$sink = $this->redirectMessages();

$message = new \core\message\message();
$message->courseid = SITEID;
$message->userfrom = $user1;
$message->userto = $user2;
$message->subject = "Test Subject";
$message->smallmessage = "Test small messsage";
$message->fullmessage = "Test full messsage";
$message->fullmessageformat = 0;
$message->fullmessagehtml = null;
$message->notification = 0;
$message->component = "moodle";
$message->name = "instantmessage";

message_send($message);

$messages = $sink->get_messages();
$message = $messages[0];

// Delete user.
delete_user($user1);

$doc = $searcharea->get_document($message);

$this->assertFalse($doc);

}
}

0 comments on commit 0426cc9

Please sign in to comment.