Skip to content

Commit

Permalink
Merge branch 'wip-MDL-51985-master' of https://github.com/marinaglanc…
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Dec 3, 2015
2 parents 38e0faa + 58e5ab1 commit b4153ff
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
10 changes: 6 additions & 4 deletions lib/filestorage/file_storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2196,7 +2196,7 @@ public function update_references_to_storedfile(stored_file $storedfile) {
$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();
}
Expand Down Expand Up @@ -2414,8 +2414,9 @@ private function get_referencefileid($repositoryid, $reference, $strictness) {
* @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);
Expand All @@ -2425,9 +2426,10 @@ public function update_references($referencefileid, $lastsync, $lifetime, $conte
$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);
Expand Down
8 changes: 6 additions & 2 deletions lib/filestorage/stored_file.php
Original file line number Diff line number Diff line change
Expand Up @@ -961,8 +961,9 @@ public function get_reference_details() {
* @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;
}
Expand All @@ -974,12 +975,15 @@ public function set_synchronized($contenthash, $filesize, $status = 0) {
$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);
}
Expand Down
3 changes: 2 additions & 1 deletion repository/filesystem/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,8 @@ public function sync_reference(stored_file $file) {
$filesize = filesize($filepath);
}
$issyncing = false;
$file->set_synchronized($contenthash, $filesize);
$modified = filemtime($filepath);
$file->set_synchronized($contenthash, $filesize, 0, $modified);
} else {
$file->set_missingsource();
}
Expand Down
2 changes: 1 addition & 1 deletion repository/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2752,7 +2752,7 @@ public function sync_reference(stored_file $file) {
$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;
}
Expand Down

0 comments on commit b4153ff

Please sign in to comment.