public function preFlush(ManagerEventArgs $args) { if (empty($this->stack)) { return; } $metadataFactory = $args->getObjectManager()->getMetadataFactory(); foreach ($this->stack as $data) { $children = $data['children']; $ctMetadata = $data['ct_metadata']; $childrenField = $data['field']; $index = 0; foreach ($children as $child) { $childMetadata = $metadataFactory->getMetadataFor(ClassUtils::getRealClass(get_class($child))); $expectedId = $this->encoder->encode($childrenField, $index++); $identifier = $childMetadata->getIdentifierValue($child); $idGenerator = $childMetadata->idGenerator; if ($idGenerator !== ClassMetadata::GENERATOR_TYPE_ASSIGNED) { throw new \InvalidArgumentException(sprintf('Currently, all documents which belong to a mapped collection must use the ' . 'assigned ID generator strategy, "%s" is using "%s".', $childMetadata->getName(), $idGenerator)); } if (!$identifier || PathHelper::getNodeName($identifier) !== $expectedId) { throw new \InvalidArgumentException(sprintf('Child mapped to content type "%s" on field "%s" has an unexpected ID "%s". ' . 'It is currently necessary to envoke the CollectionIdentifierUpdater on all ' . 'documents (at least those which have collections) before they are persisted.', $ctMetadata->getType(), $childrenField, $identifier)); } } } }
public function endFlush(ManagerEventArgs $args) { $dm = $args->getObjectManager(); $arm = $this->getAutoRouteManager(); $arm->handleDefunctRoutes(); if (!$this->postFlushDone) { $this->postFlushDone = true; $dm->flush(); } $this->postFlushDone = false; }
/** * Constructor. * * @param string $className * @param ObjectManager $objectManager */ public function __construct($className, ObjectManager $objectManager) { $this->className = (string) $className; parent::__construct($objectManager); }
public function endFlush(ManagerEventArgs $e) { $this->endFlush = true; $dm = $e->getObjectManager(); // endFlush can call ->flush(). The UOW should exit early if there is nothing // to do, avoiding an infinite recursion. $dm->flush(); }