/** * Generate robots.txt for $site * * @param ReadSiteInterface $site * * @return string */ public function generateRobots(ReadSiteInterface $site) { $txtContent = $site->getRobotsTxt(); $filename = $site->getSiteId() . '/robots.txt'; $this->filesystem->dumpFile('web/' . $filename, $txtContent); return $filename; }
/** * Dump published error pages for $site * * @param ReadSiteInterface $site * * @return string */ public function generateErrorPages(ReadSiteInterface $site) { $filenames = array(); $errorNodes = array(); $nodeCollection = $this->nodeRepository->findAllNodesOfTypeInLastPublishedVersionForSite(ReadNodeInterface::TYPE_ERROR, $site->getSiteId()); foreach ($nodeCollection as $translatedError) { $errorNodes[$translatedError->getLanguage()][$translatedError->getNodeId()] = $translatedError; } foreach ($site->getAliases() as $aliasId => $alias) { if (isset($errorNodes[$alias->getLanguage()])) { foreach ($errorNodes[$alias->getLanguage()] as $errorNode) { $filenames[] = $this->dumpErrorPageForSiteAlias($errorNode, $aliasId, $site->getSiteId()); } } } return $filenames; }
/** * Call robots.txt generation for $site * * @param ReadSiteInterface $site * @param OutputInterface $output */ protected function generateRobots(ReadSiteInterface $site, OutputInterface $output) { $robotsManager = $this->getContainer()->get('open_orchestra_front.manager.robots'); $mainAlias = $site->getMainAlias(); $alias = '' != $mainAlias->getPrefix() ? $mainAlias->getDomain() . "/" . $mainAlias->getPrefix() : $mainAlias->getDomain(); $output->writeln("<info>Generating robots file for siteId " . $site->getSiteId() . " with alias " . $alias . "</info>"); $filename = $robotsManager->generateRobots($site); $output->writeln("<comment>-> " . $filename . " generated</comment>\n"); }
/** * Call sitemap generation for $site * * @param ReadSiteInterface $site * @param OutputInterface $output */ protected function generateErrorPages(ReadSiteInterface $site, OutputInterface $output) { $errorPagesManager = $this->getContainer()->get('open_orchestra_front.manager.error_pages'); $output->writeln("\n<info>Generating error pages for siteId " . $site->getSiteId() . "</info>"); $filenames = $errorPagesManager->generateErrorPages($site); foreach ($filenames as $filename) { $output->writeln("<comment>-> " . $filename . " generated</comment>"); } }
/** * Return an array of sitemapNodes for $site * * @param ReadSiteInterface $site * * @return array */ protected function getSitemapNodesFromSite(ReadSiteInterface $site) { $nodes = array(); $nodesCollection = $this->nodeRepository->findCurrentlyPublishedVersion($site->getMainAlias()->getLanguage(), $site->getSiteId()); if ($nodesCollection) { /** @var ReadNodeInterface $node */ foreach ($nodesCollection as $node) { $nodes[] = $this->generateNodeInfos($node, $site); } } return $nodes; }
/** * Call sitemap generation for $site * * @param ReadSiteInterface $site * @param OutputInterface $output */ protected function generateSitemap(ReadSiteInterface $site, OutputInterface $output) { $sitemapManager = $this->getContainer()->get('open_orchestra_front.manager.sitemap'); $mainAlias = $site->getMainAlias(); $alias = $mainAlias->getScheme() . '://' . $mainAlias->getDomain(); if ('' != $mainAlias->getPrefix()) { $alias .= '/' . $mainAlias->getPrefix(); } $output->writeln("<info>Generating sitemap for siteId " . $site->getSiteId() . " with alias " . $alias . "</info>"); $filename = $sitemapManager->generateSitemap($site); $output->writeln("<comment>-> " . $filename . " generated</comment>\n"); }
/** * Call nodes unpublication for $site * * @param ReadSiteInterface $site * @param OutputInterface $output */ protected function unpublishNodes(ReadSiteInterface $site, OutputInterface $output) { $nodePublisherManager = $this->getContainer()->get('open_orchestra_cms.manager.node_publisher'); $output->writeln("\n<info>Unpublishing nodes for siteId " . $site->getSiteId() . "</info>"); $unpublishResult = $nodePublisherManager->unpublishNodes($site); if (NodePublisherInterface::ERROR_NO_PUBLISHED_STATUS == $unpublishResult) { $output->writeln("<error>There is no published status defined.</error>"); } elseif (NodePublisherInterface::ERROR_NO_UNPUBLISHED_STATUS == $unpublishResult) { $output->writeln("<error>There is no status defined to unpublish nodes.</error>"); } elseif (is_array($unpublishResult)) { foreach ($unpublishResult as $node) { $output->writeln("<comment>-> " . $node['name'] . " (v" . $node['version'] . " " . $node['language'] . ") unpublished</comment>"); } } }
/** * @param ReadSiteInterface $site * * @return array|int An unpublished node list or an error code */ public function unpublishNodes(ReadSiteInterface $site) { $publishedStatus = $this->statusRepository->findOneByPublished(); if (!$publishedStatus instanceof StatusInterface) { return self::ERROR_NO_PUBLISHED_STATUS; } $unpublishedStatus = $this->statusRepository->findOneByAutoUnpublishTo(); if (!$unpublishedStatus instanceof StatusInterface) { return self::ERROR_NO_UNPUBLISHED_STATUS; } $nodes = $this->nodeRepository->findNodeToAutoUnpublish($site->getSiteId(), $publishedStatus); $unpublishedNodes = array(); foreach ($nodes as $node) { $node->setStatus($unpublishedStatus); $this->objectManager->persist($node); $unpublishedNodes[] = array('name' => $node->getName(), 'version' => $node->getVersion(), 'language' => $node->getLanguage()); } $this->objectManager->flush(); return $unpublishedNodes; }
/** * @param ReadSiteInterface $site * @param ReadNodeInterface $node * @param RouteCollection $routes */ protected function generateRoutesForNode(ReadSiteInterface $site, ReadNodeInterface $node, RouteCollection $routes) { /** @var ReadSiteAliasInterface $alias */ foreach ($site->getAliases() as $key => $alias) { $nodeLanguage = $node->getLanguage(); if ($nodeLanguage == $alias->getLanguage()) { $pattern = $this->generateRoutePattern($node); if ($alias->getPrefix()) { $pattern = $this->suppressDoubleSlashes($alias->getPrefix() . '/' . $pattern); } $scheme = $node->getScheme(); if (is_null($scheme) || SchemeableInterface::SCHEME_DEFAULT == $scheme) { $scheme = $alias->getScheme(); } $nodeId = $node->getNodeId(); $siteId = $site->getSiteId(); $domain = $alias->getDomain(); $route = $this->generateRoute($pattern, $nodeLanguage, $nodeId, $siteId, $key, $domain, $scheme); $routes->add($key . '_' . $node->getId(), $route); } } }