@@ -72,7 +72,7 @@ public function get_document_recordset($modifiedfrom = 0, \context $context = nu
72
72
JOIN {customfield_category} mcc ON mcf.categoryid = mcc.id
73
73
$ contextjoin
74
74
WHERE mcd.timemodified >= ? AND mcc.component = 'mod_cms' AND mcc.area = 'cmsfield'
75
- AND mcf.type IN ('textarea', 'text')
75
+ AND mcf.type IN ('textarea', 'text', 'file' )
76
76
GROUP BY mc.id
77
77
) cdata ON ccms.id = cdata.id
78
78
JOIN {customfield_field} cmcf ON cmcf.id = cdata.fieldid
@@ -81,10 +81,11 @@ public function get_document_recordset($modifiedfrom = 0, \context $context = nu
81
81
null AS dataid, null AS value, null AS valueformat,
82
82
mc.timecreated timecreated, mc.timemodified timemodified
83
83
FROM {cms} mc
84
+ $ contextjoin
84
85
LEFT JOIN {customfield_data} mcd ON mc.id = mcd.instanceid
85
86
WHERE mcd.id IS NULL AND mc.timecreated >= ?
86
87
ORDER BY timemodified ASC " ;
87
- return $ DB ->get_recordset_sql ($ sql , array_merge ($ contextparams , [$ modifiedfrom, $ modifiedfrom ]));
88
+ return $ DB ->get_recordset_sql ($ sql , array_merge ($ contextparams , [$ modifiedfrom], $ contextparams , [ $ modifiedfrom ]));
88
89
}
89
90
90
91
/**
@@ -253,4 +254,60 @@ protected function get_data($id) {
253
254
}
254
255
return $ this ->cmsdata [$ id ];
255
256
}
257
+
258
+ /**
259
+ * Returns true if this area uses file indexing.
260
+ *
261
+ * @return bool
262
+ */
263
+ public function uses_file_indexing () {
264
+ return true ;
265
+ }
266
+
267
+ /**
268
+ * Return the context info required to index files for
269
+ * this search area.
270
+ *
271
+ * @return array
272
+ */
273
+ public function get_search_fileareas () {
274
+ return ['value ' ];
275
+ }
276
+
277
+ /**
278
+ * Add the forum post attachments.
279
+ *
280
+ * @param document $document The current document
281
+ * @return null
282
+ */
283
+ public function attach_files ($ document ) {
284
+ global $ DB ;
285
+
286
+ $ fileareas = $ this ->get_search_fileareas ();
287
+ // File is in "customfield_file" for component, "value" for filearea, and for customfield data id for itemid.
288
+ $ contextid = \context_system::instance ()->id ;
289
+ $ component = 'customfield_file ' ;
290
+ $ cmsid = $ document ->get ('itemid ' );
291
+
292
+ // Search customfield data from cms record.
293
+ $ sql = "SELECT mcd.id
294
+ FROM {cms} mc
295
+ JOIN {customfield_data} mcd ON mc.id = mcd.instanceid
296
+ JOIN {customfield_field} mcf ON mcf.id = mcd.fieldid
297
+ JOIN {customfield_category} mcc ON mcf.categoryid = mcc.id
298
+ WHERE mc.id = ? AND mcc.component = 'mod_cms' AND mcc.area = 'cmsfield' AND mcf.type = 'file' " ;
299
+ $ param = [$ cmsid ];
300
+ $ filedata = $ DB ->get_records_sql ($ sql , $ param );
301
+
302
+ foreach ($ fileareas as $ filearea ) {
303
+ foreach ($ filedata as $ data ) {
304
+ $ fs = get_file_storage ();
305
+ $ files = $ fs ->get_area_files ($ contextid , $ component , $ filearea , $ data ->id , '' , false );
306
+
307
+ foreach ($ files as $ file ) {
308
+ $ document ->add_stored_file ($ file );
309
+ }
310
+ }
311
+ }
312
+ }
256
313
}
0 commit comments