Skip to content

Commit

Permalink
MDL-75108 block_html: Search tries to index directory entries
Browse files Browse the repository at this point in the history
Search attach_files function should only attach indexable files,
not directory entries which are 0 bytes and cannot be indexed.
  • Loading branch information
sammarshallou committed Jul 1, 2022
1 parent 9ccda59 commit f83782a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
3 changes: 2 additions & 1 deletion blocks/html/classes/search/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ public function attach_files($document) {

$context = \context::instance_by_id($document->get('contextid'));

$files = $fs->get_area_files($context->id, 'block_html', 'content');
$files = $fs->get_area_files($context->id, 'block_html', 'content',
false, 'itemid, filepath, filename', false);
foreach ($files as $file) {
$document->add_stored_file($file);
}
Expand Down
6 changes: 2 additions & 4 deletions blocks/html/tests/search_content_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,9 @@ public function test_search_area() {
$this->assertCount(0, $doc->get_files());
$area->attach_files($doc);
$files = $doc->get_files();
$this->assertCount(2, $files);
// The directory entry should NOT be provided for indexing.
$this->assertCount(1, $files);
foreach ($files as $file) {
if ($file->is_directory()) {
continue;
}
$this->assertEquals('file.txt', $file->get_filename());
$this->assertEquals('File content', $file->get_content());
}
Expand Down

0 comments on commit f83782a

Please sign in to comment.