private function prepareTestData() { $products = $this->session->getNode('/cmf/sulu_io/routes/de')->addNode('products'); $products->addMixin('mix:referenceable'); $machines = $products->addNode('machines'); $machines->addMixin('mix:referenceable'); $machines1 = $products->addNode('machines-1'); $machines1->addMixin('mix:referenceable'); $drill = $machines->addNode('drill'); $drill->addMixin('mix:referenceable'); $drill1 = $machines->addNode('drill-1'); $drill1->addMixin('mix:referenceable'); $contents = $this->session->getNode('/cmf/sulu_io/contents'); $this->content1 = $contents->addNode('content1'); $this->content1->addMixin('mix:referenceable'); $this->content2 = $contents->addNode('content2'); $this->content2->addMixin('mix:referenceable'); $this->session->save(); }
/** * Process - or update - a given node. * * Provides common processing for both touch and update commands. * * @param OutputInterface $output used for status updates. * @param NodeInterface $node the node to manipulate. * @param array $operations to execute on that node. */ public function processNode(OutputInterface $output, NodeInterface $node, array $operations) { $operations = array_merge(array('setProp' => array(), 'removeProp' => array(), 'addMixins' => array(), 'removeMixins' => array(), 'applyClosures' => array(), 'dump' => false), $operations); foreach ($operations['setProp'] as $set) { $parts = explode('=', $set); $output->writeln(sprintf('<comment> > Setting property </comment>%s<comment> to </comment>%s', $parts[0], $parts[1])); $node->setProperty($parts[0], $parts[1]); } foreach ($operations['removeProp'] as $unset) { $output->writeln(sprintf('<comment> > Unsetting property </comment>%s', $unset)); $node->setProperty($unset, null); } foreach ($operations['addMixins'] as $addMixin) { $output->writeln(sprintf('<comment> > Adding mixin </comment>%s', $addMixin)); $node->addMixin($addMixin); } foreach ($operations['removeMixins'] as $removeMixin) { $output->writeln(sprintf('<comment> > Removing mixin </comment>%s', $removeMixin)); $node->removeMixin($removeMixin); } foreach ($operations['applyClosures'] as $closure) { if ($closure instanceof \Closure) { $output->writeln('<comment> > Applying closure</comment>'); } else { $closureString = $closure; $closure = create_function('$session, $node', $closure); $output->writeln(sprintf('<comment> > Applying closure: %s</comment>', strlen($closureString) > 75 ? substr($closureString, 0, 72) . '...' : $closureString)); } $closure($this->session, $node); } if ($operations['dump']) { $output->writeln('<info>Node dump: </info>'); /** @var $property PropertyInterface */ foreach ($node->getProperties() as $property) { $value = $property->getValue(); if (!is_string($value)) { $value = print_r($value, true); } $output->writeln(sprintf('<comment> - %s = </comment>%s', $property->getName(), $value)); } } }
/** * 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); } } }
/** * {@inheritdoc} */ public function addMixin($mixinName) { return $this->node->addMixin($mixinName); }
private function setMixins(Mapping\ClassMetadata $metadata, NodeInterface $node) { if ($metadata->versionable === 'full') { $node->addMixin('mix:versionable'); } else { if ($metadata->versionable === 'simple') { $node->addMixin('mix:simpleVersionable'); } if ($metadata->referenceable) { $node->addMixin('mix:referenceable'); } } // we manually set the uuid to allow creating referenced and referencing document without flush in between. if ($node->isNodeType('mix:referenceable') && !$node->hasProperty('jcr:uuid')) { // TODO do we need to check with the storage backend if the generated id really is unique? $node->setProperty('jcr:uuid', UUIDHelper::generateUUID()); } }