MDL-44596 logging: Improve management interfaces for reports and stores

This patch methods to the manager that uses callbacks from reports to determine how reports and stores are compatible with each other. This information is then displayed in the management pages.
This commit is contained in:
Ankit Agarwal 2014-03-20 12:11:30 +08:00
parent bfb6e97eae
commit f0a0f3c2bd
7 changed files with 128 additions and 8 deletions

View File

@ -41,8 +41,9 @@ echo $OUTPUT->heading(get_string('reports'));
$struninstall = get_string('uninstallplugin', 'core_admin');
$table = new flexible_table('reportplugins_administration_table');
$table->define_columns(array('name', 'version', 'uninstall'));
$table->define_headers(array(get_string('plugin'), get_string('version'), $struninstall));
$table->define_columns(array('name', 'logstoressupported', 'version', 'uninstall'));
$table->define_headers(array(get_string('plugin'), get_string('logstoressupported', 'admin'), get_string('version'),
$struninstall));
$table->define_baseurl($PAGE->url);
$table->set_attribute('id', 'reportplugins');
$table->set_attribute('class', 'admintable generaltable');
@ -71,12 +72,23 @@ foreach ($installed as $config) {
}
}
$logmanager = get_log_manager();
foreach ($plugins as $plugin => $name) {
$uninstall = '';
if ($uninstallurl = core_plugin_manager::instance()->get_uninstall_url('report_'.$plugin, 'manage')) {
$uninstall = html_writer::link($uninstallurl, $struninstall);
}
$stores = $logmanager->get_supported_logstores('report_' . $plugin);
if ($stores === false) {
$supportedstores = get_string('logstorenotrequired', 'admin');
} else if (!empty($stores)) {
$supportedstores = implode(', ', $stores);
} else {
$supportedstores = get_string('nosupportedlogstore', 'admin');;
}
if (!isset($versions[$plugin])) {
if (file_exists("$CFG->dirroot/report/$plugin/version.php")) {
// not installed yet
@ -96,7 +108,7 @@ foreach ($plugins as $plugin => $name) {
}
}
$table->add_data(array($name, $version, $uninstall));
$table->add_data(array($name, $supportedstores, $version, $uninstall));
}
$table->print_html();

View File

@ -110,6 +110,87 @@ class manager implements \core\log\manager {
return $return;
}
/**
* Get a list of reports that support the given store instance.
*
* @param string $logstore Name of the store.
*
* @return array List of supported reports
*/
public function get_supported_reports($logstore) {
$allstores = self::get_store_plugins();
if (empty($allstores[$logstore])) {
// Store doesn't exist.
return array();
}
$reports = \core_component::get_plugin_list('report');
$enabled = $this->stores;
if (empty($enabled[$logstore])) {
// Store is not enabled, init an instance.
$classname = '\\' . $logstore . '\log\store';
$instance = new $classname($this);
} else {
$instance = $enabled[$logstore];
}
$return = array();
foreach ($reports as $report => $fulldir) {
$file = $fulldir . '/lib.php';
if (file_exists($file)) {
require_once($file);
$function = 'report_' . $report . '_supports_logstore';
if (function_exists($function)) {
if ($function($instance)) {
$return[$report] = get_string('pluginname', 'report_' . $report);
}
}
}
}
return $return;
}
/**
* For a given report, returns a list of log stores that are supported.
*
* @param string $component component.
*
* @return false|array list of logstores that support the given report. It returns false if the given $component doesn't
* require logstores.
*/
public function get_supported_logstores($component) {
$allstores = self::get_store_plugins();
$enabled = $this->stores;
$function = $component . '_supports_logstore';
$file = \core_component::get_component_directory($component) . '/lib.php';
if (!file_exists($file)) {
// The report doesn't define the callback, most probably it doesn't need log stores.
return false;
}
require_once($file);
if (!function_exists($function)) {
// The report doesn't define the callback, most probably it doesn't need log stores.
return false;
}
$return = array();
foreach ($allstores as $store => $logclass) {
$instance = empty($enabled[$store]) ? new $logclass($this) : $enabled[$store];
if ($function($instance)) {
$return[$store] = get_string('pluginname', $store);
}
}
return $return;
}
/**
* Intended for store management, do not use from reports.
*

View File

@ -109,8 +109,8 @@ class tool_log_setting_managestores extends admin_setting {
$strversion = get_string('version');
$pluginmanager = core_plugin_manager::instance();
$available = \tool_log\log\manager::get_store_plugins();
$logmanager = new \tool_log\log\manager();
$available = $logmanager->get_store_plugins();
$enabled = get_config('tool_log', 'enabled_stores');
if (!$enabled) {
$enabled = array();
@ -132,8 +132,10 @@ class tool_log_setting_managestores extends admin_setting {
$return .= $OUTPUT->box_start('generalbox loggingui');
$table = new html_table();
$table->head = array(get_string('name'), $strversion, $strenable, $strup . '/' . $strdown, $strsettings, $struninstall);
$table->colclasses = array('leftalign', 'centeralign', 'centeralign', 'centeralign', 'centeralign', 'centeralign');
$table->head = array(get_string('name'), get_string('reportssupported', 'tool_log'), $strversion, $strenable,
$strup . '/' . $strdown, $strsettings, $struninstall);
$table->colclasses = array('leftalign', 'centeralign', 'centeralign', 'centeralign', 'centeralign', 'centeralign',
'centeralign');
$table->id = 'logstoreplugins';
$table->attributes['class'] = 'admintable generaltable';
$table->data = array();
@ -156,6 +158,13 @@ class tool_log_setting_managestores extends admin_setting {
$name = $store;
}
$reports = $logmanager->get_supported_reports($store);
if (!empty($reports)) {
$supportedreports = implode(', ', $reports);
} else {
$supportedreports = '-';
}
// Hide/show links.
if (isset($enabled[$store])) {
$aurl = new moodle_url($url, array('action' => 'disable', 'store' => $store));
@ -220,7 +229,7 @@ class tool_log_setting_managestores extends admin_setting {
}
// Add a row to the table.
$table->data[] = array($icon . $displayname, $version, $hideshow, $updown, $settings, $uninstall);
$table->data[] = array($icon . $displayname, $supportedreports, $version, $hideshow, $updown, $settings, $uninstall);
$printed[$store] = true;
}

View File

@ -26,4 +26,5 @@ $string['actlogshdr'] = 'Available log stores';
$string['configlogplugins'] = 'Please enable all required plugins and arrange then in appropriate order.';
$string['logging'] = 'Logging';
$string['managelogging'] = 'Manage log stores';
$string['reportssupported'] = 'Reports supported';
$string['pluginname'] = 'Log store manager';

View File

@ -651,6 +651,8 @@ $string['loginpageautofocus_help'] = 'Enabling this option improves usability of
$string['loginpasswordautocomplete'] = 'Prevent password autocompletion on login form';
$string['loginpasswordautocomplete_help'] = 'Having this off will let users save their account password in their browser. Switching this setting on will result in your site no longer following XHTML strict validation rules.';
$string['loglifetime'] = 'Keep logs for';
$string['logstorenotrequired'] = 'Log store not required';
$string['logstoressupported'] = 'Log stores that support this report';
$string['longtimewarning'] = '<b>Please note that this process can take a long time.</b>';
$string['maintenancemode'] = 'In maintenance mode';
$string['maintenancemodeisscheduled'] = 'This site will be switched to maintenance mode in {$a->min} mins {$a->sec} secs';
@ -747,6 +749,7 @@ $string['nohttpsformobilewarning'] = 'It is recommended to enable HTTPS with a v
$string['nomissingstrings'] = 'No missing strings';
$string['nonewsettings'] = 'No new settings were added during this upgrade.';
$string['nonexistentbookmark'] = 'The bookmark you requested does not exist.';
$string['nosupportedlogstore'] = 'No supported logstore found';
$string['maxtimelimit'] = 'Maximum time limit';
$string['maxtimelimit_desc'] = 'To restrict the maximum PHP execution time that Moodle will allow without any output being displayed, enter a value in seconds here. 0 means that Moodle default restrictions are used. If you have a front-end server with its own time limit, set this value lower to receive PHP errors in logs. Does not apply to CLI scripts.';
$string['noresults'] = 'No results found.';

View File

@ -34,4 +34,8 @@ class dummy_manager implements manager {
public function dispose() {
}
public function get_supported_logstores($component) {
return array();
}
}

View File

@ -49,4 +49,14 @@ interface manager {
* @return void
*/
public function dispose();
/**
* For a given report, returns a list of log stores that are supported.
*
* @param string $component component.
*
* @return false|array list of logstores that support the given report. It returns false if the given $component doesn't
* require logstores.
*/
public function get_supported_logstores($component);
}