diff --git a/lib/WeBWorK/ContentGenerator/Instructor/PGProblemEditor.pm b/lib/WeBWorK/ContentGenerator/Instructor/PGProblemEditor.pm index 6e208d6cd9..54aa863de6 100644 --- a/lib/WeBWorK/ContentGenerator/Instructor/PGProblemEditor.pm +++ b/lib/WeBWorK/ContentGenerator/Instructor/PGProblemEditor.pm @@ -704,14 +704,15 @@ sub saveFileChanges ($c, $outputFilePath, $backup = 0) { } # If the file is being saved as a new file in a new location, and the file is accompanied by auxiliary files - # transfer them as well. If the file is a pg file, then assume there are auxiliary files. Copy all files not - # ending in .pg from the original directory to the new one. - if ($c->{action} eq 'save_as' && $outputFilePath =~ /\.pg/) { + # transfer them as well. If the option 'copyAuxFiles' is set and the file is a pg file, then assume there are + # auxiliary files. Copy all files not ending in .pg from the original directory to the new one. + if ($c->{action} eq 'save_as' && $c->param('copyAuxFiles') && $outputFilePath =~ /\.pg/) { my $sourceDirectory = Mojo::File->new(($c->{sourceFilePath} || '') =~ s|/[^/]+\.pg$||r); my $outputDirectory = Mojo::File->new($outputFilePath =~ s|/[^/]+\.pg$||r); # Only perform the copy if the output directory is an actual new location. if ($sourceDirectory ne $outputDirectory && -d $sourceDirectory) { + my $filesCopied = 0; for my $file (@{ $sourceDirectory->list }) { # The .pg file being edited has already been transferred. Ignore any others in the directory. next if $file =~ /\.pg$/; @@ -719,13 +720,18 @@ sub saveFileChanges ($c, $outputFilePath, $backup = 0) { # Only copy regular files that are readable and that have not already been copied. if (-f $file && -r $file && !-e $toPath) { eval { $file->copy_to($toPath) }; - $c->addbadmessage($c->maketext('Error copying [_1] to [_2].', $file, $toPath)) if $@; + if ($@) { + $c->addbadmessage($c->maketext('Error copying [_1] to [_2].', $file, $toPath)); + } else { + $filesCopied = 1; + } } } $c->addgoodmessage($c->maketext( 'Copied auxiliary files from [_1] to new location at [_2].', $sourceDirectory, $outputDirectory - )); + )) + if $filesCopied; } } diff --git a/templates/ContentGenerator/Instructor/PGProblemEditor/save_as_form.html.ep b/templates/ContentGenerator/Instructor/PGProblemEditor/save_as_form.html.ep index 558b367d3d..91b0364a82 100644 --- a/templates/ContentGenerator/Instructor/PGProblemEditor/save_as_form.html.ep +++ b/templates/ContentGenerator/Instructor/PGProblemEditor/save_as_form.html.ep @@ -52,6 +52,12 @@ <%= hidden_field 'action.save_as.source_file' => $c->{editFilePath} =%> <%= hidden_field 'action.save_as.file_type' => $c->{file_type} =%> +
+ <%= maketext('When saving the problem in a new location (directory), by default all auxiliary files, such ' + . 'as images, or other files that do not end in ".pg", will also be copied to the new location. To ' + . 'stop this behavior, uncheck the "Copy auxiliary files" option.') =%> +
<%= maketext('You may want to create an unattached problem if you are using the current problem as a model ' . 'for a new problem. You can add the new file to a homework set from the Library Browser or via the '