Browse Source

create translations and log entries without triggering constructor

gedi 13 years ago
parent
commit
be7292ebce

+ 3 - 3
lib/Gedmo/Loggable/LoggableListener.php

@@ -223,7 +223,8 @@ class LoggableListener extends MappedEventSubscriber
         $meta = $wrapped->getMetadata();
         if ($config = $this->getConfiguration($om, $meta->name)) {
             $logEntryClass = $this->getLogEntryClass($ea, $meta->name);
-            $logEntry = new $logEntryClass;
+            $logEntryMeta = $om->getClassMetadata($logEntryClass);
+            $logEntry = $logEntryMeta->newInstance();
 
             $logEntry->setAction($action);
             $logEntry->setUsername($this->username);
@@ -260,7 +261,6 @@ class LoggableListener extends MappedEventSubscriber
                 $logEntry->setData($newValues);
             }
             $version = 1;
-            $logEntryMeta = $om->getClassMetadata($logEntryClass);
             if ($action !== self::ACTION_CREATE) {
                 $version = $ea->getNewVersion($logEntryMeta, $object);
                 if (empty($version)) {
@@ -276,4 +276,4 @@ class LoggableListener extends MappedEventSubscriber
             $uow->computeChangeSet($logEntryMeta, $logEntry);
         }
     }
-}
+}

+ 2 - 2
lib/Gedmo/Translatable/Document/Repository/TranslationRepository.php

@@ -72,7 +72,7 @@ class TranslationRepository extends DocumentRepository
             $transMeta = $this->dm->getClassMetadata($class);
             $trans = $this->findOneBy(compact('locale', 'field', 'objectClass', 'foreignKey'));
             if (!$trans) {
-                $trans = new $class();
+                $trans = $transMeta->newInstance();
                 $transMeta->getReflectionProperty('foreignKey')->setValue($trans, $foreignKey);
                 $transMeta->getReflectionProperty('objectClass')->setValue($trans, $objectClass);
                 $transMeta->getReflectionProperty('field')->setValue($trans, $field);
@@ -222,4 +222,4 @@ class TranslationRepository extends DocumentRepository
         }
         return $this->listener;
     }
-}
+}

+ 2 - 2
lib/Gedmo/Translatable/Entity/Repository/TranslationRepository.php

@@ -71,7 +71,7 @@ class TranslationRepository extends EntityRepository
             $transMeta = $this->_em->getClassMetadata($class);
             $trans = $this->findOneBy(compact('locale', 'field', 'objectClass', 'foreignKey'));
             if (!$trans) {
-                $trans = new $class();
+                $trans = $transMeta->newInstance();
                 $transMeta->getReflectionProperty('foreignKey')->setValue($trans, $foreignKey);
                 $transMeta->getReflectionProperty('objectClass')->setValue($trans, $objectClass);
                 $transMeta->getReflectionProperty('field')->setValue($trans, $field);
@@ -219,4 +219,4 @@ class TranslationRepository extends EntityRepository
         }
         return $this->listener;
     }
-}
+}

+ 1 - 1
lib/Gedmo/Translatable/TranslatableListener.php

@@ -504,7 +504,7 @@ class TranslatableListener extends MappedEventSubscriber
                 && ($locale !== $this->defaultLocale || $this->persistDefaultLocaleTranslation)
             ;
             if ($persistNewTranslation) {
-                $translation = new $translationClass();
+                $translation = $translationMetadata->newInstance();
                 $translation->setLocale($locale);
                 $translation->setField($field);
                 if ($ea->usesPersonalTranslation($translationClass)) {