private function resolveParent($document, ClassMetadata $metadata) { if (!($parentField = $metadata->parentMapping)) { throw new \RuntimeException(sprintf('A default parent path has been specified, but no parent mapping has been applied to document "%s"', get_class($document))); } if (false === $this->force) { $actualParent = $metadata->getFieldValue($document, $parentField); if ($actualParent) { return; } } $parentDocument = $this->documentManager->find(null, $this->parentPath); if (true === $this->autocreate && null === $parentDocument) { NodeHelper::createPath($this->documentManager->getPhpcrSession(), $this->parentPath); $parentDocument = $this->documentManager->find(null, $this->parentPath); } if (null === $parentDocument) { throw new \RuntimeException(sprintf('Document at default parent path "%s" does not exist. `autocreate` was set to "%s"', $this->parentPath, $this->autocreate ? 'true' : 'false')); } $metadata->setFieldValue($document, $parentField, $parentDocument); }
/** * Set the mapped mixins. * * @param ClassMetadata $metadata * @param NodeInterface $node * @param object $document The document to update autogenerated fields. */ private function setMixins(Mapping\ClassMetadata $metadata, NodeInterface $node, $document) { $repository = $this->session->getRepository(); if ($metadata->versionable === 'full') { if ($repository->getDescriptor(RepositoryInterface::OPTION_VERSIONING_SUPPORTED)) { $node->addMixin('mix:versionable'); } elseif ($repository->getDescriptor(RepositoryInterface::OPTION_SIMPLE_VERSIONING_SUPPORTED)) { $node->addMixin('mix:simpleVersionable'); } } elseif ($metadata->versionable === 'simple' && $repository->getDescriptor(RepositoryInterface::OPTION_SIMPLE_VERSIONING_SUPPORTED)) { $node->addMixin('mix:simpleVersionable'); } if (!$node->isNodeType('mix:referenceable') && $metadata->referenceable) { $node->addMixin('mix:referenceable'); } // manually set the uuid if it is not present yet, so we can assign it to documents if ($node->isNodeType('mix:referenceable') && !$node->hasProperty('jcr:uuid')) { $uuid = false; $uuidFieldName = $metadata->getUuidFieldName(); if ($uuidFieldName) { $uuid = $metadata->getFieldValue($document, $uuidFieldName); } if (!$uuid) { $uuid = $this->generateUuid(); } $node->setProperty('jcr:uuid', $uuid); if ($uuidFieldName && !$metadata->getFieldValue($document, $uuidFieldName)) { $metadata->setFieldValue($document, $uuidFieldName, $uuid); } } }