diff --git a/course/lib.php b/course/lib.php index 0cb1ad75fa4..14cf966840c 100644 --- a/course/lib.php +++ b/course/lib.php @@ -3701,11 +3701,12 @@ function course_check_module_updates_since($cm, $from, $fileareas = array(), $fi } if (!empty($fileareas) and (empty($filter) or in_array('fileareas', $filter))) { $fs = get_file_storage(); - $extrasql = 'AND (f.timecreated > :since1 OR f.timemodified > :since2)'; - $extraconditions = array('since1' => $from, 'since2' => $from); - foreach ($fileareas as $fileareaname) { - $files = $fs->get_area_files($context->id, $component, $fileareaname, false, "itemid", true, $extrasql, $extraconditions); - $updates->{$fileareaname . 'files'} = !empty($files); + $files = $fs->get_area_files($context->id, $component, $fileareas, false, "filearea, timemodified DESC", true, $from); + foreach ($fileareas as $filearea) { + $updates->{$filearea . 'files'} = false; + } + foreach ($files as $file) { + $updates->{$file->get_filearea() . 'files'} = true; } } diff --git a/lib/filestorage/file_storage.php b/lib/filestorage/file_storage.php index 1c4adeede33..c3abedda152 100644 --- a/lib/filestorage/file_storage.php +++ b/lib/filestorage/file_storage.php @@ -794,38 +794,45 @@ class file_storage { * * @param int $contextid context ID * @param string $component component - * @param string $filearea file area + * @param mixed $filearea file area/s, you cannot specify multiple fileareas as well as an itemid * @param int $itemid item ID or all files if not specified * @param string $sort A fragment of SQL to use for sorting * @param bool $includedirs whether or not include directories - * @param string $extrasql a fragment of SQL to append to the WHERE part of the query - * @param array $extraconditions an array of additional condition values for the $extrasql + * @param int $updatedsince return files updated since this time * @return stored_file[] array of stored_files indexed by pathanmehash */ public function get_area_files($contextid, $component, $filearea, $itemid = false, $sort = "itemid, filepath, filename", - $includedirs = true, $extrasql = '', $extraconditions = array()) { + $includedirs = true, $updatedsince = 0) { global $DB; - $conditions = array('contextid'=>$contextid, 'component'=>$component, 'filearea'=>$filearea); - if ($itemid !== false) { + list($areasql, $conditions) = $DB->get_in_or_equal($filearea, SQL_PARAMS_NAMED); + $conditions['contextid'] = $contextid; + $conditions['component'] = $component; + + if ($itemid !== false && is_array($filearea)) { + throw new coding_exception('You cannot specify multiple fileareas as well as an itemid.'); + } else if ($itemid !== false) { $itemidsql = ' AND f.itemid = :itemid '; $conditions['itemid'] = $itemid; } else { $itemidsql = ''; } + $updatedsincesql = ''; + if (!empty($updatedsince)) { + $conditions['time'] = $updatedsince; + $updatedsincesql = 'AND f.timemodified > :time'; + } + $sql = "SELECT ".self::instance_sql_fields('f', 'r')." FROM {files} f LEFT JOIN {files_reference} r ON f.referencefileid = r.id WHERE f.contextid = :contextid AND f.component = :component - AND f.filearea = :filearea + AND f.filearea $areasql + $updatedsincesql $itemidsql"; - if (!empty($extrasql)) { - $sql .= " $extrasql"; - $conditions = array_merge($conditions, $extraconditions); - } if (!empty($sort)) { $sql .= " ORDER BY {$sort}"; }