MDL-38509 Save uploaded ZIP into a temporary location and redirect to validator
authorDavid Mudrák <david@moodle.com>
Fri, 22 Mar 2013 16:42:31 +0000 (17:42 +0100)
committerDavid Mudrák <david@moodle.com>
Thu, 28 Mar 2013 10:54:06 +0000 (11:54 +0100)
admin/tool/installaddon/classes/installer.php
admin/tool/installaddon/index.php

index 60397ca..b7f18bc 100644 (file)
@@ -95,6 +95,24 @@ class tool_installaddon_installer {
         return $this->installfromzipform;
     }
 
+    /**
+     * Saves the ZIP file from the {@link tool_installaddon_installfromzip} form
+     *
+     * The file is saved into the given temporary location for inspection and eventual
+     * deployment. The form is expected to be submitted and validated.
+     *
+     * @param tool_installaddon_installfromzip $form
+     * @param string $targetdir full path to the directory where the ZIP should be stored to
+     * @return string filename of the saved file relative to the given target
+     */
+    public function save_installfromzip_file(tool_installaddon_installfromzip $form, $targetdir) {
+
+        $filename = clean_param($form->get_new_filename('zipfile'), PARAM_FILE);
+        $form->save_file('zipfile', $targetdir.'/'.$filename);
+
+        return $filename;
+    }
+
     /**
      * Returns localised list of available plugin types
      *
index 062e05c..8ca05d1 100644 (file)
@@ -41,7 +41,18 @@ if ($form->is_cancelled()) {
     redirect($PAGE->url);
 
 } else if ($data = $form->get_data()) {
-    // todo $installer->process_installfromzip_form($data);
+    // Save the ZIP file into a temporary location.
+    $jobid = md5(rand().uniqid('', true));
+    $sourcedir = make_temp_directory('tool_installaddon/'.$jobid.'/source');
+    $zipfilename = $installer->save_installfromzip_file($form, $sourcedir);
+    // Redirect to the validation page.
+    $nexturl = new moodle_url('/admin/tool/installaddon/validate.php', array(
+        'sesskey' => sesskey(),
+        'jobid' => $jobid,
+        'zip' => $zipfilename,
+        'type' => $data->plugintype,
+        'rootdir' => $data->rootdir));
+    redirect($nexturl);
 }
 
 $output = $PAGE->get_renderer('tool_installaddon');