Browse Source

[Loggable] Checks if there were any changes in versioned fields, otherwise don't log LogEntry with empty data.

Antoni Orfin 12 years ago
parent
commit
d92c1d15bd
1 changed files with 14 additions and 11 deletions
  1. 14 11
      lib/Gedmo/Loggable/LoggableListener.php

+ 14 - 11
lib/Gedmo/Loggable/LoggableListener.php

@@ -260,20 +260,23 @@ class LoggableListener extends MappedEventSubscriber
                 }
                 $logEntry->setData($newValues);
             }
-            $version = 1;
-            if ($action !== self::ACTION_CREATE) {
-                $version = $ea->getNewVersion($logEntryMeta, $object);
-                if (empty($version)) {
-                    // was versioned later
-                    $version = 1;
+            
+            if(0 !== count($newValues)) {
+                $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);
+            }
         }
     }
 }