Skip to content

Commit

Permalink
MDL-41437 rework plugin_manager caching and version info in blocks an…
Browse files Browse the repository at this point in the history
…d modules

This patch includes:

* version column removed from modules table, now using standard config, this allows decimal version for modules
* version column removed from block table, now using standard config, this allows decimal version for blocks
* module version.php can safely use $plugins instead of module
* new plugin_manager bulk caching, this should help with MUC performance when logged in as admin
* all missing plugins are now in plugin overview (previously only blocks and modules)
* simplified code and improved coding style
* reworked plugin_manager unit tests - now using real plugins instead of mocks
* unit tests now fail if any plugin does not contain proper version.php file
* allow uninstall of deleted filters
  • Loading branch information
skodak committed Sep 22, 2013
1 parent 81881cb commit bde002b
Show file tree
Hide file tree
Showing 50 changed files with 1,590 additions and 1,929 deletions.
3 changes: 3 additions & 0 deletions admin/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
require_once('../config.php');
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir.'/tablelib.php');
require_once($CFG->libdir.'/pluginlib.php');

require_login();
require_capability('moodle/site:config', context_system::instance());
Expand Down Expand Up @@ -52,6 +53,7 @@
set_config('registerauth', '');
}
session_gc(); // remove stale sessions
plugin_manager::reset_caches();
break;

case 'enable':
Expand All @@ -62,6 +64,7 @@
set_config('auth', implode(',', $authsenabled));
}
session_gc(); // remove stale sessions
plugin_manager::reset_caches();
break;

case 'down':
Expand Down
76 changes: 0 additions & 76 deletions admin/block.php

This file was deleted.

15 changes: 8 additions & 7 deletions admin/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require_once('../config.php');
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir.'/tablelib.php');
require_once($CFG->libdir.'/pluginlib.php');

admin_externalpage_setup('manageblocks');

Expand All @@ -29,16 +30,14 @@
$strprotect = get_string('blockprotect', 'admin');
$strunprotect = get_string('blockunprotect', 'admin');

// Purge all caches related to blocks administration.
cache::make('core', 'plugininfo_block')->purge();

/// If data submitted, then process and store.

if (!empty($hide) && confirm_sesskey()) {
if (!$block = $DB->get_record('block', array('id'=>$hide))) {
print_error('blockdoesnotexist', 'error');
}
$DB->set_field('block', 'visible', '0', array('id'=>$block->id)); // Hide block
plugin_manager::reset_caches();
admin_get_root(true, false); // settings not required - only pages
}

Expand All @@ -47,6 +46,7 @@
print_error('blockdoesnotexist', 'error');
}
$DB->set_field('block', 'visible', '1', array('id'=>$block->id)); // Show block
plugin_manager::reset_caches();
admin_get_root(true, false); // settings not required - only pages
}

Expand Down Expand Up @@ -120,12 +120,13 @@
foreach ($blocknames as $blockid=>$strblockname) {
$block = $blocks[$blockid];
$blockname = $block->name;
$dbversion = get_config('block_'.$block->name, 'version');

if (!file_exists("$CFG->dirroot/blocks/$blockname/block_$blockname.php")) {
$blockobject = false;
$strblockname = '<span class="notifyproblem">'.$strblockname.' ('.get_string('missingfromdisk').')</span>';
$plugin = new stdClass();
$plugin->version = $block->version;
$plugin->version = $dbversion;

} else {
$plugin = new stdClass();
Expand Down Expand Up @@ -186,10 +187,10 @@
$class = ' class="dimmed_text"'; // Leading space required!
}

if ($block->version == $plugin->version) {
$version = $block->version;
if ($dbversion == $plugin->version) {
$version = $dbversion;
} else {
$version = "$block->version ($plugin->version)";
$version = "$dbversion ($plugin->version)";
}

if (!$blockobject) {
Expand Down
2 changes: 2 additions & 0 deletions admin/courseformats.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@
print_error('cannotdisableformat', 'error', $return);
}
set_config('disabled', 1, 'format_'. $formatname);
plugin_manager::reset_caches();
}
break;
case 'enable':
if (!$formatplugins[$formatname]->is_enabled()) {
unset_config('disabled', 'format_'. $formatname);
plugin_manager::reset_caches();
}
break;
case 'up':
Expand Down
2 changes: 2 additions & 0 deletions admin/editors.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require_once('../config.php');
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir.'/tablelib.php');
require_once($CFG->libdir.'/pluginlib.php');

