Skip to content

Commit 7a4c715

Browse files
authored
Merge pull request #143 from catalyst/issue142
issue #142: use correct context for file indexing
2 parents 5ca8eb0 + bb11624 commit 7a4c715

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

classes/search/activity.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -105,26 +105,26 @@ public function get_search_fileareas() {
105105
public function attach_files($document) {
106106
global $DB;
107107

108-
$fileareas = $this->get_search_fileareas();
109108
// File is in "customfield_file" for component, "value" for filearea, and for customfield data id for itemid.
110-
$contextid = \context_system::instance()->id;
109+
$fileareas = $this->get_search_fileareas();
111110
$component = 'customfield_file';
112111
$cmsid = $document->get('itemid');
113112

114113
// Search customfield data from cms record.
115-
$sql = "SELECT mcd.id
114+
$sql = "SELECT mcd.id, mcd.contextid
116115
FROM {cms} mc
117116
JOIN {customfield_data} mcd ON mc.id = mcd.instanceid
118117
JOIN {customfield_field} mcf ON mcf.id = mcd.fieldid
119118
JOIN {customfield_category} mcc ON mcf.categoryid = mcc.id
119+
JOIN {context} c ON c.id = mcd.contextid
120120
WHERE mc.id = ? AND mcc.component = 'mod_cms' AND mcc.area = 'cmsfield' AND mcf.type = 'file'";
121121
$param = [$cmsid];
122122
$filedata = $DB->get_records_sql($sql, $param);
123123

124124
foreach ($fileareas as $filearea) {
125125
foreach ($filedata as $data) {
126126
$fs = get_file_storage();
127-
$files = $fs->get_area_files($contextid, $component, $filearea, $data->id, '', false);
127+
$files = $fs->get_area_files($data->contextid, $component, $filearea, $data->id, '', false);
128128

129129
foreach ($files as $file) {
130130
$document->add_stored_file($file);

0 commit comments

Comments
 (0)