mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
[MDL-15298] Don't create preset ZIP always in the same directory, as the same file name. Merged and ported from MOODLE_19_STABLE.
This commit is contained in:
parent
e72efdd426
commit
933c129603
2 changed files with 21 additions and 28 deletions
|
@ -85,7 +85,6 @@ $string['cannotmailconfirm'] = 'error sending password change confirmation email
|
||||||
$string['cannotmapfield'] = 'mapping collision detected, 2 fields maps to the same grade item $a';
|
$string['cannotmapfield'] = 'mapping collision detected, 2 fields maps to the same grade item $a';
|
||||||
$string['cannotmarktopic'] = 'Could not mark that topic for this course';
|
$string['cannotmarktopic'] = 'Could not mark that topic for this course';
|
||||||
$string['cannotmoverolewithid'] = 'Cannot move role with ID $a';
|
$string['cannotmoverolewithid'] = 'Cannot move role with ID $a';
|
||||||
$string['cannotmovezip'] = 'Cannot move zip';
|
|
||||||
$string['cannotmodulename'] = 'Cannot get the module name in build navigation.';
|
$string['cannotmodulename'] = 'Cannot get the module name in build navigation.';
|
||||||
$string['cannotmoduletype'] = 'Cannot get the module type in build navigation.';
|
$string['cannotmoduletype'] = 'Cannot get the module type in build navigation.';
|
||||||
$string['cannotmetacourse'] = 'Cannot not add the selected course to this meta course!';
|
$string['cannotmetacourse'] = 'Cannot not add the selected course to this meta course!';
|
||||||
|
|
|
@ -188,19 +188,11 @@ switch ($action) {
|
||||||
print_error('invalidrequest');
|
print_error('invalidrequest');
|
||||||
}
|
}
|
||||||
$exportfile = data_presets_export($course, $cm, $data);
|
$exportfile = data_presets_export($course, $cm, $data);
|
||||||
$downloadsubdir = "$course->id/moddata/data/$data->id";
|
$dataroot = preg_quote($CFG->dataroot, '/');
|
||||||
$filename = clean_filename($data->name . '-preset-' . gmdate("Ymd_Hi") . '.zip');
|
$downloadurl = preg_replace("/$dataroot/", $CFG->wwwroot . '/file.php', $exportfile, 1);
|
||||||
$downloadfile = "$CFG->dataroot/$downloadsubdir/$filename";
|
|
||||||
@unlink($downloadfile);
|
|
||||||
|
|
||||||
// Move the exported zip to the download folder
|
|
||||||
make_upload_directory($downloadsubdir);
|
|
||||||
if (! rename($exportfile, $downloadfile)) {
|
|
||||||
print_error('cannotmovezip');
|
|
||||||
}
|
|
||||||
echo '<div style="text-align:center">';
|
echo '<div style="text-align:center">';
|
||||||
echo get_string('exportedtozip', 'data') . '<br />';
|
echo get_string('exportedtozip', 'data') . '<br />';
|
||||||
echo "<a href='$CFG->wwwroot/file.php/$downloadsubdir/$filename'>" . get_string('download', 'data') . '</a>';
|
echo "<a href=\"$downloadurl\">" . get_string('download', 'data') . '</a>';
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -381,8 +373,10 @@ exit(0);
|
||||||
|
|
||||||
function data_presets_export($course, $cm, $data) {
|
function data_presets_export($course, $cm, $data) {
|
||||||
global $CFG, $DB;
|
global $CFG, $DB;
|
||||||
$tempfolder = $CFG->dataroot . '/temp';
|
$presetname = clean_filename($data->name) . '-preset-' . gmdate("Ymd_Hi");
|
||||||
// ToDo: Don't write directly into moodledata/temp
|
$exportsubdir = "$course->id/moddata/data/$data->id/$presetname";
|
||||||
|
make_upload_directory($exportsubdir);
|
||||||
|
$exportdir = "$CFG->dataroot/$exportsubdir";
|
||||||
|
|
||||||
// Assemble "preset.xml":
|
// Assemble "preset.xml":
|
||||||
$presetxmldata = "<preset>\n\n";
|
$presetxmldata = "<preset>\n\n";
|
||||||
|
@ -430,53 +424,53 @@ function data_presets_export($course, $cm, $data) {
|
||||||
$presetxmldata .= '</preset>';
|
$presetxmldata .= '</preset>';
|
||||||
|
|
||||||
// After opening a file in write mode, close it asap
|
// After opening a file in write mode, close it asap
|
||||||
$presetxmlfile = fopen($tempfolder . '/preset.xml', 'w');
|
$presetxmlfile = fopen($exportdir . '/preset.xml', 'w');
|
||||||
fwrite($presetxmlfile, $presetxmldata);
|
fwrite($presetxmlfile, $presetxmldata);
|
||||||
fclose($presetxmlfile);
|
fclose($presetxmlfile);
|
||||||
|
|
||||||
// Now write the template files
|
// Now write the template files
|
||||||
$singletemplate = fopen($tempfolder . '/singletemplate.html', 'w');
|
$singletemplate = fopen($exportdir . '/singletemplate.html', 'w');
|
||||||
fwrite($singletemplate, $data->singletemplate);
|
fwrite($singletemplate, $data->singletemplate);
|
||||||
fclose($singletemplate);
|
fclose($singletemplate);
|
||||||
|
|
||||||
$listtemplateheader = fopen($tempfolder . '/listtemplateheader.html', 'w');
|
$listtemplateheader = fopen($exportdir . '/listtemplateheader.html', 'w');
|
||||||
fwrite($listtemplateheader, $data->listtemplateheader);
|
fwrite($listtemplateheader, $data->listtemplateheader);
|
||||||
fclose($listtemplateheader);
|
fclose($listtemplateheader);
|
||||||
|
|
||||||
$listtemplate = fopen($tempfolder . '/listtemplate.html', 'w');
|
$listtemplate = fopen($exportdir . '/listtemplate.html', 'w');
|
||||||
fwrite($listtemplate, $data->listtemplate);
|
fwrite($listtemplate, $data->listtemplate);
|
||||||
fclose($listtemplate);
|
fclose($listtemplate);
|
||||||
|
|
||||||
$listtemplatefooter = fopen($tempfolder . '/listtemplatefooter.html', 'w');
|
$listtemplatefooter = fopen($exportdir . '/listtemplatefooter.html', 'w');
|
||||||
fwrite($listtemplatefooter, $data->listtemplatefooter);
|
fwrite($listtemplatefooter, $data->listtemplatefooter);
|
||||||
fclose($listtemplatefooter);
|
fclose($listtemplatefooter);
|
||||||
|
|
||||||
$addtemplate = fopen($tempfolder . '/addtemplate.html', 'w');
|
$addtemplate = fopen($exportdir . '/addtemplate.html', 'w');
|
||||||
fwrite($addtemplate, $data->addtemplate);
|
fwrite($addtemplate, $data->addtemplate);
|
||||||
fclose($addtemplate);
|
fclose($addtemplate);
|
||||||
|
|
||||||
$rsstemplate = fopen($tempfolder . '/rsstemplate.html', 'w');
|
$rsstemplate = fopen($exportdir . '/rsstemplate.html', 'w');
|
||||||
fwrite($rsstemplate, $data->rsstemplate);
|
fwrite($rsstemplate, $data->rsstemplate);
|
||||||
fclose($rsstemplate);
|
fclose($rsstemplate);
|
||||||
|
|
||||||
$rsstitletemplate = fopen($tempfolder . '/rsstitletemplate.html', 'w');
|
$rsstitletemplate = fopen($exportdir . '/rsstitletemplate.html', 'w');
|
||||||
fwrite($rsstitletemplate, $data->rsstitletemplate);
|
fwrite($rsstitletemplate, $data->rsstitletemplate);
|
||||||
fclose($rsstitletemplate);
|
fclose($rsstitletemplate);
|
||||||
|
|
||||||
$csstemplate = fopen($tempfolder . '/csstemplate.css', 'w');
|
$csstemplate = fopen($exportdir . '/csstemplate.css', 'w');
|
||||||
fwrite($csstemplate, $data->csstemplate);
|
fwrite($csstemplate, $data->csstemplate);
|
||||||
fclose($csstemplate);
|
fclose($csstemplate);
|
||||||
|
|
||||||
$jstemplate = fopen($tempfolder . '/jstemplate.js', 'w');
|
$jstemplate = fopen($exportdir . '/jstemplate.js', 'w');
|
||||||
fwrite($jstemplate, $data->jstemplate);
|
fwrite($jstemplate, $data->jstemplate);
|
||||||
fclose($jstemplate);
|
fclose($jstemplate);
|
||||||
|
|
||||||
$asearchtemplate = fopen($tempfolder . '/asearchtemplate.html', 'w');
|
$asearchtemplate = fopen($exportdir . '/asearchtemplate.html', 'w');
|
||||||
fwrite($asearchtemplate, $data->asearchtemplate);
|
fwrite($asearchtemplate, $data->asearchtemplate);
|
||||||
fclose($asearchtemplate);
|
fclose($asearchtemplate);
|
||||||
|
|
||||||
// Check if all files have been generated
|
// Check if all files have been generated
|
||||||
if (! is_directory_a_preset($tempfolder)) {
|
if (! is_directory_a_preset($exportdir)) {
|
||||||
error('Not all files generated!');
|
error('Not all files generated!');
|
||||||
// should be migrated to print_error()
|
// should be migrated to print_error()
|
||||||
}
|
}
|
||||||
|
@ -496,10 +490,10 @@ function data_presets_export($course, $cm, $data) {
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ($filelist as $key => $file) {
|
foreach ($filelist as $key => $file) {
|
||||||
$filelist[$key] = $tempfolder . '/' . $filelist[$key];
|
$filelist[$key] = $exportdir . '/' . $filelist[$key];
|
||||||
}
|
}
|
||||||
|
|
||||||
$exportfile = $tempfolder . '/export.zip';
|
$exportfile = "$CFG->dataroot/$course->id/moddata/data/$data->id/$presetname.zip";
|
||||||
@unlink($exportfile);
|
@unlink($exportfile);
|
||||||
$status = zip_files($filelist, $exportfile);
|
$status = zip_files($filelist, $exportfile);
|
||||||
// ToDo: status check
|
// ToDo: status check
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue