Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions Classes/Command/BootstrapSetupCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

declare(strict_types=1);

namespace Kitodo\Dlf\Command;

use Kitodo\Dlf\Service\BootstrapRootSetupService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Throwable;

/**
* CLI command for running the bootstrap root setup manually.
*/
final class BootstrapSetupCommand extends Command
{
public function __construct(private readonly BootstrapRootSetupService $bootstrapRootSetupService)
{
parent::__construct();
}

public function configure(): void
{
$this->setDescription('Create the root page tree and viewer setup manually.');
$this->addOption('identifier', null, InputOption::VALUE_REQUIRED, 'Custom site identifier.');
$this->addOption('base', null, InputOption::VALUE_REQUIRED, 'Custom site base path, for example /my-instance/.');
$this->addOption('root-title', null, InputOption::VALUE_REQUIRED, 'Custom root page title.');
$this->addOption('root-slug', null, InputOption::VALUE_REQUIRED, 'Custom root page slug.');
$this->addOption('viewer-slug', null, InputOption::VALUE_REQUIRED, 'Custom viewer page slug.');
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$io->title('Page setup');

try {
$result = $this->bootstrapRootSetupService->runSetup(
[
'identifier' => $input->getOption('identifier'),
'base' => $input->getOption('base'),
'rootTitle' => $input->getOption('root-title'),
'rootSlug' => $input->getOption('root-slug'),
'viewerSlug' => $input->getOption('viewer-slug'),
]
);
} catch (Throwable $exception) {
$io->error($exception->getMessage());
return Command::FAILURE;
}

$io->definitionList(
['Site identifier' => $result['siteIdentifier']],
['Site base' => $result['siteBase']],
['Root page' => (string) $result['rootPageId']],
['Viewer page' => (string) $result['viewerPageId']],
['Configuration page' => (string) $result['configurationPageId']],
['Template record' => (string) $result['templateId']],
['Solr core' => 'not implemented yet'],
);
$io->success('Default page setup completed.');

return Command::SUCCESS;
}
}
44 changes: 38 additions & 6 deletions Classes/Controller/Backend/NewTenantController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Kitodo\Dlf\Domain\Repository\MetadataRepository;
use Kitodo\Dlf\Domain\Repository\SolrCoreRepository;
use Kitodo\Dlf\Domain\Repository\StructureRepository;
use Kitodo\Dlf\Service\BootstrapRootSetupService;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Backend\Template\ModuleTemplateFactory;
use TYPO3\CMS\Backend\Utility\BackendUtility;
Expand Down Expand Up @@ -139,18 +140,29 @@ public function injectSolrCoreRepository(SolrCoreRepository $solrCoreRepository)
$this->solrCoreRepository = $solrCoreRepository;
}

/**
* @access protected
*/
protected BootstrapRootSetupService $bootstrapRootSetupService;

/**
* @access public
*/
public function injectBootstrapRootSetupService(BootstrapRootSetupService $bootstrapRootSetupService): void
{
$this->bootstrapRootSetupService = $bootstrapRootSetupService;
}

/**
* Returns a response object with either the given html string or the current rendered view as content.
*
* @access protected
*
* @param bool $isError whether to render the non-error or error template
*
* @param mixed[] $extraData extra view data used to render the template (in addition to $viewData of AbstractController)
*
* @return ResponseInterface the response
*/
protected function templateResponse(bool $isError, array $extraData): ResponseInterface
protected function templateResponse(string $template, array $extraData): ResponseInterface
{
$flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
$messageQueue = $flashMessageService->getMessageQueueByIdentifier();
Expand All @@ -160,7 +172,6 @@ protected function templateResponse(bool $isError, array $extraData): ResponseIn
$moduleTemplate->assignMultiple($this->viewData);
$moduleTemplate->assignMultiple($extraData);
$moduleTemplate->setFlashMessageQueue($messageQueue);
$template = $isError ? 'Backend/NewTenant/Error' : 'Backend/NewTenant/Index';
return $moduleTemplate->renderResponse($template);
}

Expand Down Expand Up @@ -195,6 +206,23 @@ protected function initializeAction(): void
}


/**
* Action creating a default page tree from the virtual root page.
*
* @access public
*/
public function createPagesAction(): ResponseInterface
{
if ($this->pid !== 0) {
return $this->redirect('error');
}

$this->bootstrapRootSetupService->runSetup();

return $this->redirect('index', null, null, ['refreshPageTree' => 1]);
}


/**
* Action adding formats records
*
Expand Down Expand Up @@ -423,6 +451,10 @@ public function indexAction(): ResponseInterface
{
$recordInfos = [];

if ($this->pid === 0) {
return $this->templateResponse('Backend/NewTenant/Root', ['refreshPageTree' => (bool) ($this->request->getQueryParams()['refreshPageTree'] ?? false)]);
}

$this->pageInfo = BackendUtility::readPageAccess($this->pid, $GLOBALS['BE_USER']->getPagePermsClause(1)) ?: [];

if (!isset($this->pageInfo['doktype']) || $this->pageInfo['doktype'] != 254) {
Expand All @@ -445,7 +477,7 @@ public function indexAction(): ResponseInterface

$viewData = ['recordInfos' => $recordInfos];

return $this->templateResponse(false, $viewData);
return $this->templateResponse('Backend/NewTenant/Index', $viewData);
}

/**
Expand All @@ -457,7 +489,7 @@ public function indexAction(): ResponseInterface
*/
public function errorAction(): ResponseInterface
{
return $this->templateResponse(true, []);
return $this->templateResponse('Backend/NewTenant/Error', []);
}

/**
Expand Down
Loading
Loading