From 2ca1c18de9e5a4015b072b2be9232e19149c1276 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come@opensides.be>
Date: Thu, 4 Aug 2016 16:17:05 +0200
Subject: [PATCH] Fixes #4945 Support template filling in DateAttribute part 2

---
 include/simpleplugin/class_attribute.inc      |  6 +++++-
 plugins/personal/posix/class_posixAccount.inc | 10 +++++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/include/simpleplugin/class_attribute.inc b/include/simpleplugin/class_attribute.inc
index ce22c8398..8836f0f52 100644
--- a/include/simpleplugin/class_attribute.inc
+++ b/include/simpleplugin/class_attribute.inc
@@ -1513,7 +1513,11 @@ class DateAttribute extends Attribute
         try {
           $this->getDateValue();
         } catch (Exception $e) {
-          return _("Error, incorrect date: ").$e->getMessage();
+          if (is_object($this->plugin) && $this->plugin->is_template) {
+            return;
+          } else {
+            return sprintf(_('Error, incorrect date: %s'), $e->getMessage());
+          }
         }
       }
     }
diff --git a/plugins/personal/posix/class_posixAccount.inc b/plugins/personal/posix/class_posixAccount.inc
index 3e78d40e8..e5dd5a894 100644
--- a/plugins/personal/posix/class_posixAccount.inc
+++ b/plugins/personal/posix/class_posixAccount.inc
@@ -60,7 +60,15 @@ class EpochDaysDateAttribute extends DateAttribute
     if (empty($this->value)) {
       return 0;
     } else {
-      return $this->dateToLdap($this->getDateValue());
+      try {
+        return $this->dateToLdap($this->getDateValue());
+      } catch (Exception $e) {
+        if (is_object($this->plugin) && $this->plugin->is_template) {
+          return $this->value;
+        } else {
+          throw $e;
+        }
+      }
     }
   }
 }
-- 
GitLab