/**
  * Remove given site all nodes for that site and all domains associated.
  *
  * @param Site $site
  * @return void
  */
 public function pruneSite(Site $site)
 {
     $siteNodePath = '/sites/' . $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);
 }
 /**
  * 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);
 }
 /**
  * Returns the node of the current site.
  *
  * @return NodeInterface
  */
 public function getCurrentSiteNode()
 {
     if ($this->currentSite !== null && $this->currentSiteNode === null) {
         $siteNodePath = NodePaths::addNodePathSegment(SiteService::SITES_ROOT_PATH, $this->currentSite->getNodeName());
         $this->currentSiteNode = $this->getNode($siteNodePath);
         if (!$this->currentSiteNode instanceof NodeInterface) {
             $this->systemLogger->log(sprintf('Warning: %s::getCurrentSiteNode() couldn\'t load the site node for path "%s" in workspace "%s". This is probably due to a missing baseworkspace for the workspace of the current user.', __CLASS__, $siteNodePath, $this->workspaceName), LOG_WARNING);
         }
     }
     return $this->currentSiteNode;
 }
 /**
  * Returns the node of the current site.
  *
  * @return NodeInterface
  */
 public function getCurrentSiteNode()
 {
     if ($this->currentSite !== NULL && $this->currentSiteNode === NULL) {
         $siteNodePath = '/sites/' . $this->currentSite->getNodeName();
         $this->currentSiteNode = $this->getNode($siteNodePath);
         if (!$this->currentSiteNode instanceof NodeInterface) {
             $this->systemLogger->log(sprintf('Warning: %s::getCurrentSiteNode() couldn\'t load the site node for path "%s" in workspace "%s". This is probably due to a missing baseworkspace for the workspace of the current user.', __CLASS__, $siteNodePath, $this->workspaceName), LOG_WARNING);
         }
     }
     return $this->currentSiteNode;
 }
 /**
  * If the imported site is of a legacy schema where the near-root <site> element wasn't
  * an actual node, the respective site xml is "upgraded" to become of type Shortcut,
  * get a `title` property being the site's name, and being set to hidden in index.
  *
  * @param \SimpleXMLElement $siteXml
  * @param \TYPO3\Neos\Domain\Model\Site $site
  * @return void
  */
 protected function upgradeLegacySiteXml(\SimpleXMLElement $siteXml, Site $site)
 {
     $siteXml->addAttribute('type', 'TYPO3.Neos:Shortcut');
     $siteXml->addAttribute('hiddenInIndex', 'true');
     if (property_exists($siteXml->properties, 'title') === false) {
         $siteXml->properties->addChild('title', $site->getName());
     }
 }
 /**
  * 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');
 }
 /**
  * @test
  */
 public function theSiteResourcesPackageKeyCanBeSetAndRetrieved()
 {
     $site = new Site('');
     $site->setSiteResourcesPackageKey('Foo');
     $this->assertSame('Foo', $site->getSiteResourcesPackageKey());
 }
 /**
  * Export the given $site to the XMLWriter
  *
  * @param Site $site
  * @param string $nodeTypeFilter
  * @return void
  */
 protected function exportSite(Site $site, $nodeTypeFilter)
 {
     /** @var ContentContext $contentContext */
     $contentContext = $this->contextFactory->create(array('currentSite' => $site, 'invisibleContentShown' => true, 'inaccessibleContentShown' => true));
     $siteNode = $contentContext->getCurrentSiteNode();
     $this->xmlWriter->startElement('site');
     $this->xmlWriter->writeAttribute('name', $site->getName());
     $this->xmlWriter->writeAttribute('state', $site->getState());
     $this->xmlWriter->writeAttribute('siteResourcesPackageKey', $site->getSiteResourcesPackageKey());
     $this->xmlWriter->writeAttribute('siteNodeName', $siteNode->getName());
     $this->nodeExportService->export($siteNode->getPath(), $contentContext->getWorkspaceName(), $this->xmlWriter, false, false, $this->resourcesPath, $nodeTypeFilter);
     $this->xmlWriter->endElement();
 }
 /**
  * Internal event handler to forward domain changes to the "siteChanged" signal
  *
  * @ORM\PostPersist
  * @ORM\PostUpdate
  * @ORM\PostRemove
  * @return void
  */
 public function onPostFlush()
 {
     $this->site->emitSiteChanged();
 }
 /**
  * @param ControllerContext $controllerContext
  * @param Site $site
  * @return string
  * @throws NeosException
  */
 public function createSiteUri(ControllerContext $controllerContext, Site $site)
 {
     $primaryDomain = $site->getPrimaryDomain();
     if ($primaryDomain === null) {
         throw new NeosException(sprintf('Cannot link to a site "%s" since it has no active domains.', $site->getName()), 1460443524);
     }
     $requestUri = $controllerContext->getRequest()->getHttpRequest()->getUri();
     $baseUri = $controllerContext->getRequest()->getHttpRequest()->getBaseUri();
     $port = $primaryDomain->getPort() ?: $requestUri->getPort();
     return sprintf('%s://%s%s%s', $primaryDomain->getScheme() ?: $requestUri->getScheme(), $primaryDomain->getHostPattern(), $port && !in_array($port, [80, 443], true) ? ':' . $port : '', rtrim($baseUri->getPath(), '/'));
 }
 /**
  * @param Site $site
  * @param string $contentType
  * @return void
  */
 public function purgeAllVarnishCacheAction(Site $site = NULL, $contentType = NULL)
 {
     $domain = $site !== NULL ? $site->getFirstActiveDomain()->getHostPattern() : NULL;
     $service = new VarnishBanService();
     $service->banAll($domain, $contentType);
     $this->flashMessageContainer->addMessage(new Message(sprintf('All varnish cache cleared for %s%s', $site ? 'site ' . $site->getName() : 'installation', $contentType ? ' with content type "' . $contentType . '"' : '')));
     $this->redirect('index');
 }
 /**
  * Create a new site
  *
  * This command allows to create a blank site with just a single empty document in the default dimension.
  * The name of the site, the packageKey must be specified.
  *
  * If no ``nodeType`` option is specified the command will use `TYPO3.Neos.NodeTypes:Page` as fallback. The node type
  * must already exists and have the superType ``TYPO3.Neos:Document``.
  *
  * If no ``nodeName` option is specified the command will create a unique node-name from the name of the site.
  * If a node name is given it has to be unique for the setup.
  *
  * If the flag ``activate` is set to false new site will not be activated.
  *
  * @param string $name The name of the site
  * @param string $packageKey The site package
  * @param string $nodeType The node type to use for the site node. (Default = TYPO3.Neos.NodeTypes:Page)
  * @param string $nodeName The name of the site node. If no nodeName is given it will be determined from the siteName.
  * @param boolean $inactive The new site is not activated immediately (default = false).
  * @return void
  */
 public function createCommand($name, $packageKey, $nodeType = 'TYPO3.Neos.NodeTypes:Page', $nodeName = null, $inactive = false)
 {
     if ($nodeName === null) {
         $nodeName = $this->nodeService->generateUniqueNodeName(SiteService::SITES_ROOT_PATH, $name);
     }
     if ($this->siteRepository->findOneByNodeName($nodeName)) {
         $this->outputLine('<error>A site with siteNodeName "%s" already exists</error>', [$nodeName]);
         $this->quit(1);
     }
     if ($this->packageManager->isPackageAvailable($packageKey) === false) {
         $this->outputLine('<error>Could not find package "%s"</error>', [$packageKey]);
         $this->quit(1);
     }
     $siteNodeType = $this->nodeTypeManager->getNodeType($nodeType);
     if ($siteNodeType === null || $siteNodeType->getName() === 'TYPO3.Neos:FallbackNode') {
         $this->outputLine('<error>The given node type "%s" was not found</error>', [$nodeType]);
         $this->quit(1);
     }
     if ($siteNodeType->isOfType('TYPO3.Neos:Document') === false) {
         $this->outputLine('<error>The given node type "%s" is not based on the superType "%s"</error>', [$nodeType, 'TYPO3.Neos:Document']);
         $this->quit(1);
     }
     $rootNode = $this->nodeContextFactory->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(SiteService::SITES_ROOT_PATH);
     if ($sitesNode === null) {
         $sitesNode = $rootNode->createNode(NodePaths::getNodeNameFromPath(SiteService::SITES_ROOT_PATH));
     }
     $siteNode = $sitesNode->createNode($nodeName, $siteNodeType);
     $siteNode->setProperty('title', $name);
     $site = new Site($nodeName);
     $site->setSiteResourcesPackageKey($packageKey);
     $site->setState($inactive ? Site::STATE_OFFLINE : Site::STATE_ONLINE);
     $site->setName($name);
     $this->siteRepository->add($site);
     $this->outputLine('Successfully created site "%s" with siteNode "%s", type "%s", packageKey "%s" and state "%s"', [$name, $nodeName, $nodeType, $packageKey, $inactive ? 'offline' : 'online']);
 }
 /**
  * @Given /^I have the site "([^"]*)"$/
  */
 public function iHaveTheSite($siteName)
 {
     $site = new Site($siteName);
     $site->setSiteResourcesPackageKey('Neos.Demo');
     /** @var SiteRepository $siteRepository */
     $siteRepository = $this->objectManager->get(SiteRepository::class);
     $siteRepository->add($site);
     $this->getSubContext('flow')->persistAll();
 }