MDL-12330 - moving a question that uses an image in a subfolder of course files, where the same subfolder does not exist at the destination, fails. Merged from MOODLE_19_STABLE.

This commit is contained in:
tjhunt
2007-11-28 16:43:20 +00:00
parent 66fef744d4
commit e049dee30a
2 changed files with 13 additions and 5 deletions
+4
View File
@@ -99,6 +99,10 @@
$source = $CFG->dataroot."/$fromcoursefilesid/".$flipurls[$key];
$destination = $flipurls[$key];
if (($urlaction != QUESTION_FILEDONOTHING) && ($urlaction != QUESTION_FILEMOVELINKSONLY)){
// Ensure the target folder exists.
check_dir_exists(dirname($CFG->dataroot."/$tocoursefilesid/".$destination), true);
// Then make sure the destination file name does not exist. If it does, change the name to be unique.
while (file_exists($CFG->dataroot."/$tocoursefilesid/".$destination)){
$matches = array();
//check for '_'. copyno after filename, before extension.
+9 -5
View File
@@ -105,6 +105,10 @@ if ($contextmoveform->is_cancelled()){
$source = $CFG->dataroot."/$fromcoursefilesid/".$flipurls[$key];
$destination = $flipurls[$key];
if (($urlaction != QUESTION_FILEDONOTHING) && ($urlaction != QUESTION_FILEMOVELINKSONLY)){
// Ensure the target folder exists.
check_dir_exists(dirname($CFG->dataroot."/$tocoursefilesid/".$destination), true);
// Then make sure the destination file name does not exist. If it does, change the name to be unique.
while (file_exists($CFG->dataroot."/$tocoursefilesid/".$destination)){
$matches = array();
//check for '_'. copyno after filename, before extension.
@@ -120,19 +124,19 @@ if ($contextmoveform->is_cancelled()){
switch ($urlaction){
case QUESTION_FILECOPY :
if (!copy($source, $CFG->dataroot."/$tocoursefilesid/".$destination)){
print_error('errorfilecannotbecopied', 'question', $onerrorurl, $source);
print_error('errorfilecannotbecopied', 'question', $returnurl, $source);
}
break;
case QUESTION_FILEMOVE :
if (!rename($source, $CFG->dataroot."/$tocoursefilesid/".$destination)){
print_error('errorfilecannotbemoved', 'question', $onerrorurl, $source);
print_error('errorfilecannotbemoved', 'question', $returnurl, $source);
}
break;
case QUESTION_FILEMOVELINKSONLY :
case QUESTION_FILEDONOTHING :
break;
default :
error('Invalid action selected!', $onerrorurl);
error('Invalid action selected!', $returnurl);
}
//now search and replace urls in questions.
switch ($urlaction){
@@ -148,7 +152,7 @@ if ($contextmoveform->is_cancelled()){
case QUESTION_FILEDONOTHING :
break;
default :
error('Invalid action selected!', $onerrorurl);
error('Invalid action selected!', $returnurl);
break;
}
@@ -157,7 +161,7 @@ if ($contextmoveform->is_cancelled()){
}
//now move questions
if (!execute_sql("UPDATE {$CFG->prefix}question SET category = {$tocat->id} WHERE id IN ({$ids})", false)){
error("Could not move the questions {$ids} to category ".$tocat->name, $onerrorurl);
error("Could not move the questions {$ids} to category ".$tocat->name, $returnurl);
}
redirect($returnurl);
}