Entity/DocumentRepository.php
changeset 80 cf6a88559482
parent 74 901463f9b11c
--- a/Entity/DocumentRepository.php	Mon Feb 27 11:45:38 2012 +0100
+++ b/Entity/DocumentRepository.php	Thu Mar 01 18:43:05 2012 +0100
@@ -406,15 +406,19 @@
     public function copyTags($src_doc, $tgt_doc)
     {
         //remove the previous tags
-        foreach ($tgt_doc->getTags() as $doctag) {
-            $this->getEntityManager()->remove($doctag);
+        if(!is_null($tgt_doc->getTags())) {
+            foreach ($tgt_doc->getTags() as $doctag) {
+                $this->getEntityManager()->remove($doctag);
+            }
         }
         
         // add the new ones
-        foreach ($src_doc->getTags() as $doctag) {
-            $new_doctag = clone $doctag;
-            $new_doctag->setDocument($tgt_doc);
-            $this->getEntityManager()->persist($new_doctag);
+        if(!is_null($src_doc->getTags())) {
+            foreach ($src_doc->getTags() as $doctag) {
+                $new_doctag = clone $doctag;
+                $new_doctag->setDocument($tgt_doc);
+                $this->getEntityManager()->persist($new_doctag);
+            }
         }
         
         $tgt_doc->setManualOrder(false);