Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
 * UI for general plugins management
20
 *
21
 * @package    core
22
 * @subpackage admin
23
 * @copyright  2011 David Mudrak <david@moodle.com>
24
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
 */
26
 
27
require_once(__DIR__ . '/../config.php');
28
require_once($CFG->libdir . '/adminlib.php');
29
require_once($CFG->libdir . '/filelib.php');
30
 
31
$fetchupdates = optional_param('fetchupdates', false, PARAM_BOOL); // Check for available plugins updates.
32
$updatesonly = optional_param('updatesonly', false, PARAM_BOOL); // Show updateable plugins only.
33
$contribonly = optional_param('contribonly', false, PARAM_BOOL); // Show additional plugins only.
34
$uninstall = optional_param('uninstall', '', PARAM_COMPONENT); // Uninstall the plugin.
35
$delete = optional_param('delete', '', PARAM_COMPONENT); // Delete the plugin folder after it is uninstalled.
36
$confirmed = optional_param('confirm', false, PARAM_BOOL); // Confirm the uninstall/delete action.
37
$return = optional_param('return', 'overview', PARAM_ALPHA); // Where to return after uninstall.
38
$installupdate = optional_param('installupdate', null, PARAM_COMPONENT); // Install given available update.
39
$installupdateversion = optional_param('installupdateversion', null, PARAM_INT); // Version of the available update to install.
40
$installupdatex = optional_param('installupdatex', false, PARAM_BOOL); // Install all available plugin updates.
41
$confirminstallupdate = optional_param('confirminstallupdate', false, PARAM_BOOL); // Available update(s) install confirmed?
42
 
43
// NOTE: do not use admin_externalpage_setup() here because it loads
44
//       full admin tree which is not possible during uninstallation.
45
 
46
require_admin();
47
$syscontext = context_system::instance();
48
 
49
// URL params we want to maintain on redirects.
50
$pageparams = array('updatesonly' => $updatesonly, 'contribonly' => $contribonly);
51
$pageurl = new moodle_url('/admin/plugins.php', $pageparams);
52
 
53
$pluginman = core_plugin_manager::instance();
54
 
55
$PAGE->set_primary_active_tab('siteadminnode');
56
 
