/**
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $this->nodeDataRepository = $this->objectManager->get(NodeDataRepository::class);
     $domainRepository = $this->objectManager->get(DomainRepository::class);
     $siteRepository = $this->objectManager->get(SiteRepository::class);
     $this->contextFactory = $this->objectManager->get(ContextFactoryInterface::class);
     $contextProperties = array('workspaceName' => 'live');
     $contentContext = $this->contextFactory->create($contextProperties);
     $siteImportService = $this->objectManager->get(SiteImportService::class);
     $siteImportService->importFromFile(__DIR__ . '/../Fixtures/NodeStructure.xml', $contentContext);
     $this->persistenceManager->persistAll();
     $currentDomain = $domainRepository->findOneByActiveRequest();
     if ($currentDomain !== null) {
         $contextProperties['currentSite'] = $currentDomain->getSite();
         $contextProperties['currentDomain'] = $currentDomain;
     } else {
         $contextProperties['currentSite'] = $siteRepository->findFirst();
     }
     $contentContext = $this->contextFactory->create($contextProperties);
     $this->contentContext = $contentContext;
     $this->propertyMapper = $this->objectManager->get(PropertyMapper::class);
     $this->baseNode = $this->contentContext->getCurrentSiteNode()->getNode('home');
     $this->linkingService = $this->objectManager->get(LinkingService::class);
     /** @var $requestHandler FunctionalTestRequestHandler */
     $requestHandler = self::$bootstrap->getActiveRequestHandler();
     $this->controllerContext = new ControllerContext(new ActionRequest($requestHandler->getHttpRequest()), $requestHandler->getHttpResponse(), new Arguments(array()), new UriBuilder());
 }
 /**
  * Add the current node and all parent identifiers to be used for cache entry tagging
  *
  * @Flow\Before("method(TYPO3\Flow\Mvc\Routing\RouterCachingService->extractUuids())")
  * @param \TYPO3\Flow\Aop\JoinPointInterface $joinPoint The current join point
  * @return void
  */
 public function addCurrentNodeIdentifier(JoinPointInterface $joinPoint)
 {
     $values = $joinPoint->getMethodArgument('values');
     if (!isset($values['node']) || strpos($values['node'], '@') === false) {
         return;
     }
     // Build context explicitly without authorization checks because the security context isn't available yet
     // anyway and any Entity Privilege targeted on Workspace would fail at this point:
     $this->securityContext->withoutAuthorizationChecks(function () use($joinPoint, $values) {
         $contextPathPieces = NodePaths::explodeContextPath($values['node']);
         $context = $this->contextFactory->create(['workspaceName' => $contextPathPieces['workspaceName'], 'dimensions' => $contextPathPieces['dimensions'], 'invisibleContentShown' => true]);
         $node = $context->getNode($contextPathPieces['nodePath']);
         if (!$node instanceof NodeInterface) {
             return;
         }
         $values['node-identifier'] = $node->getIdentifier();
         $node = $node->getParent();
         $values['node-parent-identifier'] = array();
         while ($node !== null) {
             $values['node-parent-identifier'][] = $node->getIdentifier();
             $node = $node->getParent();
         }
         $joinPoint->setMethodArgument('values', $values);
     });
 }
 /**
  * @test
  */
 public function createNodeFromTemplateUsesWorkspacesOfContext()
 {
     $nodeTemplate = $this->generateBasicNodeTemplate();
     $this->context = $this->contextFactory->create(array('workspaceName' => 'user1'));
     $rootNode = $this->context->getNode('/');
     $node = $rootNode->createNodeFromTemplate($nodeTemplate, 'just-a-node');
     $workspace = $node->getWorkspace();
     $this->assertEquals('user1', $workspace->getName(), 'Node should be created in workspace of context');
 }
 /**
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $this->nodeDataRepository = new \TYPO3\TYPO3CR\Domain\Repository\NodeDataRepository();
     $this->contextFactory = $this->objectManager->get(\TYPO3\TYPO3CR\Domain\Service\ContextFactoryInterface::class);
     $this->context = $this->contextFactory->create(array('workspaceName' => 'live'));
     $this->nodeTypeManager = $this->objectManager->get(\TYPO3\TYPO3CR\Domain\Service\NodeTypeManager::class);
     $this->contentDimensionRepository = $this->objectManager->get(\TYPO3\TYPO3CR\Domain\Repository\ContentDimensionRepository::class);
     $this->workspaceRepository = $this->objectManager->get(\TYPO3\TYPO3CR\Domain\Repository\WorkspaceRepository::class);
     $this->nodeService = $this->objectManager->get(NodeService::class);
 }
 public function setUp()
 {
     parent::setUp();
     $this->markSkippedIfNodeTypesPackageIsNotInstalled();
     $this->contextFactory = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Service\\ContextFactoryInterface');
     $contentContext = $this->contextFactory->create(array('workspaceName' => 'live'));
     $this->siteImportService = $this->objectManager->get('TYPO3\\Neos\\Domain\\Service\\SiteImportService');
     $this->siteExportService = $this->objectManager->get('TYPO3\\Neos\\Domain\\Service\\SiteExportService');
     $this->importedSite = $this->siteImportService->importFromFile(__DIR__ . '/' . $this->fixtureFileName, $contentContext);
     $this->persistenceManager->persistAll();
 }
 /**
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $this->nodeDataRepository = new NodeDataRepository();
     $this->contextFactory = $this->objectManager->get(ContextFactoryInterface::class);
     $this->nodeTypeManager = $this->objectManager->get(NodeTypeManager::class);
     $workspace = new Workspace('live');
     $this->objectManager->get(WorkspaceRepository::class)->add($workspace);
     $this->persistenceManager->persistAll();
     $context = $this->contextFactory->create(array('workspaceName' => 'live'));
     $this->rootNode = $context->getRootNode();
 }
 /**
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $this->nodeTypeManager = $this->objectManager->get(\TYPO3\TYPO3CR\Domain\Service\NodeTypeManager::class);
     $this->liveWorkspace = new Workspace('live');
     $this->workspaceRepository = $this->objectManager->get(\TYPO3\TYPO3CR\Domain\Repository\WorkspaceRepository::class);
     $this->workspaceRepository->add($this->liveWorkspace);
     $this->persistenceManager->persistAll();
     $this->contextFactory = $this->objectManager->get(\TYPO3\TYPO3CR\Domain\Service\ContextFactoryInterface::class);
     $this->context = $this->contextFactory->create(['workspaceName' => 'live']);
     $this->nodeDataRepository = $this->objectManager->get(\TYPO3\TYPO3CR\Domain\Repository\NodeDataRepository::class);
 }
 /**
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $this->nodeTypeManager = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Service\\NodeTypeManager');
     $this->liveWorkspace = new Workspace('live');
     $this->workspaceRepository = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Repository\\WorkspaceRepository');
     $this->workspaceRepository->add($this->liveWorkspace);
     $this->persistenceManager->persistAll();
     $this->contextFactory = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Service\\ContextFactoryInterface');
     $this->context = $this->contextFactory->create(array('workspaceName' => 'live'));
     $this->nodeDataRepository = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Repository\\NodeDataRepository');
 }
 /**
  * Create a context object based on the context stored in the node path
  *
  * @param string $contextArguments
  * @return Context
  */
 protected function getContext($contextArguments)
 {
     $contextConfiguration = explode(';', $contextArguments);
     $workspaceName = array_shift($contextConfiguration);
     $dimensionConfiguration = explode('&', array_shift($contextConfiguration));
     $dimensions = array();
     foreach ($contextConfiguration as $dimension) {
         list($dimensionName, $dimensionValue) = explode('=', $dimension);
         $dimensions[$dimensionName] = explode(',', $dimensionValue);
     }
     $context = $this->contextFactory->create(array('workspaceName' => $workspaceName, 'dimensions' => $dimensions, 'invisibleContentShown' => true));
     return $context;
 }
 public function setUp()
 {
     parent::setUp();
     $this->markSkippedIfNodeTypesPackageIsNotInstalled();
     $this->contextFactory = $this->objectManager->get(ContextFactoryInterface::class);
     $contentContext = $this->contextFactory->create(array('workspaceName' => 'live'));
     $siteImportService = $this->objectManager->get(SiteImportService::class);
     $siteImportService->importFromFile(__DIR__ . '/' . $this->fixtureFileName, $contentContext);
     $this->persistenceManager->persistAll();
     if ($this->nodeContextPath !== null) {
         $this->node = $this->getNodeWithContextPath($this->nodeContextPath);
     }
 }
 /**
  * @return string
  */
 public final function getList()
 {
     $context = $this->contextFactory->create(['workspaceName' => 'live']);
     $flowQuery = new FlowQuery([$context->getRootNode()]);
     $events = $flowQuery->find('[instanceof Nieuwenhuizen.BuJitsuDo:Article]')->get();
     $result['articles'] = [];
     usort($events, function (NodeInterface $a, NodeInterface $b) {
         return $this->sortNodesSelection($a, $b, 'publicationDate', false);
     });
     foreach ($events as $event) {
         $result['articles'][] = $this->buildSingleItemJson($event);
     }
     return $result;
 }
 public function setUp()
 {
     parent::setUp();
     $this->router->setRoutesConfiguration(null);
     $this->nodeDataRepository = $this->objectManager->get(NodeDataRepository::class);
     $domainRepository = $this->objectManager->get(DomainRepository::class);
     $siteRepository = $this->objectManager->get(SiteRepository::class);
     $this->contextFactory = $this->objectManager->get(ContextFactoryInterface::class);
     $contextProperties = array('workspaceName' => 'live');
     $contentContext = $this->contextFactory->create($contextProperties);
     $siteImportService = $this->objectManager->get(SiteImportService::class);
     $siteImportService->importFromFile(__DIR__ . '/../../Fixtures/NodeStructure.xml', $contentContext);
     $this->persistenceManager->persistAll();
     /** @var Domain $currentDomain */
     $currentDomain = $domainRepository->findOneByActiveRequest();
     if ($currentDomain !== null) {
         $contextProperties['currentSite'] = $currentDomain->getSite();
         $contextProperties['currentDomain'] = $currentDomain;
     } else {
         $contextProperties['currentSite'] = $siteRepository->findFirst();
     }
     $contentContext = $this->contextFactory->create($contextProperties);
     $this->contentContext = $contentContext;
     $this->propertyMapper = $this->objectManager->get(PropertyMapper::class);
     $this->viewHelper = new NodeViewHelper();
     /** @var $requestHandler FunctionalTestRequestHandler */
     $requestHandler = self::$bootstrap->getActiveRequestHandler();
     $httpRequest = $requestHandler->getHttpRequest();
     $httpRequest->setBaseUri(new Uri('http://neos.test/'));
     $controllerContext = new ControllerContext(new ActionRequest($httpRequest), $requestHandler->getHttpResponse(), new Arguments(array()), new UriBuilder());
     $this->inject($this->viewHelper, 'controllerContext', $controllerContext);
     $typoScriptObject = $this->getAccessibleMock(TemplateImplementation::class, array('dummy'), array(), '', false);
     $this->tsRuntime = new Runtime(array(), $controllerContext);
     $this->tsRuntime->pushContextArray(array('documentNode' => $this->contentContext->getCurrentSiteNode()->getNode('home'), 'alternativeDocumentNode' => $this->contentContext->getCurrentSiteNode()->getNode('home/about-us/mission')));
     $this->inject($typoScriptObject, 'tsRuntime', $this->tsRuntime);
     /** @var AbstractTemplateView|\PHPUnit_Framework_MockObject_MockObject $mockView */
     $mockView = $this->getAccessibleMock(FluidView::class, array(), array(), '', false);
     $mockView->expects($this->any())->method('getTypoScriptObject')->will($this->returnValue($typoScriptObject));
     $viewHelperVariableContainer = new ViewHelperVariableContainer();
     $viewHelperVariableContainer->setView($mockView);
     $this->inject($this->viewHelper, 'viewHelperVariableContainer', $viewHelperVariableContainer);
     $templateVariableContainer = new TemplateVariableContainer(array());
     $this->inject($this->viewHelper, 'templateVariableContainer', $templateVariableContainer);
     $this->viewHelper->setRenderChildrenClosure(function () use($templateVariableContainer) {
         $linkedNode = $templateVariableContainer->get('linkedNode');
         return $linkedNode !== null ? $linkedNode->getLabel() : '';
     });
     $this->viewHelper->initialize();
 }
 /**
  * Change the property on the given node.
  *
  * @param NodeData $node
  * @return NodeData
  */
 public function execute(NodeData $node)
 {
     $node = $this->nodeFactory->createFromNodeData($node, $this->contextFactory->create(array('workspaceName' => $node->getWorkspace()->getName(), 'invisibleContentShown' => true, 'inaccessibleContentShown' => true)));
     if (!$node) {
         return;
     }
     $column0 = $node->getPrimaryChildNode();
     if (!$column0) {
         return;
     }
     foreach ($column0->getChildNodes() as $childNode) {
         $node = $childNode->copyAfter($node, NodePaths::generateRandomNodeName());
     }
     return $node;
 }
 /**
  * {@inheritdoc}
  *
  * @param FlowQuery $flowQuery The FlowQuery object
  * @param array $arguments The arguments for this operation
  * @return void
  */
 public function evaluate(FlowQuery $flowQuery, array $arguments)
 {
     if (!isset($arguments[0]) || !is_array($arguments[0])) {
         throw new \TYPO3\Eel\FlowQuery\FlowQueryException('context() requires an array argument of context properties', 1398030427);
     }
     $output = array();
     foreach ($flowQuery->getContext() as $contextNode) {
         $contextProperties = $contextNode->getContext()->getProperties();
         $modifiedContext = $this->contextFactory->create(array_merge($contextProperties, $arguments[0]));
         $nodeInModifiedContext = $modifiedContext->getNodeByIdentifier($contextNode->getIdentifier());
         if ($nodeInModifiedContext !== null) {
             $output[$nodeInModifiedContext->getPath()] = $nodeInModifiedContext;
         }
     }
     $flowQuery->setContext(array_values($output));
 }
 /**
  * @param \TYPO3\Form\Core\Model\FinisherContext $finisherContext
  * @return void
  * @throws \TYPO3\Setup\Exception
  */
 public function importSite(\TYPO3\Form\Core\Model\FinisherContext $finisherContext)
 {
     $formValues = $finisherContext->getFormRuntime()->getFormState()->getFormValues();
     if (isset($formValues['prune']) && intval($formValues['prune']) === 1) {
         $this->nodeDataRepository->removeAll();
         $this->workspaceRepository->removeAll();
         $this->domainRepository->removeAll();
         $this->siteRepository->removeAll();
         $this->persistenceManager->persistAll();
     }
     if (!empty($formValues['packageKey'])) {
         if ($this->packageManager->isPackageAvailable($formValues['packageKey'])) {
             throw new \TYPO3\Setup\Exception(sprintf('The package key "%s" already exists.', $formValues['packageKey']), 1346759486);
         }
         $packageKey = $formValues['packageKey'];
         $siteName = $formValues['siteName'];
         $generatorService = $this->objectManager->get('TYPO3\\Neos\\Kickstarter\\Service\\GeneratorService');
         $generatorService->generateSitePackage($packageKey, $siteName);
     } elseif (!empty($formValues['site'])) {
         $packageKey = $formValues['site'];
     }
     $this->deactivateOtherSitePackages($packageKey);
     $this->packageManager->activatePackage($packageKey);
     if (!empty($packageKey)) {
         try {
             $contentContext = $this->contextFactory->create(array('workspaceName' => 'live'));
             $this->siteImportService->importFromPackage($packageKey, $contentContext);
         } catch (\Exception $exception) {
             $finisherContext->cancel();
             $this->systemLogger->logException($exception);
             throw new SetupException(sprintf('Error: During the import of the "Sites.xml" from the package "%s" an exception occurred: %s', $packageKey, $exception->getMessage()), 1351000864);
         }
     }
 }
 /**
  * @test
  */
 public function setDimensionsToEMptyArrayRemovesDimensions()
 {
     $siteImportService = $this->objectManager->get(SiteImportService::class);
     $siteImportService->importFromFile(__DIR__ . '/../Fixtures/NodeStructure.xml', $this->context);
     $this->persistenceManager->persistAll();
     $this->inject($this->contextFactory, 'contextInstances', []);
     $nodeDataRepository = $this->objectManager->get(NodeDataRepository::class);
     // The context is not important here, just a quick way to get a (live) workspace
     $context = $this->contextFactory->create();
     // The identifier comes from the Fixture.
     /** @var \TYPO3\TYPO3CR\Domain\Model\NodeData $resultingNodeData */
     $resultingNodeData = $nodeDataRepository->findOneByIdentifier('9fa376af-a1b8-83ac-bedc-9ad83c8598bc', $context->getWorkspace(true), []);
     $this->assertNotEmpty($resultingNodeData->getDimensions());
     $resultingNodeData->setDimensions([]);
     $nodeDataRepository->update($resultingNodeData);
     $this->persistenceManager->persistAll();
     $this->persistenceManager->clearState();
     $this->inject($this->contextFactory, 'contextInstances', []);
     // The context is not important here, just a quick way to get a (live) workspace
     $context = $this->contextFactory->create();
     // The identifier comes from the Fixture.
     /** @var \TYPO3\TYPO3CR\Domain\Model\NodeData $resultingNodeData */
     $resultingNodeData = $nodeDataRepository->findOneByIdentifier('9fa376af-a1b8-83ac-bedc-9ad83c8598bc', $context->getWorkspace(true), []);
     $this->assertEmpty($resultingNodeData->getDimensions());
 }
 /**
  * Create a node for the given NodeData, given that it is a variant of the current node
  *
  * @param NodeData $nodeData
  * @return Node
  */
 protected function createNodeForVariant($nodeData)
 {
     $contextProperties = $this->context->getProperties();
     $contextProperties['dimensions'] = $nodeData->getDimensionValues();
     unset($contextProperties['targetDimensions']);
     $adjustedContext = $this->contextFactory->create($contextProperties);
     return $this->nodeFactory->createFromNodeData($nodeData, $adjustedContext);
 }
 /**
  * Flush the node changes and reset the persistence manager and node data registry
  *
  * @return void
  */
 public function flushNodeChanges()
 {
     $nodeDataRepository = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Repository\\NodeDataRepository');
     $nodeDataRepository->flushNodeRegistry();
     $this->persistenceManager->persistAll();
     $this->persistenceManager->clearState();
     $this->contextFactory->reset();
 }
 /**
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $workspaceRepository = $this->objectManager->get(\TYPO3\TYPO3CR\Domain\Repository\WorkspaceRepository::class);
     $workspaceRepository->add(new Workspace('live'));
     $this->persistenceManager->persistAll();
     $this->contextFactory = $this->objectManager->get(\TYPO3\TYPO3CR\Domain\Service\ContextFactoryInterface::class);
     $this->context = $this->contextFactory->create(array('workspaceName' => 'live'));
     $siteImportService = $this->objectManager->get(\TYPO3\Neos\Domain\Service\SiteImportService::class);
     $siteImportService->importFromFile(__DIR__ . '/Fixtures/SortableNodes.xml', $this->context);
     $this->persistenceManager->persistAll();
     $this->persistenceManager->clearState();
     $this->inject($this->contextFactory, 'contextInstances', array());
     // The context is not important here, just a quick way to get a (live) workspace
     //        $context = $this->contextFactory->create();
     $this->nodeDataRepository = $this->objectManager->get(\TYPO3\TYPO3CR\Domain\Repository\NodeDataRepository::class);
 }
 /**
  * Flush the node changes and reset the persistence manager and node data registry
  *
  * @return void
  */
 public function flushNodeChanges()
 {
     $nodeDataRepository = $this->objectManager->get(NodeDataRepository::class);
     $nodeDataRepository->flushNodeRegistry();
     $this->persistenceManager->persistAll();
     $this->persistenceManager->clearState();
     $this->contextFactory->reset();
 }
 /**
  * Returns the node this even refers to, if it can be resolved.
  *
  * It might happen that, if this event refers to a node contained in a site which is not available anymore,
  * Doctrine's proxy class of the Site domain model will fail with an EntityNotFoundException. We catch this
  * case and return NULL.
  *
  * @return NodeInterface
  */
 public function getNode()
 {
     try {
         $context = $this->contextFactory->create(array('workspaceName' => $this->userService->getUserWorkspace()->getName(), 'dimensions' => $this->dimension, 'currentSite' => $this->getCurrentSite(), 'invisibleContentShown' => true));
         return $context->getNodeByIdentifier($this->nodeIdentifier);
     } catch (EntityNotFoundException $e) {
         return null;
     }
 }
