Skip to content

Commit

Permalink
BUGFIX: Reimplement Import site based on new SiteImportService
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Jan 16, 2025
1 parent 8bff3cc commit cb7f171
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@

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;
use Neos\Error\Messages\Message;
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;
Expand All @@ -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
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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.
Expand Down
6 changes: 0 additions & 6 deletions Neos.Neos/Resources/Private/Translations/en/Modules.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -548,12 +548,6 @@ Click on one of the nodes to only see its fallbacks and variants. Click again to
<trans-unit id="sites.theSiteHasBeenImported.body" xml:space="preserve">
<source>The site has been imported.</source>
</trans-unit>
<trans-unit id="sites.importError.title" xml:space="preserve">
<source>Import error</source>
</trans-unit>
<trans-unit id="sites.importError.body" xml:space="preserve">
<source>Error: During the import of the "Sites.xml" from the package "{0}" an exception occurred: {1}</source>
</trans-unit>
<trans-unit id="sites.siteCreationError.siteWithSiteNodeNameAlreadyExists.title" xml:space="preserve">
<source>Site creation error</source>
</trans-unit>
Expand Down

0 comments on commit cb7f171

Please sign in to comment.