}
}
- /**
- * Returns location of filedir (file pool).
- *
- * Do not use, this method is intended for stored_file instances only!!!
- *
- * @return string pathname
- */
- public function get_filedir() {
- return $this->filedir;
- }
-
/**
* Calculates sha1 hash of unique full path name information.
*
return $DB->record_exists('files', array('pathnamehash'=>$pathnamehash));
}
+ /**
+ * Create instance of file class from database record.
+ *
+ * @param stdClass $file_record record from the files table
+ * @return stored_file instance of file abstraction class
+ */
+ public function get_file_instance(stdClass $file_record) {
+ return new stored_file($this, $file_record, $this->filedir);
+ }
+
/**
* Fetch file using local file id.
*
global $DB;
if ($file_record = $DB->get_record('files', array('id'=>$fileid))) {
- return new stored_file($this, $file_record);
+ return $this->get_file_instance($file_record);
} else {
return false;
}
global $DB;
if ($file_record = $DB->get_record('files', array('pathnamehash'=>$pathnamehash))) {
- return new stored_file($this, $file_record);
+ return $this->get_file_instance($file_record);
} else {
return false;
}
if (!$includedirs and $file_record->filename === '.') {
continue;
}
- $result[$file_record->pathnamehash] = new stored_file($this, $file_record);
+ $result[$file_record->pathnamehash] = $this->get_file_instance($file_record);
}
return $result;
}
$file_records = $DB->get_records_sql($sql, $params);
foreach ($file_records as $file_record) {
if ($file_record->filename == '.') {
- $dirs[$file_record->pathnamehash] = new stored_file($this, $file_record);
+ $dirs[$file_record->pathnamehash] = $this->get_file_instance($file_record);
} else {
- $files[$file_record->pathnamehash] = new stored_file($this, $file_record);
+ $files[$file_record->pathnamehash] = $this->get_file_instance($file_record);
}
}
$result = array_merge($dirs, $files);
if (substr_count($file_record->filepath, '/') !== $reqlevel) {
continue;
}
- $result[$file_record->pathnamehash] = new stored_file($this, $file_record);
+ $result[$file_record->pathnamehash] = $this->get_file_instance($file_record);
}
}
$file_records = $DB->get_records_sql($sql, $params);
foreach ($file_records as $file_record) {
- $result[$file_record->pathnamehash] = new stored_file($this, $file_record);
+ $result[$file_record->pathnamehash] = $this->get_file_instance($file_record);
}
}
$file_records = $DB->get_records('files', $conditions);
foreach ($file_records as $file_record) {
- $stored_file = new stored_file($this, $file_record);
+ $stored_file = $this->get_file_instance($file_record);
$stored_file->delete();
}
// update the existing directory with the new data
$newrecord->id = $directory->get_id();
$DB->update_record('files', $newrecord);
- return new stored_file($this, $newrecord);
+ return $this->get_file_instance($newrecord);
}
try {
$this->create_directory($newrecord->contextid, $newrecord->component, $newrecord->filearea, $newrecord->itemid, $newrecord->filepath, $newrecord->userid);
- return new stored_file($this, $newrecord);
+ return $this->get_file_instance($newrecord);
}
/**
$this->create_directory($newrecord->contextid, $newrecord->component, $newrecord->filearea, $newrecord->itemid, $newrecord->filepath, $newrecord->userid);
- return new stored_file($this, $newrecord);
+ return $this->get_file_instance($newrecord);
}
/**
$this->create_directory($newrecord->contextid, $newrecord->component, $newrecord->filearea, $newrecord->itemid, $newrecord->filepath, $newrecord->userid);
- return new stored_file($this, $newrecord);
+ return $this->get_file_instance($newrecord);
}
/**
private $fs;
/** @var object record from the files table */
private $file_record;
+ /** @var string location of content files */
+ private $filedir;
/**
* Constructor, this constructor should be called ONLY from the file_storage class!
*
* @param file_storage $fs file storage instance
* @param object $file_record description of file
+ * @param string $filepool location of file directory with sh1 named content files
*/
- public function __construct(file_storage $fs, stdClass $file_record) {
+ public function __construct(file_storage $fs, stdClass $file_record, $filedir) {
$this->fs = $fs;
$this->file_record = clone($file_record); // prevent modifications
+ $this->filedir = $filedir; // keep secret, do not expose!
}
/**
* @return string full path to pool file with file content
**/
protected function get_content_file_location() {
- $filedir = $this->fs->get_filedir();
$contenthash = $this->file_record->contenthash;
$l1 = $contenthash[0].$contenthash[1];
$l2 = $contenthash[2].$contenthash[3];
- return "$filedir/$l1/$l2/$contenthash";
+ return "$this->filedir/$l1/$l2/$contenthash";
}
/**