From 585b64a6079a6d63a19ae9537da8b2085966a63d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mudr=C3=A1k?= Date: Fri, 22 Mar 2013 17:42:31 +0100 Subject: [PATCH] MDL-38509 Save uploaded ZIP into a temporary location and redirect to validator --- admin/tool/installaddon/classes/installer.php | 18 ++++++++++++++++++ admin/tool/installaddon/index.php | 13 ++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/admin/tool/installaddon/classes/installer.php b/admin/tool/installaddon/classes/installer.php index 60397cacf9b..b7f18bc0a69 100644 --- a/admin/tool/installaddon/classes/installer.php +++ b/admin/tool/installaddon/classes/installer.php @@ -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 * diff --git a/admin/tool/installaddon/index.php b/admin/tool/installaddon/index.php index 062e05cbc69..8ca05d187f0 100644 --- a/admin/tool/installaddon/index.php +++ b/admin/tool/installaddon/index.php @@ -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');