From a0ff4137d90c7a3e3d2f8952eab5e576693118bd Mon Sep 17 00:00:00 2001 From: Dongsheng Cai Date: Fri, 6 Nov 2009 09:32:44 +0000 Subject: [PATCH] "MDL-13766, fixed a bug in move_to_filepool and moving code block" --- repository/lib.php | 66 ++++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/repository/lib.php b/repository/lib.php index 091a9084c5d76..357a0065aa596 100644 --- a/repository/lib.php +++ b/repository/lib.php @@ -447,6 +447,31 @@ abstract class repository { public $options; public $readonly; public $returntypes; + /** + * 1. Initialize context and options + * 2. Accept necessary parameters + * + * @param integer $repositoryid + * @param integer $contextid + * @param array $options + */ + public function __construct($repositoryid, $contextid = SITEID, $options = array(), $readonly = 0) { + $this->id = $repositoryid; + $this->context = get_context_instance_by_id($contextid); + $this->readonly = $readonly; + $this->options = array(); + if (is_array($options)) { + $options = array_merge($this->get_option(), $options); + } else { + $options = $this->get_option(); + } + foreach ($options as $n => $v) { + $this->options[$n] = $v; + } + $this->name = $this->get_name(); + $this->returntypes = $this->supported_returntypes(); + $this->super_called = true; + } /** * Return a type for a given type name. @@ -795,7 +820,7 @@ public static function move_to_filepool($path, $name, $itemid, $filepath = '/', } $fs = get_file_storage(); $browser = get_file_browser(); - if ($existingfile = $fs->get_file($context->id, $filearea, $itemid, $path, $name)) { + if ($existingfile = $fs->get_file($context->id, $filearea, $itemid, $filepath, $name)) { $existingfile->delete(); } if ($file = $fs->create_file_from_pathname($entry, $path)) { @@ -805,7 +830,8 @@ public static function move_to_filepool($path, $name, $itemid, $filepath = '/', } $ret = $browser->get_file_info($context, $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename()); if(!empty($ret)) { - return array('url'=>$ret->get_url(), + return array( + 'url'=>$ret->get_url(), 'id'=>$file->get_itemid(), 'file'=>$file->get_filename(), 'icon' => $OUTPUT->old_icon_url(file_extension_icon($path, 32)) @@ -819,7 +845,7 @@ public static function move_to_filepool($path, $name, $itemid, $filepath = '/', } /** - * Save file to local filesystem pool + * Upload file to local filesystem pool * @param string $elname name of element * @param string $filearea * @param string $filepath @@ -827,7 +853,7 @@ public static function move_to_filepool($path, $name, $itemid, $filepath = '/', * @param bool $override override file if exists * @return mixed stored_file object or false if error; may throw exception if duplicate found */ - public static function store_to_filepool($elname, $filearea='user_draft', $filepath='/', $itemid='', $filename = '', $override = false) { + public static function upload_to_filepool($elname, $filearea='user_draft', $filepath='/', $itemid='', $filename = '', $override = false) { global $USER; if ($filepath !== '/') { @@ -867,8 +893,11 @@ public static function store_to_filepool($elname, $filearea='user_draft', $filep $file = $fs->create_file_from_pathname($file_record, $_FILES[$elname]['tmp_name']); $info = $browser->get_file_info($context, $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename()); - $ret = array('url'=>$info->get_url(),'id'=>$itemid, 'file'=>$file->get_filename()); - return $ret; + return array( + 'url'=>$info->get_url(), + 'id'=>$itemid, + 'file'=>$file->get_filename() + ); } /** @@ -1124,31 +1153,6 @@ public static function display_instances_list($context, $typename = null) { //print the list + creation links print($output); } - /** - * 1. Initialize context and options - * 2. Accept necessary parameters - * - * @param integer $repositoryid - * @param integer $contextid - * @param array $options - */ - public function __construct($repositoryid, $contextid = SITEID, $options = array(), $readonly = 0) { - $this->id = $repositoryid; - $this->context = get_context_instance_by_id($contextid); - $this->readonly = $readonly; - $this->options = array(); - if (is_array($options)) { - $options = array_merge($this->get_option(), $options); - } else { - $options = $this->get_option(); - } - foreach ($options as $n => $v) { - $this->options[$n] = $v; - } - $this->name = $this->get_name(); - $this->returntypes = $this->supported_returntypes(); - $this->super_called = true; - } /** * Decide where to save the file, can be