/**
  * @return void
  */
 public function initializeObject()
 {
     $this->settings = $this->configurationManager->getConfiguration('Settings', 'TYPO3.Media');
     $domain = $this->domainRepository->findOneByActiveRequest();
     // Set active asset collection to the current site's asset collection, if it has one, on the first view if a matching domain is found
     if ($domain !== null && !$this->browserState->get('activeAssetCollection') && $this->browserState->get('automaticAssetCollectionSelection') !== true && $domain->getSite()->getAssetCollection() !== null) {
         $this->browserState->set('activeAssetCollection', $domain->getSite()->getAssetCollection());
         $this->browserState->set('automaticAssetCollectionSelection', true);
     }
 }
 /**
  * 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);
     }
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * 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));
 }
 /**
  * Remove given site all nodes for that site and all domains associated.
  *
  * @param Site $site
  * @return void
  */
 public function pruneSite(Site $site)
 {
     $siteNodePath = NodePaths::addNodePathSegment(static::SITES_ROOT_PATH, $site->getNodeName());
     $this->nodeDataRepository->removeAllInPath($siteNodePath);
     $siteNodes = $this->nodeDataRepository->findByPath($siteNodePath);
     foreach ($siteNodes as $siteNode) {
         $this->nodeDataRepository->remove($siteNode);
     }
     $domainsForSite = $this->domainRepository->findBySite($site);
     foreach ($domainsForSite as $domain) {
         $this->domainRepository->remove($domain);
     }
     $this->siteRepository->remove($site);
     $this->emitSitePruned($site);
 }
 /**
  * @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);
         }
     }
 }
 /**
  * Deactivates a domain
  *
  * @param Domain $domain Domain to deactivate
  * @return void
  */
 public function deactivateDomainAction(Domain $domain)
 {
     $domain->setActive(FALSE);
     $this->domainRepository->update($domain);
     $this->addFlashMessage('The domain "%s" has been deactivated.', 'Domain deactivated', Message::SEVERITY_OK, array($domain->getHostPattern()), 1412373425);
     $this->unsetLastVisitedNodeAndRedirect('edit', NULL, NULL, array('site' => $domain->getSite()));
 }
 /**
  * Deactivates a domain
  *
  * @param Domain $domain Domain to deactivate
  * @Flow\IgnoreValidation("$domain")
  * @return void
  */
 public function deactivateDomainAction(Domain $domain)
 {
     $domain->setActive(false);
     $this->domainRepository->update($domain);
     $this->addFlashMessage('The domain "%s" has been deactivated.', 'Domain deactivated', Message::SEVERITY_OK, array(htmlspecialchars($domain)), 1412373425);
     $this->unsetLastVisitedNodeAndRedirect('edit', null, null, array('site' => $domain->getSite()));
 }
 /**
  * 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);
 }
 /**
  * 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);
 }
 /**
  * Deactivate a domain record
  *
  * @param string $hostPattern The host pattern of the domain to deactivate
  * @return void
  */
 public function deactivateCommand($hostPattern)
 {
     $domain = $this->domainRepository->findOneByHostPattern($hostPattern);
     if (!$domain instanceof Domain) {
         $this->outputLine('<error>Domain not found.</error>');
         $this->quit(1);
     }
     $domain->setActive(false);
     $this->domainRepository->update($domain);
     $this->outputLine('Domain deactivated.');
 }
 /**
  * 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);
 }
 /**
  * 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]);
 }
예제 #15
0
 /**
  * @param string $sitePackage
  * @param string $siteName
  * @param string $baseDomain
  * @return Site
  */
 public function importSiteFromTemplate($sitePackage, $siteName, $baseDomain = '')
 {
     if (empty($baseDomain)) {
         $request = Request::createFromEnvironment();
         $baseDomain = $request->getBaseUri()->getHost();
     }
     $siteTemplate = new StandaloneView();
     $siteTemplate->setTemplatePathAndFilename(FLOW_PATH_PACKAGES . 'Sites/' . $sitePackage . '/Resources/Private/Templates/Content/Sites.xml');
     $siteTemplate->assignMultiple(['siteName' => $siteName, 'siteNodeName' => \TYPO3\TYPO3CR\Utility::renderValidNodeName($siteName), 'packageKey' => $sitePackage]);
     $generatedSiteImportXmlContent = $siteTemplate->render();
     $dataTemporaryPath = $this->environment->getPathToTemporaryDirectory();
     $temporarySiteXml = $dataTemporaryPath . uniqid($siteName) . '.xml';
     file_put_contents($temporarySiteXml, $generatedSiteImportXmlContent);
     $site = $this->siteImportService->importFromFile($temporarySiteXml);
     $domain = new Domain();
     $domain->setActive(true);
     $domain->setSite($site);
     $domain->setHostPattern(\TYPO3\TYPO3CR\Utility::renderValidNodeName($siteName) . '.' . $baseDomain);
     $this->domainRepository->add($domain);
     return $site;
 }
 /**
  * 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);
 }
 /**
  * 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');
 }
 /**
  * Creates a new content context based on the given workspace and the NodeData object and additionally takes
  * the current site and current domain into account.
  *
  * @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())
 {
     if ($this->currentDomain === false) {
         $this->currentDomain = $this->domainRepository->findOneByActiveRequest();
     }
     if ($this->currentDomain !== null) {
         $contextProperties['currentSite'] = $this->currentDomain->getSite();
         $contextProperties['currentDomain'] = $this->currentDomain;
     } else {
         if ($this->currentSite === false) {
             $this->currentSite = $this->siteRepository->findFirstOnline();
         }
         $contextProperties['currentSite'] = $this->currentSite;
     }
     return parent::createContext($workspace, $dimensionValues, $contextProperties);
 }
 /**
  * @return string
  */
 public function render()
 {
     $configuration = array('window.T3Configuration = {};', 'window.T3Configuration.UserInterface = ' . json_encode($this->settings['userInterface']) . ';', 'window.T3Configuration.nodeTypes = {};', 'window.T3Configuration.nodeTypes.groups = ' . json_encode($this->getNodeTypeGroupsSettings()) . ';', 'window.T3Configuration.requirejs = {};', 'window.T3Configuration.neosStaticResourcesBaseUri = ' . json_encode($this->resourceManager->getPublicPackageResourceUri('TYPO3.Neos', '')) . ';', 'window.T3Configuration.requirejs.paths = ' . json_encode($this->getRequireJsPathMapping()) . ';', 'window.T3Configuration.maximumFileUploadSize = ' . $this->renderMaximumFileUploadSize());
     $neosJavaScriptBasePath = $this->getStaticResourceWebBaseUri('resource://TYPO3.Neos/Public/JavaScript');
     $configuration[] = 'window.T3Configuration.neosJavascriptBasePath = ' . json_encode($neosJavaScriptBasePath) . ';';
     if ($this->backendAssetsUtility->shouldLoadMinifiedJavascript()) {
         $configuration[] = 'window.T3Configuration.neosJavascriptVersion = ' . json_encode($this->backendAssetsUtility->getJavascriptBuiltVersion()) . ';';
     }
     if ($this->bootstrap->getContext()->isDevelopment()) {
         $configuration[] = 'window.T3Configuration.DevelopmentMode = true;';
     }
     if ($activeDomain = $this->domainRepository->findOneByActiveRequest()) {
         $configuration[] = 'window.T3Configuration.site = "' . $activeDomain->getSite()->getNodeName() . '";';
     }
     return implode("\n", $configuration);
 }
 /**
  * @test
  */
 public function resolveCreatesContextForCurrentDomainIfGivenValueIsAStringAndADomainIsFound()
 {
     $mockContext = $this->buildMockContext(array('workspaceName' => 'user-johndoe'));
     $mockContext->mockSite = $this->getMock('TYPO3\\TYPO3CR\\Domain\\Model\\Site', array(), array(), '', false);
     $mockSiteNode = $this->buildSiteNode($mockContext, '/sites/examplecom');
     $mockContext->mockSiteNode = $mockSiteNode;
     $mockContext->expects($this->any())->method('getNode')->will($this->returnCallback(function ($nodePath) use($mockSiteNode) {
         return $nodePath === '/sites/examplecom' ? $mockSiteNode : null;
     }));
     $mockDomain = $this->getMockBuilder('TYPO3\\Neos\\Domain\\Model\\Domain')->disableOriginalConstructor()->getMock();
     $this->mockDomainRepository->expects($this->atLeastOnce())->method('findOneByActiveRequest')->will($this->returnValue($mockDomain));
     $that = $this;
     $this->mockContextFactory->expects($this->once())->method('create')->will($this->returnCallback(function ($contextProperties) use($that, $mockContext, $mockDomain) {
         // The important assertion:
         $that->assertSame($mockDomain, $contextProperties['currentDomain']);
         return $mockContext;
     }));
     $routeValues = array('node' => '/sites/examplecom');
     $this->assertTrue($this->routePartHandler->resolve($routeValues));
 }
 /**
  * @param NodeType $nodetype
  * @return boolean
  */
 private function isNodeTypeInAllowedSite(NodeType $nodetype)
 {
     // dont restrict abstract nodes
     if ($nodetype->isAbstract()) {
         return true;
     }
     $deniedWilcard = false;
     $allowedSites = $nodetype->getConfiguration('allowedSites');
     if ($allowedSites) {
         $currentDomain = $this->domainRepository->findOneByActiveRequest();
         if ($currentDomain !== null) {
             $currentSite = $currentDomain->getSite();
         } else {
             $currentSite = $this->siteRepository->findFirstOnline();
         }
         if (!$currentSite) {
             return true;
         }
         foreach ($allowedSites as $siteName => $allowed) {
             if ($allowed == TRUE && $siteName == '*' | $currentSite->getSiteResourcesPackageKey() == $siteName) {
                 return true;
             }
             if ($allowed == FALSE && $currentSite->getSiteResourcesPackageKey() == $siteName) {
                 return false;
             }
             if ($allowed == TRUE && $siteName == '*') {
                 $deniedWilcard = false;
             }
             if ($allowed == FALSE && $siteName == '*') {
                 $deniedWilcard = true;
             }
         }
         if ($deniedWilcard == true) {
             return false;
         }
     }
     return true;
 }
 /**
  * @return void
  */
 protected function createContentContext()
 {
     $domain = $this->domainRepository->findOneByActiveRequest();
     $this->contentContext = new ContentContext('live', new \DateTime(), [], [], false, false, false, $domain ? $domain->getSite() : $this->siteRepository->findFirstOnline(), $domain);
 }