Skip to content
Permalink
Browse files

MDL-61824 core_search: Deleting restored context caused error

When restoring content, this adds it to a queue for indexing. If the
restored content was then deleted before the indexing takes place,
this caused an exception in the scheduled task.

This change makes it continue safely past missing contexts.
  • Loading branch information...
sammarshallou committed Apr 9, 2018
1 parent 2bd2660 commit a539e5605caa9fcf3e0b34c8faae9d1a07112e7e
Showing with 25 additions and 1 deletion.
  1. +6 −1 search/classes/manager.php
  2. +19 −0 search/tests/manager_test.php
@@ -1303,7 +1303,12 @@ public function process_index_requests($timelimit = 0.0, \progress_trace $progre
}
// Show a message before each request, indicating what will be indexed.
$context = \context::instance_by_id($request->contextid);
$context = \context::instance_by_id($request->contextid, IGNORE_MISSING);
if (!$context) {
$DB->delete_records('search_index_requests', ['id' => $request->id]);
$progress->output('Skipped deleted context: ' . $request->contextid);
continue;
}
$contextname = $context->get_context_name();
if ($request->searcharea) {
$contextname .= ' (search area: ' . $request->searcharea . ')';
@@ -1190,5 +1190,24 @@ public function test_process_index_requests() {
$this->assertContains(
'Completed requested context: Forum: TForum1 (search area: mod_forum-activity)',
$out);
// Make a request for a course context...
$course = $generator->create_course();
$context = context_course::instance($course->id);
$search::request_index($context);
// ...but then delete it (note: delete_course spews output, so we throw it away).
ob_start();
delete_course($course);
ob_end_clean();
// Process requests - it should only note the deleted context.
$search->process_index_requests(10, $progress);
$out = $progress->get_buffer();
$progress->reset_buffer();
$this->assertContains('Skipped deleted context: ' . $context->id, $out);
// Confirm request table is now empty.
$this->assertEquals(0, $DB->count_records('search_index_requests'));
}
}

0 comments on commit a539e56

Please sign in to comment.
You can’t perform that action at this time.