/** * Synchronizes update scheduled documents entities fields before flushing * No need to recompute the change set as it hasn't be calculated yet * * @param PreFlushEventArgs $args */ public function preFlush(PreFlushEventArgs $args) { $dm = $args->getDocumentManager(); $uow = $dm->getUnitOfWork(); foreach ($uow->getScheduledDocumentUpdates() as $document) { $metadata = $dm->getClassMetadata(get_class($document)); $this->synchronizeReferencedCollectionIds($document, $metadata); } foreach ($uow->getScheduledDocumentInsertions() as $document) { $metadata = $dm->getClassMetadata(get_class($document)); $this->synchronizeReferencedCollectionIds($document, $metadata); } }
function it_synchronizes_ids_field_with_entities_type_of_scheduled_to_update_documents_before_flushing(PreFlushEventArgs $args, DocumentManager $dm, UnitOfWork $uow, ClassMetadata $metadata, ValuesStub $document, \ReflectionProperty $reflFoo, \ReflectionProperty $reflFooIds, ReferencedCollection $bars) { $args->getDocumentManager()->willReturn($dm); $dm->getUnitOfWork()->willReturn($uow); $uow->getScheduledDocumentUpdates()->willReturn([$document]); $uow->getScheduledDocumentInsertions()->willReturn([]); $dm->getClassMetadata(Argument::any())->willReturn($metadata); $metadata->fieldMappings = ['foo' => ['type' => 'entities', 'idsField' => 'fooIds']]; $metadata->reflFields = ['foo' => $reflFoo, 'fooIds' => $reflFooIds]; $reflFoo->getValue($document)->willReturn($bars); $bars->map(Argument::any())->willReturn($bars); $bars->toArray()->willReturn([1, 2, 3]); $reflFooIds->setValue($document, [1, 2, 3])->shouldBeCalled(); $this->preFlush($args); }
/** * [postFlush description] * @param LifecycleEventArgs $eventArgs [description] * @return [type] [description] */ public function preFlush(PreFlushEventArgs $eventArgs) { $dm = $eventArgs->getDocumentManager(); if (!is_null($this->configuration_to_be_updated)) { $class = $dm->getClassMetadata(get_class($this->configuration_to_be_updated)); $dm->getUnitOfWork()->recomputeSingleDocumentChangeSet($class, $this->configuration_to_be_updated); } $this->preflush_done = true; }