57
if ($uninstall) {
58
 
59
    if (!$confirmed) {
60
        admin_externalpage_setup('pluginsoverview', '', $pageparams);
61
    } else {
62
        $PAGE->set_url($pageurl);
63
        $PAGE->set_context($syscontext);
64
        $PAGE->set_pagelayout('maintenance');
65
        $PAGE->set_popup_notification_allowed(false);
66
    }
67
 
68
    /** @var core_admin_renderer $output */
69
    $output = $PAGE->get_renderer('core', 'admin');
70
 
71
    $pluginfo = $pluginman->get_plugin_info($uninstall);
72
 
73
    // Make sure we know the plugin.
74
    if (is_null($pluginfo)) {
75
        throw new moodle_exception('err_uninstalling_unknown_plugin', 'core_plugin', '', array('plugin' => $uninstall),
76
            'core_plugin_manager::get_plugin_info() returned null for the plugin to be uninstalled');
77
    }
78
 
79
    $pluginname = $pluginman->plugin_name($pluginfo->component);
80
    $PAGE->set_title($pluginname);
81
    $PAGE->navbar->add(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
82
 
83
    if (!$pluginman->can_uninstall_plugin($pluginfo->component)) {
84
        throw new moodle_exception('err_cannot_uninstall_plugin', 'core_plugin', '',
85
            array('plugin' => $pluginfo->component),
86
            'core_plugin_manager::can_uninstall_plugin() returned false');
87
    }
88
 
89
    if (!$confirmed) {
90
        $continueurl = new moodle_url($PAGE->url, array('uninstall' => $pluginfo->component, 'sesskey' => sesskey(), 'confirm' => 1, 'return'=>$return));
91
        $cancelurl = $pluginfo->get_return_url_after_uninstall($return);
92
        echo $output->plugin_uninstall_confirm_page($pluginman, $pluginfo, $continueurl, $cancelurl);
93
        exit();
94
 
95
    } else {
96
        require_sesskey();
97
        $SESSION->pluginuninstallreturn = $pluginfo->get_return_url_after_uninstall($return);
98
        $progress = new progress_trace_buffer(new text_progress_trace(), false);
99
        $pluginman->uninstall_plugin($pluginfo->component, $progress);
100
        $progress->finished();
101
 
102
        if ($pluginman->is_plugin_folder_removable($pluginfo->component)) {
103
            $continueurl = new moodle_url($PAGE->url, array('delete' => $pluginfo->component, 'sesskey' => sesskey(), 'confirm' => 1));
104
            echo $output->plugin_uninstall_results_removable_page($pluginman, $pluginfo, $progress, $continueurl);
105
            // Reset op code caches.
106
            if (function_exists('opcache_reset')) {
107
                opcache_reset();
108
            }
109
            exit();
110
 
111
        } else {
112
            echo $output->plugin_uninstall_results_page($pluginman, $pluginfo, $progress);
113
            // Reset op code caches.
114
            if (function_exists('opcache_reset')) {
115
                opcache_reset();
116
            }
117
            exit();
118
        }
119
    }
120
}
121
 
122
if ($delete and $confirmed) {
123
    require_sesskey();
124
 
125
    $PAGE->set_url($pageurl);
126
    $PAGE->set_context($syscontext);
127
    $PAGE->set_pagelayout('maintenance');
128
    $PAGE->set_popup_notification_allowed(false);
129
 
130
    /** @var core_admin_renderer $output */
131
    $output = $PAGE->get_renderer('core', 'admin');
132
 
133
    $pluginfo = $pluginman->get_plugin_info($delete);
134
 
135
    // Make sure we know the plugin.
136
    if (is_null($pluginfo)) {
137
        throw new moodle_exception('err_removing_unknown_plugin', 'core_plugin', '', array('plugin' => $delete),
138
            'core_plugin_manager::get_plugin_info() returned null for the plugin to be deleted');
139
    }
140
 
141
    $pluginname = $pluginman->plugin_name($pluginfo->component);
142
    $PAGE->set_title($pluginname);
143
    $PAGE->navbar->add(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
144
 
145
    // Make sure it is not installed.
146
    if (!is_null($pluginfo->versiondb)) {
147
        throw new moodle_exception('err_removing_installed_plugin', 'core_plugin', '',
148
            array('plugin' => $pluginfo->component, 'versiondb' => $pluginfo->versiondb),
149
            'core_plugin_manager::get_plugin_info() returned not-null versiondb for the plugin to be deleted');
150
    }
151
 
152
    // Make sure the folder is within Moodle installation tree.
153
    if (strpos($pluginfo->rootdir, $CFG->dirroot) !== 0) {
154
        throw new moodle_exception('err_unexpected_plugin_rootdir', 'core_plugin', '',
155
            array('plugin' => $pluginfo->component, 'rootdir' => $pluginfo->rootdir, 'dirroot' => $CFG->dirroot),
156
            'plugin root folder not in the moodle dirroot');
157
    }
158
 
159
    // So long, and thanks for all the bugs.
160
    $pluginman->remove_plugin_folder($pluginfo);
161
 
162
    // We need to execute upgrade to make sure everything including caches is up to date.
163
    redirect(new moodle_url('/admin/index.php'));
164
}
165
 
166
// Install all avilable updates.
167
if ($installupdatex) {
168
    require_once($CFG->libdir.'/upgradelib.php');
169
    require_sesskey();
170
 
171
    $PAGE->set_url($pageurl);
172
    $PAGE->set_context($syscontext);
173
    $PAGE->set_pagelayout('maintenance');
174
    $PAGE->set_popup_notification_allowed(false);
175
 
176
    $installable = $pluginman->filter_installable($pluginman->available_updates());
177
    upgrade_install_plugins($installable, $confirminstallupdate,
178
        get_string('updateavailableinstallallhead', 'core_admin'),
179
        new moodle_url($PAGE->url, array('installupdatex' => 1, 'confirminstallupdate' => 1))
180
    );
181
}
182
 
183
// Install single available update.
184
if ($installupdate and $installupdateversion) {
185
    require_once($CFG->libdir.'/upgradelib.php');
186
    require_sesskey();
187
 
188
    $PAGE->set_url($pageurl);
189
    $PAGE->set_context($syscontext);
190
    $PAGE->set_pagelayout('maintenance');
191
    $PAGE->set_popup_notification_allowed(false);
192
 
193
    if ($pluginman->is_remote_plugin_installable($installupdate, $installupdateversion)) {
194
        $installable = array($pluginman->get_remote_plugin_info($installupdate, $installupdateversion, true));
195
        upgrade_install_plugins($installable, $confirminstallupdate,
196
            get_string('updateavailableinstallallhead', 'core_admin'),
197
            new moodle_url($PAGE->url, array('installupdate' => $installupdate,
198
                'installupdateversion' => $installupdateversion, 'confirminstallupdate' => 1)
199
            )
200
        );
201
    }
202
}
203
 
204
admin_externalpage_setup('pluginsoverview', '', $pageparams);
205
 
206
/** @var core_admin_renderer $output */
207
$output = $PAGE->get_renderer('core', 'admin');
208
 
209
$checker = \core\update\checker::instance();
210
 
211
if ($fetchupdates) {
212
    require_sesskey();
213
    $checker->fetch();
214
    redirect($PAGE->url);
215
}
216
 
217
echo $output->plugin_management_page($pluginman, $checker, $pageparams);