getNodeNameFromPath() public static method

Get the name for a Node based on the given path.
public static getNodeNameFromPath ( string $path ) : string
$path string
return string
コード例 #1
0
 /**
  * Returns the name of this node
  *
  * @return string
  */
 public function getName()
 {
     return NodePaths::getNodeNameFromPath($this->path);
 }
コード例 #2
0
 /**
  * Imports one or multiple sites from the XML file at $pathAndFilename
  *
  * @param string $pathAndFilename
  * @return Site The imported site
  * @throws UnknownPackageException|InvalidPackageStateException|NeosException
  */
 public function importFromFile($pathAndFilename)
 {
     /** @var Site $importedSite */
     $site = null;
     $xmlReader = new \XMLReader();
     $xmlReader->open($pathAndFilename, null, LIBXML_PARSEHUGE);
     if ($this->workspaceRepository->findOneByName('live') === null) {
         $this->workspaceRepository->add(new Workspace('live'));
         $this->persistenceManager->persistAll();
     }
     while ($xmlReader->read()) {
         if ($xmlReader->nodeType != \XMLReader::ELEMENT || $xmlReader->name !== 'site') {
             continue;
         }
         $site = $this->getSiteByNodeName($xmlReader->getAttribute('siteNodeName'));
         $site->setName($xmlReader->getAttribute('name'));
         $site->setState((int) $xmlReader->getAttribute('state'));
         $siteResourcesPackageKey = $xmlReader->getAttribute('siteResourcesPackageKey');
         if (!$this->packageManager->isPackageAvailable($siteResourcesPackageKey)) {
             throw new UnknownPackageException(sprintf('Package "%s" specified in the XML as site resources package does not exist.', $siteResourcesPackageKey), 1303891443);
         }
         if (!$this->packageManager->isPackageActive($siteResourcesPackageKey)) {
             throw new InvalidPackageStateException(sprintf('Package "%s" specified in the XML as site resources package is not active.', $siteResourcesPackageKey), 1303898135);
         }
         $site->setSiteResourcesPackageKey($siteResourcesPackageKey);
         $rootNode = $this->contextFactory->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));
         }
         $this->nodeImportService->import($xmlReader, $sitesNode->getPath(), dirname($pathAndFilename) . '/Resources');
     }
     if ($site === null) {
         throw new NeosException(sprintf('The XML file did not contain a valid site node.'), 1418999522);
     }
     $this->emitSiteImported($site);
     return $site;
 }
コード例 #3
0
 /**
  * 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 `Neos.Neos.NodeTypes:Page` as fallback. The node type
  * must already exists and have the superType ``Neos.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 = Neos.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 = 'Neos.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() === 'Neos.Neos:FallbackNode') {
         $this->outputLine('<error>The given node type "%s" was not found</error>', [$nodeType]);
         $this->quit(1);
     }
     if ($siteNodeType->isOfType('Neos.Neos:Document') === false) {
         $this->outputLine('<error>The given node type "%s" is not based on the superType "%s"</error>', [$nodeType, 'Neos.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']);
 }
コード例 #4
0
 /**
  * Create a new empty site.
  *
  * @param string $packageKey Package Name to create
  * @param string $siteName Site Name to create
  * @param string $nodeType NodeType name for the root node to create
  * @Flow\Validate(argumentName="$packageKey", type="\Neos\Neos\Validation\Validator\PackageKeyValidator")
  * @return void
  */
 public function createSiteNodeAction($packageKey, $siteName, $nodeType)
 {
     $nodeName = $this->nodeService->generateUniqueNodeName(SiteService::SITES_ROOT_PATH, $siteName);
     if ($this->siteRepository->findOneByNodeName($nodeName)) {
         $this->addFlashMessage('Error:A site with siteNodeName "%s" already exists', Message::SEVERITY_ERROR, [$nodeName], 1412372375);
         $this->redirect('createSiteNode');
     }
     $siteNodeType = $this->nodeTypeManager->getNodeType($nodeType);
     if ($siteNodeType === null || $siteNodeType->getName() === 'Neos.Neos:FallbackNode') {
         $this->addFlashMessage('Error: The given node type "%s" was not found', 'Import error', Message::SEVERITY_ERROR, [$nodeType], 1412372375);
         $this->redirect('createSiteNode');
     }
     if ($siteNodeType->isOfType('Neos.Neos:Document') === false) {
         $this->addFlashMessage('Error: The given node type "%s" is not based on the superType "%s"', Message::SEVERITY_ERROR, [$nodeType, 'Neos.Neos:Document'], 1412372375);
         $this->redirect('createSiteNode');
     }
     $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', $siteName);
     $site = new Site($nodeName);
     $site->setSiteResourcesPackageKey($packageKey);
     $site->setState(Site::STATE_ONLINE);
     $site->setName($siteName);
     $this->siteRepository->add($site);
     $this->addFlashMessage('Successfully created site "%s" with siteNode "%s", type "%s" and packageKey "%s"', '', null, [$siteName, $nodeName, $nodeType, $packageKey], 1412372266);
     $this->unsetLastVisitedNodeAndRedirect('index');
 }