From 6196b1ad7008cda83439e2686e2d393ee46797ec Mon Sep 17 00:00:00 2001
From: "arnaud.pauget" <arnaud.pauget@maarch.org>
Date: Tue, 26 Feb 2019 11:33:24 +0100
Subject: [PATCH] Fix bug if no archives is in message

---
 .../maarchRM/Presenter/medona/message.php     | 35 ++++++++++---------
 1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/presentation/maarchRM/Presenter/medona/message.php b/presentation/maarchRM/Presenter/medona/message.php
index aecfff0..1da40eb 100644
--- a/presentation/maarchRM/Presenter/medona/message.php
+++ b/presentation/maarchRM/Presenter/medona/message.php
@@ -314,24 +314,25 @@ class message
                     }
                 }
             }
-            
-            foreach ($messageObject->archive as $archive) {
-                if (isset($archive->appraisalRule)) {
-                    $dateInter = new \DateInterval($archive->appraisalRule->duration);
-                    $numberDuration = 0;
-                    $toDisplay = '';
-                    if ($dateInter->y != 0) {
-                        $numberDuration = $dateInter->y;
-                        $toDisplay = "Year(s)";
-                    } elseif ($dateInter->m != 0) {
-                        $numberDuration = $dateInter->m;
-                        $toDisplay = "Month(s)";
-                    } elseif ($dateInter->d != 0) {
-                        $numberDuration = $dateInter->d;
-                        $toDisplay = "Day(s)";
+            if (isset($messageObject->archive)) {
+                foreach ($messageObject->archive as $archive) {
+                    if (isset($archive->appraisalRule)) {
+                        $dateInter = new \DateInterval($archive->appraisalRule->duration);
+                        $numberDuration = 0;
+                        $toDisplay = '';
+                        if ($dateInter->y != 0) {
+                            $numberDuration = $dateInter->y;
+                            $toDisplay = "Year(s)";
+                        } elseif ($dateInter->m != 0) {
+                            $numberDuration = $dateInter->m;
+                            $toDisplay = "Month(s)";
+                        } elseif ($dateInter->d != 0) {
+                            $numberDuration = $dateInter->d;
+                            $toDisplay = "Day(s)";
+                        }
+                        $archive->appraisalRule->durationNumber = $numberDuration;
+                        $archive->appraisalRule->durationToDisplay = $toDisplay;
                     }
-                    $archive->appraisalRule->durationNumber = $numberDuration;
-                    $archive->appraisalRule->durationToDisplay = $toDisplay;
                 }
             }
             $messageObjects[] = $messageObject;
-- 
GitLab