MDL-16596 adding missing get_parent_directory() method
This commit is contained in:
@@ -199,6 +199,30 @@ class stored_file {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns parent directory, creates missing parents if needed
|
||||
* @return object stored_file
|
||||
*/
|
||||
public function get_parent_directory() {
|
||||
if ($this->file_record->filepath === '/' and $this->file_record->filename === '.') {
|
||||
//root dir does not have parent
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($this->file_record->filename !== '.') {
|
||||
return $this->fs->create_directory($this->file_record->contextid, $this->file_record->filearea, $this->file_record->itemid, $this->file_record->filepath);
|
||||
}
|
||||
|
||||
$filepath = $this->file_record->filepath;
|
||||
$filepath = trim($filepath, '/');
|
||||
$dirs = explode('/', $filepath);
|
||||
array_pop($dirs);
|
||||
$filepath = implode('/', $dirs);
|
||||
$filepath = ($filepath === '') ? '/' : "/$filepath/";
|
||||
|
||||
return $this->fs->create_directory($this->file_record->contextid, $this->file_record->filearea, $this->file_record->itemid, $filepath);
|
||||
}
|
||||
|
||||
public function get_contextid() {
|
||||
return $this->file_record->contextid;
|
||||
}
|
||||
|
||||
@@ -119,6 +119,14 @@ class virtual_root_file {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns parent directory
|
||||
* @return object stored_file
|
||||
*/
|
||||
public function get_parent_directory() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function get_contextid() {
|
||||
return $this->contextid;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user