Proyectos de Subversion Moodle

Rev

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