Skip to content

Commit

Permalink
MDL-42666 repository_boxnet: Avoid re-download of sync'd references
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederic Massart committed Nov 6, 2013
1 parent 05c9a3d commit 550be25
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions repository/boxnet/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ function repository_boxnet_migrate_references_from_apiv1() {
'author', 'license', 'timecreated', 'timemodified', 'sortorder', 'referencefileid');
$referencefields = array('repositoryid' => 'repositoryid',
'reference' => 'reference',
'lifetime' => 'referencelifetime',
'lastsync' => 'referencelastsync');
$fields = array();
$fields[] = 'f.id AS id';
Expand Down Expand Up @@ -130,20 +131,20 @@ function repository_boxnet_migrate_references_from_apiv1() {
// set it synchronized or there is a risk that repository::sync_reference() will try to download
// the file again. We cannot use $file->get_contenthash() and $file->get_filesize() because they
// cause repository::sync_reference() to be called.
$file->set_synchronized($filerecord->contenthash, $filerecord->filesize);
$file->set_synchronized($filerecord->contenthash, $filerecord->filesize, 0, DAYSECS);
mtrace('Could not download reference, using last synced file. (id: ' . $file->get_referencefileid() . ')');
} else {
// We don't know what the file was, but what can we do? In order to prevent a re-attempt to fetch the
// file in the next bit of this script (import_external_file()), we set a dummy content to the reference.
$file->set_synchronized($dummyhash, $dummysize);
$file->set_synchronized($dummyhash, $dummysize, 0, DAYSECS);
mtrace('Could not download reference, dummy file used. (id: ' . $file->get_referencefileid() . ')');
}
} else {
try {
// The file has been downloaded, we add it to the file pool and synchronize
// all the files using this reference.
list($contenthash, $filesize, $unused) = $fs->add_file_to_pool($saveas);
$file->set_synchronized($contenthash, $filesize);
$file->set_synchronized($contenthash, $filesize, 0, DAYSECS);
} catch (moodle_exception $e) {
// Something wrong happened...
mtrace('Something went wrong during sync (id: ' . $file->get_referencefileid() . ')');
Expand Down

0 comments on commit 550be25

Please sign in to comment.