From f9071947e927d58917e8f9f2319da45b02aba997 Mon Sep 17 00:00:00 2001 From: Amaia Anabitarte Date: Fri, 27 Nov 2020 13:19:11 +0100 Subject: [PATCH] MDL-65284 analytics: Final deprecation get_analysables() --- analytics/classes/local/analyser/base.php | 25 +--- analytics/upgrade.txt | 3 + lib/tests/analysers_test.php | 15 -- lib/tests/fixtures/deprecated_analyser.php | 158 --------------------- 4 files changed, 6 insertions(+), 195 deletions(-) delete mode 100644 lib/tests/fixtures/deprecated_analyser.php diff --git a/analytics/classes/local/analyser/base.php b/analytics/classes/local/analyser/base.php index 7a958f95108..6908c19369a 100644 --- a/analytics/classes/local/analyser/base.php +++ b/analytics/classes/local/analyser/base.php @@ -106,21 +106,10 @@ abstract class base { } /** - * Returns the list of analysable elements available on the site. - * - * \core_analytics\local\analyser\by_course and \core_analytics\local\analyser\sitewide are implementing - * this method returning site courses (by_course) and the whole system (sitewide) as analysables. - * - * @todo MDL-65284 This will be removed in Moodle 3.11 - * @deprecated - * @see get_analysables_iterator - * @throws \coding_exception - * @return \core_analytics\analysable[] Array of analysable elements using the analysable id as array key. + * @deprecated since Moodle 3.7 */ public function get_analysables() { - // This function should only be called from get_analysables_iterator and we keep it here until Moodle 3.11 - // for backwards compatibility. - throw new \coding_exception('This method is deprecated in favour of get_analysables_iterator.'); + throw new \coding_exception('get_analysables() method has been removed and cannot be used any more.'); } /** @@ -134,15 +123,7 @@ abstract class base { * @param \context[] $contexts Only analysables that depend on the provided contexts. All analysables in the system if empty. * @return \Iterator */ - public function get_analysables_iterator(?string $action = null, array $contexts = []) { - - debugging('Please overwrite get_analysables_iterator with your own implementation, we only keep this default - implementation for backwards compatibility purposes with get_analysables(). note that $action param will - be ignored so the analysable elements will be processed using get_analysables order, regardless of the - last time they were processed.'); - - return new \ArrayIterator($this->get_analysables()); - } + abstract public function get_analysables_iterator(?string $action = null, array $contexts = []); /** * This function returns this analysable list of samples. diff --git a/analytics/upgrade.txt b/analytics/upgrade.txt index 9501afbeeae..419613d83b1 100644 --- a/analytics/upgrade.txt +++ b/analytics/upgrade.txt @@ -2,8 +2,11 @@ This files describes API changes in analytics sub system, information provided here is intended especially for developers. === 3.11 === + * Final deprecation get_enabled_time_splitting_methods. Method has been removed. Use get_time_splitting_methods_for_evaluation instead. +* Final deprecation - get_analysables(). Please see get_analysables_interator() instead. + get_analysables_iterator() needs to be overridden by the child class. === 3.8 === diff --git a/lib/tests/analysers_test.php b/lib/tests/analysers_test.php index 2c6160326aa..be60ee62918 100644 --- a/lib/tests/analysers_test.php +++ b/lib/tests/analysers_test.php @@ -27,7 +27,6 @@ defined('MOODLE_INTERNAL') || die(); require_once(__DIR__ . '/../../analytics/tests/fixtures/test_target_course_level_shortname.php'); require_once(__DIR__ . '/../../analytics/tests/fixtures/test_target_shortname.php'); -require_once(__DIR__ . '/fixtures/deprecated_analyser.php'); require_once(__DIR__ . '/../../lib/enrollib.php'); /** @@ -197,20 +196,6 @@ class core_analytics_analysers_testcase extends advanced_testcase { $this->assertCount(2, $analyser->get_analysables_iterator(false, [$category1context, $category2context])); } - /** - * test_deprecated_analyser - * - * @return void - */ - public function test_deprecated_analyser() { - - $target = new test_target_shortname(); - $analyser = new deprecated_analyser(1, $target, [], [], []); - - $analysables = $analyser->get_analysables_iterator(); - $this->assertDebuggingCalled(); - } - /** * test_get_analysables_iterator description * diff --git a/lib/tests/fixtures/deprecated_analyser.php b/lib/tests/fixtures/deprecated_analyser.php deleted file mode 100644 index a4a48efeab8..00000000000 --- a/lib/tests/fixtures/deprecated_analyser.php +++ /dev/null @@ -1,158 +0,0 @@ -. - -/** - * Deprecated analyser for testing purposes. - * - * @package core_analytics - * @copyright 2019 David Monllao {@link http://www.davidmonllao.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -/** - * Deprecated analyser for testing purposes. - * - * @package core_analytics - * @copyright 2019 David Monllao {@link http://www.davidmonllao.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class deprecated_analyser extends \core_analytics\local\analyser\base { - - /** - * Implementation of a deprecated method. - * - * It should be called by get_analysables_iterator, which triggers a debugging message. - * @return \core_analytics\analysable[] - */ - public function get_analysables() { - $analysable = new \core_analytics\site(); - return [SYSCONTEXTID => $analysable]; - } - - /** - * Samples origin is course table. - * - * @return string - */ - public function get_samples_origin() { - return 'user'; - } - - /** - * Returns the sample analysable - * - * @param int $sampleid - * @return \core_analytics\analysable - */ - public function get_sample_analysable($sampleid) { - return new \core_analytics\site(); - } - - /** - * Data this analyer samples provide. - * - * @return string[] - */ - protected function provided_sample_data() { - return array('user'); - } - - /** - * Returns the sample context. - * - * @param int $sampleid - * @return \context - */ - public function sample_access_context($sampleid) { - return \context_system::instance(); - } - - /** - * Returns all site courses. - * - * @param \core_analytics\analysable $site - * @return array - */ - public function get_all_samples(\core_analytics\analysable $site) { - global $DB; - - $users = $DB->get_records('user'); - $userids = array_keys($users); - $sampleids = array_combine($userids, $userids); - - $users = array_map(function($user) { - return array('user' => $user); - }, $users); - - return array($sampleids, $users); - } - - /** - * Return all complete samples data from sample ids. - * - * @param int[] $sampleids - * @return array - */ - public function get_samples($sampleids) { - global $DB; - - list($userssql, $params) = $DB->get_in_or_equal($sampleids, SQL_PARAMS_NAMED); - $users = $DB->get_records_select('user', "id {$userssql}", $params); - $userids = array_keys($users); - $sampleids = array_combine($userids, $userids); - - $users = array_map(function($user) { - return array('user' => $user); - }, $users); - - return array($sampleids, $users); - } - - /** - * Returns the description of a sample. - * - * @param int $sampleid - * @param int $contextid - * @param array $sampledata - * @return array array(string, \renderable) - */ - public function sample_description($sampleid, $contextid, $sampledata) { - $description = fullname($sampledata['user']); - $userimage = new \pix_icon('i/user', get_string('user')); - return array($description, $userimage); - } - - /** - * We need to delete associated data if a user requests his data to be deleted. - * - * @return bool - */ - public function processes_user_data() { - return true; - } - - /** - * Join the samples origin table with the user id table. - * - * @param string $sampletablealias - * @return string - */ - public function join_sample_user($sampletablealias) { - return "JOIN {user} u ON u.id = {$sampletablealias}.sampleid"; - } -} \ No newline at end of file