Skip to content

Commit

Permalink
"MDL-13766, fixed a bug in move_to_filepool and moving code block"
Browse files Browse the repository at this point in the history
  • Loading branch information
Dongsheng Cai committed Nov 6, 2009
1 parent d742249 commit a0ff413
Showing 1 changed file with 35 additions and 31 deletions.
66 changes: 35 additions & 31 deletions repository/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)) {
Expand All @@ -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))
Expand All @@ -819,15 +845,15 @@ 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
* @param string $filename - use specified filename, if not specified name of uploaded file used
* @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 !== '/') {
Expand Down Expand Up @@ -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()
);
}

/**
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a0ff413

Please sign in to comment.