mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
Merge branch 'MDL-59459_Increase_file_indexing_coverage' of https://github.com/mattporritt/moodle
This commit is contained in:
commit
743c937dae
33 changed files with 765 additions and 68 deletions
|
@ -34,6 +34,7 @@ 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.
|
||||
*
|
||||
|
@ -44,24 +45,14 @@ class activity extends \core_search\base_activity {
|
|||
}
|
||||
|
||||
/**
|
||||
* Add the main file to the index.
|
||||
* Return the context info required to index files for
|
||||
* this search area.
|
||||
*
|
||||
* @param document $document The current document
|
||||
* @return null
|
||||
* @return array
|
||||
*/
|
||||
public function attach_files($document) {
|
||||
$fs = get_file_storage();
|
||||
public function get_search_fileareas() {
|
||||
$fileareas = array('intro', 'content'); // Fileareas.
|
||||
|
||||
$cm = $this->get_cm($this->get_module_name(), $document->get('itemid'), $document->get('courseid'));
|
||||
$context = \context_module::instance($cm->id);
|
||||
|
||||
// Order by sortorder desc, the first is consided the main file.
|
||||
$files = $fs->get_area_files($context->id, 'mod_resource', 'content', 0, 'sortorder DESC, id ASC', false);
|
||||
|
||||
$mainfile = $files ? reset($files) : null;
|
||||
if ($mainfile && $mainfile->get_sortorder() > 0) {
|
||||
$document->add_stored_file($mainfile);
|
||||
}
|
||||
return $fileareas;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@ class mod_resource_search_testcase extends advanced_testcase {
|
|||
);
|
||||
$fs->create_file_from_string($filerecord, 'Test resource file');
|
||||
|
||||
// Attach a second file that shouldn't be returned with the search doc.
|
||||
// Attach a second file.
|
||||
$filerecord['filename'] = 'extrafile';
|
||||
$filerecord['sortorder'] = 0;
|
||||
$fs->create_file_from_string($filerecord, 'Test resource file 2');
|
||||
|
@ -101,10 +101,15 @@ class mod_resource_search_testcase extends advanced_testcase {
|
|||
$searcharea->attach_files($doc);
|
||||
$files = $doc->get_files();
|
||||
|
||||
// Resources should only return their main file.
|
||||
$this->assertCount(1, $files);
|
||||
$file = reset($files);
|
||||
$this->assertEquals('mainfile', $file->get_filename());
|
||||
// Resources should return all added files.
|
||||
$this->assertCount(2, $files);
|
||||
|
||||
$filenames = array();
|
||||
foreach ($files as $file) {
|
||||
$filenames[] = $file->get_filename();
|
||||
}
|
||||
$this->assertContains('mainfile', $filenames);
|
||||
$this->assertContains('extrafile', $filenames);
|
||||
|
||||
$nrecords++;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue