private function upgradeWebspace(Webspace $webspace, OutputInterface $output) { $output->writeln('<info>> Upgrade Webspace: ' . $webspace->getName() . '</info>'); foreach ($webspace->getAllLocalizations() as $localization) { $this->upgradeLocale($webspace, $localization, $output); } }
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->getLocalization(); } if ($this->nodeManager->has($homePath)) { $homeDocument = $this->documentManager->find($homePath, 'fr', ['load_ghost_content' => false, 'auto_create' => true, 'path' => $homePath]); $existingLocales = $this->inspector->getLocales($homeDocument); } else { $homeDocument = new HomeDocument(); $homeDocument->setTitle('Homepage'); $homeDocument->setStructureType($webspace->getTheme()->getDefaultTemplate('homepage')); $homeDocument->setWorkflowStage(WorkflowStage::PUBLISHED); $existingLocales = []; } foreach ($webspaceLocales as $webspaceLocale) { $output->writeln(sprintf('<info>Homepage</info>: %s (%s)', $homePath, $webspaceLocale)); if (in_array($webspaceLocale, $existingLocales)) { continue; } $this->nodeManager->createPath($routesPath . '/' . $webspaceLocale); $this->documentManager->persist($homeDocument, $webspaceLocale, ['path' => $homePath]); } }
/** * Upgrade a single webspace. * * @param Webspace $webspace */ private function upgradeWebspace(Webspace $webspace) { $sessionManager = $this->container->get('sulu.phpcr.session'); $node = $sessionManager->getContentNode($webspace->getKey()); foreach ($webspace->getAllLocalizations() as $localization) { $locale = $localization->getLocalization(); $propertyName = $this->getPropertyName(self::SHADOW_ON_PROPERTY, $locale); $this->upgradeNode($node, $propertyName, $locale); } }
/** * Validate that all localizations are used in the portals. * * @throws Exception\PortalDefaultLocalizationNotFoundException * @throws Exception\InvalidPortalDefaultLocalizationException */ protected function validateLocalizations() { $locales = array_unique(array_map(function (Localization $localization) { return $localization->getLocale(Localization::UNDERSCORE); }, $this->webspace->getAllLocalizations())); $portalLocales = []; foreach ($this->webspace->getPortals() as $portal) { $portalLocales = array_merge($portalLocales, array_map(function (Localization $localization) { return $localization->getLocale(Localization::UNDERSCORE); }, $portal->getLocalizations())); } $portalLocales = array_unique($portalLocales); if (array_diff($locales, $portalLocales) || array_diff($portalLocales, $locales)) { throw new WebspaceLocalizationNotUsedException($this->webspace); } }
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(); }
/** * Dump given webspace. * * @param Webspace $webspace */ private function dumpWebspace(Webspace $webspace) { foreach ($webspace->getAllLocalizations() as $localization) { $this->output->writeln(sprintf(' - %s (%s)', $webspace->getKey(), $localization->getLocale())); $this->dumpPortalInformations($this->webspaceManager->findPortalInformationsByWebspaceKeyAndLocale($webspace->getKey(), $localization->getLocale(), $this->environment)); } }