Skip to content

Commit

Permalink
"MDL-13766, fixed user_draft area files for user_private block, not d…
Browse files Browse the repository at this point in the history
…isplay draft files in recent plugin, it has problems"
  • Loading branch information
Dongsheng Cai committed May 5, 2010
1 parent bed59ff commit c7e4621
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
8 changes: 4 additions & 4 deletions repository/local/repository.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ public function get_name(){
public function supported_returntypes() {
return FILE_INTERNAL;
}

/**
* Copy a file to draft area
* Copy a file to file area
*
* @global object $USER
* @global object $DB
Expand All @@ -167,7 +167,7 @@ public function supported_returntypes() {
* @param string $new_filepath the new path in draft area
* @return array The information of file
*/
public function copy_to_draft($encoded, $new_filename = '', $new_itemid = '', $new_filepath = '/') {
public function copy_to_area($encoded, $new_filearea='user_draft', $new_itemid = '', $new_filepath = '/', $new_filename = '') {
global $USER, $DB;
$info = array();

Expand All @@ -183,7 +183,7 @@ public function copy_to_draft($encoded, $new_filename = '', $new_itemid = '', $n
$context = get_context_instance_by_id($contextid);
try {
$file_info = $browser->get_file_info($context, $filearea, $fileitemid, $filepath, $filename);
$file_info->copy_to_storage($user_context->id, 'user_draft', $new_itemid, $new_filepath, $new_filename);
$file_info->copy_to_storage($user_context->id, $new_filearea, $new_itemid, $new_filepath, $new_filename);
} catch (Exception $e) {
throw $e;
}
Expand Down
14 changes: 7 additions & 7 deletions repository/recent/repository.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ private function get_recent_files($limitfrom = 0, $limit = DEFAULT_RECENT_FILES_
// TODO: should exclude user_draft area files?
$sql = 'SELECT * FROM {files} files1
JOIN (SELECT contenthash, filename, MAX(id) AS id
FROM {files}
WHERE userid = ? AND filename != ?
FROM {files}
WHERE userid = ? AND filename != ? AND filearea != ?
GROUP BY contenthash, filename) files2 ON files1.id = files2.id
ORDER BY files1.timemodified DESC';
$params = array('userid'=>$USER->id, 'filename'=>'.');
$params = array('userid'=>$USER->id, 'filename'=>'.', 'filearea'=>'user_draft');
$rs = $DB->get_recordset_sql($sql, $params, $limitfrom, $limit);
$result = array();
foreach ($rs as $file_record) {
Expand Down Expand Up @@ -155,7 +155,7 @@ public function supported_returntypes() {
return FILE_INTERNAL;
}
/**
* Copy a file to draft area
* Copy a file to file area
*
* @global object $USER
* @global object $DB
Expand All @@ -165,7 +165,7 @@ public function supported_returntypes() {
* @param string $new_filepath the new path in draft area
* @return array The information of file
*/
public function copy_to_draft($encoded, $new_filename = '', $new_itemid = '', $new_filepath = '/') {
public function copy_to_area($encoded, $new_filearea='user_draft', $new_itemid = '', $new_filepath = '/', $new_filename = '') {
global $USER, $DB;
$info = array();
$fs = get_file_storage();
Expand All @@ -187,9 +187,9 @@ public function copy_to_draft($encoded, $new_filename = '', $new_itemid = '', $n
// To get 'recent' plugin working, we need to use lower level file_stoarge class to bypass the
// capability check, we will use a better workaround to improve it.
if ($stored_file = $fs->get_file($contextid, $filearea, $fileitemid, $filepath, $filename)) {
$file_record = array('contextid'=>$user_context->id, 'filearea'=>'user_draft',
$file_record = array('contextid'=>$user_context->id, 'filearea'=>$new_filearea,
'itemid'=>$new_itemid, 'filepath'=>$new_filepath, 'filename'=>$new_filename);
if ($file = $fs->get_file($user_context->id, 'user_draft', $new_itemid, $new_filepath, $new_filename)) {
if ($file = $fs->get_file($user_context->id, $new_filearea, $new_itemid, $new_filepath, $new_filename)) {
$file->delete();
}
$fs->create_file_from_storedfile($file_record, $stored_file);
Expand Down
3 changes: 2 additions & 1 deletion repository/repository_ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,9 @@
try {
// we have two special repoisitory type need to deal with
if ($repo->options['type'] == 'local' || $repo->options['type'] == 'recent' ) {
// saveas_filearea
try {
$fileinfo = $repo->copy_to_draft($source, $saveas_filename, $itemid, $saveas_path);
$fileinfo = $repo->copy_to_area($source, $saveas_filearea, $itemid, $saveas_path, $saveas_filename);
} catch (Exception $e) {
throw $e;
}
Expand Down

0 comments on commit c7e4621

Please sign in to comment.