mirror of
https://github.com/moodle/moodle.git
synced 2025-08-08 18:36:42 +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
|
@ -36,6 +36,7 @@ require_once($CFG->dirroot . '/mod/assign/locallib.php');
|
|||
* @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.
|
||||
*
|
||||
|
@ -46,22 +47,14 @@ class activity extends \core_search\base_activity {
|
|||
}
|
||||
|
||||
/**
|
||||
* Add the attached description files.
|
||||
* 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', ASSIGN_INTROATTACHMENT_FILEAREA); // Fileareas.
|
||||
|
||||
$cm = $this->get_cm($this->get_module_name(), $document->get('itemid'), $document->get('courseid'));
|
||||
$context = \context_module::instance($cm->id);
|
||||
|
||||
$files = $fs->get_area_files($context->id, 'mod_assign', ASSIGN_INTROATTACHMENT_FILEAREA, 0,
|
||||
'sortorder DESC, id ASC', false);
|
||||
|
||||
foreach ($files as $file) {
|
||||
$document->add_stored_file($file);
|
||||
}
|
||||
return $fileareas;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -158,4 +158,25 @@ class chapter extends \core_search\base_mod {
|
|||
$contextmodule = \context::instance_by_id($doc->get('contextid'));
|
||||
return new \moodle_url('/mod/book/view.php', array('id' => $contextmodule->instanceid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this area uses file indexing.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function uses_file_indexing() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the context info required to index files for
|
||||
* this search area.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_search_fileareas() {
|
||||
$fileareas = array('chapter'); // Filearea.
|
||||
|
||||
return $fileareas;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,4 +34,14 @@ 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,21 +45,14 @@ class activity extends \core_search\base_activity {
|
|||
}
|
||||
|
||||
/**
|
||||
* Add all the folder files 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);
|
||||
|
||||
$files = $fs->get_area_files($context->id, 'mod_folder', 'content', 0, 'sortorder DESC, id ASC', false);
|
||||
|
||||
foreach ($files as $file) {
|
||||
$document->add_stored_file($file);
|
||||
}
|
||||
return $fileareas;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -193,4 +193,25 @@ class entry extends \core_search\base_mod {
|
|||
}
|
||||
return $this->entriesdata[$entryid];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this area uses file indexing.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function uses_file_indexing() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the context info required to index files for
|
||||
* this search area.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_search_fileareas() {
|
||||
$fileareas = array('attachment', 'entry'); // Fileareas.
|
||||
|
||||
return $fileareas;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,6 +38,15 @@ defined('MOODLE_INTERNAL') || die();
|
|||
*/
|
||||
class activity extends \core_search\base_activity {
|
||||
|
||||
/**
|
||||
* Returns true if this area uses file indexing.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function uses_file_indexing() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwritten as labels are displayed in-course.
|
||||
*
|
||||
|
|
|
@ -34,4 +34,25 @@ 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the context info required to index files for
|
||||
* this search area.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_search_fileareas() {
|
||||
$fileareas = array('intro', 'page_contents'); // Fileareas.
|
||||
|
||||
return $fileareas;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,6 @@ defined('MOODLE_INTERNAL') || die();
|
|||
*/
|
||||
class activity extends \core_search\base_activity {
|
||||
|
||||
|
||||
/**
|
||||
* Returns the document associated with this activity.
|
||||
*
|
||||
|
@ -74,4 +73,25 @@ class activity extends \core_search\base_activity {
|
|||
|
||||
return $doc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this area uses file indexing.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function uses_file_indexing() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the context info required to index files for
|
||||
* this search area.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_search_fileareas() {
|
||||
$fileareas = array('intro', 'content'); // Fileareas.
|
||||
|
||||
return $fileareas;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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++;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,15 @@ defined('MOODLE_INTERNAL') || die();
|
|||
*/
|
||||
class activity extends \core_search\base_activity {
|
||||
|
||||
/**
|
||||
* Returns true if this area uses file indexing.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function uses_file_indexing() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns recordset containing required data for indexing activities.
|
||||
*
|
||||
|
|
|
@ -35,6 +35,15 @@ defined('MOODLE_INTERNAL') || die();
|
|||
*/
|
||||
class activity extends \core_search\base_activity {
|
||||
|
||||
/**
|
||||
* Returns true if this area uses file indexing.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function uses_file_indexing() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the document associated with this activity.
|
||||
*
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -175,4 +175,25 @@ class collaborative_page extends \core_search\base_mod {
|
|||
$contextmodule = \context::instance_by_id($doc->get('contextid'));
|
||||
return new \moodle_url('/mod/wiki/view.php', array('id' => $contextmodule->instanceid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this area uses file indexing.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function uses_file_indexing() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the context info required to index files for
|
||||
* this search area.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_search_fileareas() {
|
||||
$fileareas = array('attachments'); // Filearea.
|
||||
|
||||
return $fileareas;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,4 +34,25 @@ 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the context info required to index files for
|
||||
* this search area.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_search_fileareas() {
|
||||
$fileareas = array('intro', 'instructauthors', 'instructreviewers', 'conclusion'); // Fileareas.
|
||||
|
||||
return $fileareas;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue