/**
  * @param string $searchWord
  * @param Site $selectedSite
  * @return void
  */
 public function searchForNodeAction($searchWord, Site $selectedSite = NULL)
 {
     $documentNodeTypes = $this->nodeTypeManager->getSubNodeTypes('TYPO3.Neos:Document');
     $shortcutNodeType = $this->nodeTypeManager->getNodeType('TYPO3.Neos:Shortcut');
     $nodeTypes = array_diff($documentNodeTypes, array($shortcutNodeType));
     $sites = array();
     $activeSites = $this->siteRepository->findOnline();
     foreach ($selectedSite ? array($selectedSite) : $activeSites as $site) {
         /** @var Site $site */
         $contextProperties = array('workspaceName' => 'live', 'currentSite' => $site);
         $contentDimensionPresets = $this->contentDimensionPresetSource->getAllPresets();
         if (count($contentDimensionPresets) > 0) {
             $mergedContentDimensions = array();
             foreach ($contentDimensionPresets as $contentDimensionIdentifier => $contentDimension) {
                 $mergedContentDimensions[$contentDimensionIdentifier] = array($contentDimension['default']);
                 foreach ($contentDimension['presets'] as $contentDimensionPreset) {
                     $mergedContentDimensions[$contentDimensionIdentifier] = array_merge($mergedContentDimensions[$contentDimensionIdentifier], $contentDimensionPreset['values']);
                 }
                 $mergedContentDimensions[$contentDimensionIdentifier] = array_values(array_unique($mergedContentDimensions[$contentDimensionIdentifier]));
             }
             $contextProperties['dimensions'] = $mergedContentDimensions;
         }
         /** @var ContentContext $liveContext */
         $liveContext = $this->contextFactory->create($contextProperties);
         $firstActiveDomain = $site->getFirstActiveDomain();
         $nodes = $this->nodeSearchService->findByProperties($searchWord, $nodeTypes, $liveContext, $liveContext->getCurrentSiteNode());
         if (count($nodes) > 0) {
             $sites[$site->getNodeName()] = array('site' => $site, 'domain' => $firstActiveDomain ? $firstActiveDomain->getHostPattern() : $this->request->getHttpRequest()->getUri()->getHost(), 'nodes' => $nodes);
         }
     }
     $this->view->assignMultiple(array('searchWord' => $searchWord, 'protocol' => $this->request->getHttpRequest()->getUri()->getScheme(), 'selectedSite' => $selectedSite, 'sites' => $sites, 'activeSites' => $activeSites));
 }
 /**
  * Build a list of sites
  *
  * @param ControllerContext $controllerContext
  * @return array
  */
 public function buildSiteList(ControllerContext $controllerContext)
 {
     $requestUriHost = $controllerContext->getRequest()->getHttpRequest()->getUri()->getHost();
     $domainsFound = false;
     $sites = array();
     foreach ($this->siteRepository->findOnline() as $site) {
         $uri = null;
         $active = false;
         /** @var $site Site */
         if ($site->hasActiveDomains()) {
             $activeHostPatterns = $site->getActiveDomains()->map(function ($domain) {
                 return $domain->getHostPattern();
             })->toArray();
             $active = in_array($requestUriHost, $activeHostPatterns, true);
             if ($active) {
                 $uri = $controllerContext->getUriBuilder()->reset()->setCreateAbsoluteUri(true)->uriFor('index', array(), 'Backend\\Backend', 'TYPO3.Neos');
             } else {
                 $uri = $controllerContext->getUriBuilder()->reset()->uriFor('switchSite', array('site' => $site), 'Backend\\Backend', 'TYPO3.Neos');
             }
             $domainsFound = true;
         }
         $sites[] = array('name' => $site->getName(), 'nodeName' => $site->getNodeName(), 'uri' => $uri, 'active' => $active);
     }
     if ($domainsFound === false) {
         $uri = $controllerContext->getUriBuilder()->reset()->setCreateAbsoluteUri(true)->uriFor('index', array(), 'Backend\\Backend', 'TYPO3.Neos');
         $sites[0]['uri'] = $uri;
     }
     return $sites;
 }
 /**
  * Creates a big collection of node for performance benchmarking
  * @param string $siteNode
  * @param string $preset
  */
 public function nodesCommand($siteNode, $preset)
 {
     if (!isset($this->presets[$preset])) {
         $this->outputLine('Error: Invalid preset');
         $this->quit(1);
     }
     $preset = $this->presets[$preset];
     /** @var Site $currentSite */
     $currentSite = $this->siteRepository->findOneByNodeName($siteNode);
     if ($currentSite === null) {
         $this->outputLine('Error: No site for exporting found');
         $this->quit(1);
     }
     /** @var ContentContext $contentContext */
     $contentContext = $this->createContext($currentSite, 'live');
     $workspace = 'live';
     if ($this->workspaceRepository->findByName($workspace)->count() === 0) {
         $this->outputLine('Workspace "%s" does not exist', array($workspace));
         $this->quit(1);
     }
     /** @var Node $siteNode */
     $siteNode = $contentContext->getCurrentSiteNode();
     if ($siteNode === null) {
         $this->outputLine('Error: No site root node');
         $this->quit(1);
     }
     $preset = new PresetDefinition($siteNode, $preset);
     $generator = new NodesGenerator($preset);
     $generator->generate();
 }
示例#4
0
 public function isActive(NodeInterface $siteNode)
 {
     if ($siteModel = $this->siteRepository->findOneByNodeName($siteNode->getName())) {
         return $siteModel->isOnline();
     }
     throw new \RuntimeException('Could not find a site for the given site node', 1473366137);
 }
 /**
  * Add a domain record
  *
  * @param string $siteNodeName The nodeName of the site rootNode, e.g. "neostypo3org"
  * @param string $hostPattern The host pattern to match on, e.g. "neos.typo3.org"
  * @param string $scheme The scheme for linking (http/https)
  * @param integer $port The port for linking (0-49151)
  * @return void
  */
 public function addCommand($siteNodeName, $hostPattern, $scheme = null, $port = null)
 {
     $site = $this->siteRepository->findOneByNodeName($siteNodeName);
     if (!$site instanceof Site) {
         $this->outputLine('<error>No site found with nodeName "%s".</error>', array($siteNodeName));
         $this->quit(1);
     }
     $domains = $this->domainRepository->findByHostPattern($hostPattern);
     if ($domains->count() > 0) {
         $this->outputLine('<error>The host pattern "%s" is not unique.</error>', array($hostPattern));
         $this->quit(1);
     }
     $domain = new Domain();
     if ($scheme !== null) {
         $domain->setScheme($scheme);
     }
     if ($port !== null) {
         $domain->setPort($port);
     }
     $domain->setSite($site);
     $domain->setHostPattern($hostPattern);
     $domainValidator = $this->validatorResolver->getBaseValidatorConjunction(Domain::class);
     $result = $domainValidator->validate($domain);
     if ($result->hasErrors()) {
         foreach ($result->getFlattenedErrors() as $propertyName => $errors) {
             $firstError = array_pop($errors);
             $this->outputLine('<error>Validation failed for "' . $propertyName . '": ' . $firstError . '</error>');
             $this->quit(1);
         }
     }
     $this->domainRepository->add($domain);
     $this->outputLine('Domain created.');
 }
 /**
  * Remove all nodes, workspaces, domains and sites.
  *
  * @return void
  */
 public function pruneAll()
 {
     $sites = $this->siteRepository->findAll();
     $this->nodeDataRepository->removeAll();
     $this->workspaceRepository->removeAll();
     $this->domainRepository->removeAll();
     $this->siteRepository->removeAll();
     foreach ($sites as $site) {
         $this->emitSitePruned($site);
     }
 }
 /**
  * Default action, displays the login screen
  *
  * @param string $username Optional: A username to pre-fill into the username field
  * @param boolean $unauthorized
  * @return void
  */
 public function indexAction($username = null, $unauthorized = false)
 {
     if ($this->securityContext->getInterceptedRequest() || $unauthorized) {
         $this->response->setStatus(401);
     }
     if ($this->authenticationManager->isAuthenticated()) {
         $this->redirect('index', 'Backend\\Backend');
     }
     $currentDomain = $this->domainRepository->findOneByActiveRequest();
     $currentSite = $currentDomain !== null ? $currentDomain->getSite() : $this->siteRepository->findFirstOnline();
     $this->view->assignMultiple(array('username' => $username, 'site' => $currentSite));
 }
 /**
  * Additionally add the current site and domain to the Context properties.
  *
  * {@inheritdoc}
  */
 protected function prepareContextProperties($workspaceName, \TYPO3\Flow\Property\PropertyMappingConfigurationInterface $configuration = null, array $dimensions = null)
 {
     $contextProperties = parent::prepareContextProperties($workspaceName, $configuration, $dimensions);
     $currentDomain = $this->domainRepository->findOneByActiveRequest();
     if ($currentDomain !== null) {
         $contextProperties['currentSite'] = $currentDomain->getSite();
         $contextProperties['currentDomain'] = $currentDomain;
     } else {
         $contextProperties['currentSite'] = $this->siteRepository->findFirstOnline();
     }
     return $contextProperties;
 }
 /**
  * @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);
         }
     }
 }
 /**
  * Upload a new image, and return its metadata.
  *
  * Depending on the $metadata argument it will return asset metadata for the AssetEditor
  * or image metadata for the ImageEditor
  *
  * @param Asset $asset
  * @param string $metadata Type of metadata to return ("Asset" or "Image")
  * @return string
  */
 public function uploadAssetAction(Asset $asset, $metadata)
 {
     $this->response->setHeader('Content-Type', 'application/json');
     /** @var Site $currentSite */
     $currentSite = $this->siteRepository->findOneByNodeName($this->request->getInternalArgument('__siteNodeName'));
     if ($currentSite !== null && $currentSite->getAssetCollection() !== null) {
         $currentSite->getAssetCollection()->addAsset($asset);
         $this->assetCollectionRepository->update($currentSite->getAssetCollection());
     }
     switch ($metadata) {
         case 'Asset':
             $result = $this->getAssetProperties($asset);
             if ($this->persistenceManager->isNewObject($asset)) {
                 $this->assetRepository->add($asset);
             }
             break;
         case 'Image':
             $result = $this->getImageInterfacePreviewData($asset);
             if ($this->persistenceManager->isNewObject($asset)) {
                 $this->imageRepository->add($asset);
             }
             break;
         default:
             $this->response->setStatus(400);
             $result = array('error' => 'Invalid "metadata" type: ' . $metadata);
     }
     return json_encode($result);
 }
 /**
  * Prevents invalid calls to the site respository in case the site data property is not available.
  *
  * @return null|object
  */
 protected function getCurrentSite()
 {
     if (!isset($this->data['site']) || $this->data['site'] === null) {
         return null;
     }
     return $this->siteRepository->findByIdentifier($this->data['site']);
 }
 /**
  * Deactivates a site
  *
  * @param Site $site Site to deactivate
  * @return void
  */
 public function deactivateSiteAction(Site $site)
 {
     $site->setState($site::STATE_OFFLINE);
     $this->siteRepository->update($site);
     $this->addFlashMessage('The site "%s" has been deactivated.', 'Site deactivated', Message::SEVERITY_OK, array(htmlspecialchars($site->getName())), 1412372975);
     $this->unsetLastVisitedNodeAndRedirect('index');
 }
 /**
  * Setup the most commonly used mocks and a real FrontendRoutePartHandler. The mock objects created by this function
  * will not be sufficient for most tests, but they are the lowest common denominator.
  *
  * @return void
  */
 protected function setUp()
 {
     $this->routePartHandler = new FrontendNodeRoutePartHandler();
     $this->routePartHandler->setName('node');
     // The mockContextFactory is configured to return the last mock context which has been built with buildMockContext():
     $mockContextFactory = $this->getMock('TYPO3\\TYPO3CR\\Domain\\Service\\ContextFactory', array('create'));
     $mockContextFactory->mockContext = null;
     $mockContextFactory->expects($this->any())->method('create')->will($this->returnCallback(function ($contextProperties) use($mockContextFactory) {
         if (isset($contextProperties['currentSite'])) {
             $mockContextFactory->mockContext->mockSite = $contextProperties['currentSite'];
         }
         if (isset($contextProperties['currentDomain'])) {
             $mockContextFactory->mockContext->mockDomain = $contextProperties['currentDomain'];
         }
         if (isset($contextProperties['dimensions'])) {
             $mockContextFactory->mockContext->mockDimensions = $contextProperties['dimensions'];
         }
         if (isset($contextProperties['targetDimensions'])) {
             $mockContextFactory->mockContext->mockTargetDimensions = $contextProperties['targetDimensions'];
         }
         return $mockContextFactory->mockContext;
     }));
     $this->mockContextFactory = $mockContextFactory;
     $this->inject($this->routePartHandler, 'contextFactory', $this->mockContextFactory);
     $this->mockSystemLogger = $this->getMock('TYPO3\\Flow\\Log\\SystemLoggerInterface');
     $this->inject($this->routePartHandler, 'systemLogger', $this->mockSystemLogger);
     $this->mockDomainRepository = $this->getMockBuilder('TYPO3\\Neos\\Domain\\Repository\\DomainRepository')->disableOriginalConstructor()->getMock();
     $this->inject($this->routePartHandler, 'domainRepository', $this->mockDomainRepository);
     $this->mockSiteRepository = $this->getMockBuilder('TYPO3\\Neos\\Domain\\Repository\\SiteRepository')->disableOriginalConstructor()->getMock();
     $this->mockSiteRepository->expects($this->any())->method('findFirstOnline')->will($this->returnValue(null));
     $this->inject($this->routePartHandler, 'siteRepository', $this->mockSiteRepository);
     $this->contentDimensionPresetSource = new ConfigurationContentDimensionPresetSource();
     $this->contentDimensionPresetSource->setConfiguration(array());
     $this->inject($this->routePartHandler, 'contentDimensionPresetSource', $this->contentDimensionPresetSource);
 }
 /**
  * Display a list of available sites
  *
  * @return void
  */
 public function listCommand()
 {
     $sites = $this->siteRepository->findAll();
     if ($sites->count() === 0) {
         $this->outputLine('No sites available');
         $this->quit(0);
     }
     $longestSiteName = 4;
     $longestNodeName = 9;
     $longestSiteResource = 17;
     $availableSites = array();
     foreach ($sites as $site) {
         /** @var \TYPO3\Neos\Domain\Model\Site $site */
         array_push($availableSites, array('name' => $site->getName(), 'nodeName' => $site->getNodeName(), 'siteResourcesPackageKey' => $site->getSiteResourcesPackageKey()));
         if (strlen($site->getName()) > $longestSiteName) {
             $longestSiteName = strlen($site->getName());
         }
         if (strlen($site->getNodeName()) > $longestNodeName) {
             $longestNodeName = strlen($site->getNodeName());
         }
         if (strlen($site->getSiteResourcesPackageKey()) > $longestSiteResource) {
             $longestSiteResource = strlen($site->getSiteResourcesPackageKey());
         }
     }
     $this->outputLine();
     $this->outputLine(' ' . str_pad('Name', $longestSiteName + 15) . str_pad('Node name', $longestNodeName + 15) . 'Resources package');
     $this->outputLine(str_repeat('-', $longestSiteName + $longestNodeName + $longestSiteResource + 15 + 15 + 2));
     foreach ($availableSites as $site) {
         $this->outputLine(' ' . str_pad($site['name'], $longestSiteName + 15) . str_pad($site['nodeName'], $longestNodeName + 15) . $site['siteResourcesPackageKey']);
     }
     $this->outputLine();
 }
 /**
  * @param AssetCollection $assetCollection
  * @return void
  */
 public function deleteAssetCollectionAction(AssetCollection $assetCollection)
 {
     foreach ($this->siteRepository->findByAssetCollection($assetCollection) as $site) {
         $site->setAssetCollection(null);
         $this->siteRepository->update($site);
     }
     parent::deleteAssetCollectionAction($assetCollection);
 }
 /**
  * Show a list of sites and assigned GA profiles
  *
  * @return void
  */
 public function indexAction()
 {
     $siteConfigurations = $this->siteConfigurationRepository->findAll();
     $sites = $this->siteRepository->findAll();
     $sitesWithConfiguration = array();
     foreach ($sites as $site) {
         $item = array('site' => $site);
         foreach ($siteConfigurations as $siteConfiguration) {
             if ($siteConfiguration->getSite() === $site) {
                 $item['configuration'] = $siteConfiguration;
             }
         }
         $sitesWithConfiguration[] = $item;
     }
     $this->view->assign('sitesWithConfiguration', $sitesWithConfiguration);
     $profiles = $this->getGroupedProfiles();
     $this->view->assign('groupedProfiles', $profiles);
 }
 /**
  * Add a domain record
  *
  * @param string $siteNodeName The nodeName of the site rootNode, e.g. "neostypo3org"
  * @param string $hostPattern The host pattern to match on, e.g. "neos.typo3.org"
  * @return void
  */
 public function addCommand($siteNodeName, $hostPattern)
 {
     $site = $this->siteRepository->findOneByNodeName($siteNodeName);
     if (!$site instanceof Site) {
         $this->outputLine('No site found with nodeName "%s".', array($siteNodeName));
         $this->quit(1);
     }
     $domains = $this->domainRepository->findByHostPattern($hostPattern);
     if ($domains->count() > 0) {
         $this->outputLine('The host pattern "%s" is not unique.', array($hostPattern));
         $this->quit(1);
     }
     $domain = new Domain();
     $domain->setSite($site);
     $domain->setHostPattern($hostPattern);
     $this->domainRepository->add($domain);
     $this->outputLine('Domain created.');
 }
 /**
  * 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->siteRepository->findByIdentifier($this->data['site']), 'invisibleContentShown' => true));
         return $context->getNodeByIdentifier($this->nodeIdentifier);
     } catch (EntityNotFoundException $e) {
         return null;
     }
 }
 /**
  * Create a ContentContext based on the given workspace name
  *
  * @param string $workspaceName Name of the workspace to set for the context
  * @param array $dimensions Optional list of dimensions and their values which should be set
  * @return \TYPO3\Neos\Domain\Service\ContentContext
  */
 protected function createContentContext($workspaceName, array $dimensions = array())
 {
     $contextProperties = array('workspaceName' => $workspaceName, 'invisibleContentShown' => true, 'inaccessibleContentShown' => true);
     if ($dimensions !== array()) {
         $contextProperties['dimensions'] = $dimensions;
         $contextProperties['targetDimensions'] = array_map(function ($dimensionValues) {
             return array_shift($dimensionValues);
         }, $dimensions);
     }
     $currentDomain = $this->_domainRepository->findOneByActiveRequest();
     if ($currentDomain !== null) {
         $contextProperties['currentSite'] = $currentDomain->getSite();
         $contextProperties['currentDomain'] = $currentDomain;
     } else {
         $contextProperties['currentSite'] = $this->_siteRepository->findFirstOnline();
     }
     return $this->_contextFactory->create($contextProperties);
 }
 /**
  * @param ACLCheckerDto $dto
  * @return array
  */
 protected function getNodes(ACLCheckerDto $dto)
 {
     $context = $this->createContext();
     $site = $this->siteRepository->findFirstOnline();
     $startNode = $context->getNode('/sites/' . $site->getNodeName());
     $roles = $this->getRolesByDto($dto);
     $nodes = [];
     $this->getChildNodeData($nodes, $startNode, $roles, $dto->getNodeTreeLoadingDepth());
     return $nodes;
 }
 /**
  * Updates or creates a site with the given $siteNodeName
  *
  * @param string $siteNodeName
  * @return Site
  */
 protected function getSiteByNodeName($siteNodeName)
 {
     $site = $this->siteRepository->findOneByNodeName($siteNodeName);
     if ($site === null) {
         $site = new Site($siteNodeName);
         $this->siteRepository->add($site);
         return $site;
     }
     $this->siteRepository->update($site);
     return $site;
 }
 /**
  * Deletes a domain attached to a site
  *
  * @param Domain $domain A domain to delete
  * @Flow\IgnoreValidation("$domain")
  * @return void
  */
 public function deleteDomainAction(Domain $domain)
 {
     $site = $domain->getSite();
     if ($site->getPrimaryDomain() === $domain) {
         $site->setPrimaryDomain(null);
         $this->siteRepository->update($site);
     }
     $this->domainRepository->remove($domain);
     $this->addFlashMessage('The domain "%s" has been deleted.', 'Domain deleted', Message::SEVERITY_OK, array(htmlspecialchars($domain)), 1412373310);
     $this->unsetLastVisitedNodeAndRedirect('edit', null, null, array('site' => $site));
 }
 /**
  * Deactivate a site
  *
  * This command deactivates the specified site.
  *
  * @param string $siteNode The node name of the site to deactivate
  * @return void
  */
 public function deactivateCommand($siteNode)
 {
     $site = $this->siteRepository->findOneByNodeName($siteNode);
     if (!$site instanceof Site) {
         $this->outputLine('<error>Site not found.</error>');
         $this->quit(1);
     }
     $site->setState(Site::STATE_OFFLINE);
     $this->siteRepository->update($site);
     $this->outputLine('Site deactivated.');
 }
 /**
  * Determines the current domain and site from the request and sets the resulting values as
  * as defaults.
  *
  * @param array $defaultContextProperties
  * @return array
  */
 protected function setDefaultSiteAndDomainFromCurrentRequest(array $defaultContextProperties)
 {
     $currentDomain = $this->domainRepository->findOneByActiveRequest();
     if ($currentDomain !== null) {
         $defaultContextProperties['currentSite'] = $currentDomain->getSite();
         $defaultContextProperties['currentDomain'] = $currentDomain;
     } else {
         $defaultContextProperties['currentSite'] = $this->siteRepository->findFirstOnline();
     }
     return $defaultContextProperties;
 }
 /**
  * Default action, displays the login screen
  *
  * @param string $username Optional: A username to pre-fill into the username field
  * @param boolean $unauthorized
  * @return void
  */
 public function indexAction($username = null, $unauthorized = false)
 {
     if ($this->securityContext->getInterceptedRequest() || $unauthorized) {
         $this->response->setStatus(401);
     }
     if ($this->authenticationManager->isAuthenticated()) {
         $this->redirect('index', 'Backend\\Backend');
     }
     $currentDomain = $this->domainRepository->findOneByActiveRequest();
     $currentSite = $currentDomain !== null ? $currentDomain->getSite() : $this->siteRepository->findDefault();
     $this->view->assignMultiple(['styles' => array_filter($this->settings['userInterface']['backendLoginForm']['stylesheets']), 'username' => $username, 'site' => $currentSite]);
 }
 /**
  * Create a ContentContext to be used for the backend redirects.
  *
  * @param string $workspaceName
  * @return ContentContext
  */
 protected function createContext($workspaceName)
 {
     $contextProperties = array('workspaceName' => $workspaceName, 'invisibleContentShown' => true, 'inaccessibleContentShown' => true);
     $currentDomain = $this->domainRepository->findOneByActiveRequest();
     if ($currentDomain !== null) {
         $contextProperties['currentSite'] = $currentDomain->getSite();
         $contextProperties['currentDomain'] = $currentDomain;
     } else {
         $contextProperties['currentSite'] = $this->siteRepository->findFirstOnline();
     }
     return $this->contextFactory->create($contextProperties);
 }
 /**
  * Sets context properties like "invisibleContentShown" according to the workspace (live or not) and returns a
  * ContentContext object.
  *
  * @param string $workspaceName Name of the workspace to use in the context
  * @param array $dimensionsAndDimensionValues An array of dimension names (index) and their values (array of strings). See also: ContextFactory
  * @return ContentContext
  */
 protected function buildContextFromWorkspaceNameAndDimensions($workspaceName, array $dimensionsAndDimensionValues)
 {
     $contextProperties = array('workspaceName' => $workspaceName, 'invisibleContentShown' => $workspaceName !== 'live', 'inaccessibleContentShown' => $workspaceName !== 'live', 'dimensions' => $dimensionsAndDimensionValues);
     $currentDomain = $this->domainRepository->findOneByActiveRequest();
     if ($currentDomain !== NULL) {
         $contextProperties['currentSite'] = $currentDomain->getSite();
         $contextProperties['currentDomain'] = $currentDomain;
     } else {
         $contextProperties['currentSite'] = $this->siteRepository->findFirstOnline();
     }
     return $this->contextFactory->create($contextProperties);
 }
 /**
  * Build a list of sites
  *
  * @param \TYPO3\Flow\Mvc\Controller\ControllerContext $controllerContext
  * @return array
  */
 public function buildSiteList(ControllerContext $controllerContext)
 {
     $requestUri = $controllerContext->getRequest()->getHttpRequest()->getUri();
     $baseUri = $controllerContext->getRequest()->getHttpRequest()->getBaseUri();
     $domainsFound = FALSE;
     $sites = array();
     foreach ($this->siteRepository->findOnline() as $site) {
         $uri = NULL;
         /** @var $site \TYPO3\Neos\Domain\Model\Site */
         if ($site->hasActiveDomains()) {
             $uri = $controllerContext->getUriBuilder()->reset()->uriFor('index', array(), 'Backend\\Backend', 'TYPO3.Neos');
             $uri = sprintf('%s://%s%s%s', $requestUri->getScheme(), $site->getFirstActiveDomain()->getHostPattern(), rtrim($baseUri->getPath(), '/'), $uri);
             $domainsFound = TRUE;
         }
         $sites[] = array('name' => $site->getName(), 'nodeName' => $site->getNodeName(), 'uri' => $uri, 'active' => parse_url($uri, PHP_URL_HOST) === $requestUri->getHost() ? TRUE : FALSE);
     }
     if ($domainsFound === FALSE) {
         $uri = $controllerContext->getUriBuilder()->reset()->setCreateAbsoluteUri(TRUE)->uriFor('index', array(), 'Backend\\Backend', 'TYPO3.Neos');
         $sites[0]['uri'] = $uri;
     }
     return $sites;
 }
 /**
  * Converts a given context path to a node object
  *
  * @param string $contextPath
  * @return NodeInterface
  */
 public function getNodeFromContextPath($contextPath, Site $site = null, Domain $domain = null)
 {
     $nodePathAndContext = NodePaths::explodeContextPath($contextPath);
     $nodePath = $nodePathAndContext['nodePath'];
     $workspaceName = $nodePathAndContext['workspaceName'];
     $dimensions = $nodePathAndContext['dimensions'];
     $contextProperties = $this->prepareContextProperties($workspaceName, $dimensions);
     if ($site === null) {
         list(, , $siteNodeName) = explode('/', $nodePath);
         $site = $this->siteRepository->findOneByNodeName($siteNodeName);
     }
     if ($domain === null) {
         $domain = $this->domainRepository->findOneBySite($site);
     }
     $contextProperties['currentSite'] = $site;
     $contextProperties['currentDomain'] = $domain;
     $context = $this->contextFactory->create($contextProperties);
     $workspace = $context->getWorkspace(false);
     if (!$workspace) {
         return new \TYPO3\Flow\Error\Error(sprintf('Could not convert the given source to Node object because the workspace "%s" as specified in the context node path does not exist.', $workspaceName), 1451392329);
     }
     return $context->getNode($nodePath);
 }
 /**
  * Remove all nodes, workspaces, domains and sites.
  *
  * @param boolean $confirmation
  * @return void
  */
 public function pruneCommand($confirmation = FALSE)
 {
     if ($confirmation === FALSE) {
         $this->outputLine('Please confirm that you really want to remove all content from the database.');
         $this->outputLine('');
         $this->outputLine('Syntax:');
         $this->outputLine('  ./flow facets:prune --confirmation TRUE');
         exit;
     }
     $this->nodeDataRepository->removeAll();
     $this->workspaceRepository->removeAll();
     $this->domainRepository->removeAll();
     $this->siteRepository->removeAll();
     $this->outputLine('Database cleared');
 }