Skip to content

Commit cb7f171

Browse files
committed
BUGFIX: Reimplement Import site based on new SiteImportService
see neos#5307
1 parent 8bff3cc commit cb7f171

File tree

2 files changed

+42
-35
lines changed

2 files changed

+42
-35
lines changed

Neos.Neos/Classes/Controller/Module/Administration/SitesController.php

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,19 @@
1616

1717
use Neos\ContentRepository\Core\Feature\NodeRenaming\Command\ChangeNodeAggregateName;
1818
use Neos\ContentRepository\Core\Projection\ContentGraph\NodeAggregate;
19-
use Neos\ContentRepository\Core\SharedModel\Workspace\Workspace;
2019
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;
2120
use Neos\ContentRepository\Core\SharedModel\Exception\NodeNameIsAlreadyCovered;
2221
use Neos\ContentRepository\Core\SharedModel\Exception\NodeTypeNotFound;
2322
use Neos\ContentRepository\Core\SharedModel\Node\NodeName;
23+
use Neos\ContentRepository\Core\SharedModel\Workspace\Workspace;
2424
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
2525
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
2626
use Neos\ContentRepositoryRegistry\Exception\ContentRepositoryNotFoundException;
2727
use Neos\Error\Messages\Message;
2828
use Neos\Flow\Annotations as Flow;
2929
use Neos\Flow\Package;
3030
use Neos\Flow\Package\PackageManager;
31+
use Neos\Flow\Security\Context as SecurityContext;
3132
use Neos\Flow\Session\SessionInterface;
3233
use Neos\Media\Domain\Repository\AssetCollectionRepository;
3334
use Neos\Neos\Controller\Module\AbstractModuleController;
@@ -39,12 +40,10 @@
3940
use Neos\Neos\Domain\Repository\DomainRepository;
4041
use Neos\Neos\Domain\Repository\SiteRepository;
4142
use Neos\Neos\Domain\Service\NodeTypeNameFactory;
43+
use Neos\Neos\Domain\Service\SiteImportService;
4244
use Neos\Neos\Domain\Service\SiteService;
4345
use Neos\Neos\Domain\Service\UserService;
44-
use Neos\Neos\FrontendRouting\SiteDetection\SiteDetectionResult;
45-
use Neos\SiteKickstarter\Generator\SitePackageGeneratorInterface;
46-
use Neos\SiteKickstarter\Service\SiteGeneratorCollectingService;
47-
use Neos\SiteKickstarter\Service\SitePackageGeneratorNameService;
46+
use Neos\Utility\Files;
4847

4948
/**
5049
* The Neos Sites Management module controller
@@ -97,6 +96,18 @@ class SitesController extends AbstractModuleController
9796
*/
9897
protected $defaultContentRepositoryForNewSites;
9998

99+
/**
100+
* @Flow\Inject
101+
* @var SecurityContext
102+
*/
103+
protected $securityContext;
104+
105+
/**
106+
* @Flow\Inject
107+
* @var SiteImportService
108+
*/
109+
protected $siteImportService;
110+
100111
#[Flow\Inject]
101112
protected UserService $domainUserService;
102113

@@ -272,33 +283,35 @@ public function newSiteAction(): void
272283
* @Flow\Validate(argumentName="$packageKey", type="\Neos\Neos\Validation\Validator\PackageKeyValidator")
273284
* @return void
274285
*/
275-
/*public function importSiteAction($packageKey)
286+
public function importSiteAction($packageKey)
276287
{
277288
try {
278-
$this->siteImportService->importFromPackage($packageKey);
279-
$this->addFlashMessage(
280-
$this->getModuleLabel('sites.theSiteHasBeenImported.body'),
281-
'',
282-
Message::SEVERITY_OK,
283-
[],
284-
1412372266
285-
);
286-
} catch (\Exception $exception) {
287-
$logMessage = $this->throwableStorage->logThrowable($exception);
288-
$this->logger->error($logMessage, LogEnvironment::fromMethodName(__METHOD__));
289-
$this->addFlashMessage(
290-
$this->getModuleLabel(
291-
'sites.importError.body',
292-
[htmlspecialchars($packageKey), htmlspecialchars($exception->getMessage())]
293-
),
294-
$this->getModuleLabel('sites.importError.title'),
295-
Message::SEVERITY_ERROR,
296-
[],
297-
1412372375
298-
);
289+
$contentRepositoryId = ContentRepositoryId::fromString($this->defaultContentRepositoryForNewSites ?? '');
290+
} catch (\InvalidArgumentException $e) {
291+
throw new \RuntimeException('The default content repository for new sites configured in "Neos.Neos.sitePresets.default.contentRepository" is not valid.', 1736946907, $e);
299292
}
300-
$this->unsetLastVisitedNodeAndRedirect('index');
301-
}*/
293+
294+
$package = $this->packageManager->getPackage($packageKey);
295+
$path = Files::concatenatePaths([$package->getPackagePath(), 'Resources/Private/Content']);
296+
297+
// CreateRootWorkspace was denied: Creation of root workspaces is currently only allowed with disabled authorization checks
298+
$this->securityContext->withoutAuthorizationChecks(fn () => $this->siteImportService->importFromPath(
299+
$contentRepositoryId,
300+
$path,
301+
fn () => null,
302+
fn () => null
303+
));
304+
305+
$this->addFlashMessage(
306+
$this->getModuleLabel('sites.theSiteHasBeenImported.body'),
307+
'',
308+
Message::SEVERITY_OK,
309+
[],
310+
1412372266
311+
);
312+
313+
$this->redirect('index');
314+
}
302315

303316
/**
304317
* Create a new empty site.

Neos.Neos/Resources/Private/Translations/en/Modules.xlf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -548,12 +548,6 @@ Click on one of the nodes to only see its fallbacks and variants. Click again to
548548
<trans-unit id="sites.theSiteHasBeenImported.body" xml:space="preserve">
549549
<source>The site has been imported.</source>
550550
</trans-unit>
551-
<trans-unit id="sites.importError.title" xml:space="preserve">
552-
<source>Import error</source>
553-
</trans-unit>
554-
<trans-unit id="sites.importError.body" xml:space="preserve">
555-
<source>Error: During the import of the "Sites.xml" from the package "{0}" an exception occurred: {1}</source>
556-
</trans-unit>
557551
<trans-unit id="sites.siteCreationError.siteWithSiteNodeNameAlreadyExists.title" xml:space="preserve">
558552
<source>Site creation error</source>
559553
</trans-unit>

0 commit comments

Comments
 (0)