Permalink
Browse files

MDL-38509 Add hook for the installaddonrequest into admin/index.php

If the user selects a plugin in Moodle plugins directory to be installed
into their site, Moodle plugins directory will redirect them into their
site's admin/index.php script, providing the installaddonrequest
parameter.

This patch makes sure that only if the user is logged-in as the admin
and the site is fully installed and up-to-date, the add-on installation
request will be dispatched to the tool_installaddon for actual
processing.

We need to store the installaddonrequest value in the $PAGE's URL so
that is is stored in $SESSION->wantsurl in case the user needs to log in
at their site. Thanks to this, the request is dispatched after the user
logs in.
  • Loading branch information...
1 parent af96f12 commit 0a6a344d29c333fb9e498afdc173e112dd14c1f1 @mudrd8mz mudrd8mz committed Mar 29, 2013
Showing with 20 additions and 1 deletion.
  1. +20 −1 admin/index.php
View
@@ -59,10 +59,18 @@
$showallplugins = optional_param('showallplugins', 0, PARAM_BOOL);
$agreelicense = optional_param('agreelicense', 0, PARAM_BOOL);
$fetchupdates = optional_param('fetchupdates', 0, PARAM_BOOL);
+$newaddonreq = optional_param('installaddonrequest', null, PARAM_RAW);
// Check some PHP server settings
-$PAGE->set_url('/admin/index.php');
+if (is_null($newaddonreq)) {
+ $PAGE->set_url('/admin/index.php');
+} else {
+ // We need to set the eventual add-on installation request in the $PAGE's URL
+ // so that it is stored in $SESSION->wantsurl and the admin is redirected
+ // correctly once they are logged-in.
+ $PAGE->set_url('/admin/index.php', array('installaddonrequest' => $newaddonreq));
+}
$PAGE->set_pagelayout('admin'); // Set a default pagelayout
$documentationlink = '<a href="http://docs.moodle.org/en/Installation">Installation docs</a>';
@@ -423,6 +431,17 @@
set_config('registered', time());
}
+// Check if we are returning from an add-on installation request at moodle.org/plugins
+if (!is_null($newaddonreq)) {
+ if (!empty($CFG->disableonclickaddoninstall)) {
+ // The feature is disabled in config.php, ignore the request.
+ } else {
+ redirect(new moodle_url('/admin/tool/installaddon/index.php', array(
+ 'installaddonrequest' => $newaddonreq,
+ 'confirm' => 0)));
+ }
+}
+
// setup critical warnings before printing admin tree block
$insecuredataroot = is_dataroot_insecure(true);
$SESSION->admin_critical_warning = ($insecuredataroot==INSECURE_DATAROOT_ERROR);

0 comments on commit 0a6a344

Please sign in to comment.