public function initialize(OutputInterface $output, $purge = false) { $nodeTypeManager = $this->sessionManager->getSession()->getWorkspace()->getNodeTypeManager(); foreach ([new CustomUrlNodeType(), new CustomUrlRouteNodeType()] as $nodeType) { $nodeTypeManager->registerNodeType($nodeType, true); } /** @var Webspace $webspace */ foreach ($this->webspaceManager->getWebspaceCollection() as $webspace) { $itemsPath = $this->pathBuilder->build(['%base%', $webspace->getKey(), '%custom_urls%', '%custom_urls_items%']); $routesPath = $this->pathBuilder->build(['%base%', $webspace->getKey(), '%custom_urls%', '%custom_urls_routes%']); $output->writeln(sprintf(' <info>%s</info>:', $webspace->getName())); if (true === $this->nodeManager->has($itemsPath)) { $output->writeln(sprintf(' [ ] <info>items path:</info>: %s ', $itemsPath)); } else { $output->writeln(sprintf(' [+] <info>items path:</info>: %s ', $itemsPath)); $this->nodeManager->createPath($itemsPath); } if (true === $this->nodeManager->has($routesPath)) { $output->writeln(sprintf(' [ ] <info>items path:</info>: %s ', $routesPath)); } else { $output->writeln(sprintf(' [+] <info>items path:</info>: %s ', $routesPath)); $this->nodeManager->createPath($routesPath); } $this->nodeManager->save(); } }
private function initializeWebspace(OutputInterface $output, Webspace $webspace) { $homePath = $this->pathBuilder->build(['%base%', $webspace->getKey(), '%content%']); $routesPath = $this->pathBuilder->build(['%base%', $webspace->getKey(), '%route%']); $webspaceLocales = []; foreach ($webspace->getAllLocalizations() as $localization) { $webspaceLocales[] = $localization->getLocale(); } $homeType = $webspace->getDefaultTemplate('home'); $existingLocales = []; $homeDocument = null; if ($this->nodeManager->has($homePath)) { $homeDocument = $this->documentManager->find($homePath, null, ['load_ghost_content' => false, 'auto_create' => true, 'path' => $homePath]); $existingLocales = $this->inspector->getLocales($homeDocument); } foreach ($webspaceLocales as $webspaceLocale) { if (in_array($webspaceLocale, $existingLocales)) { $output->writeln(sprintf(' [ ] <info>homepage</info>: %s (%s)', $homePath, $webspaceLocale)); continue; } $output->writeln(sprintf(' [+] <info>homepage</info>: [%s] %s (%s)', $homeType, $homePath, $webspaceLocale)); $persistOptions = ['ignore_required' => true]; if (!$homeDocument) { $homeDocument = new HomeDocument(); $persistOptions['path'] = $homePath; $persistOptions['auto_create'] = true; } else { $homeDocument = $this->documentManager->find($homePath, $webspaceLocale, ['load_ghost_content' => false]); } $homeDocument->setTitle('Homepage'); $homeDocument->setStructureType($homeType); $this->documentManager->persist($homeDocument, $webspaceLocale, $persistOptions); $this->documentManager->publish($homeDocument, $webspaceLocale); $routePath = $routesPath . '/' . $webspaceLocale; try { $routeDocument = $this->documentManager->find($routePath); } catch (DocumentNotFoundException $e) { $routeDocument = $this->documentManager->create('route'); } $routeDocument->setTargetDocument($homeDocument); $this->documentManager->persist($routeDocument, $webspaceLocale, ['path' => $routePath, 'auto_create' => true]); $this->documentManager->publish($routeDocument, $webspaceLocale); } $this->documentManager->flush(); }
/** * Return routes path for custom-url in given webspace. * * @param string $webspaceKey * * @return string */ protected function getRoutesPath($webspaceKey) { return $this->pathBuilder->build(['%base%', $webspaceKey, '%custom_urls%', '%custom_urls_routes%']); }