$action = required_param('action', PARAM_ALPHANUMEXT);
$editor = required_param('editor', PARAM_PLUGIN);
Expand Down Expand Up @@ -93,6 +94,7 @@
}

set_config('texteditors', implode(',', $active_editors));
plugin_manager::reset_caches();

if ($return) {
redirect ($returnurl);
Expand Down
3 changes: 3 additions & 0 deletions admin/enrol.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

require_once('../config.php');
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir.'/pluginlib.php');

$action = required_param('action', PARAM_ALPHANUMEXT);
$enrol = required_param('enrol', PARAM_PLUGIN);
Expand All @@ -50,6 +51,7 @@
case 'disable':
unset($enabled[$enrol]);
set_config('enrol_plugins_enabled', implode(',', array_keys($enabled)));
plugin_manager::reset_caches();
$syscontext->mark_dirty(); // resets all enrol caches
break;

Expand All @@ -60,6 +62,7 @@
$enabled = array_keys($enabled);
$enabled[] = $enrol;
set_config('enrol_plugins_enabled', implode(',', $enabled));
plugin_manager::reset_caches();
$syscontext->mark_dirty(); // resets all enrol caches
break;

Expand Down
7 changes: 3 additions & 4 deletions admin/filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

require_once(dirname(__FILE__) . '/../config.php');
require_once($CFG->libdir . '/adminlib.php');
require_once($CFG->libdir . '/pluginlib.php');

$action = optional_param('action', '', PARAM_ALPHANUMEXT);
$filterpath = optional_param('filterpath', '', PARAM_SAFEDIR);
Expand All @@ -44,9 +45,6 @@
$returnurl = "$CFG->wwwroot/$CFG->admin/filters.php";
admin_externalpage_setup('managefilters');

// Purge all caches related to filter administration.
cache::make('core', 'plugininfo_filter')->purge();

$filters = filter_get_global_states();

// In case any new filters have been installed, but not put in the table yet.
Expand All @@ -59,7 +57,7 @@
/// Process actions ============================================================

if ($action) {
if (!isset($filters[$filterpath]) && !isset($newfilters[$filterpath])) {
if ($action !== 'delete' and !isset($filters[$filterpath]) and !isset($newfilters[$filterpath])) {
throw new moodle_exception('filternotinstalled', 'error', $returnurl, $filterpath);
}

Expand Down Expand Up @@ -138,6 +136,7 @@

// Reset caches and return
if ($action) {
plugin_manager::reset_caches();
reset_text_filters_cache();
redirect($returnurl);
}
Expand Down
1 change: 1 addition & 0 deletions admin/localplugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
require_once(dirname(dirname(__FILE__)) . '/config.php');
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir.'/tablelib.php');
require_once($CFG->libdir.'/pluginlib.php');

admin_externalpage_setup('managelocalplugins');

Expand Down
3 changes: 3 additions & 0 deletions admin/message.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
require_once(dirname(__FILE__) . '/../config.php');
require_once($CFG->dirroot . '/message/lib.php');
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir.'/pluginlib.php');

// This is an admin page
admin_externalpage_setup('managemessageoutputs');
Expand All @@ -44,13 +45,15 @@
print_error('outputdoesnotexist', 'message');
}
$DB->set_field('message_processors', 'enabled', '0', array('id'=>$processor->id)); // Disable output
plugin_manager::reset_caches();
}

if (!empty($enable) && confirm_sesskey()) {
if (!$processor = $DB->get_record('message_processors', array('id'=>$enable))) {
print_error('outputdoesnotexist', 'message');
}
$DB->set_field('message_processors', 'enabled', '1', array('id'=>$processor->id)); // Enable output
plugin_manager::reset_caches();
}

