浏览代码

[Loggable] Changed behaviour of non-logging empty data-changes: check if data changes is empty only on UPDATE.

Antoni Orfin 12 年之前
父节点
当前提交
9563acb8cb
共有 1 个文件被更改,包括 15 次插入13 次删除
  1. 15 13
      lib/Gedmo/Loggable/LoggableListener.php

+ 15 - 13
lib/Gedmo/Loggable/LoggableListener.php

@@ -261,22 +261,24 @@ class LoggableListener extends MappedEventSubscriber
                 $logEntry->setData($newValues);
             }
             
-            if(0 !== count($newValues)) {
-                $version = 1;
-                if ($action !== self::ACTION_CREATE) {
-                    $version = $ea->getNewVersion($logEntryMeta, $object);
-                    if (empty($version)) {
-                        // was versioned later
-                        $version = 1;
-                    }
+            if($action === self::ACTION_UPDATE && 0 === count($newValues)) {
+                return;
+            }
+            
+            $version = 1;
+            if ($action !== self::ACTION_CREATE) {
+                $version = $ea->getNewVersion($logEntryMeta, $object);
+                if (empty($version)) {
+                    // was versioned later
+                    $version = 1;
                 }
-                $logEntry->setVersion($version);
+            }
+            $logEntry->setVersion($version);
 
-                $this->prePersistLogEntry($logEntry, $object);
+            $this->prePersistLogEntry($logEntry, $object);
 
-                $om->persist($logEntry);
-                $uow->computeChangeSet($logEntryMeta, $logEntry);
-            }
+            $om->persist($logEntry);
+            $uow->computeChangeSet($logEntryMeta, $logEntry);
         }
     }
 }