Skip to content

Commit 53a7dc8

Browse files
committed
feat: Update for TYPO3 v13
1 parent 747a13f commit 53a7dc8

14 files changed

+59
-374
lines changed

Classes/Command/GenerateErrorPagesCommand.php

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
namespace Netlogix\Nxerrorhandler\Command;
66

77
use InvalidArgumentException;
8-
use Netlogix\Nxerrorhandler\ErrorHandler\GeneralExceptionHandler;
9-
use Netlogix\Nxerrorhandler\Exception\Exception;
108
use Netlogix\Nxerrorhandler\Service\ConfigurationService;
119
use Psr\Http\Message\ServerRequestInterface;
10+
use Psr\Log\LoggerAwareInterface;
11+
use Psr\Log\LoggerAwareTrait;
1212
use Symfony\Component\Console\Command\Command;
1313
use Symfony\Component\Console\Input\InputArgument;
1414
use Symfony\Component\Console\Input\InputInterface;
@@ -22,11 +22,11 @@
2222
use TYPO3\CMS\Core\Site\SiteFinder;
2323
use TYPO3\CMS\Core\Utility\GeneralUtility;
2424

25-
class GenerateErrorPagesCommand extends Command
25+
class GenerateErrorPagesCommand extends Command implements LoggerAwareInterface
2626
{
27-
private int|bool|null $deploymentDate = null;
27+
use LoggerAwareTrait;
2828

29-
private ?GeneralExceptionHandler $exceptionHandler = null;
29+
private int|bool|null $deploymentDate = null;
3030

3131
protected function configure()
3232
{
@@ -74,6 +74,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7474
GeneralUtility::setIndpEnv('TYPO3_REQUEST_URL', (string) $site->getBase());
7575
foreach ($errorHandlingConfiguration as $errorCode => $configuration) {
7676
foreach ($site->getLanguages() as $language) {
77+
if ($language->isEnabled() === false) {
78+
continue;
79+
}
80+
7781
if (!$forceGeneration && !$this->checkIfErrorPageNeedsRegeneration($errorCode, $site, $language)) {
7882
continue;
7983
}
@@ -87,15 +91,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8791
$resolvedUrl = $this->resolveUrl($request, $configuration['errorContentSource']);
8892
$content = GeneralUtility::getUrl($resolvedUrl);
8993
if ($content === false || $content === '') {
90-
$message = sprintf(
94+
$this->logger->error(sprintf(
9195
'Could not retrieve [%1$s] error page on rootPageId [%2$d] with language [%3$d]. Requested url was "%4$s".',
9296
$errorCode,
9397
$site->getRootPageId(),
9498
$language->getLanguageId(),
9599
$resolvedUrl
96-
);
97-
$this->getExceptionHandler()
98-
->logError(new \Exception($message, 1395152041), GeneralExceptionHandler::CONTEXT_CLI);
100+
));
99101

100102
continue;
101103
}
@@ -113,7 +115,7 @@ private function initializeTargetDirectory(): void
113115
if (!file_exists(ConfigurationService::getErrorDocumentDirectory())) {
114116
GeneralUtility::mkdir(ConfigurationService::getErrorDocumentDirectory());
115117
} elseif (!is_dir(ConfigurationService::getErrorDocumentDirectory())) {
116-
throw new Exception('Target directory is not a directory', 1394124945);
118+
throw new \RuntimeException('Target directory is not a directory', 1394124945);
117119
}
118120
}
119121

@@ -127,15 +129,6 @@ protected function saveErrorPage(int $errorCode, Site $site, SiteLanguage $langu
127129
GeneralUtility::writeFile($file, $content);
128130
}
129131

130-
private function getExceptionHandler(): GeneralExceptionHandler
131-
{
132-
if (!$this->exceptionHandler instanceof GeneralExceptionHandler) {
133-
$this->exceptionHandler = GeneralUtility::makeInstance(GeneralExceptionHandler::class);
134-
}
135-
136-
return $this->exceptionHandler;
137-
}
138-
139132
private function checkIfErrorPageNeedsRegeneration(int $errorCode, Site $site, SiteLanguage $language): bool
140133
{
141134
$file = $this->getErrorDocumentFilePath($errorCode, $site, $language);
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Netlogix\Nxerrorhandler\Controller;
6+
7+
use Netlogix\Nxerrorhandler\ErrorHandler\Component\StaticDocumentComponent;
8+
use Psr\Http\Message\ServerRequestInterface;
9+
use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
10+
use TYPO3\CMS\Core\Utility\GeneralUtility;
11+
12+
#[Autoconfigure(public: true)]
13+
readonly class ErrorPageController extends \TYPO3\CMS\Core\Controller\ErrorPageController
14+
{
15+
public function errorAction(string $title, string $message, int $errorCode = 0, ?int $httpStatusCode = null): string
16+
{
17+
$output = GeneralUtility::makeInstance(StaticDocumentComponent::class)
18+
->getOutput($httpStatusCode ?? 500, $this->getRequest(), $message);
19+
20+
if ($output === '') {
21+
return parent::errorAction($title, $message, $errorCode, $httpStatusCode);
22+
}
23+
24+
return $output;
25+
}
26+
27+
private function getRequest(): ServerRequestInterface
28+
{
29+
return $GLOBALS['TYPO3_REQUEST'];
30+
}
31+
}

Classes/Error/PageContentErrorHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function handlePageError(
2424
}
2525

2626
$staticDocumentComponent = GeneralUtility::makeInstance(StaticDocumentComponent::class);
27-
$content = $staticDocumentComponent->getOutput(404, $request, $message);
27+
$content = $staticDocumentComponent->getOutput($this->statusCode, $request, $message);
2828
if ($content === '') {
2929
return parent::handlePageError($request, $message, $reasons);
3030
}

Classes/ErrorHandler/Component/AbstractComponent.php

Lines changed: 0 additions & 39 deletions
This file was deleted.

Classes/ErrorHandler/Component/ExtbaseArgumentsToBadRequestComponent.php

Lines changed: 0 additions & 31 deletions
This file was deleted.

Classes/ErrorHandler/Component/StaticDocumentComponent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
/**
1414
* Manage static error pages
1515
*/
16-
class StaticDocumentComponent extends AbstractComponent
16+
class StaticDocumentComponent
1717
{
1818
public function getOutput(int $errorCode, ServerRequestInterface $request, string $reason = ''): string
1919
{

Classes/ErrorHandler/GeneralExceptionHandler.php

Lines changed: 0 additions & 176 deletions
This file was deleted.

Classes/Exception/Exception.php

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)