/**
  * Execute the migration
  *
  * @return void
  */
 public function execute()
 {
     foreach ($this->nodeDataRepository->findAll() as $node) {
         foreach ($this->configuration as $migrationDescription) {
             if ($this->nodeFilterService->matchFilters($node, $migrationDescription['filters'])) {
                 $this->nodeTransformationService->execute($node, $migrationDescription['transformations']);
                 if (!$this->nodeDataRepository->isInRemovedNodes($node)) {
                     $this->nodeDataRepository->update($node);
                 }
             }
         }
     }
 }
 /**
  * Remove dimensions on nodes "/" and "/sites"
  *
  * This empties the content dimensions on those nodes, so when traversing via the Node API from the root node,
  * the nodes below "/sites" are always reachable.
  *
  * @param string $workspaceName
  * @param boolean $dryRun
  * @return void
  */
 public function removeContentDimensionsFromRootAndSitesNode($workspaceName, $dryRun)
 {
     $workspace = $this->workspaceRepository->findByIdentifier($workspaceName);
     $rootNodes = $this->nodeDataRepository->findByPath('/', $workspace);
     $sitesNodes = $this->nodeDataRepository->findByPath('/sites', $workspace);
     $this->output->outputLine('Checking for root and site nodes with content dimensions set ...');
     /** @var \TYPO3\TYPO3CR\Domain\Model\NodeData $rootNode */
     foreach ($rootNodes as $rootNode) {
         if ($rootNode->getDimensionValues() !== []) {
             if ($dryRun === false) {
                 $rootNode->setDimensions([]);
                 $this->nodeDataRepository->update($rootNode);
                 $this->output->outputLine('Removed content dimensions from root node');
             } else {
                 $this->output->outputLine('Found root node with content dimensions set.');
             }
         }
     }
     /** @var \TYPO3\TYPO3CR\Domain\Model\NodeData $sitesNode */
     foreach ($sitesNodes as $sitesNode) {
         if ($sitesNode->getDimensionValues() !== []) {
             if ($dryRun === false) {
                 $sitesNode->setDimensions([]);
                 $this->nodeDataRepository->update($sitesNode);
                 $this->output->outputLine('Removed content dimensions from node "/sites"');
             } else {
                 $this->output->outputLine('Found node "/sites"');
             }
         }
     }
 }
 /**
  * Create missing child nodes for the given node type
  *
  * @param NodeType $nodeType
  * @param string $workspaceName
  * @param boolean $dryRun
  * @return void
  */
 protected function createChildNodesByNodeType(NodeType $nodeType, $workspaceName, $dryRun)
 {
     $createdNodesCount = 0;
     $updatedNodesCount = 0;
     $nodeCreationExceptions = 0;
     $nodeTypes = $this->nodeTypeManager->getSubNodeTypes($nodeType->getName(), false);
     $nodeTypes[$nodeType->getName()] = $nodeType;
     if ($this->nodeTypeManager->hasNodeType((string) $nodeType)) {
         $nodeType = $this->nodeTypeManager->getNodeType((string) $nodeType);
         $nodeTypeNames[$nodeType->getName()] = $nodeType;
     } else {
         $this->output->outputLine('Node type "%s" does not exist', array((string) $nodeType));
         exit(1);
     }
     /** @var $nodeType NodeType */
     foreach ($nodeTypes as $nodeTypeName => $nodeType) {
         $childNodes = $nodeType->getAutoCreatedChildNodes();
         foreach ($this->getNodeDataByNodeTypeAndWorkspace($nodeTypeName, $workspaceName) as $nodeData) {
             $context = $this->nodeFactory->createContextMatchingNodeData($nodeData);
             $node = $this->nodeFactory->createFromNodeData($nodeData, $context);
             if (!$node instanceof NodeInterface) {
                 continue;
             }
             foreach ($childNodes as $childNodeName => $childNodeType) {
                 try {
                     $childNode = $node->getNode($childNodeName);
                     $childNodeIdentifier = Utility::buildAutoCreatedChildNodeIdentifier($childNodeName, $node->getIdentifier());
                     if ($childNode === null) {
                         if ($dryRun === false) {
                             $node->createNode($childNodeName, $childNodeType, $childNodeIdentifier);
                             $this->output->outputLine('Auto created node named "%s" in "%s"', array($childNodeName, $node->getPath()));
                         } else {
                             $this->output->outputLine('Missing node named "%s" in "%s"', array($childNodeName, $node->getPath()));
                         }
                         $createdNodesCount++;
                     } elseif ($childNode->getIdentifier() !== $childNodeIdentifier) {
                         if ($dryRun === false) {
                             $nodeData = $childNode->getNodeData();
                             $nodeData->setIdentifier($childNodeIdentifier);
                             $this->nodeDataRepository->update($nodeData);
                             $this->output->outputLine('Updated identifier to %s for child node "%s" in "%s"', array($childNodeIdentifier, $childNodeName, $node->getPath()));
                         } else {
                             $this->output->outputLine('Child node "%s" in "%s" does not have a stable identifier', array($childNodeName, $node->getPath()));
                         }
                         $updatedNodesCount++;
                     }
                 } catch (\Exception $exception) {
                     $this->output->outputLine('Could not create node named "%s" in "%s" (%s)', array($childNodeName, $node->getPath(), $exception->getMessage()));
                     $nodeCreationExceptions++;
                 }
             }
         }
     }
     if ($createdNodesCount !== 0 || $nodeCreationExceptions !== 0 || $updatedNodesCount !== 0) {
         if ($dryRun === false) {
             if ($createdNodesCount > 0) {
                 $this->output->outputLine('Created %s new child nodes', array($createdNodesCount));
             }
             if ($updatedNodesCount > 0) {
                 $this->output->outputLine('Updated identifier of %s child nodes', array($updatedNodesCount));
             }
             if ($nodeCreationExceptions > 0) {
                 $this->output->outputLine('%s Errors occurred during child node creation', array($nodeCreationExceptions));
             }
             $this->persistenceManager->persistAll();
         } else {
             if ($createdNodesCount > 0) {
                 $this->output->outputLine('%s missing child nodes need to be created', array($createdNodesCount));
             }
             if ($updatedNodesCount > 0) {
                 $this->output->outputLine('%s identifiers of child nodes need to be updated', array($updatedNodesCount));
             }
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Updates this node in the Node Repository
  *
  * @return void
  */
 protected function update()
 {
     $this->nodeDataRepository->update($this);
 }