]> git.mjollnir.org Git - moodle.git/commitdiff
[MDL-15298] Don't create preset ZIP always in the same directory, as the same file...
authorrobertall <robertall>
Wed, 18 Jun 2008 11:53:15 +0000 (11:53 +0000)
committerrobertall <robertall>
Wed, 18 Jun 2008 11:53:15 +0000 (11:53 +0000)
lang/en_utf8/error.php
mod/data/preset.php

index d8ef3741e279c6c14918432cd7d89937a41021b2..ff5b3fd52e1926712f7bfe22312369516f1bc295 100644 (file)
@@ -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['cannotmarktopic'] = 'Could not mark that topic for this course';
 $string['cannotmoverolewithid'] = 'Cannot move role with ID $a';
-$string['cannotmovezip'] = 'Cannot move zip';
 $string['cannotmodulename'] = 'Cannot get the module name 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!';
index 08899bdb6198b549df2715176be137847df3144e..54dd568a8e47928eb1ba6ab2ab051586492aaeec 100644 (file)
@@ -188,19 +188,11 @@ switch ($action) {
             print_error('invalidrequest');
         }
         $exportfile = data_presets_export($course, $cm, $data);
-        $downloadsubdir = "$course->id/moddata/data/$data->id";
-        $filename = clean_filename($data->name . '-preset-' . gmdate("Ymd_Hi") . '.zip');
-        $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');
-        }
+        $dataroot = preg_quote($CFG->dataroot, '/');
+        $downloadurl = preg_replace("/$dataroot/", $CFG->wwwroot . '/file.php', $exportfile, 1);
         echo '<div style="text-align:center">';
         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>';
         break;
 
@@ -381,8 +373,10 @@ exit(0);
 
 function data_presets_export($course, $cm, $data) {
     global $CFG, $DB;
-    $tempfolder = $CFG->dataroot . '/temp';
-    // ToDo: Don't write directly into moodledata/temp
+    $presetname = clean_filename($data->name) . '-preset-' . gmdate("Ymd_Hi");
+    $exportsubdir = "$course->id/moddata/data/$data->id/$presetname";
+    make_upload_directory($exportsubdir);
+    $exportdir = "$CFG->dataroot/$exportsubdir";
 
     // Assemble "preset.xml":
     $presetxmldata = "<preset>\n\n";
@@ -430,53 +424,53 @@ function data_presets_export($course, $cm, $data) {
     $presetxmldata .= '</preset>';
 
     // 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);
     fclose($presetxmlfile);
 
     // Now write the template files
-    $singletemplate = fopen($tempfolder . '/singletemplate.html', 'w');
+    $singletemplate = fopen($exportdir . '/singletemplate.html', 'w');
     fwrite($singletemplate, $data->singletemplate);
     fclose($singletemplate);
 
-    $listtemplateheader = fopen($tempfolder . '/listtemplateheader.html', 'w');
+    $listtemplateheader = fopen($exportdir . '/listtemplateheader.html', 'w');
     fwrite($listtemplateheader, $data->listtemplateheader);
     fclose($listtemplateheader);
 
-    $listtemplate = fopen($tempfolder . '/listtemplate.html', 'w');
+    $listtemplate = fopen($exportdir . '/listtemplate.html', 'w');
     fwrite($listtemplate, $data->listtemplate);
     fclose($listtemplate);
 
-    $listtemplatefooter = fopen($tempfolder . '/listtemplatefooter.html', 'w');
+    $listtemplatefooter = fopen($exportdir . '/listtemplatefooter.html', 'w');
     fwrite($listtemplatefooter, $data->listtemplatefooter);
     fclose($listtemplatefooter);
 
-    $addtemplate = fopen($tempfolder . '/addtemplate.html', 'w');
+    $addtemplate = fopen($exportdir . '/addtemplate.html', 'w');
     fwrite($addtemplate, $data->addtemplate);
     fclose($addtemplate);
 
-    $rsstemplate = fopen($tempfolder . '/rsstemplate.html', 'w');
+    $rsstemplate = fopen($exportdir . '/rsstemplate.html', 'w');
     fwrite($rsstemplate, $data->rsstemplate);
     fclose($rsstemplate);
 
-    $rsstitletemplate = fopen($tempfolder . '/rsstitletemplate.html', 'w');
+    $rsstitletemplate = fopen($exportdir . '/rsstitletemplate.html', 'w');
     fwrite($rsstitletemplate, $data->rsstitletemplate);
     fclose($rsstitletemplate);
 
-    $csstemplate = fopen($tempfolder . '/csstemplate.css', 'w');
+    $csstemplate = fopen($exportdir . '/csstemplate.css', 'w');
     fwrite($csstemplate, $data->csstemplate);
     fclose($csstemplate);
 
-    $jstemplate = fopen($tempfolder . '/jstemplate.js', 'w');
+    $jstemplate = fopen($exportdir . '/jstemplate.js', 'w');
     fwrite($jstemplate, $data->jstemplate);
     fclose($jstemplate);
 
-    $asearchtemplate = fopen($tempfolder . '/asearchtemplate.html', 'w');
+    $asearchtemplate = fopen($exportdir . '/asearchtemplate.html', 'w');
     fwrite($asearchtemplate, $data->asearchtemplate);
     fclose($asearchtemplate);
 
     // Check if all files have been generated
-    if (! is_directory_a_preset($tempfolder)) {
+    if (! is_directory_a_preset($exportdir)) {
         error('Not all files generated!');
         // should be migrated to print_error()
     }
@@ -496,10 +490,10 @@ function data_presets_export($course, $cm, $data) {
     );
 
     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);
     $status = zip_files($filelist, $exportfile);
     // ToDo: status check