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

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

Ported code to xenial

File size: 2.9 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 * Deploy the validated contents of the ZIP package to the $CFG->dirroot
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.'/filelib.php');
28
29require_login();
30require_capability('moodle/site:config', context_system::instance());
31
32if (!empty($CFG->disableonclickaddoninstall)) {
33    notice(get_string('featuredisabled', 'tool_installaddon'));
34}
35
36require_sesskey();
37
38$jobid = required_param('jobid', PARAM_ALPHANUM);
39$plugintype = required_param('type', PARAM_ALPHANUMEXT);
40$pluginname = required_param('name', PARAM_PLUGIN);
41
42$zipcontentpath = $CFG->tempdir.'/tool_installaddon/'.$jobid.'/contents';
43
44if (!is_dir($zipcontentpath)) {
45    debugging('Invalid location of the extracted ZIP package: '.s($zipcontentpath), DEBUG_DEVELOPER);
46    redirect(new moodle_url('/admin/tool/installaddon/index.php'),
47        get_string('invaliddata', 'core_error'));
48}
49
50if (!is_dir($zipcontentpath.'/'.$pluginname)) {
51    debugging('Invalid location of the plugin root directory: '.$zipcontentpath.'/'.$pluginname, DEBUG_DEVELOPER);
52    redirect(new moodle_url('/admin/tool/installaddon/index.php'),
53        get_string('invaliddata', 'core_error'));
54}
55
56$installer = tool_installaddon_installer::instance();
57
58if (!$installer->is_plugintype_writable($plugintype)) {
59    debugging('Plugin type location not writable', DEBUG_DEVELOPER);
60    redirect(new moodle_url('/admin/tool/installaddon/index.php'),
61        get_string('invaliddata', 'core_error'));
62}
63
64$plugintypepath = $installer->get_plugintype_root($plugintype);
65
66if (file_exists($plugintypepath.'/'.$pluginname)) {
67    debugging('Target location already exists', DEBUG_DEVELOPER);
68    redirect(new moodle_url('/admin/tool/installaddon/index.php'),
69        get_string('invaliddata', 'core_error'));
70}
71
72// Copy permissions form the plugin type directory.
73$dirpermissions = fileperms($plugintypepath);
74$filepermissions = ($dirpermissions & 0666); // Strip execute flags.
75
76$installer->move_directory($zipcontentpath.'/'.$pluginname, $plugintypepath.'/'.$pluginname, $dirpermissions, $filepermissions);
77fulldelete($CFG->tempdir.'/tool_installaddon/'.$jobid);
78redirect(new moodle_url('/admin'));
Note: See TracBrowser for help on using the repository browser.