Exemple #22
0
 /**
  * Returns the NodeData instance with the given identifier from the target workspace.
  * If no NodeData instance is found, NULL is returned.
  *
  * @param NodeInterface $node
  * @param Workspace $targetWorkspace
  * @return NodeData
  */
 protected function findNodeDataInTargetWorkspace(NodeInterface $node, Workspace $targetWorkspace)
 {
     $properties = $node->getContext()->getProperties();
     $properties['workspaceName'] = $targetWorkspace->getName();
     $targetWorkspaceContext = $this->contextFactory->create($properties);
     $targetNodeInstance = $targetWorkspaceContext->getNodeByIdentifier($node->getIdentifier());
     $targetNode = $targetNodeInstance !== NULL ? $targetNodeInstance->getNodeData() : NULL;
     return $targetNode;
 }
 /**
  * Creates a new content context based on the given workspace and the NodeData object.
  *
  * @param Workspace $workspace Workspace for the new context
  * @param array $dimensionValues The dimension values for the new context
  * @param array $contextProperties Additional pre-defined context properties
  * @return Context
  */
 protected function createContext(Workspace $workspace, array $dimensionValues, array $contextProperties = array())
 {
     $presetsMatchingDimensionValues = $this->contentDimensionPresetSource->findPresetsByTargetValues($dimensionValues);
     $dimensions = array_map(function ($preset) {
         return $preset['values'];
     }, $presetsMatchingDimensionValues);
     $contextProperties += array('workspaceName' => $workspace->getName(), 'inaccessibleContentShown' => true, 'invisibleContentShown' => true, 'removedContentShown' => true, 'dimensions' => $dimensions);
     return $this->contextFactory->create($contextProperties);
 }
 /**
  * @param string $property
  * @return NodeInterface|null
  */
 protected function findProfileNode($property)
 {
     $contentContext = $this->contextFactory->create(array());
     $result = $this->nodeSearchService->findByProperties($property, array('BuJitsuDo.Authentication:Person'), $contentContext);
     if ($result === array()) {
         return NULL;
     }
     return array_shift($result);
 }
 /**
  * Create a Context for a workspace given by name to be used in this controller.
  *
  * @param string $workspaceName Name of the current workspace
  * @return \TYPO3\TYPO3CR\Domain\Service\Context
  */
 protected function createContext($workspaceName)
 {
     $contextProperties = array('workspaceName' => $workspaceName);
     $currentDomain = $this->domainRepository->findOneByActiveRequest();
     if ($currentDomain !== null) {
         $contextProperties['currentSite'] = $currentDomain->getSite();
         $contextProperties['currentDomain'] = $currentDomain;
     }
     return $this->contextFactory->create($contextProperties);
 }
 /**
  * @param string $workspaceName
  */
 protected function indexWorkspace($workspaceName)
 {
     $dimensionCombinations = $this->nodeIndexer->calculateDimensionCombinations();
     if ($dimensionCombinations !== array()) {
         foreach ($dimensionCombinations as $combination) {
             $context = $this->contextFactory->create(array('workspaceName' => $workspaceName, 'dimensions' => $combination));
             $rootNode = $context->getRootNode();
             $this->traverseNodes($rootNode);
             $this->outputLine('Workspace "' . $workspaceName . '" and dimensions "' . json_encode($combination) . '" done. (Indexed ' . $this->indexedNodes . ' nodes)');
             $this->indexedNodes = 0;
         }
     } else {
         $context = $this->contextFactory->create(array('workspaceName' => $workspaceName));
         $rootNode = $context->getRootNode();
         $this->traverseNodes($rootNode);
         $this->outputLine('Workspace "' . $workspaceName . '" without dimensions done. (Indexed ' . $this->indexedNodes . ' nodes)');
         $this->indexedNodes = 0;
     }
 }
 public function setUp()
 {
     parent::setUp();
     $this->workspaceRepository = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Repository\\WorkspaceRepository');
     $liveWorkspace = new \TYPO3\TYPO3CR\Domain\Model\Workspace("live");
     $this->workspaceRepository->add($liveWorkspace);
     $this->nodeTypeManager = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Service\\NodeTypeManager');
     $this->contextFactory = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Service\\ContextFactoryInterface');
     $this->context = $this->contextFactory->create(array('workspaceName' => 'live', 'dimensions' => array('language' => array('de'))));
     $this->nodeDataRepository = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Repository\\NodeDataRepository');
     $this->queryBuilder = $this->objectManager->get('Flowpack\\ElasticSearch\\ContentRepositoryAdaptor\\Eel\\ElasticSearchQueryBuilder');
     $this->queryBuilder->log();
     // we need to make sure that the index will be prefixed with an unique name. so we add a sleet as it is not
     // possible right now to set the index name
     sleep(4);
     $this->nodeIndexCommandController = $this->objectManager->get('Flowpack\\ElasticSearch\\ContentRepositoryAdaptor\\Command\\NodeIndexCommandController');
     $this->nodeIndexCommandController->buildCommand();
     $this->createNodesForNodeSearchTest();
 }
 /**
  * @param Context $context
  * @return NodeInterface
  * @throws NodeTypeNotFoundException
  * @throws NodeConfigurationException
  */
 public function findOrCreateMetaDataRootNode(Context $context)
 {
     if ($this->metaDataRootNode instanceof NodeInterface) {
         return $this->metaDataRootNode;
     }
     $metaDataRootNodeData = $this->metaDataRepository->findOneByPath('/' . MetaDataRepository::METADATA_ROOT_NODE_NAME, $context->getWorkspace());
     if ($metaDataRootNodeData !== null) {
         $metaDataRootNode = $this->nodeFactory->createFromNodeData($metaDataRootNodeData, $context);
         return $metaDataRootNode;
     }
     $nodeTemplate = new NodeTemplate();
     $nodeTemplate->setNodeType($this->nodeTypeManager->getNodeType('unstructured'));
     $nodeTemplate->setName(MetaDataRepository::METADATA_ROOT_NODE_NAME);
     $context = $this->contextFactory->create(['workspaceName' => 'live']);
     $rootNode = $context->getRootNode();
     $this->metaDataRootNode = $rootNode->createNodeFromTemplate($nodeTemplate);
     $this->persistenceManager->persistAll();
     return $this->metaDataRootNode;
 }
 /**
  * @test
  */
 public function adoptNodeWithExistingNodeMatchingTargetDimensionValuesWillReuseNode()
 {
     $this->contentDimensionRepository->setDimensionsConfiguration(['test' => ['default' => 'a']]);
     $variantContextA = $this->contextFactory->create(['dimensions' => ['test' => ['a']], 'targetDimensions' => ['test' => 'a']]);
     $variantContextB = $this->contextFactory->create(['dimensions' => ['test' => ['b', 'a']], 'targetDimensions' => ['test' => 'b']]);
     $variantContextA->getRootNode()->getNodeData()->createNodeData('test', null, null, $variantContextA->getWorkspace(), ['test' => ['a', 'b']]);
     $this->persistenceManager->persistAll();
     $variantNodeA = $variantContextA->getRootNode()->getNode('test');
     $variantNodeB = $variantContextB->adoptNode($variantNodeA);
     $this->assertSame($variantNodeA->getDimensions(), $variantNodeB->getDimensions());
 }
 /**
  * Imports one or multiple sites from the XML file at $pathAndFilename
  *
  * @param string $pathAndFilename
  * @return Site The imported site
  * @throws UnknownPackageException|InvalidPackageStateException|NeosException
  */
 public function importFromFile($pathAndFilename)
 {
     /** @var Site $importedSite */
     $site = NULL;
     $this->eventEmittingService->withoutEventLog(function () use($pathAndFilename, &$site) {
         $xmlReader = new \XMLReader();
         $xmlReader->open($pathAndFilename, NULL, LIBXML_PARSEHUGE);
         if ($this->workspaceRepository->findOneByName('live') === NULL) {
             $this->workspaceRepository->add(new Workspace('live'));
         }
         $rootNode = $this->contextFactory->create()->getRootNode();
         $this->persistenceManager->persistAll();
         $sitesNode = $rootNode->getNode('/sites');
         if ($sitesNode === NULL) {
             $sitesNode = $rootNode->createSingleNode('sites');
         }
         while ($xmlReader->read()) {
             if ($xmlReader->nodeType != \XMLReader::ELEMENT || $xmlReader->name !== 'site') {
                 continue;
             }
             $isLegacyFormat = $xmlReader->getAttribute('nodeName') !== NULL && $xmlReader->getAttribute('state') === NULL && $xmlReader->getAttribute('siteResourcesPackageKey') === NULL;
             if ($isLegacyFormat) {
                 $site = $this->legacySiteImportService->importSitesFromFile($pathAndFilename);
                 return;
             }
             $site = $this->getSiteByNodeName($xmlReader->getAttribute('siteNodeName'));
             $site->setName($xmlReader->getAttribute('name'));
             $site->setState((int) $xmlReader->getAttribute('state'));
             $siteResourcesPackageKey = $xmlReader->getAttribute('siteResourcesPackageKey');
             if (!$this->packageManager->isPackageAvailable($siteResourcesPackageKey)) {
                 throw new UnknownPackageException(sprintf('Package "%s" specified in the XML as site resources package does not exist.', $siteResourcesPackageKey), 1303891443);
             }
             if (!$this->packageManager->isPackageActive($siteResourcesPackageKey)) {
                 throw new InvalidPackageStateException(sprintf('Package "%s" specified in the XML as site resources package is not active.', $siteResourcesPackageKey), 1303898135);
             }
             $site->setSiteResourcesPackageKey($siteResourcesPackageKey);
             $rootNode = $this->contextFactory->create()->getRootNode();
             // We fetch the workspace to be sure it's known to the persistence manager and persist all
             // so the workspace and site node are persisted before we import any nodes to it.
             $rootNode->getContext()->getWorkspace();
             $this->persistenceManager->persistAll();
             $sitesNode = $rootNode->getNode('/sites');
             if ($sitesNode === NULL) {
                 $sitesNode = $rootNode->createNode('sites');
             }
             $this->nodeImportService->import($xmlReader, $sitesNode->getPath(), dirname($pathAndFilename) . '/Resources');
         }
     });
     if ($site === NULL) {
         throw new NeosException(sprintf('The XML file did not contain a valid site node.'), 1418999522);
     }
     $this->emitSiteImported($site);
     return $site;
 }