/** * Change the property on the given node. * * @param NodeData $node * @return void */ public function execute(NodeData $node) { foreach ($node->getNodeType()->getProperties() as $propertyName => $propertyConfiguration) { if (isset($propertyConfiguration['type']) && in_array(trim($propertyConfiguration['type']), $this->getHandledObjectTypes())) { if (!isset($nodeProperties)) { $nodeRecordQuery = $this->entityManager->getConnection()->prepare('SELECT properties FROM typo3_typo3cr_domain_model_nodedata WHERE persistence_object_identifier=?'); $nodeRecordQuery->execute([$this->persistenceManager->getIdentifierByObject($node)]); $nodeRecord = $nodeRecordQuery->fetch(\PDO::FETCH_ASSOC); $nodeProperties = unserialize($nodeRecord['properties']); } if (!isset($nodeProperties[$propertyName]) || !is_object($nodeProperties[$propertyName])) { continue; } /** @var Asset $assetObject */ $assetObject = $nodeProperties[$propertyName]; $nodeProperties[$propertyName] = null; $stream = $assetObject->getResource()->getStream(); if ($stream === false) { continue; } fclose($stream); $objectType = TypeHandling::getTypeForValue($assetObject); $objectIdentifier = ObjectAccess::getProperty($assetObject, 'Persistence_Object_Identifier', true); $nodeProperties[$propertyName] = array('__flow_object_type' => $objectType, '__identifier' => $objectIdentifier); } } if (isset($nodeProperties)) { $nodeUpdateQuery = $this->entityManager->getConnection()->prepare('UPDATE typo3_typo3cr_domain_model_nodedata SET properties=? WHERE persistence_object_identifier=?'); $nodeUpdateQuery->execute([serialize($nodeProperties), $this->persistenceManager->getIdentifierByObject($node)]); } }
/** * @test */ public function getNodeTypeReturnsFallbackNodeTypeForUnknownNodeType() { $mockFallbackNodeType = $this->getMockBuilder(NodeType::class)->disableOriginalConstructor()->getMock(); $mockNonExistingNodeType = $this->getMockBuilder(NodeType::class)->disableOriginalConstructor()->getMock(); $mockNonExistingNodeType->expects($this->atLeastOnce())->method('getName')->willReturn('definitelyNotAvailableNodeType'); /** @var NodeTypeManager|\PHPUnit_Framework_MockObject_MockObject $mockNodeTypeManager */ $mockNodeTypeManager = $this->getMockBuilder('TYPO3\\TYPO3CR\\Domain\\Service\\NodeTypeManager')->disableOriginalConstructor()->getMock(); $mockNodeTypeManager->expects($this->atLeastOnce())->method('getNodeType')->with('definitelyNotAvailableNodeType')->will($this->returnValue($mockFallbackNodeType)); $this->inject($this->nodeData, 'nodeTypeManager', $mockNodeTypeManager); $this->inject($this->nodeData, 'nodeType', $mockNonExistingNodeType); $this->assertSame($mockFallbackNodeType, $this->nodeData->getNodeType()); }
/** * Creates a node from the given NodeData container. * * If this factory has previously created a Node for the given $node and it's dimensions, * it will return the same node again. * * @param NodeData $nodeData * @param Context $context * @return \TYPO3\TYPO3CR\Domain\Model\NodeInterface * @throws \TYPO3\TYPO3CR\Exception\NodeConfigurationException if a configured 'class' for a Node does not exist or does not inherit NodeInterface */ public function createFromNodeData(NodeData $nodeData, Context $context) { if ($nodeData->isInternal()) { return null; } $internalNodeIdentifier = $nodeData->getIdentifier() . spl_object_hash($context); // In case there is a Node with an internal NodeData (because the NodeData was changed in the meantime) we need to flush it. if (isset($this->nodes[$internalNodeIdentifier]) && $this->nodes[$internalNodeIdentifier]->getNodeData()->isInternal()) { unset($this->nodes[$internalNodeIdentifier]); } if (!isset($this->nodes[$internalNodeIdentifier])) { // Warning: Alternative node implementations are considered internal for now, feature can change or be removed anytime. We want to be sure it works well and makes sense before declaring it public. $class = $nodeData->getNodeType()->getConfiguration('class') ?: $this->objectManager->getClassNameByObjectName('TYPO3\\TYPO3CR\\Domain\\Model\\NodeInterface'); if (!in_array($class, static::getNodeInterfaceImplementations($this->objectManager))) { throw new NodeConfigurationException('The configured implementation class name "' . $class . '" for NodeType "' . $nodeData->getNodeType() . '" does not inherit from TYPO3\\TYPO3CR\\Domain\\Model\\NodeInterface.', 1406884014); } $this->nodes[$internalNodeIdentifier] = new $class($nodeData, $context); } $node = $this->nodes[$internalNodeIdentifier]; return $this->filterNodeByContext($node, $context); }
/** * @test */ public function theNodeTypeCanBeSetAndRetrieved() { $nodeTypeManager = $this->getMock('TYPO3\\TYPO3CR\\Domain\\Service\\NodeTypeManager'); $nodeTypeManager->expects($this->any())->method('getNodeType')->will($this->returnCallback(function ($name) { return new NodeType($name, array(), array()); })); $this->nodeData->_set('nodeTypeManager', $nodeTypeManager); $this->assertEquals('unstructured', $this->nodeData->getNodeType()->getName()); $myNodeType = $nodeTypeManager->getNodeType('typo3:mycontent'); $this->nodeData->setNodeType($myNodeType); $this->assertEquals($myNodeType, $this->nodeData->getNodeType()); }
/** * Returns TRUE if the given node is of the node type this filter expects. * * @param \TYPO3\TYPO3CR\Domain\Model\NodeData $node * @return boolean */ public function matches(\TYPO3\TYPO3CR\Domain\Model\NodeData $node) { if ($this->withSubTypes === true) { $nodeIsMatchingNodeType = $node->getNodeType()->isOfType($this->nodeTypeName); } else { // This is needed to get the raw string NodeType to prevent errors for NodeTypes that no longer exist. $nodeType = \TYPO3\Flow\Reflection\ObjectAccess::getProperty($node, 'nodeType', true); $nodeIsMatchingNodeType = $nodeType === $this->nodeTypeName; } if ($this->exclude === true) { return !$nodeIsMatchingNodeType; } return $nodeIsMatchingNodeType; }
/** * Generates cache tags to be flushed for a node which is flushed on shutdown. * * Code duplicated from Neos' ContentCacheFlusher class * * @param NodeInterface|NodeData $node The node which has changed in some way * @return void */ protected function generateCacheTags($node) { $this->tagsToFlush[ContentCache::TAG_EVERYTHING] = 'which were tagged with "Everything".'; $nodeTypesToFlush = $this->getAllImplementedNodeTypes($node->getNodeType()); foreach ($nodeTypesToFlush as $nodeType) { /** @var NodeType $nodeType */ $nodeTypeName = $nodeType->getName(); $this->tagsToFlush['NodeType_' . $nodeTypeName] = sprintf('which were tagged with "NodeType_%s" because node "%s" has changed and was of type "%s".', $nodeTypeName, $node->getPath(), $node->getNodeType()->getName()); } $this->tagsToFlush['Node_' . $node->getIdentifier()] = sprintf('which were tagged with "Node_%s" because node "%s" has changed.', $node->getIdentifier(), $node->getPath()); while ($node->getDepth() > 1) { $node = $node->getParent(); if ($node === NULL) { break; } $this->tagsToFlush['DescendantOf_' . $node->getIdentifier()] = sprintf('which were tagged with "DescendantOf_%s" because node "%s" has changed.', $node->getIdentifier(), $node->getPath()); } if ($node instanceof NodeInterface && $node->getContext() instanceof ContentContext) { $firstActiveDomain = $node->getContext()->getCurrentSite()->getFirstActiveDomain(); if ($firstActiveDomain) { $this->domainsToFlush[] = $firstActiveDomain->getHostPattern(); } } }
/** * Returns the node type of this node. * * @return \TYPO3\TYPO3CR\Domain\Model\NodeType * @api */ public function getNodeType() { return $this->nodeData->getNodeType(); }
/** * Change the property on the given node. * * @param NodeData $node * @return void */ public function execute(NodeData $node) { foreach ($node->getNodeType()->getProperties() as $propertyName => $propertyConfiguration) { if (isset($propertyConfiguration['type']) && ($propertyConfiguration['type'] === 'TYPO3\\Media\\Domain\\Model\\ImageInterface' || preg_match('/array\\<.*\\>/', $propertyConfiguration['type']))) { if (!isset($nodeProperties)) { $nodeRecordQuery = $this->entityManager->getConnection()->prepare('SELECT properties FROM typo3_typo3cr_domain_model_nodedata WHERE persistence_object_identifier=?'); $nodeRecordQuery->execute([$this->persistenceManager->getIdentifierByObject($node)]); $nodeRecord = $nodeRecordQuery->fetch(\PDO::FETCH_ASSOC); $nodeProperties = unserialize($nodeRecord['properties']); } if (!isset($nodeProperties[$propertyName]) || empty($nodeProperties[$propertyName])) { continue; } if ($propertyConfiguration['type'] === 'TYPO3\\Media\\Domain\\Model\\ImageInterface') { $adjustments = array(); $oldVariantConfiguration = $nodeProperties[$propertyName]; if (is_array($oldVariantConfiguration)) { foreach ($oldVariantConfiguration as $variantPropertyName => $property) { switch (substr($variantPropertyName, 3)) { case 'originalImage': /** * @var $originalAsset \TYPO3\Media\Domain\Model\Image */ $originalAsset = $this->assetRepository->findByIdentifier($this->persistenceManager->getIdentifierByObject($property)); break; case 'processingInstructions': $adjustments = $this->processingInstructionsConverter->convertFrom($property, 'array'); break; } } $nodeProperties[$propertyName] = NULL; if (isset($originalAsset)) { $stream = $originalAsset->getResource()->getStream(); if ($stream === FALSE) { continue; } fclose($stream); $newImageVariant = new \TYPO3\Media\Domain\Model\ImageVariant($originalAsset); foreach ($adjustments as $adjustment) { $newImageVariant->addAdjustment($adjustment); } $originalAsset->addVariant($newImageVariant); $this->assetRepository->update($originalAsset); $nodeProperties[$propertyName] = $this->persistenceManager->getIdentifierByObject($newImageVariant); } } } elseif (preg_match('/array\\<.*\\>/', $propertyConfiguration['type'])) { if (is_array($nodeProperties[$propertyName])) { $convertedValue = []; foreach ($nodeProperties[$propertyName] as $entryValue) { if (!is_object($entryValue)) { continue; } $stream = $entryValue->getResource()->getStream(); if ($stream === FALSE) { continue; } fclose($stream); $existingObjectIdentifier = NULL; try { $existingObjectIdentifier = $this->persistenceManager->getIdentifierByObject($entryValue); if ($existingObjectIdentifier !== NULL) { $convertedValue[] = $existingObjectIdentifier; } } catch (\Exception $exception) { } } $nodeProperties[$propertyName] = $convertedValue; } } } } if (isset($nodeProperties)) { $nodeUpdateQuery = $this->entityManager->getConnection()->prepare('UPDATE typo3_typo3cr_domain_model_nodedata SET properties=? WHERE persistence_object_identifier=?'); $nodeUpdateQuery->execute([serialize($nodeProperties), $this->persistenceManager->getIdentifierByObject($node)]); } }
/** * Get properties ordering hash * * @param NodeData $nodeData * @return string */ public function getOrderingHash(NodeData $nodeData) { $data = ''; foreach ($nodeData->getNodeType()->getConfiguration('indexedNodes')['properties'] as $key => $val) { $data .= $key . ":"; } return md5($data); }