if (!empty($uninstall) && confirm_sesskey()) {
Expand Down
10 changes: 5 additions & 5 deletions admin/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require_once('../course/lib.php');
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir.'/tablelib.php');
require_once($CFG->libdir.'/pluginlib.php');

// defines
define('MODULE_TABLE','module_administration_table');
Expand All @@ -27,9 +28,6 @@
$stractivitymodule = get_string("activitymodule");
$strshowmodulecourse = get_string('showmodulecourse');

// Purge all caches related to activity modules administration.
cache::make('core', 'plugininfo_mod')->purge();

/// If data submitted, then process and store.

if (!empty($hide) and confirm_sesskey()) {
Expand All @@ -50,6 +48,7 @@
FROM {course_modules}
WHERE visibleold=1 AND module=?)",
array($module->id));
plugin_manager::reset_caches();
admin_get_root(true, false); // settings not required - only pages
}

Expand All @@ -66,6 +65,7 @@
FROM {course_modules}
WHERE visible=1 AND module=?)",
array($module->id));
plugin_manager::reset_caches();
admin_get_root(true, false); // settings not required - only pages
}

Expand Down Expand Up @@ -143,12 +143,12 @@
$visible = "";
$class = "";
}

$version = get_config('mod_'.$module->name, 'version');

$table->add_data(array(
'<span'.$class.'>'.$strmodulename.'</span>',
$countlink,
'<span'.$class.'>'.$module->version.'</span>',
'<span'.$class.'>'.$version.'</span>',
$visible,
$uninstall,
$settings
Expand Down
2 changes: 2 additions & 0 deletions admin/plagiarism.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
require_once(dirname(dirname(__FILE__)) . '/config.php');
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir.'/tablelib.php');
require_once($CFG->libdir.'/pluginlib.php');


admin_externalpage_setup('manageplagiarismplugins');

Expand Down
6 changes: 3 additions & 3 deletions admin/portfolio.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require_once($CFG->libdir . '/portfoliolib.php');
require_once($CFG->libdir . '/portfolio/forms.php');
require_once($CFG->libdir . '/adminlib.php');
require_once($CFG->libdir . '/pluginlib.php');

$portfolio = optional_param('pf', '', PARAM_ALPHANUMEXT);
$action = optional_param('action', '', PARAM_ALPHA);
Expand Down Expand Up @@ -43,9 +44,6 @@

$return = true; // direct back to the main page

// Purge all caches related to portfolio administration.
cache::make('core', 'plugininfo_portfolio')->purge();

/**
* Helper function that generates a moodle_url object
* relevant to the portfolio
Expand Down Expand Up @@ -91,6 +89,7 @@ function portfolio_action_url($portfolio) {
} else {
portfolio_static_function($plugin, 'create_instance', $plugin, $fromform->name, $fromform);
}
plugin_manager::reset_caches();
$savedstr = get_string('instancesaved', 'portfolio');
redirect($baseurl, $savedstr, 1);
exit;
Expand Down Expand Up @@ -119,6 +118,7 @@ function portfolio_action_url($portfolio) {

$instance->set('visible', $visible);
$instance->save();
plugin_manager::reset_caches();
$return = true;
} else if ($action == 'delete') {
$instance = portfolio_instance($portfolio);
Expand Down
2 changes: 2 additions & 0 deletions admin/qbehaviours.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
$disabledbehaviours[] = $disable;
set_config('disabledbehaviours', implode(',', $disabledbehaviours), 'question');
}
plugin_manager::reset_caches();
redirect($thispageurl);
}

Expand All @@ -109,6 +110,7 @@
unset($disabledbehaviours[$key]);
set_config('disabledbehaviours', implode(',', $disabledbehaviours), 'question');
}
plugin_manager::reset_caches();
redirect($thispageurl);
}

Expand Down
Loading

0 comments on commit bde002b

Please sign in to comment.