Skip to content

Commit

Permalink
MDL-35238 Add a new admin setting to enable updates deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
mudrd8mz committed Nov 8, 2012
1 parent 9dcb528 commit 02fd7f4
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
2 changes: 2 additions & 0 deletions admin/settings/server.php
Expand Up @@ -228,6 +228,8 @@
$temp = new admin_settingpage('updatenotifications', new lang_string('updatenotifications', 'core_admin'));
$temp->add(new admin_setting_configcheckbox('updateautocheck', new lang_string('updateautocheck', 'core_admin'),
new lang_string('updateautocheck_desc', 'core_admin'), 1));
$temp->add(new admin_setting_updateautodeploy('updateautodeploy', new lang_string('updateautodeploy', 'core_admin'),
new lang_string('updateautodeploy_desc', 'core_admin'), 0));
$temp->add(new admin_setting_configselect('updateminmaturity', new lang_string('updateminmaturity', 'core_admin'),
new lang_string('updateminmaturity_desc', 'core_admin'), MATURITY_STABLE,
array(
Expand Down
3 changes: 3 additions & 0 deletions lang/en/admin.php
Expand Up @@ -1011,6 +1011,9 @@
$string['updatenotificationsubject'] = 'Moodle updates are available ({$a->siteurl})';
$string['updateautocheck'] = 'Automatically check for available updates';
$string['updateautocheck_desc'] = 'If enabled, your site will automatically check for available updates for both Moodle code and all additional plugins. If there is a new update available, a notification will be sent to site admins.';
$string['updateautodeploy'] = 'Enable updates deployment';
$string['updateautodeploy_desc'] = 'If enabled, you will be able to download and install available updates directly from Moodle administration pages. Note that your web server process has to have write access into folders with Moodle installation to make this work. That can be seen as a potential security risk.';
$string['updateautodeploy_unablewriteplugins'] = 'Can\'t enable the feature - unable to write into plugin locations!';
$string['updateminmaturity'] = 'Required code maturity';
$string['updateminmaturity_desc'] = 'Notify about available updates only if the available code has the selected maturity level at least. Updates for plugins that do not declare their code maturity level are always reported regardless this setting.';
$string['updatenotifybuilds'] = 'Notify about new builds';
Expand Down
74 changes: 74 additions & 0 deletions lib/adminlib.php
Expand Up @@ -8052,3 +8052,77 @@ public function load_choices() {
return true;
}
}


/**
* Checkbox for the updateautodeploy setting
*
* This class implements the extra check to make sure that the web server
* process user has write access to the $CFG->dirroot.
*
* @copyright 2012 David Mudrak <david@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_updateautodeploy extends admin_setting_configcheckbox {

/**
* Sets the value for the setting
*
* When the feature is just about to be enabled, proceed some extra checks
* prior to setting the value.
*
* @param string $data the checkbox value
* @return string empty string or error
*/
public function write_setting($data) {

// Are we just going to activate the feature?
$currentlyenabled = $this->config_read('updateautodeploy');
if ((string)$data === $this->yes and empty($currentlyenabled)) {
if (!$this->plugin_locations_writeable()) {
return get_string('updateautodeploy_unablewriteplugins', 'core_admin');
}
// TODO MDL-35239 check if the whole dirroot is writeable
}

// Let the parent class actually save the value.
return parent::write_setting($data);
}

/**
* Check if it is possible to write into plugin locations
*
* @return bool
*/
private function plugin_locations_writeable() {
global $CFG;
require_once($CFG->libdir.'/pluginlib.php');

// Check that the web server process is able to deploy new plugins of all types
$plugintypes = get_plugin_types(true);
foreach ($plugintypes as $plugintype => $plugintyperoot) {
if (!is_writeable($plugintyperoot)) {
debugging('Plugin type location not writeable: '.$plugintyperoot, DEBUG_ALL);
return false;
}
}

// Check that the web server process is able to modify contributed plugins
$pluginman = plugin_manager::instance();
$plugininfo = $pluginman->get_plugins();
foreach ($plugininfo as $plugintype => $plugininstances) {
foreach ($plugininstances as $pluginname => $plugininfo) {
if ($plugininfo->is_standard()) {
// No need to check for these now until MDL-35239 is implemented
continue;
}
if (!is_writeable($plugininfo->rootdir)) {
debugging('Contributed plugin directory not writeable: '.$plugininfo->rootdir);
return false;
}
}
}

return true;
}
}

0 comments on commit 02fd7f4

Please sign in to comment.