MDL-51985 files: sync timemodified when possible
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
+1
-1
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user