diff --git a/analytics/classes/local/analyser/base.php b/analytics/classes/local/analyser/base.php index 68f73420308..06b7468e847 100644 --- a/analytics/classes/local/analyser/base.php +++ b/analytics/classes/local/analyser/base.php @@ -577,9 +577,14 @@ abstract class base { return $result; } - // Remove samples the target consider invalid. - $this->analysabletarget->add_sample_data($samplesdata); - $this->analysabletarget->filter_out_invalid_samples($sampleids, $analysable, $includetarget); + try { + // Remove samples the target consider invalid. + $this->analysabletarget->add_sample_data($samplesdata); + $this->analysabletarget->filter_out_invalid_samples($sampleids, $analysable, $includetarget); + } catch (\Throwable $e) { + $dataset->close_process(); + throw $e; + } if (!$sampleids) { $result->status = \core_analytics\model::NO_DATASET; @@ -588,19 +593,24 @@ abstract class base { return $result; } - foreach ($this->indicators as $key => $indicator) { - // The analyser attaches the main entities the sample depends on and are provided to the - // indicator to calculate the sample. - $this->indicators[$key]->add_sample_data($samplesdata); - } + try { + foreach ($this->indicators as $key => $indicator) { + // The analyser attaches the main entities the sample depends on and are provided to the + // indicator to calculate the sample. + $this->indicators[$key]->add_sample_data($samplesdata); + } - // Here we start the memory intensive process that will last until $data var is - // unset (until the method is finished basically). - if ($includetarget) { - $data = $timesplitting->calculate($sampleids, $this->get_samples_origin(), $this->indicators, $ranges, - $this->analysabletarget); - } else { - $data = $timesplitting->calculate($sampleids, $this->get_samples_origin(), $this->indicators, $ranges); + // Here we start the memory intensive process that will last until $data var is + // unset (until the method is finished basically). + if ($includetarget) { + $data = $timesplitting->calculate($sampleids, $this->get_samples_origin(), $this->indicators, $ranges, + $this->analysabletarget); + } else { + $data = $timesplitting->calculate($sampleids, $this->get_samples_origin(), $this->indicators, $ranges); + } + } catch (\Throwable $e) { + $dataset->close_process(); + throw $e; } if (!$data) { @@ -610,11 +620,16 @@ abstract class base { return $result; } - // Add extra metadata. - $this->add_model_metadata($data); + try { + // Add extra metadata. + $this->add_model_metadata($data); - // Write all calculated data to a file. - $file = $dataset->store($data); + // Write all calculated data to a file. + $file = $dataset->store($data); + } catch (\Throwable $e) { + $dataset->close_process(); + throw $e; + } // Flag the model + analysable + timesplitting as analysed. $dataset->close_process();