MDL-23268, throw error message instead of deleting existing file

This commit is contained in:
Dongsheng Cai
2010-07-27 03:10:59 +00:00
parent 6999d9cf75
commit 1311e4dd00
5 changed files with 8 additions and 4 deletions
+1
View File
@@ -219,6 +219,7 @@ $string['errorunzippingfiles'] = 'Error unzipping files';
$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';
+1 -1
View File
@@ -829,7 +829,7 @@ abstract class repository {
}
$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)) {
+4 -1
View File
@@ -197,9 +197,12 @@ class repository_local extends repository {
$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);
+1 -1
View File
@@ -188,7 +188,7 @@ class repository_recent extends repository {
$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);
}
+1 -1
View File
@@ -104,7 +104,7 @@ class repository_upload extends repository {
}
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;