Merge branch 'MDL-59459_Increase_file_indexing_coverage' of https://github.com/mattporritt/moodle

This commit is contained in:
Dan Poltawski 2017-09-11 14:01:40 +01:00
commit 743c937dae
33 changed files with 765 additions and 68 deletions

View file

@ -34,4 +34,13 @@ defined('MOODLE_INTERNAL') || die();
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class activity extends \core_search\base_activity {
/**
* Returns true if this area uses file indexing.
*
* @return bool
*/
public function uses_file_indexing() {
return true;
}
}

View file

@ -120,6 +120,21 @@ class post extends \core_search\base_mod {
return true;
}
/**
* Return the context info required to index files for
* this search area.
*
* @return array
*/
public function get_search_fileareas() {
$fileareas = array(
'attachment',
'post'
);
return $fileareas;
}
/**
* Add the forum post attachments.
*
@ -142,14 +157,21 @@ class post extends \core_search\base_mod {
// Because this is used during indexing, we don't want to cache posts. Would result in memory leak.
unset($this->postsdata[$postid]);
$cm = $this->get_cm('forum', $post->forum, $document->get('courseid'));
$cm = $this->get_cm($this->get_module_name(), $post->forum, $document->get('courseid'));
$context = \context_module::instance($cm->id);
$contextid = $context->id;
$fileareas = $this->get_search_fileareas();
$component = $this->get_component_name();
// Get the files and attach them.
$fs = get_file_storage();
$files = $fs->get_area_files($context->id, 'mod_forum', 'attachment', $postid, "filename", false);
foreach ($files as $file) {
$document->add_stored_file($file);
foreach ($fileareas as $filearea) {
$fs = get_file_storage();
$files = $fs->get_area_files($contextid, $component, $filearea, $postid, '', false);
foreach ($files as $file) {
$document->add_stored_file($file);
}
}
}