/**
  * Set object updater
  *
  * @param PreUpdateEventArgs $args The event arguments
  */
 public function preUpdate(PreUpdateEventArgs $args)
 {
     $obj = $args->getDocument();
     $blameable = $this->driver->getBlameableAnnotation($obj);
     if (null !== $blameable) {
         $this->updateEntity($obj, $blameable);
         $dm = $args->getDocumentManager();
         $uow = $dm->getUnitOfWork();
         $metadata = $dm->getClassMetadata(get_class($obj));
         $uow->recomputeSingleDocumentChangeSet($metadata, $obj);
     }
 }
 /**
  * @param PreUpdateEventArgs $event
  */
 public function preUpdate(PreUpdateEventArgs $event)
 {
     $document = $event->getDocument();
     if ($document instanceof SiteInterface && $event->hasChangedField("theme")) {
         $siteTheme = $document->getTheme()->getName();
         $nodesToUpdate = $this->container->get('open_orchestra_model.repository.node')->findBySiteIdAndDefaultTheme($document->getSiteId());
         /* @var $node NodeInterface */
         foreach ($nodesToUpdate as $node) {
             $node->setTheme($siteTheme);
         }
     }
 }
Пример #3
0
 /**
  * @param PreUpdateEventArgs $args
  */
 public function preUpdate($args)
 {
     $object = $args->getDocument();
     if ($object instanceof UserInterface) {
         $this->updateUserFields($object);
         // We are doing a update, so we must force Doctrine to update the
         // changeset in case we changed something above
         $dm = $args->getDocumentManager();
         $uow = $dm->getUnitOfWork();
         $meta = $dm->getClassMetadata(get_class($object));
         $uow->recomputeSingleDocumentChangeSet($meta, $object);
     }
 }
 public function preUpdate(PreUpdateEventArgs $e)
 {
     switch (get_class($e->getDocument())) {
         case Book::class:
             if (in_array(Book::class, $this->allowed)) {
                 $this->phpunit->assertTrue($e->hasChangedField('chapters'));
             }
             break;
         case Chapter::class:
             if (in_array(Chapter::class, $this->allowed)) {
                 $this->phpunit->assertTrue($e->hasChangedField('pages'));
             }
             break;
     }
 }
Пример #5
0
 /**
  * @param PreUpdateEventArgs $eventArgs
  */
 public function preUpdate(PreUpdateEventArgs $eventArgs)
 {
     $organization = $eventArgs->getDocument();
     // check for a organization instance
     if (!$organization instanceof Organization) {
         return;
     }
     // check if the image has been changed
     if (!$eventArgs->hasChangedField('image')) {
         return;
     }
     $image = $eventArgs->getOldValue('image');
     // check if any image existed
     if (!$image instanceof OrganizationImage) {
         return;
     }
     // mark image for deletion
     $this->delete[] = $image;
 }
 /**
  * {@inheritdoc}
  */
 public function preUpdate(PreUpdateEventArgs $args)
 {
     $document = $args->getDocument();
     $metadata = $args->getDocumentManager()->getClassMetadata(get_class($document));
     foreach ($metadata->fieldMappings as $field => $mapping) {
         if ('entity' === $mapping['type'] && $args->hasChangedField($field)) {
             $newValue = $args->getNewValue($field);
             if (is_object($newValue)) {
                 if (null === ($id = $newValue->getId())) {
                     // For some reason, sometimes a newValue with no id is set as the new value
                     // In that case, we ignore it and rely on the old value
                     $id = $args->getOldValue($field);
                 }
                 // Cast into int is mandatory to prevent storing string id (for data consistency purpose)
                 $args->setNewValue($field, (int) $id);
             }
         }
     }
 }
 function it_keeps_old_value_if_new_entity_has_no_id_before_update(PreUpdateEventArgs $args, ValueStub $document, DocumentManager $dm, ClassMetadata $documentMetadata, FooStub $entity)
 {
     $args->getDocument()->willReturn($document->getWrappedObject());
     $args->getDocumentManager()->willReturn($dm);
     $dm->getClassMetadata(Argument::any())->willReturn($documentMetadata);
     $documentMetadata->fieldMappings = ['foo' => ['type' => 'text'], 'bar' => ['type' => 'entity']];
     $args->hasChangedField('bar')->willReturn(true);
     $args->getNewValue('bar')->willReturn($entity);
     $args->getOldValue('bar')->willReturn(26);
     $entity->getId()->willReturn(null);
     $args->setNewValue('bar', 26)->shouldBeCalled();
     $this->preUpdate($args);
 }