From 16e59c6af8f7d013d8db50999fb6a7690cd63132 Mon Sep 17 00:00:00 2001 From: Ankit Agarwal Date: Tue, 25 Mar 2014 18:09:37 +0800 Subject: [PATCH] MDL-44596 logging: Refecator code to use component_callback() and get_plugin_list_with_function() --- admin/tool/log/classes/log/manager.php | 26 ++++--------------- .../log/store/database/tests/store_test.php | 4 +-- .../log/store/legacy/tests/store_test.php | 10 +++---- .../log/store/standard/tests/store_test.php | 10 +++---- report/log/tests/lib_test.php | 2 +- report/loglive/tests/lib_test.php | 2 +- report/outline/tests/lib_test.php | 2 +- report/participation/tests/lib_test.php | 2 +- report/stats/tests/lib_test.php | 2 +- report/upgrade.txt | 2 ++ 10 files changed, 24 insertions(+), 38 deletions(-) diff --git a/admin/tool/log/classes/log/manager.php b/admin/tool/log/classes/log/manager.php index b113bad287f..129389f2e1c 100644 --- a/admin/tool/log/classes/log/manager.php +++ b/admin/tool/log/classes/log/manager.php @@ -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; } diff --git a/admin/tool/log/store/database/tests/store_test.php b/admin/tool/log/store/database/tests/store_test.php index 05633efb663..71e65432581 100644 --- a/admin/tool/log/store/database/tests/store_test.php +++ b/admin/tool/log/store/database/tests/store_test.php @@ -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. diff --git a/admin/tool/log/store/legacy/tests/store_test.php b/admin/tool/log/store/legacy/tests/store_test.php index 00629bfbeb9..c78e013d1b8 100644 --- a/admin/tool/log/store/legacy/tests/store_test.php +++ b/admin/tool/log/store/legacy/tests/store_test.php @@ -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. diff --git a/admin/tool/log/store/standard/tests/store_test.php b/admin/tool/log/store/standard/tests/store_test.php index 7244b687f75..2d42b4cf202 100644 --- a/admin/tool/log/store/standard/tests/store_test.php +++ b/admin/tool/log/store/standard/tests/store_test.php @@ -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. diff --git a/report/log/tests/lib_test.php b/report/log/tests/lib_test.php index 0b605f61deb..4c0996de99b 100644 --- a/report/log/tests/lib_test.php +++ b/report/log/tests/lib_test.php @@ -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); diff --git a/report/loglive/tests/lib_test.php b/report/loglive/tests/lib_test.php index 5461902407b..ddc20f5139d 100644 --- a/report/loglive/tests/lib_test.php +++ b/report/loglive/tests/lib_test.php @@ -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); diff --git a/report/outline/tests/lib_test.php b/report/outline/tests/lib_test.php index 95593fb984d..9f1f1438957 100644 --- a/report/outline/tests/lib_test.php +++ b/report/outline/tests/lib_test.php @@ -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); diff --git a/report/participation/tests/lib_test.php b/report/participation/tests/lib_test.php index 3f2d05be46a..89b637a3b1b 100644 --- a/report/participation/tests/lib_test.php +++ b/report/participation/tests/lib_test.php @@ -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); diff --git a/report/stats/tests/lib_test.php b/report/stats/tests/lib_test.php index 6d6630f17f7..a7eb5008609 100644 --- a/report/stats/tests/lib_test.php +++ b/report/stats/tests/lib_test.php @@ -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); diff --git a/report/upgrade.txt b/report/upgrade.txt index eb434830fa8..e6f06a74bf1 100644 --- a/report/upgrade.txt +++ b/report/upgrade.txt @@ -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 ===