NOTE: This is internal only and should not be used or extended by userland code.
Inheritance: extends AbstractNodeData
 /**
  * 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)]);
     }
 }
 /**
  * Add dimensions to the node.
  *
  * @param NodeData $node
  * @return void
  */
 public function execute(NodeData $node)
 {
     $dimensionValuesToBeAdded = $node->getDimensionValues();
     foreach ($this->dimensionValues as $dimensionName => $dimensionValues) {
         if (!isset($dimensionValuesToBeAdded[$dimensionName])) {
             if (is_array($dimensionValues)) {
                 $dimensionValuesToBeAdded[$dimensionName] = $dimensionValues;
             } else {
                 $dimensionValuesToBeAdded[$dimensionName] = array($dimensionValues);
             }
         }
     }
     if ($this->addDefaultDimensionValues === true) {
         $configuredDimensions = $this->contentDimensionRepository->findAll();
         foreach ($configuredDimensions as $configuredDimension) {
             if (!isset($dimensionValuesToBeAdded[$configuredDimension->getIdentifier()])) {
                 $dimensionValuesToBeAdded[$configuredDimension->getIdentifier()] = array($configuredDimension->getDefault());
             }
         }
     }
     $dimensionsToBeSet = array();
     foreach ($dimensionValuesToBeAdded as $dimensionName => $dimensionValues) {
         foreach ($dimensionValues as $dimensionValue) {
             $dimensionsToBeSet[] = new NodeDimension($node, $dimensionName, $dimensionValue);
         }
     }
     $node->setDimensions($dimensionsToBeSet);
 }
 /**
  * Returns TRUE if the given node has the property and the value is not empty.
  *
  * @param NodeData $node
  * @return boolean
  */
 public function matches(NodeData $node)
 {
     if ($node->hasProperty($this->propertyName)) {
         $propertyValue = $node->getProperty($this->propertyName);
         return !empty($propertyValue);
     }
     return false;
 }
 /**
  * Returns TRUE if the given node has the default dimension values.
  *
  * @param NodeData $node
  * @return boolean
  */
 public function matches(NodeData $node)
 {
     if ($this->filterForDefaultDimensionValues === true) {
         $configuredDimensions = $this->contentDimensionRepository->findAll();
         foreach ($configuredDimensions as $dimension) {
             $this->dimensionValues[$dimension->getIdentifier()] = array($dimension->getDefault());
         }
     }
     return $node->getDimensionValues() === $this->dimensionValues;
 }
 /**
  * Generates a Context that exactly fits the given NodeData Workspace, Dimensions & Site.
  *
  * @param NodeData $nodeData
  * @return ContentContext
  */
 protected function createContextMatchingNodeData(NodeData $nodeData)
 {
     $nodePath = NodePaths::getRelativePathBetween(SiteService::SITES_ROOT_PATH, $nodeData->getPath());
     list($siteNodeName) = explode('/', $nodePath);
     $site = $this->siteRepository->findOneByNodeName($siteNodeName);
     $contextProperties = ['workspaceName' => $nodeData->getWorkspace()->getName(), 'invisibleContentShown' => true, 'inaccessibleContentShown' => true, 'removedContentShown' => true, 'dimensions' => $nodeData->getDimensionValues(), 'currentSite' => $site];
     if ($domain = $site->getFirstActiveDomain()) {
         $contextProperties['currentDomain'] = $domain;
     }
     return $this->_contextFactory->create($contextProperties);
 }
 /**
  * Returns TRUE if the given node is of the node type this filter expects.
  *
  * @param NodeData $node
  * @return boolean
  */
 public function matches(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 = ObjectAccess::getProperty($node, 'nodeType', true);
         $nodeIsMatchingNodeType = $nodeType === $this->nodeTypeName;
     }
     if ($this->exclude === true) {
         return !$nodeIsMatchingNodeType;
     }
     return $nodeIsMatchingNodeType;
 }
