From cd59d03500d125d6680948825fbadfc0da1d3db9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Monlla=C3=B3?= Date: Fri, 21 Jun 2019 10:12:00 +0200 Subject: [PATCH] MDL-65839 core_analytics: New indicator instances for each analysable --- analytics/classes/analysis.php | 3 ++- analytics/classes/local/analyser/base.php | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/analytics/classes/analysis.php b/analytics/classes/analysis.php index 25d926a16981a..32b5abe9fa72b 100644 --- a/analytics/classes/analysis.php +++ b/analytics/classes/analysis.php @@ -313,7 +313,8 @@ protected function process_time_splitting(\core_analytics\local\time_splitting\b } try { - $indicators = $this->analyser->get_indicators(); + // Instantiate empty indicators to ensure that no garbage is dragged from previous analyses. + $indicators = $this->analyser->instantiate_indicators(); foreach ($indicators as $key => $indicator) { // The analyser attaches the main entities the sample depends on and are provided to the // indicator to calculate the sample. diff --git a/analytics/classes/local/analyser/base.php b/analytics/classes/local/analyser/base.php index 1c65e2c627352..185f573cddb00 100644 --- a/analytics/classes/local/analyser/base.php +++ b/analytics/classes/local/analyser/base.php @@ -237,6 +237,18 @@ public function get_indicators(): array { return $this->indicators; } + /** + * Instantiate the indicators. + * + * @return \core_analytics\local\indicator\base[] + */ + public function instantiate_indicators() { + foreach ($this->indicators as $key => $indicator) { + $this->indicators[$key] = call_user_func(array($indicator, 'instance')); + } + return $this->indicators; + } + /** * Samples data this analyser provides. *