From 5c73688b4a098bbd1ffa52e9410822beffa44951 Mon Sep 17 00:00:00 2001 From: David Monllao Date: Thu, 4 Jun 2015 12:22:38 +0800 Subject: [PATCH] MDL-50408 tool_log: Extra deprecation tip Adding a debugging message and returning alternative data to keep backwards compatibility as get_readers is a widely used function. --- admin/tool/log/classes/log/manager.php | 33 ++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/admin/tool/log/classes/log/manager.php b/admin/tool/log/classes/log/manager.php index 9c286f0f4d7..4077347d51b 100644 --- a/admin/tool/log/classes/log/manager.php +++ b/admin/tool/log/classes/log/manager.php @@ -106,7 +106,40 @@ class manager implements \core\log\manager { if (empty($interface) || ($reader instanceof $interface)) { $return[$plugin] = $reader; } + // TODO MDL-49291 These conditions should be removed as part of the 2nd stage deprecation. + if ($reader instanceof \core\log\sql_internal_reader) { + debugging('\core\log\sql_internal_reader has been deprecated in favour of \core\log\sql_internal_table_reader.' . + ' Update ' . get_class($reader) . ' to use the new interface.', DEBUG_DEVELOPER); + } else if ($reader instanceof \core\log\sql_select_reader) { + debugging('\core\log\sql_select_reader has been deprecated in favour of \core\log\sql_reader. Update ' . + get_class($reader) . ' to use the new interface.', DEBUG_DEVELOPER); + } + } + + // TODO MDL-49291 This section below (until the final return) should be removed as part of the 2nd stage deprecation. + $isselectreader = (ltrim($interface, '\\') === 'core\log\sql_select_reader'); + $isinternalreader = (ltrim($interface, '\\') === 'core\log\sql_internal_reader'); + if ($isselectreader || $isinternalreader) { + + if ($isselectreader) { + $alternative = '\core\log\sql_reader'; + } else { + $alternative = '\core\log\sql_internal_table_reader'; + } + + if (count($return) === 0) { + // If there are no classes implementing the provided interface and the provided interface is one of + // the deprecated ones, we return the non-deprecated alternatives. It should be safe as the new interface + // is adding a new method but not changing the existing ones. + debugging($interface . ' has been deprecated in favour of ' . $alternative . '. Returning ' . $alternative . + ' instances instead. Please call get_readers() using the new interface.', DEBUG_DEVELOPER); + $return = $this->get_readers($alternative); + } else { + debugging($interface . ' has been deprecated in favour of ' . $alternative . + '. Please call get_readers() using the new interface.', DEBUG_DEVELOPER); + } } + return $return; } -- 2.43.0