@@ -105,26 +105,26 @@ public function get_search_fileareas() {
105
105
public function attach_files ($ document ) {
106
106
global $ DB ;
107
107
108
- $ fileareas = $ this ->get_search_fileareas ();
109
108
// 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 () ;
111
110
$ component = 'customfield_file ' ;
112
111
$ cmsid = $ document ->get ('itemid ' );
113
112
114
113
// Search customfield data from cms record.
115
- $ sql = "SELECT mcd.id
114
+ $ sql = "SELECT mcd.id, mcd.contextid
116
115
FROM {cms} mc
117
116
JOIN {customfield_data} mcd ON mc.id = mcd.instanceid
118
117
JOIN {customfield_field} mcf ON mcf.id = mcd.fieldid
119
118
JOIN {customfield_category} mcc ON mcf.categoryid = mcc.id
119
+ JOIN {context} c ON c.id = mcd.contextid
120
120
WHERE mc.id = ? AND mcc.component = 'mod_cms' AND mcc.area = 'cmsfield' AND mcf.type = 'file' " ;
121
121
$ param = [$ cmsid ];
122
122
$ filedata = $ DB ->get_records_sql ($ sql , $ param );
123
123
124
124
foreach ($ fileareas as $ filearea ) {
125
125
foreach ($ filedata as $ data ) {
126
126
$ 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 );
128
128
129
129
foreach ($ files as $ file ) {
130
130
$ document ->add_stored_file ($ file );
0 commit comments