Skip to content

Commit

Permalink
MDL-33127 stored_file::update should use get_content_file_location be…
Browse files Browse the repository at this point in the history
…cause it tried to update file_record
  • Loading branch information
Dongsheng Cai authored and marinaglancy committed May 21, 2012
1 parent 0f1bdd0 commit 70c1bc8
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions lib/filestorage/stored_file.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ protected function update($dataobject) {
}
}
// Validate mimetype field
$pathname = $this->get_content_file_location();
// we don't use {@link stored_file::get_content_file_location()} here becaues it will try to update file_record
$pathname = $this->get_pathname_by_contenthash();
// try to recover the content from trash
if (!is_readable($pathname)) {
if (!$this->fs->try_content_recovery($this) or !is_readable($pathname)) {
Expand Down Expand Up @@ -262,22 +263,35 @@ public function delete() {
}

/**
* Protected - developers must not gain direct access to this function.
* Get file pathname by contenthash
*
* NOTE: do not make this public, we must not modify or delete the pool files directly! ;-)
* NOTE, this function is not calling sync_external_file, it assume the contenthash is current
* Protected - developers must not gain direct access to this function.
*
* @return string full path to pool file with file content
**/
protected function get_content_file_location() {
$this->sync_external_file();
*/
protected function get_pathname_by_contenthash() {
// Detect is local file or not.
$contenthash = $this->file_record->contenthash;
$l1 = $contenthash[0].$contenthash[1];
$l2 = $contenthash[2].$contenthash[3];
$path = "$this->filedir/$l1/$l2/$contenthash";
return "$this->filedir/$l1/$l2/$contenthash";
}

/**
* Get file pathname by given contenthash, this method will try to sync files
*
* Protected - developers must not gain direct access to this function.
*
* NOTE: do not make this public, we must not modify or delete the pool files directly! ;-)
*
* @return string full path to pool file with file content
**/
protected function get_content_file_location() {
$this->sync_external_file();
return $this->get_pathname_by_contenthash();
}

/**
* adds this file path to a curl request (POST only)
*
Expand Down

0 comments on commit 70c1bc8

Please sign in to comment.