Skip to content

Commit

Permalink
MDL-23268, throw error message instead of deleting existing file
Browse files Browse the repository at this point in the history
  • Loading branch information
Dongsheng Cai committed Jul 27, 2010
1 parent 6999d9c commit 1311e4d
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions lang/en/error.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@
$string['expiredkey'] = 'Expired key';
$string['failtoloadblocks'] = 'One or more blocks are registered in the database, but they all failed to load!';
$string['fieldrequired'] = '"{$a}" is a required field';
$string['fileexists'] = 'File exists';
$string['filemismatch'] = 'Non-core file name mismatch. The file "{$a->current}" should be {$a->file}';
$string['filenotfound'] = 'Sorry, the requested file could not be found';
$string['filenotreadable'] = 'File is not readable';
Expand Down
2 changes: 1 addition & 1 deletion repository/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ public static function move_to_filepool($thefile, $record) {
}
$fs = get_file_storage();
if ($existingfile = $fs->get_file($context->id, $record->component, $record->filearea, $record->itemid, $record->filepath, $record->filename)) {
$existingfile->delete();
throw new moodle_exception('fileexists');
}
if ($file = $fs->create_file_from_pathname($record, $thefile)) {
if (empty($CFG->repository_no_delete)) {
Expand Down
5 changes: 4 additions & 1 deletion repository/local/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,12 @@ public function copy_to_area($encoded, $draftitemid, $new_filepath, $new_filenam
$filepath = clean_param($params['filepath'], PARAM_PATH);;
$filearea = clean_param($params['filearea'], PARAM_ALPHAEXT);
$component = clean_param($params['component'], PARAM_ALPHAEXT);

$context = get_context_instance_by_id($contextid);

if ($existingfile = $fs->get_file($user_context->id, 'user', 'draft', $draftitemid, $new_filepath, $new_filename)) {
throw new moodle_exception('fileexists');
}

$file_info = $browser->get_file_info($context, $component, $filearea, $fileitemid, $filepath, $filename);
$file_info->copy_to_storage($user_context->id, 'user', 'draft', $draftitemid, $new_filepath, $new_filename);

Expand Down
2 changes: 1 addition & 1 deletion repository/recent/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public function copy_to_area($encoded, $draftitemid, $new_filepath, $new_filenam
$file_record = array('contextid'=>$user_context->id, 'component'=>'user', 'filearea'=>'draft',
'itemid'=>$draftitemid, 'filepath'=>$new_filepath, 'filename'=>$new_filename);
if ($file = $fs->get_file($user_context->id, 'user', 'draft', $draftitemid, $new_filepath, $new_filename)) {
$file->delete();
throw new moodle_exception('fileexists');
}
$fs->create_file_from_storedfile($file_record, $stored_file);
}
Expand Down
2 changes: 1 addition & 1 deletion repository/upload/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function upload() {
}

if ($file = $fs->get_file($context->id, $record->component, $record->filearea, $record->itemid, $record->filepath, $record->filename)) {
throw new moodle_exception('fileexist');
throw new moodle_exception('fileexists');
}

$record->contextid = $context->id;
Expand Down

0 comments on commit 1311e4d

Please sign in to comment.