diff --git a/lib/filestorage/file_storage.php b/lib/filestorage/file_storage.php index c832f619057..e4ba86e5434 100644 --- a/lib/filestorage/file_storage.php +++ b/lib/filestorage/file_storage.php @@ -2154,7 +2154,7 @@ class file_storage { $now = time(); foreach ($rs as $record) { $this->update_references($record->id, $now, null, - $storedfile->get_contenthash(), $storedfile->get_filesize(), 0); + $storedfile->get_contenthash(), $storedfile->get_filesize(), 0, $storedfile->get_timemodified()); } $rs->close(); } @@ -2372,8 +2372,9 @@ class file_storage { * @param string $contenthash * @param int $filesize * @param int $status 0 if ok or 666 if source is missing + * @param int $timemodified last time modified of the source, if known */ - public function update_references($referencefileid, $lastsync, $lifetime, $contenthash, $filesize, $status) { + public function update_references($referencefileid, $lastsync, $lifetime, $contenthash, $filesize, $status, $timemodified = null) { global $DB; $referencefileid = clean_param($referencefileid, PARAM_INT); $lastsync = clean_param($lastsync, PARAM_INT); @@ -2383,9 +2384,10 @@ class file_storage { $params = array('contenthash' => $contenthash, 'filesize' => $filesize, 'status' => $status, - 'referencefileid' => $referencefileid); + 'referencefileid' => $referencefileid, + 'timemodified' => $timemodified); $DB->execute('UPDATE {files} SET contenthash = :contenthash, filesize = :filesize, - status = :status + status = :status ' . ($timemodified ? ', timemodified = :timemodified' : '') . ' WHERE referencefileid = :referencefileid', $params); $data = array('id' => $referencefileid, 'lastsync' => $lastsync); $DB->update_record('files_reference', (object)$data); diff --git a/lib/filestorage/stored_file.php b/lib/filestorage/stored_file.php index a959baf7053..b115f965673 100644 --- a/lib/filestorage/stored_file.php +++ b/lib/filestorage/stored_file.php @@ -961,8 +961,9 @@ class stored_file { * @param null|string $contenthash if set to null contenthash is not changed * @param int $filesize new size of the file * @param int $status new status of the file (0 means OK, 666 - source missing) + * @param int $timemodified last time modified of the source, if known */ - public function set_synchronized($contenthash, $filesize, $status = 0) { + public function set_synchronized($contenthash, $filesize, $status = 0, $timemodified = null) { if (!$this->is_external_file()) { return; } @@ -974,12 +975,15 @@ class stored_file { $oldcontenthash = $this->file_record->contenthash; } // this will update all entries in {files} that have the same filereference id - $this->fs->update_references($this->file_record->referencefileid, $now, null, $contenthash, $filesize, $status); + $this->fs->update_references($this->file_record->referencefileid, $now, null, $contenthash, $filesize, $status, $timemodified); // we don't need to call update() for this object, just set the values of changed fields $this->file_record->contenthash = $contenthash; $this->file_record->filesize = $filesize; $this->file_record->status = $status; $this->file_record->referencelastsync = $now; + if ($timemodified) { + $this->file_record->timemodified = $timemodified; + } if (isset($oldcontenthash)) { $this->fs->deleted_file_cleanup($oldcontenthash); } diff --git a/repository/filesystem/lib.php b/repository/filesystem/lib.php index 1585d883ac5..5ce146166d6 100644 --- a/repository/filesystem/lib.php +++ b/repository/filesystem/lib.php @@ -375,7 +375,8 @@ class repository_filesystem extends repository { $filesize = filesize($filepath); } $issyncing = false; - $file->set_synchronized($contenthash, $filesize); + $modified = filemtime($filepath); + $file->set_synchronized($contenthash, $filesize, 0, $modified); } else { $file->set_missingsource(); } diff --git a/repository/lib.php b/repository/lib.php index fdf9c3dd9b4..b8c3d20ecc2 100644 --- a/repository/lib.php +++ b/repository/lib.php @@ -2752,7 +2752,7 @@ abstract class repository implements cacheable_object { $params['filename']))) { $file->set_missingsource(); } else { - $file->set_synchronized($storedfile->get_contenthash(), $storedfile->get_filesize()); + $file->set_synchronized($storedfile->get_contenthash(), $storedfile->get_filesize(), 0, $storedfile->get_timemodified()); } return true; }