/** * Get the size of the <strong>stored</strong> data stream in this * resource. * * You should call this method instead of anything else to know the file * size as PHPCR implementations are expected to be able to provide this * information without needing to to load the actual data stream. * * Do not use this right after updating data before flushing, as it will * only look at the stored data. * * @return int the resource size in bytes. */ public function getSize() { if (null === $this->node) { throw new BadMethodCallException('Do not call Resource::getSize on unsaved objects, as it only reads the stored size.'); } return $this->node->getProperty('jcr:data')->getLength(); }
/** * {@inheritdoc} */ public function remove(NodeInterface $node, PropertyInterface $property, $webspaceKey, $languageCode, $segmentKey) { // if exist remove property of node if ($node->hasProperty($property->getName())) { $node->getProperty($property->getName())->remove(); } }
/** * {@inheritdoc} */ public function removeTranslation($document, NodeInterface $node, ClassMetadata $metadata, $locale) { foreach ($metadata->translatableFields as $field) { $propName = $this->getTranslatedPropertyName($locale, $field); $prop = $node->getProperty($propName); $prop->remove(); } }
/** * * * @param NodeInterface $contentNode * @param string $filesystemPath * @return Boolean */ protected function saveData($contentNode, $filesystemPath) { $data = $contentNode->getProperty('jcr:data')->getString(); $dirname = dirname($filesystemPath); if (!file_exists($dirname)) { mkdir($dirname, 0755, true); } return file_put_contents($filesystemPath, $data); }
/** * Determine the class name from a given node * * @param DocumentManager * @param NodeInterface $node * @param string $className * * @return string * * @throws \RuntimeException if no class name could be determined */ public function getClassName(DocumentManager $dm, NodeInterface $node, $className = null) { if (empty($className) && $node->hasProperty('phpcr:class')) { $className = $node->getProperty('phpcr:class')->getString(); } // default to the built in generic document class if (empty($className)) { $className = 'Doctrine\\ODM\\PHPCR\\Document\\Generic'; } return $className; }
/** * @group getWeakReferences */ public function testGetWeakReferencesName() { $target = $this->rootNode->getNode('tests_general_base/idExample/jcr:content/weakreference_target'); $source = $this->rootNode->getProperty('tests_general_base/idExample/jcr:content/weakreference_source1/ref1'); $iterator = $target->getWeakReferences('ref1'); $this->assertInstanceOf('Iterator', $iterator); $this->assertCount(1, $iterator, 'Wrong number of weak references to weakreference_target'); foreach ($iterator as $prop) { $this->assertInstanceOf('\\PHPCR\\PropertyInterface', $prop); $this->assertEquals($prop, $source); } }
public function testRemove() { $type = new ContactSelectionContentType($this->template, $this->contactManager->reveal(), $this->accountManager->reveal(), $this->serializer->reveal(), new CustomerIdConverter(), new IndexComparator()); $nodeProperty = $this->prophesize(\PHPCR\PropertyInterface::class); $nodeProperty->remove()->shouldBeCalled(); $nodeProperty->setValue(Argument::any())->shouldNotBeCalled(); $nodeProperty->getValue(Argument::any())->shouldNotBeCalled(); $this->property->getName()->willReturn('test'); $this->property->getValue()->shouldNotBeCalled(); $this->node->hasProperty('test')->willReturn(true); $this->node->getProperty('test')->willReturn($nodeProperty->reveal()); $this->node->setProperty(Argument::any(), Argument::any())->shouldNotBeCalled(); $type->remove($this->node->reveal(), $this->property->reveal(), $this->webspaceKey, $this->locale, $this->segmentKey); }
/** * {@inheritDoc} */ public function getClassName(DocumentManagerInterface $dm, NodeInterface $node, $className = null) { $className = $this->expandClassName($dm, $className); if ($node->hasProperty('phpcr:class')) { $nodeClassName = $node->getProperty('phpcr:class')->getString(); if (!empty($className) && $nodeClassName !== $className && !is_subclass_of($nodeClassName, $className)) { throw ClassMismatchException::incompatibleClasses($node->getPath(), $nodeClassName, $className); } $className = $nodeClassName; } // default to the built in generic document class if (empty($className)) { $className = 'Doctrine\\ODM\\PHPCR\\Document\\Generic'; } return $className; }
/** * Remove an associative array form the properties stored with the node * * @param NodeInterface $node the node where to store the assoc array * @param array $mapping the field's mapping */ public function removeAssoc(NodeInterface $node, array $mapping) { if ($node->hasProperty($mapping['assoc'])) { $node->getProperty($mapping['assoc'])->remove(); } if ($node->hasProperty($mapping['assocNulls'])) { $node->getProperty($mapping['assocNulls'])->remove(); } }
/** * Validate this node with the nodetype and generate not yet existing * autogenerated properties as necessary. * * @param NodeInterface $node * @param NodeType $nodeTypeDefinition * * @return AddNodeOperation[] Additional operations to handle autocreated nodes. * * @throws \InvalidArgumentException * @throws RepositoryException * @throws ItemExistsException * @throws LockException * @throws ConstraintViolationException * @throws PathNotFoundException * @throws VersionException * @throws ValueFormatException */ private function processNodeWithType(NodeInterface $node, NodeType $nodeTypeDefinition) { $additionalOperations = array(); foreach ($nodeTypeDefinition->getDeclaredChildNodeDefinitions() as $childDef) { /* @var $childDef NodeDefinitionInterface */ if (!$node->hasNode($childDef->getName())) { if ('*' === $childDef->getName()) { continue; } if ($childDef->isMandatory() && !$childDef->isAutoCreated()) { throw new RepositoryException(sprintf('Child "%s" is mandatory, but is not present while saving "%s" at path "%s"', $childDef->getName(), $nodeTypeDefinition->getName(), $node->getPath())); } if ($childDef->isAutoCreated()) { $requiredPrimaryTypeNames = $childDef->getRequiredPrimaryTypeNames(); $primaryType = count($requiredPrimaryTypeNames) ? current($requiredPrimaryTypeNames) : null; $newNode = $node->addNode($childDef->getName(), $primaryType); $absPath = $node->getPath() . '/' . $childDef->getName(); $operation = new AddNodeOperation($absPath, $newNode); $additionalOperations[] = $operation; } } } foreach ($nodeTypeDefinition->getDeclaredPropertyDefinitions() as $propertyDef) { /* @var $propertyDef PropertyDefinitionInterface */ if ('*' === $propertyDef->getName()) { continue; } if (!$node->hasProperty($propertyDef->getName())) { if ($propertyDef->isMandatory() && !$propertyDef->isAutoCreated()) { throw new RepositoryException(sprintf('Property "%s" is mandatory, but is not present while saving "%s" at "%s"', $propertyDef->getName(), $nodeTypeDefinition->getName(), $node->getPath())); } if ($propertyDef->isAutoCreated()) { switch ($propertyDef->getName()) { case 'jcr:uuid': $value = UUIDHelper::generateUUID(); break; case 'jcr:createdBy': case 'jcr:lastModifiedBy': $value = $this->userId; break; case 'jcr:created': case 'jcr:lastModified': $value = new \DateTime(); break; case 'jcr:etag': // TODO: http://www.day.com/specs/jcr/2.0/3_Repository_Model.html#3.7.12.1%20mix:etag $value = 'TODO: generate from binary properties of this node'; break; default: $defaultValues = $propertyDef->getDefaultValues(); if ($propertyDef->isMultiple()) { $value = $defaultValues; } elseif (isset($defaultValues[0])) { $value = $defaultValues[0]; } else { // When implementing versionable or activity, we need to handle more properties explicitly throw new RepositoryException(sprintf('No default value for autocreated property "%s" at "%s"', $propertyDef->getName(), $node->getPath())); } } $node->setProperty($propertyDef->getName(), $value, $propertyDef->getRequiredType()); } } elseif ($propertyDef->isAutoCreated()) { $prop = $node->getProperty($propertyDef->getName()); if (!$prop->isModified() && !$prop->isNew()) { switch ($propertyDef->getName()) { case 'jcr:lastModified': if ($this->autoLastModified) { $prop->setValue(new \DateTime()); } break; case 'jcr:lastModifiedBy': if ($this->autoLastModified) { $prop->setValue($this->userId); } break; case 'jcr:etag': // TODO: update etag if needed break; } } } } foreach ($nodeTypeDefinition->getDeclaredSupertypes() as $superType) { $this->processNodeWithType($node, $superType); } foreach ($node->getProperties() as $property) { $this->assertValidProperty($property); } return $additionalOperations; }
/** * {@inheritdoc} */ public function removeTranslation($document, NodeInterface $node, ClassMetadata $metadata, $locale) { foreach ($metadata->translatableFields as $field) { $mapping = $metadata->mappings[$field]; $propName = $this->getTranslatedPropertyName($locale, $mapping['property']); if ($node->hasProperty($propName)) { $prop = $node->getProperty($propName); $prop->remove(); $mapping = $metadata->mappings[$field]; if (true === $mapping['multivalue'] && isset($mapping['assoc'])) { $transMapping = $this->getTranslatedPropertyNameAssoc($locale, $mapping); $this->dm->getUnitOfWork()->removeAssoc($node, $transMapping); } } } if ($node->hasProperty($this->prefix . ':' . $locale . self::NULLFIELDS)) { $node->setProperty($this->prefix . ':' . $locale . self::NULLFIELDS, null); } }
/** * {@inheritdoc} */ public function remove(NodeInterface $node, PropertyInterface $property, $webspaceKey, $languageCode, $segmentKey) { foreach ($node->getProperties($property->getName() . '-*') as $nodeProperty) { $node->getProperty($nodeProperty->getName())->remove(); } }
/** * {@inheritdoc} */ public function remove(NodeInterface $node, PropertyInterface $property, $webspaceKey, $languageCode, $segmentKey) { if ($node->hasProperty($property->getName())) { $property = $node->getProperty($property->getName()); $property->remove(); } }
/** * {@inheritdoc} */ public function remove(NodeInterface $node, PropertyInterface $property, $webspaceKey, $languageCode, $segmentKey = null) { $this->strategy->deleteByPath($property->getValue(), $webspaceKey, $languageCode, $segmentKey); if ($node->hasProperty($property->getName())) { $node->getProperty($property->getName())->remove(); } }
/** * Renders a property of a node * * @param \PHPCR\NodeInterface $node * @param string $property * @return string String representation of the property */ public function renderNodeProperty(NodeInterface $node, $property) { return $node->getProperty($property)->getString(); }
/** * Gather all UUIDs to pre-fetch nodes in MANY_TO_ONE mappings. * * @param ClassMetadata $class The metadata about the document to know what to do. * @param NodeInterface $node The node to prefetch parent and childs for. * * @return array List of UUID to fetch in one go. */ public function collectPrefetchReferences(ClassMetadata $class, NodeInterface $node) { $refNodeUUIDs = array(); foreach ($class->referenceMappings as $fieldName) { $mapping = $class->mappings[$fieldName]; if (!$node->hasProperty($mapping['property'])) { continue; } if ($mapping['type'] & ClassMetadata::MANY_TO_ONE && $mapping['strategy'] !== 'path') { $refNodeUUIDs[] = $node->getProperty($mapping['property'])->getString(); } } return $refNodeUUIDs; }
/** * {@inheritdoc} */ public function getProperty($relPath) { return $this->node->getProperty($relPath); }