@@ 223-241 (lines=19) @@ | ||
220 | * @param mixed $entity |
|
221 | * @param ORM\Event\LifecycleEventArgs $eventArgs |
|
222 | */ |
|
223 | public function preUpdate($entity, Doctrine\ORM\Event\LifecycleEventArgs $eventArgs) |
|
224 | { |
|
225 | $em = $eventArgs->getEntityManager(); |
|
226 | $uow = $em->getUnitOfWork(); |
|
227 | $classMetadata = $em->getClassMetadata(get_class($entity)); |
|
228 | ||
229 | if ($config = $this->driver->getObjectConfigurations($classMetadata->getName())) { |
|
230 | if (isset($config['update'])) { |
|
231 | foreach ($config['update'] as $field) { |
|
232 | $currentValue = $classMetadata->getReflectionProperty($field)->getValue($entity); |
|
233 | $newValue = $this->getUserValue($classMetadata, $field); |
|
234 | ||
235 | if ($currentValue === NULL || $currentValue !== $newValue) { // let manual values |
|
236 | $this->updateField($uow, $entity, $classMetadata, $field); |
|
237 | } |
|
238 | } |
|
239 | } |
|
240 | } |
|
241 | } |
|
242 | ||
243 | /** |
|
244 | * @param mixed $entity |
|
@@ 247-265 (lines=19) @@ | ||
244 | * @param mixed $entity |
|
245 | * @param ORM\Event\LifecycleEventArgs $eventArgs |
|
246 | */ |
|
247 | public function preRemove($entity, Doctrine\ORM\Event\LifecycleEventArgs $eventArgs) |
|
248 | { |
|
249 | $em = $eventArgs->getEntityManager(); |
|
250 | $uow = $em->getUnitOfWork(); |
|
251 | $classMetadata = $em->getClassMetadata(get_class($entity)); |
|
252 | ||
253 | if ($config = $this->driver->getObjectConfigurations($classMetadata->getName())) { |
|
254 | if (isset($config['delete'])) { |
|
255 | foreach ($config['delete'] as $field) { |
|
256 | $currentValue = $classMetadata->getReflectionProperty($field)->getValue($entity); |
|
257 | $newValue = $this->getUserValue($classMetadata, $field); |
|
258 | ||
259 | if ($currentValue === NULL || $currentValue !== $newValue) { // let manual values |
|
260 | $this->updateField($uow, $entity, $classMetadata, $field); |
|
261 | } |
|
262 | } |
|
263 | } |
|
264 | } |
|
265 | } |
|
266 | ||
267 | /** |
|
268 | * Set a custom representation of current user |