Commit 16e59c6a authored by Ankit Agarwal's avatar Ankit Agarwal
Browse files

MDL-44596 logging: Refecator code to use component_callback() and get_plugin_list_with_function()

parent 96c8d59d
......@@ -125,7 +125,7 @@ class manager implements \core\log\manager {
return array();
}
$reports = \core_component::get_plugin_list('report');
$reports = get_plugin_list_with_function('report', 'supports_logstore', 'lib.php');
$enabled = $this->stores;
if (empty($enabled[$logstore])) {
......@@ -138,16 +138,8 @@ class manager implements \core\log\manager {
$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);
}
}
if (component_callback($report, 'supports_logstore', array($instance), false)) {
$return[$report] = get_string('pluginname', $report);
}
}
......@@ -167,16 +159,8 @@ class manager implements \core\log\manager {
$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)) {
$function = component_callback_exists($component, 'supports_logstore');
if (!$function) {
// The report doesn't define the callback, most probably it doesn't need log stores.
return false;
}
......
......@@ -233,8 +233,8 @@ class logstore_database_store_testcase extends advanced_testcase {
$allreports = \core_component::get_plugin_list('report');
$supportedreports = array(
'log' => '/report/log',
'loglive' => '/report/loglive'
'report_log' => '/report/log',
'report_loglive' => '/report/loglive'
);
// Make sure all supported reports are installed.
......
......@@ -258,11 +258,11 @@ class logstore_legacy_store_testcase extends advanced_testcase {
$allreports = \core_component::get_plugin_list('report');
$supportedreports = array(
'log' => '/report/log',
'loglive' => '/report/loglive',
'outline' => '/report/outline',
'participation' => '/report/participation',
'stats' => '/report/stats'
'report_log' => '/report/log',
'report_loglive' => '/report/loglive',
'report_outline' => '/report/outline',
'report_participation' => '/report/participation',
'report_stats' => '/report/stats'
);
// Make sure all supported reports are installed.
......
......@@ -204,11 +204,11 @@ class logstore_standard_store_testcase extends advanced_testcase {
$allreports = \core_component::get_plugin_list('report');
$supportedreports = array(
'log' => '/report/log',
'loglive' => '/report/loglive',
'outline' => '/report/outline',
'participation' => '/report/participation',
'stats' => '/report/stats'
'report_log' => '/report/log',
'report_loglive' => '/report/loglive',
'report_outline' => '/report/outline',
'report_participation' => '/report/participation',
'report_stats' => '/report/stats'
);
// Make sure all supported reports are installed.
......
......@@ -48,7 +48,7 @@ class report_log_lib_testcase extends advanced_testcase {
// Make sure all supported stores are installed.
$expectedstores = array_keys(array_intersect($allstores, $supportedstores));
$stores = $logmanager->get_supported_logstores('log');
$stores = $logmanager->get_supported_logstores('report_log');
$stores = array_keys($stores);
foreach ($expectedstores as $expectedstore) {
$this->assertContains($expectedstore, $stores);
......
......@@ -48,7 +48,7 @@ class report_loglive_lib_testcase extends advanced_testcase {
// Make sure all supported stores are installed.
$expectedstores = array_keys(array_intersect($allstores, $supportedstores));
$stores = $logmanager->get_supported_logstores('loglive');
$stores = $logmanager->get_supported_logstores('report_loglive');
$stores = array_keys($stores);
foreach ($expectedstores as $expectedstore) {
$this->assertContains($expectedstore, $stores);
......
......@@ -47,7 +47,7 @@ class report_outline_lib_testcase extends advanced_testcase {
// Make sure all supported stores are installed.
$expectedstores = array_keys(array_intersect($allstores, $supportedstores));
$stores = $logmanager->get_supported_logstores('outline');
$stores = $logmanager->get_supported_logstores('report_outline');
$stores = array_keys($stores);
foreach ($expectedstores as $expectedstore) {
$this->assertContains($expectedstore, $stores);
......
......@@ -47,7 +47,7 @@ class report_participation_lib_testcase extends advanced_testcase {
// Make sure all supported stores are installed.
$expectedstores = array_keys(array_intersect($allstores, $supportedstores));
$stores = $logmanager->get_supported_logstores('participation');
$stores = $logmanager->get_supported_logstores('report_participation');
$stores = array_keys($stores);
foreach ($expectedstores as $expectedstore) {
$this->assertContains($expectedstore, $stores);
......
......@@ -47,7 +47,7 @@ class report_stats_lib_testcase extends advanced_testcase {
// Make sure all supported stores are installed.
$expectedstores = array_keys(array_intersect($allstores, $supportedstores));
$stores = $logmanager->get_supported_logstores('stats');
$stores = $logmanager->get_supported_logstores('report_stats');
$stores = array_keys($stores);
foreach ($expectedstores as $expectedstore) {
$this->assertContains($expectedstore, $stores);
......
......@@ -4,6 +4,8 @@ information provided here is intended especially for developers.
=== 2.7 ===
* How to migrate reports accessing table 'log':
http://docs.moodle.org/dev/Migrating_log_access_in_reports
* All reports that use logstores must implement a callback report_reportname_supports_logstore($storeinstance) in lib.php of the
report. Refer MDL-44596 for details.
=== 2.2 ===
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment