From 8bff3cc935ed6c06302d2d9f8b02159809e220d7 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Wed, 15 Jan 2025 14:17:57 +0100 Subject: [PATCH 01/11] TASK: Refine logic to determine content repository for new site beforehand This bases on the thesis that the created site's name will use the configuration "*" which by default uses the default preset. --- .../Module/Administration/SitesController.php | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Neos.Neos/Classes/Controller/Module/Administration/SitesController.php b/Neos.Neos/Classes/Controller/Module/Administration/SitesController.php index e124b5cd0a1..e54ccf9b270 100755 --- a/Neos.Neos/Classes/Controller/Module/Administration/SitesController.php +++ b/Neos.Neos/Classes/Controller/Module/Administration/SitesController.php @@ -89,6 +89,14 @@ class SitesController extends AbstractModuleController */ protected $session; + /** + * This is not 100% correct, but it is as good as we can get it to work right now + * It works when the created site's name will use the configuration "*" which by default uses the default preset. + * + * @Flow\InjectConfiguration("sitePresets.default.contentRepository") + */ + protected $defaultContentRepositoryForNewSites; + #[Flow\Inject] protected UserService $domainUserService; @@ -236,22 +244,19 @@ public function updateSiteAction(Site $site, $newSiteNodeName) */ public function newSiteAction(): void { - // This is not 100% correct, but it is as good as we can get it to work right now try { - $contentRepositoryId = SiteDetectionResult::fromRequest($this->request->getHttpRequest()) - ->contentRepositoryId; - } catch (\RuntimeException) { - $contentRepositoryId = ContentRepositoryId::fromString('default'); + $contentRepositoryId = ContentRepositoryId::fromString($this->defaultContentRepositoryForNewSites ?? ''); + } catch (\InvalidArgumentException $e) { + throw new \RuntimeException('The default content repository for new sites configured in "Neos.Neos.sitePresets.default.contentRepository" is not valid.', 1736946907, $e); } try { $contentRepository = $this->contentRepositoryRegistry->get($contentRepositoryId); $documentNodeTypes = $contentRepository->getNodeTypeManager()->getSubNodeTypes(NodeTypeNameFactory::forSite(), false); - } catch (ContentRepositoryNotFoundException) { - $documentNodeTypes = []; + } catch (ContentRepositoryNotFoundException $e) { + throw new \RuntimeException(sprintf('The default content repository for new sites "%s" could not be instantiated.', $contentRepositoryId->value), 1736946907, $e); } - $sitePackages = $this->packageManager->getFilteredPackages('available', 'neos-site'); $this->view->assignMultiple([ From cb7f171bf06b682793e21e38134027d1558e7727 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Thu, 16 Jan 2025 12:38:44 +0100 Subject: [PATCH 02/11] BUGFIX: Reimplement Import site based on new SiteImportService see https://github.com/neos/neos-development-collection/pull/5307 --- .../Module/Administration/SitesController.php | 71 +++++++++++-------- .../Private/Translations/en/Modules.xlf | 6 -- 2 files changed, 42 insertions(+), 35 deletions(-) diff --git a/Neos.Neos/Classes/Controller/Module/Administration/SitesController.php b/Neos.Neos/Classes/Controller/Module/Administration/SitesController.php index e54ccf9b270..aa76ee5a02a 100755 --- a/Neos.Neos/Classes/Controller/Module/Administration/SitesController.php +++ b/Neos.Neos/Classes/Controller/Module/Administration/SitesController.php @@ -16,11 +16,11 @@ use Neos\ContentRepository\Core\Feature\NodeRenaming\Command\ChangeNodeAggregateName; use Neos\ContentRepository\Core\Projection\ContentGraph\NodeAggregate; -use Neos\ContentRepository\Core\SharedModel\Workspace\Workspace; use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId; use Neos\ContentRepository\Core\SharedModel\Exception\NodeNameIsAlreadyCovered; use Neos\ContentRepository\Core\SharedModel\Exception\NodeTypeNotFound; use Neos\ContentRepository\Core\SharedModel\Node\NodeName; +use Neos\ContentRepository\Core\SharedModel\Workspace\Workspace; use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName; use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry; use Neos\ContentRepositoryRegistry\Exception\ContentRepositoryNotFoundException; @@ -28,6 +28,7 @@ use Neos\Flow\Annotations as Flow; use Neos\Flow\Package; use Neos\Flow\Package\PackageManager; +use Neos\Flow\Security\Context as SecurityContext; use Neos\Flow\Session\SessionInterface; use Neos\Media\Domain\Repository\AssetCollectionRepository; use Neos\Neos\Controller\Module\AbstractModuleController; @@ -39,12 +40,10 @@ use Neos\Neos\Domain\Repository\DomainRepository; use Neos\Neos\Domain\Repository\SiteRepository; use Neos\Neos\Domain\Service\NodeTypeNameFactory; +use Neos\Neos\Domain\Service\SiteImportService; use Neos\Neos\Domain\Service\SiteService; use Neos\Neos\Domain\Service\UserService; -use Neos\Neos\FrontendRouting\SiteDetection\SiteDetectionResult; -use Neos\SiteKickstarter\Generator\SitePackageGeneratorInterface; -use Neos\SiteKickstarter\Service\SiteGeneratorCollectingService; -use Neos\SiteKickstarter\Service\SitePackageGeneratorNameService; +use Neos\Utility\Files; /** * The Neos Sites Management module controller @@ -97,6 +96,18 @@ class SitesController extends AbstractModuleController */ protected $defaultContentRepositoryForNewSites; + /** + * @Flow\Inject + * @var SecurityContext + */ + protected $securityContext; + + /** + * @Flow\Inject + * @var SiteImportService + */ + protected $siteImportService; + #[Flow\Inject] protected UserService $domainUserService; @@ -272,33 +283,35 @@ public function newSiteAction(): void * @Flow\Validate(argumentName="$packageKey", type="\Neos\Neos\Validation\Validator\PackageKeyValidator") * @return void */ - /*public function importSiteAction($packageKey) + public function importSiteAction($packageKey) { try { - $this->siteImportService->importFromPackage($packageKey); - $this->addFlashMessage( - $this->getModuleLabel('sites.theSiteHasBeenImported.body'), - '', - Message::SEVERITY_OK, - [], - 1412372266 - ); - } catch (\Exception $exception) { - $logMessage = $this->throwableStorage->logThrowable($exception); - $this->logger->error($logMessage, LogEnvironment::fromMethodName(__METHOD__)); - $this->addFlashMessage( - $this->getModuleLabel( - 'sites.importError.body', - [htmlspecialchars($packageKey), htmlspecialchars($exception->getMessage())] - ), - $this->getModuleLabel('sites.importError.title'), - Message::SEVERITY_ERROR, - [], - 1412372375 - ); + $contentRepositoryId = ContentRepositoryId::fromString($this->defaultContentRepositoryForNewSites ?? ''); + } catch (\InvalidArgumentException $e) { + throw new \RuntimeException('The default content repository for new sites configured in "Neos.Neos.sitePresets.default.contentRepository" is not valid.', 1736946907, $e); } - $this->unsetLastVisitedNodeAndRedirect('index'); - }*/ + + $package = $this->packageManager->getPackage($packageKey); + $path = Files::concatenatePaths([$package->getPackagePath(), 'Resources/Private/Content']); + + // CreateRootWorkspace was denied: Creation of root workspaces is currently only allowed with disabled authorization checks + $this->securityContext->withoutAuthorizationChecks(fn () => $this->siteImportService->importFromPath( + $contentRepositoryId, + $path, + fn () => null, + fn () => null + )); + + $this->addFlashMessage( + $this->getModuleLabel('sites.theSiteHasBeenImported.body'), + '', + Message::SEVERITY_OK, + [], + 1412372266 + ); + + $this->redirect('index'); + } /** * Create a new empty site. diff --git a/Neos.Neos/Resources/Private/Translations/en/Modules.xlf b/Neos.Neos/Resources/Private/Translations/en/Modules.xlf index 1844d588155..5235978e3c0 100755 --- a/Neos.Neos/Resources/Private/Translations/en/Modules.xlf +++ b/Neos.Neos/Resources/Private/Translations/en/Modules.xlf @@ -548,12 +548,6 @@ Click on one of the nodes to only see its fallbacks and variants. Click again to The site has been imported. - - Import error - - - Error: During the import of the "Sites.xml" from the package "{0}" an exception occurred: {1} - Site creation error From 93be073781dab2852218cb73dd39e683cb0afe92 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Thu, 16 Jan 2025 15:48:11 +0100 Subject: [PATCH 03/11] BUGFIX: Prevent site import to be run again if the event store contains events - also add notes for this case --- .../Module/Administration/SitesController.php | 8 ++++++-- .../Module/Administration/Sites/NewSite.html | 12 +++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Neos.Neos/Classes/Controller/Module/Administration/SitesController.php b/Neos.Neos/Classes/Controller/Module/Administration/SitesController.php index aa76ee5a02a..fb3563dc919 100755 --- a/Neos.Neos/Classes/Controller/Module/Administration/SitesController.php +++ b/Neos.Neos/Classes/Controller/Module/Administration/SitesController.php @@ -263,14 +263,18 @@ public function newSiteAction(): void try { $contentRepository = $this->contentRepositoryRegistry->get($contentRepositoryId); - $documentNodeTypes = $contentRepository->getNodeTypeManager()->getSubNodeTypes(NodeTypeNameFactory::forSite(), false); } catch (ContentRepositoryNotFoundException $e) { - throw new \RuntimeException(sprintf('The default content repository for new sites "%s" could not be instantiated.', $contentRepositoryId->value), 1736946907, $e); + throw new \RuntimeException(sprintf('The default content repository for new sites "%s" could not be instantiated.', $contentRepositoryId->value), 1736946907); } + $documentNodeTypes = $contentRepository->getNodeTypeManager()->getSubNodeTypes(NodeTypeNameFactory::forSite(), false); + $sitePackages = $this->packageManager->getFilteredPackages('available', 'neos-site'); $this->view->assignMultiple([ + 'defaultContentRepositoryForNewSites' => $contentRepositoryId->value, + // The live workspace has to be empty prior to importing, that's why we disable the functionality + 'canImportFromPackage' => $this->siteRepository->findFirst() === null, 'sitePackages' => $sitePackages, 'documentNodeTypes' => $documentNodeTypes ]); diff --git a/Neos.Neos/Resources/Private/Templates/Module/Administration/Sites/NewSite.html b/Neos.Neos/Resources/Private/Templates/Module/Administration/Sites/NewSite.html index fc2a4a830c0..a1384e2db8e 100644 --- a/Neos.Neos/Resources/Private/Templates/Module/Administration/Sites/NewSite.html +++ b/Neos.Neos/Resources/Private/Templates/Module/Administration/Sites/NewSite.html @@ -3,20 +3,26 @@

{neos:backend.translate(id: 'sites.new', value: 'New site', source: 'Modules')}

+ All site creations will target the content repository: "{defaultContentRepositoryForNewSites}"
{neos:backend.translate(id: 'sites.import', value: 'Import a site', source: 'Modules')} - + + NOTE: Currently it's only possible to import once into a content repository from a site package. + To reimport please prune the sites first via ./flow site:pruneall. +

+
+
- +
- +

{neos:backend.translate(id: 'sites.noPackackeInfo', value: 'No site packages are available. Make sure you have an active site package.', source: 'Modules')} From 41f1c31cde9387f288a8f8fae7b8b3c017edc024 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Thu, 16 Jan 2025 15:48:46 +0100 Subject: [PATCH 04/11] TASK: Add notes to UI that creating sites via site module is deprecated --- .../Templates/Module/Administration/Sites/Index.html | 2 +- .../Templates/Module/Administration/Sites/NewSite.html | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Neos.Neos/Resources/Private/Templates/Module/Administration/Sites/Index.html b/Neos.Neos/Resources/Private/Templates/Module/Administration/Sites/Index.html index eff259abf0a..426e4d46d39 100644 --- a/Neos.Neos/Resources/Private/Templates/Module/Administration/Sites/Index.html +++ b/Neos.Neos/Resources/Private/Templates/Module/Administration/Sites/Index.html @@ -100,7 +100,7 @@