/**
  * 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');
 }
 /**
  * @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);
 }
 /**
  * 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);
     }
     $site->setPrimaryDomain(null);
     $this->siteRepository->update($site);
     $domainsForSite = $this->domainRepository->findBySite($site);
     foreach ($domainsForSite as $domain) {
         $this->domainRepository->remove($domain);
     }
     $this->persistenceManager->persistAll();
     $this->siteRepository->remove($site);
     $this->emitSitePruned($site);
 }
 /**
  * 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.');
 }
 /**
  * Imports the specified bundle into the configured "importRootNodePath".
  *
  * @param string $bundle
  * @return void
  */
 protected function importBundle($bundle)
 {
     $nodeTypes = array('page' => $this->nodeTypeManager->getNodeType($this->bundleConfiguration['nodeTypes']['page']), 'section' => $this->nodeTypeManager->getNodeType($this->bundleConfiguration['nodeTypes']['section']), 'text' => $this->nodeTypeManager->getNodeType($this->bundleConfiguration['nodeTypes']['text']));
     $this->outputLine('Importing bundle "%s"', array($bundle));
     $renderedDocumentationRootPath = rtrim($this->bundleConfiguration['renderedDocumentationRootPath'], '/');
     $importRootNode = $this->siteNode->getNode($this->bundleConfiguration['importRootNodePath']);
     if ($importRootNode === NULL) {
         $this->output('ImportRootNode "%s" does not exist!', array($this->bundleConfiguration['importRootNodePath']));
         $this->quit(1);
     }
     if (!is_dir($renderedDocumentationRootPath)) {
         $this->outputLine('The folder "%s" does not exist. Did you render the documentation?', array($renderedDocumentationRootPath));
         $this->quit(1);
     }
     $unorderedJsonFileNames = Files::readDirectoryRecursively($renderedDocumentationRootPath, '.fjson');
     if ($unorderedJsonFileNames === array()) {
         $this->outputLine('The folder "%s" contains no fjson files. Did you render the documentation?', array($renderedDocumentationRootPath));
         $this->quit(1);
     }
     $orderedNodePaths = array();
     foreach ($unorderedJsonFileNames as $jsonPathAndFileName) {
         if (basename($jsonPathAndFileName) === 'Index.fjson') {
             $chapterRelativeNodePath = substr($jsonPathAndFileName, strlen($renderedDocumentationRootPath), -12) . '/';
             $indexArray = json_decode(file_get_contents($jsonPathAndFileName), TRUE);
             foreach (explode(chr(10), $indexArray['body']) as $tocHtmlLine) {
                 preg_match('!^\\<li class="toctree-l1"\\>\\<a class="reference internal" href="\\.\\./([a-zA-Z0-9-]+)/.*$!', $tocHtmlLine, $matches);
                 if ($matches !== array()) {
                     $orderedNodePaths[] = $this->normalizeNodePath($chapterRelativeNodePath . $matches[1]);
                 }
             }
         }
     }
     foreach ($unorderedJsonFileNames as $jsonPathAndFileName) {
         $data = json_decode(file_get_contents($jsonPathAndFileName));
         if (!isset($data->body)) {
             continue;
         }
         $relativeNodePath = substr($jsonPathAndFileName, strlen($renderedDocumentationRootPath) + 1, -6);
         $relativeNodePath = $this->normalizeNodePath($relativeNodePath);
         $segments = explode('/', $relativeNodePath);
         $pageNode = $importRootNode;
         while ($segment = array_shift($segments)) {
             $nodeName = preg_replace('/[^a-z0-9\\-]/', '', $segment);
             $subPageNode = $pageNode->getNode($nodeName);
             if ($subPageNode === NULL) {
                 $this->outputLine('Creating page node "%s"', array($relativeNodePath));
                 /** @var NodeInterface $subPageNode */
                 $subPageNode = $pageNode->createNode($nodeName, $nodeTypes['page']);
                 if (!$subPageNode->hasProperty('title')) {
                     $subPageNode->setProperty('title', $nodeName);
                 }
             } else {
                 $subPageNode->setNodeType($nodeTypes['page']);
             }
             $pageNode = $subPageNode;
         }
         $sectionNode = $pageNode->getNode('main');
         if ($sectionNode === NULL) {
             $this->outputLine('Creating section node "%s"', array($relativeNodePath . '/main'));
             $sectionNode = $pageNode->createNode('main', $nodeTypes['section']);
         } else {
             $sectionNode->setNodeType($nodeTypes['section']);
         }
         $textNode = $sectionNode->getNode('text1');
         if ($textNode === NULL) {
             $this->outputLine('Creating text node "%s"', array($relativeNodePath . '/main/text1'));
             $textNode = $sectionNode->createNode('text1', $nodeTypes['text']);
         } else {
             $textNode->setNodeType($nodeTypes['text']);
         }
         $pageNode->setProperty('title', htmlspecialchars_decode($data->title));
         $this->outputLine('Setting page title of page "%s" to "%s"', array($relativeNodePath, $data->title));
         $bodyText = $this->prepareBodyText($data->body, $relativeNodePath);
         $textNode->setProperty('title', '');
         $textNode->setProperty('text', $bodyText);
     }
     $importRootNodePath = $importRootNode->getPath();
     $currentParentNodePath = '';
     /** @var NodeInterface $previousNode */
     $previousNode = NULL;
     foreach ($orderedNodePaths as $nodePath) {
         $node = $importRootNode->getNode($importRootNodePath . $nodePath);
         if ($node !== NULL) {
             if ($node->getParent()->getPath() !== $currentParentNodePath) {
                 $currentParentNodePath = $node->getParent()->getPath();
                 $previousNode = NULL;
             }
             if ($previousNode !== NULL) {
                 $this->outputLine('Moved node %s', array($node->getPath()));
                 $this->outputLine('after node %s', array($previousNode->getPath()));
                 $node->moveAfter($previousNode);
             } else {
                 // FIXME: Node->isFirst() or Node->moveFirst() would be needed here
             }
             $previousNode = $node;
         } else {
             $this->outputLine('Node %s does not exist.', array($importRootNodePath . $nodePath));
         }
     }
     $this->siteRepository->update($this->currentSite);
 }