From e8715659428ac2c6c3c789a36a7f1f0e41326e5e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come@opensides.be>
Date: Wed, 13 Jul 2016 07:28:11 +0200
Subject: [PATCH] Fixes #4893 first go at fixing copy/paste for new save
 workflow

---
 include/class_CopyPasteHandler.inc | 37 +++++++++++++++---------------
 1 file changed, 19 insertions(+), 18 deletions(-)

diff --git a/include/class_CopyPasteHandler.inc b/include/class_CopyPasteHandler.inc
index 43dde793c..934ee897b 100644
--- a/include/class_CopyPasteHandler.inc
+++ b/include/class_CopyPasteHandler.inc
@@ -258,11 +258,18 @@ class CopyPasteHandler
     if (count($this->clean_objects)) {
       $this->save_object();
       foreach ($this->clean_objects as $key => $entry) {
-        /* Remove from queue -> avoid saving twice */
-        unset($this->queue[$key]);
-        unset($this->clean_objects[$key]);
+        $this->current = $entry;
+        $dn     = $this->current['object']->dn;
+        $errors = $this->current['object']->save();
 
-        $this->save_current($entry);
+        if (empty($errors)) {
+          $this->current_saved($dn);
+          /* Remove from queue -> avoid saving twice */
+          unset($this->queue[$key]);
+        } else {
+          $this->objects_to_fix[$key] = $entry;
+        }
+        unset($this->clean_objects[$key]);
       }
     }
 
@@ -273,14 +280,13 @@ class CopyPasteHandler
 
     /* Save current object if edition is finished */
     if (isset($_POST['edit_finish']) && $this->current) {
-      $msgs = $this->current['object']->check();
+      $dn     = $this->current['object']->dn;
+      $errors = $this->current['object']->save();
 
-      if (!count($msgs)) {
-        $this->save_current();
+      if (empty($errors)) {
+        $this->current_saved($dn);
       } else {
-        foreach ($msgs as $msg) {
-          msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
-        }
+        msg_dialog::displayChecks($errors);
       }
     }
 
@@ -315,18 +321,13 @@ class CopyPasteHandler
     return "";
   }
 
-  private function save_current($object = NULL)
+  private function current_saved($dn)
   {
-    if ($object !== NULL) {
-      $this->current = $object;
-    }
-    $this->lastdn = $this->current['object']->dn;
-    $this->current['object']->save();
+    $this->lastdn   = $dn;
     $this->handleReferences();
-    $this->current = FALSE;
+    $this->current  = FALSE;
   }
 
-
   /*!
    * \brief Get the last endited entry
    *
-- 
GitLab