Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-34290, MDL-33416 prepare to deprecate fields files.referencelasts…

…ync and referencelifetime
  • Loading branch information...
commit 3dce698981e55489ed07d04dccdc14daf3c55068 1 parent 29ea4e9
@marinaglancy marinaglancy authored
Showing with 26 additions and 22 deletions.
  1. +13 −19 lib/filestorage/file_storage.php
  2. +13 −3 lib/filestorage/stored_file.php
View
32 lib/filestorage/file_storage.php
@@ -976,10 +976,6 @@ public function create_file_from_pathname($filerecord, $pathname) {
$filerecord->sortorder = 0;
}
- $filerecord->referencefileid = !isset($filerecord->referencefileid) ? 0 : $filerecord->referencefileid;
- $filerecord->referencelastsync = !isset($filerecord->referencelastsync) ? 0 : $filerecord->referencelastsync;
- $filerecord->referencelifetime = !isset($filerecord->referencelifetime) ? 0 : $filerecord->referencelifetime;
-
$filerecord->filepath = clean_param($filerecord->filepath, PARAM_PATH);
if (strpos($filerecord->filepath, '/') !== 0 or strrpos($filerecord->filepath, '/') !== strlen($filerecord->filepath)-1) {
// path must start and end with '/'
@@ -1094,9 +1090,6 @@ public function create_file_from_string($filerecord, $content) {
} else {
$filerecord->sortorder = 0;
}
- $filerecord->referencefileid = !isset($filerecord->referencefileid) ? 0 : $filerecord->referencefileid;
- $filerecord->referencelastsync = !isset($filerecord->referencelastsync) ? 0 : $filerecord->referencelastsync;
- $filerecord->referencelifetime = !isset($filerecord->referencelifetime) ? 0 : $filerecord->referencelifetime;
$filerecord->filepath = clean_param($filerecord->filepath, PARAM_PATH);
if (strpos($filerecord->filepath, '/') !== 0 or strrpos($filerecord->filepath, '/') !== strlen($filerecord->filepath)-1) {
@@ -1217,9 +1210,10 @@ public function create_file_from_reference($filerecord, $repositoryid, $referenc
$filerecord->sortorder = 0;
}
- $filerecord->referencefileid = empty($filerecord->referencefileid) ? 0 : $filerecord->referencefileid;
- $filerecord->referencelastsync = empty($filerecord->referencelastsync) ? 0 : $filerecord->referencelastsync;
- $filerecord->referencelifetime = empty($filerecord->referencelifetime) ? 0 : $filerecord->referencelifetime;
+ // TODO MDL-33416 [2.4] fields referencelastsync and referencelifetime to be removed from {files} table completely
+ unset($filerecord->referencelastsync);
+ unset($filerecord->referencelifetime);
+
$filerecord->mimetype = empty($filerecord->mimetype) ? $this->mimetype($filerecord->filename) : $filerecord->mimetype;
$filerecord->userid = empty($filerecord->userid) ? null : $filerecord->userid;
$filerecord->source = empty($filerecord->source) ? null : $filerecord->source;
@@ -1309,10 +1303,8 @@ public function create_file_from_reference($filerecord, $repositoryid, $referenc
$transaction->allow_commit();
- // Adding repositoryid and reference to file record to create stored_file instance
- $filerecord->repositoryid = $repositoryid;
- $filerecord->reference = $reference;
- return $this->get_file_instance($filerecord);
+ // this will retrieve all reference information from DB as well
+ return $this->get_file_by_id($filerecord->id);
}
/**
@@ -1973,10 +1965,12 @@ private static function instance_sql_fields($filesprefix, $filesreferenceprefix)
// else problems like MDL-33172 occur.
$filefields = array('contenthash', 'pathnamehash', 'contextid', 'component', 'filearea',
'itemid', 'filepath', 'filename', 'userid', 'filesize', 'mimetype', 'status', 'source',
- 'author', 'license', 'timecreated', 'timemodified', 'sortorder', 'referencefileid',
- 'referencelastsync', 'referencelifetime');
+ 'author', 'license', 'timecreated', 'timemodified', 'sortorder', 'referencefileid');
- $referencefields = array('repositoryid', 'reference');
+ $referencefields = array('repositoryid' => 'repositoryid',
+ 'reference' => 'reference',
+ 'lastsync' => 'referencelastsync',
+ 'lifetime' => 'referencelifetime');
// id is specifically named to prevent overlaping between the two tables.
$fields = array();
@@ -1985,8 +1979,8 @@ private static function instance_sql_fields($filesprefix, $filesreferenceprefix)
$fields[] = "{$filesprefix}.{$field}";
}
- foreach ($referencefields as $field) {
- $fields[] = "{$filesreferenceprefix}.{$field}";
+ foreach ($referencefields as $field => $alias) {
+ $fields[] = "{$filesreferenceprefix}.{$field} AS {$alias}";
}
return implode(', ', $fields);
View
16 lib/filestorage/stored_file.php
@@ -70,6 +70,12 @@ public function __construct(file_storage $fs, stdClass $file_record, $filedir) {
} else {
$this->repository = null;
}
+ // make sure all reference fields exist in file_record even when it is not a reference
+ foreach (array('referencelastsync', 'referencelifetime', 'referencefileid', 'reference', 'repositoryid') as $key) {
+ if (empty($this->file_record->$key)) {
+ $this->file_record->$key = null;
+ }
+ }
}
/**
@@ -142,12 +148,18 @@ protected function update($dataobject) {
}
}
- if ($field === 'referencefileid' or $field === 'referencelastsync' or $field === 'referencelifetime') {
+ if ($field === 'referencefileid') {
if (!is_null($value) and !is_number($value)) {
throw new file_exception('storedfileproblem', 'Invalid reference info');
}
}
+ if ($field === 'referencelastsync' or $field === 'referencelifetime') {
+ // do not update those fields
+ // TODO MDL-33416 [2.4] fields referencelastsync and referencelifetime to be removed from {files} table completely
+ continue;
+ }
+
// adding the field
$this->file_record->$field = $value;
} else {
@@ -226,8 +238,6 @@ public function delete_reference() {
// Update the underlying record in the database.
$update = new stdClass();
$update->referencefileid = null;
- $update->referencelastsync = null;
- $update->referencelifetime = null;
$this->update($update);
$transaction->allow_commit();
Please sign in to comment.
Something went wrong with that request. Please try again.