示例#7
0
 /**
  * Given a context a new node is returned that is like this node, but
  * lives in the new context.
  *
  * @param Context $context
  * @return NodeInterface
  */
 public function createVariantForContext($context)
 {
     $autoCreatedChildNodes = [];
     $nodeType = $this->getNodeType();
     foreach ($nodeType->getAutoCreatedChildNodes() as $childNodeName => $childNodeConfiguration) {
         $childNode = $this->getNode($childNodeName);
         if ($childNode !== null) {
             $autoCreatedChildNodes[$childNodeName] = $childNode;
         }
     }
     $nodeData = new NodeData($this->nodeData->getPath(), $context->getWorkspace(), $this->nodeData->getIdentifier(), $context->getTargetDimensionValues());
     $nodeData->similarize($this->nodeData);
     if ($this->context !== $context) {
         $node = $this->nodeFactory->createFromNodeData($nodeData, $context);
     } else {
         $this->setNodeData($nodeData);
         $node = $this;
     }
     $this->context->getFirstLevelNodeCache()->flush();
     $this->emitNodeAdded($node);
     /**
      * @var $autoCreatedChildNode NodeInterface
      */
     foreach ($autoCreatedChildNodes as $autoCreatedChildNode) {
         $autoCreatedChildNode->createVariantForContext($context);
     }
     return $node;
 }
 /**
  * Change the property on the given node.
  *
  * @param NodeData $nodeData
  * @return void
  */
 public function execute(NodeData $nodeData)
 {
     $dimensions = $nodeData->getDimensions();
     if ($dimensions !== array()) {
         $hasChanges = false;
         $newDimensions = array();
         foreach ($dimensions as $dimension) {
             /** @var NodeDimension $dimension */
             if ($dimension->getName() === $this->oldDimensionName) {
                 $dimension = new NodeDimension($dimension->getNodeData(), $this->newDimensionName, $dimension->getValue());
                 $hasChanges = true;
             } else {
                 $dimension = new NodeDimension($dimension->getNodeData(), $dimension->getName(), $dimension->getValue());
             }
             $newDimensions[] = $dimension;
         }
         if ($hasChanges) {
             $nodeData->setDimensions($newDimensions);
         }
     }
 }
 /**
  * Change the property on the given node.
  *
  * @param NodeData $node
  * @return NodeData
  */
 public function execute(NodeData $node)
 {
     $reference = (string) $node->getProperty('plugin');
     $workspace = $node->getWorkspace();
     do {
         if ($this->reverse === false && preg_match(NodeInterface::MATCH_PATTERN_PATH, $reference)) {
             $pluginNode = $this->nodeDataRepository->findOneByPath($reference, $node->getWorkspace());
         } else {
             $pluginNode = $this->nodeDataRepository->findOneByIdentifier($reference, $node->getWorkspace());
         }
         if (isset($pluginNode)) {
             break;
         }
         $workspace = $workspace->getBaseWorkspace();
     } while ($workspace && $workspace->getName() !== 'live');
     if (isset($pluginNode)) {
         $node->setProperty('plugin', $this->reverse === false ? $pluginNode->getIdentifier() : $pluginNode->getPath());
     }
     return $node;
 }
 /**
  * Remove the given node
  *
  * @param NodeData $node
  * @return void
  */
 public function execute(NodeData $node)
 {
     $node->setRemoved(true);
 }
 /**
  * Create a shadow NodeData at the given path with the same workspace and dimensions as this
  *
  * Note: The constructor will already add the new object to the repository
  * Internal method, do not use outside of the content repository.
  *
  * @param string $path The (original) path for the node data
  * @return NodeData
  */
 public function createShadow($path)
 {
     $shadowNode = new NodeData($path, $this->workspace, $this->identifier, $this->dimensionValues);
     $shadowNode->similarize($this);
     $shadowNode->setAsShadowOf($this);
     return $shadowNode;
 }
 /**
  * @test
  */
 public function setDimensionsRemovesDimensionValuesNotGiven()
 {
     $nodeData = new NodeData('/foo/bar', $this->mockWorkspace, null, array('c' => array('c1', 'c2'), 'a' => array('a1')));
     $dimensionsToSet = array(new NodeDimension($nodeData, 'c', 'c1'), new NodeDimension($nodeData, 'b', 'b1'), new NodeDimension($nodeData, 'f', 'f1'));
     $expectedDimensionValues = array('b' => array('b1'), 'c' => array('c1'), 'f' => array('f1'));
     $nodeData->setDimensions($dimensionsToSet);
     $setDimensionValues = $nodeData->getDimensionValues();
     $this->assertSame($expectedDimensionValues, $setDimensionValues);
 }
 /**
  * Change the property on the given node.
  *
  * @param NodeData $node
  * @return void
  */
 public function execute(NodeData $node)
 {
     $currentPropertyValue = $node->getProperty($this->propertyName);
     $newValueWithReplacedCurrentValue = str_replace($this->currentValuePlaceholder, $currentPropertyValue, $this->newValue);
     $newValueWithReplacedSearch = str_replace($this->search, $this->replace, $newValueWithReplacedCurrentValue);
     $node->setProperty($this->propertyName, $newValueWithReplacedSearch);
 }
 /**
  * Returns TRUE if the given node is in the workspace this filter expects.
  *
  * @param NodeData $node
  * @return boolean
  */
 public function matches(NodeData $node)
 {
     return $node->getWorkspace() !== null && $node->getWorkspace()->getName() === $this->workspaceName;
 }
 /**
  * Adjusts the path of $shadowNodeData to $path, if needed/possible.
  *
  * If the $path is occupied in $targetWorkspace, the shadow is removed.
  *
  * @param NodeData $shadowNodeData
  * @param $path
  * @param Workspace $targetWorkspace
  * @param array $dimensionValues
  * @return void
  */
 protected function adjustShadowNodePath(NodeData $shadowNodeData, $path, Workspace $targetWorkspace, array $dimensionValues)
 {
     $nodeOnSamePathInTargetWorkspace = $this->nodeDataRepository->findOneByPath($path, $targetWorkspace, $dimensionValues);
     if ($nodeOnSamePathInTargetWorkspace === null || $nodeOnSamePathInTargetWorkspace->getWorkspace() !== $targetWorkspace) {
         $shadowNodeData->setPath($path, false);
         return;
     }
     // A node exists in that path, so no shadow node is needed/possible.
     $this->nodeDataRepository->remove($shadowNodeData);
 }
 /**
  * Returns TRUE if the given node is of the node type this filter expects.
  *
  * @param NodeData $node
  * @return boolean
  */
 public function matches(NodeData $node)
 {
     return $node->getName() === $this->nodeName;
 }
 /**
  * Assigns an index to the given node which reflects the specified position.
  * If the position is "before" or "after", an index will be chosen which makes
  * the given node the previous or next node of the given reference node.
  * If the position "last" is specified, an index higher than any existing index
  * will be chosen.
  *
  * If no free index is available between two nodes (for "before" and "after"),
  * the whole index of the current node level will be renumbered.
  *
  * @param NodeData $node The node to set the new index for
  * @param integer $position The position the new index should reflect, must be one of the POSITION_* constants
  * @param NodeInterface $referenceNode The reference node. Mandatory for POSITION_BEFORE and POSITION_AFTER
  * @return void
  * @throws \InvalidArgumentException
  */
 public function setNewIndex(NodeData $node, $position, NodeInterface $referenceNode = null)
 {
     $parentPath = $node->getParentPath();
     switch ($position) {
         case self::POSITION_BEFORE:
             if ($referenceNode === null) {
                 throw new \InvalidArgumentException('The reference node must be specified for POSITION_BEFORE.', 1317198857);
             }
             $referenceIndex = $referenceNode->getIndex();
             $nextLowerIndex = $this->findNextLowerIndex($parentPath, $referenceIndex);
             if ($nextLowerIndex === null) {
                 // FIXME: $nextLowerIndex returns 0 and not NULL in case no lower index is found. So this case seems to be
                 // never executed. We need to check that again!
                 $newIndex = (int) round($referenceIndex / 2);
             } elseif ($nextLowerIndex < $referenceIndex - 1) {
                 // there is free space left between $referenceNode and preceding sibling.
                 $newIndex = (int) round($nextLowerIndex + ($referenceIndex - $nextLowerIndex) / 2);
             } else {
                 // there is no free space left between $referenceNode and following sibling -> we have to make room!
                 $this->openIndexSpace($parentPath, $referenceIndex);
                 $referenceIndex = $referenceNode->getIndex();
                 $nextLowerIndex = $this->findNextLowerIndex($parentPath, $referenceIndex);
                 if ($nextLowerIndex === null) {
                     $newIndex = (int) round($referenceIndex / 2);
                 } else {
                     $newIndex = (int) round($nextLowerIndex + ($referenceIndex - $nextLowerIndex) / 2);
                 }
             }
             break;
         case self::POSITION_AFTER:
             if ($referenceNode === null) {
                 throw new \InvalidArgumentException('The reference node must be specified for POSITION_AFTER.', 1317198858);
             }
             $referenceIndex = $referenceNode->getIndex();
             $nextHigherIndex = $this->findNextHigherIndex($parentPath, $referenceIndex);
             if ($nextHigherIndex === null) {
                 // $referenceNode is last node, so we can safely add an index at the end by incrementing the reference index.
                 $newIndex = $referenceIndex + 100;
                 $this->setHighestIndexInParentPath($parentPath, $newIndex);
             } elseif ($nextHigherIndex > $referenceIndex + 1) {
                 // $referenceNode is not last node, but there is free space left between $referenceNode and following sibling.
                 $newIndex = (int) round($referenceIndex + ($nextHigherIndex - $referenceIndex) / 2);
             } else {
                 // $referenceNode is not last node, and no free space is left -> we have to make room after the reference node!
                 $this->openIndexSpace($parentPath, $referenceIndex + 1);
                 $nextHigherIndex = $this->findNextHigherIndex($parentPath, $referenceIndex);
                 if ($nextHigherIndex === null) {
                     $newIndex = $referenceIndex + 100;
                     $this->setHighestIndexInParentPath($parentPath, $newIndex);
                 } else {
                     $newIndex = (int) round($referenceIndex + ($nextHigherIndex - $referenceIndex) / 2);
                 }
             }
             break;
         case self::POSITION_LAST:
             $nextFreeIndex = $this->findNextFreeIndexInParentPath($parentPath);
             $newIndex = $nextFreeIndex;
             break;
         default:
             throw new \InvalidArgumentException('Invalid position for new node index given.', 1329729088);
     }
     $node->setIndex($newIndex);
 }
 /**
  * Add the new property with the given value on the given node.
  *
  * @param NodeData $node
  * @return void
  */
 public function execute(NodeData $node)
 {
     $node->setProperty($this->newPropertyName, $this->value);
 }
 /**
  * Strips tags on the value of the property to work on.
  *
  * @param NodeData $node
  * @return void
  */
 public function execute(NodeData $node)
 {
     $node->setProperty($this->propertyName, strip_tags($node->getProperty($this->propertyName)));
 }
 /**
  * Remove the property from the given node.
  *
  * @param NodeData $node
  * @return void
  */
 public function execute(NodeData $node)
 {
     $node->removeProperty($this->propertyName);
 }
 /**
  * Renames the configured property to the new name.
  *
  * @param NodeData $node
  * @return void
  */
 public function execute(NodeData $node)
 {
     $node->setProperty($this->newPropertyName, $node->getProperty($this->oldPropertyName));
     $node->removeProperty($this->oldPropertyName);
 }
 /**
  * Change the Node Type on the given node.
  *
  * @param NodeData $node
  * @return void
  */
 public function execute(NodeData $node)
 {
     $nodeType = $this->nodeTypeManager->getNodeType($this->newType);
     $node->setNodeType($nodeType);
 }
 /**
  * Generates a Context that exactly fits the given NodeData Workspace and Dimensions.
  *
  * TODO: We could get more specific about removed and invisible content by adding some more logic here that generates fitting values.
  *
  * @param NodeData $nodeData
  * @return Context
  */
 public function createContextMatchingNodeData(NodeData $nodeData)
 {
     return $this->contextFactory->create(array('workspaceName' => $nodeData->getWorkspace()->getName(), 'invisibleContentShown' => true, 'inaccessibleContentShown' => true, 'removedContentShown' => true, 'dimensions' => $nodeData->getDimensionValues()));
 }
 /**
  * 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'] === ImageInterface::class || 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'] === ImageInterface::class) {
                 $adjustments = array();
                 $oldVariantConfiguration = $nodeProperties[$propertyName];
                 if (is_array($oldVariantConfiguration)) {
                     foreach ($oldVariantConfiguration as $variantPropertyName => $property) {
                         switch (substr($variantPropertyName, 3)) {
                             case 'originalImage':
                                 /**
                                  * @var $originalAsset 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 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)]);
     }
 }
 /**
  * Returns TRUE if the given node is removed
  *
  * @param NodeData $node
  * @return boolean
  */
 public function matches(NodeData $node)
 {
     return $node->isRemoved();
 }
 /**
  * Renames the node to the new name.
  *
  * @param NodeData $node
  * @return void
  */
 public function execute(NodeData $node)
 {
     $newNodePath = $node->getParentPath() . '/' . $this->newName;
     $node->setPath($newNodePath);
 }