MDL-65839 core_analytics: New indicator instances for each analysable

This commit is contained in:
David Monllaó
2019-06-28 21:00:25 +02:00
parent 035d608c59
commit cd59d03500
2 changed files with 14 additions and 1 deletions
+2 -1
View File
@@ -313,7 +313,8 @@ class analysis {
}
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.
+12
View File
@@ -237,6 +237,18 @@ abstract class base {
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.
*