Skip to content
Browse files

MDL-38509 Save uploaded ZIP into a temporary location and redirect to…

… validator
  • Loading branch information...
1 parent 30bec5b commit 585b64a6079a6d63a19ae9537da8b2085966a63d @mudrd8mz mudrd8mz committed Mar 22, 2013
Showing with 30 additions and 1 deletion.
  1. +18 −0 admin/tool/installaddon/classes/installer.php
  2. +12 −1 admin/tool/installaddon/index.php
View
18 admin/tool/installaddon/classes/installer.php
@@ -96,6 +96,24 @@ public function get_installfromzip_form() {
}
/**
+ * 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
*
* @return array (string)plugintype => (string)plugin name
View
13 admin/tool/installaddon/index.php
@@ -41,7 +41,18 @@
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');

0 comments on commit 585b64a

Please sign in to comment.
Something went wrong with that request. Please try again.