From: skodak Date: Sun, 21 Sep 2008 19:53:46 +0000 (+0000) Subject: MDL-16596 adding missing get_parent_directory() method X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=4b6b5ce7d91005decd6bf82dffdc98c9601be97d;p=moodle.git MDL-16596 adding missing get_parent_directory() method --- diff --git a/lib/file/stored_file.php b/lib/file/stored_file.php index 3ad8575151..d3e1afe241 100644 --- a/lib/file/stored_file.php +++ b/lib/file/stored_file.php @@ -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; } diff --git a/lib/file/virtual_root_file.php b/lib/file/virtual_root_file.php index cebd7ae20e..526956180d 100644 --- a/lib/file/virtual_root_file.php +++ b/lib/file/virtual_root_file.php @@ -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; }