source: moodle/trunk/fuentes/admin/tool/installaddon/validate.php @ 136

Last change on this file since 136 was 136, checked in by mabarracus, 4 years ago

Ported code to xenial

File size: 2.8 KB
Line 
1<?php
2
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
17
18/**
19 * The ZIP package validation.
20 *
21 * @package     tool_installaddon
22 * @copyright   2013 David Mudrak <david@moodle.com>
23 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25
26require(dirname(__FILE__) . '/../../../config.php');
27require_once($CFG->libdir.'/adminlib.php');
28require_once($CFG->libdir.'/filelib.php');
29
30navigation_node::override_active_url(new moodle_url('/admin/tool/installaddon/index.php'));
31admin_externalpage_setup('tool_installaddon_validate');
32
33if (!empty($CFG->disableonclickaddoninstall)) {
34    notice(get_string('featuredisabled', 'tool_installaddon'));
35}
36
37require_sesskey();
38
39$jobid = required_param('jobid', PARAM_ALPHANUM);
40$zipfilename = required_param('zip', PARAM_FILE);
41$plugintype = required_param('type', PARAM_ALPHANUMEXT);
42$rootdir = optional_param('rootdir', '', PARAM_PLUGIN);
43
44$zipfilepath = $CFG->tempdir.'/tool_installaddon/'.$jobid.'/source/'.$zipfilename;
45if (!file_exists($zipfilepath)) {
46    redirect(new moodle_url('/admin/tool/installaddon/index.php'),
47        get_string('invaliddata', 'core_error'));
48}
49
50$installer = tool_installaddon_installer::instance();
51
52// Extract the ZIP contents.
53fulldelete($CFG->tempdir.'/tool_installaddon/'.$jobid.'/contents');
54$zipcontentpath = make_temp_directory('tool_installaddon/'.$jobid.'/contents');
55$zipcontentfiles = $installer->extract_installfromzip_file($zipfilepath, $zipcontentpath, $rootdir);
56
57// Validate the contents of the plugin ZIP file.
58$validator = tool_installaddon_validator::instance($zipcontentpath, $zipcontentfiles);
59$validator->assert_plugin_type($plugintype);
60$validator->assert_moodle_version($CFG->version);
61$result = $validator->execute();
62
63if ($result) {
64    $validator->set_continue_url(new moodle_url('/admin/tool/installaddon/deploy.php', array(
65        'sesskey' => sesskey(),
66        'jobid' => $jobid,
67        'type' => $plugintype,
68        'name' => $validator->get_rootdir())));
69
70} else {
71    fulldelete($CFG->tempdir.'/tool_installaddon/'.$jobid);
72}
73
74// Display the validation results.
75$output = $PAGE->get_renderer('tool_installaddon');
76$output->set_installer_instance($installer);
77$output->set_validator_instance($validator);
78echo $output->validation_page();
Note: See TracBrowser for help on using the repository browser.