From 60660d5963781ef25854850a214307ef0563bcac Mon Sep 17 00:00:00 2001 From: Thibault Debatty <t.debatty@cylab.be> Date: Tue, 5 Jan 2021 09:54:11 +0100 Subject: [PATCH] handle the case of invlide evidence id (can happen if we restart the server) --- app/Feedback.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app/Feedback.php b/app/Feedback.php index 09eb4c0..84713ed 100644 --- a/app/Feedback.php +++ b/app/Feedback.php @@ -36,9 +36,23 @@ class Feedback extends Model } } + private $report = null; + public function report() : \Cylab\Mark\Evidence { - return Mark::get()->findEvidenceById($this->report_id); + if ($this->report != null) { + return $this->report; + } + + try { + $this->report = Mark::get()->findEvidenceById($this->report_id); + } catch (\JsonRPC\Exception\ServerErrorException $ex) { + // may happen if the saved id is invalid (old data) + // should be replace by a static call Evidence::getNullReport() + $this->report = new \Cylab\Mark\Evidence(["id" => "?", "label" => "?", "time" => 0, "subject" => [], "score" => 0, "report" => "", "references" => [], "requests" => [], "profile" => ["label" => ""]]); + } + + return $this->report; } public static function findByReportId(string $id) -- GitLab