Commit ef15df7b authored by Kevin Ditscheid's avatar Kevin Ditscheid

[BUGFIX] Fix the page not found handling for non existent languages

If a language is configured in the site config, but not present as a
language record in sys_language, we need to catch that issue and
redirect the page not found handling to the default language
parent d6df4f74
......@@ -26,26 +26,20 @@ namespace SGalinski\SgRoutes\Service;
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Controller\ErrorPageController;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Error\Http\PageNotFoundException;
use TYPO3\CMS\Core\Http\MiddlewareDispatcher;
use TYPO3\CMS\Core\Http\MiddlewareStackResolver;
use TYPO3\CMS\Core\Http\Request;
use TYPO3\CMS\Core\Http\ServerRequestFactory;
use TYPO3\CMS\Core\Http\Uri;
use TYPO3\CMS\Core\Package\PackageManager;
use TYPO3\CMS\Core\Service\DependencyOrderingService;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\HttpUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\Controller\ErrorController;
use TYPO3\CMS\Frontend\Http\RequestHandler;
use TYPO3\CMS\Frontend\Page\PageRepository;
/**
* Class SGalinski\SgRoutes\Service\RoutingService
......@@ -105,7 +99,9 @@ class RoutingService {
$configurationFound = FALSE;
if ($rootUid) {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_sgroutes_domain_model_pagenotfoundhandling');
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(
'tx_sgroutes_domain_model_pagenotfoundhandling'
);
$handling = $queryBuilder->select('function', 'header')
->from('tx_sgroutes_domain_model_pagenotfoundhandling')
->where(
......@@ -123,14 +119,36 @@ class RoutingService {
) ||
$isFunctionStartsWithT3Prefix
) {
if ($isFunctionStartsWithT3Prefix) {
$function = (int) \substr($function, 14);
}
$function = 'index.php?id=' . $function;
$languageId = GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('language', 'id');
$GLOBALS['TSFE']->sys_page = GeneralUtility::makeInstance(PageRepository::class);
$contentObjectRenderer = GeneralUtility::makeInstance(
ContentObjectRenderer::class, $GLOBALS['TSFE']
);
$parameters = [
'parameter' => $function
];
$languageId = GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect(
'language', 'id'
);
if ($languageId) {
$function .= '&L=' . $languageId;
$queryBuilder = GeneralUtility::makeInstance(
ConnectionPool::class
)->getQueryBuilderForTable('sys_language');
$languageCount = $queryBuilder->select('uid')
->from('sys_language')
->where(
$queryBuilder->expr()->eq(
'uid', $queryBuilder->createNamedParameter($languageId, \PDO::PARAM_INT)
)
)
->setMaxResults(1)->execute()->rowCount();
if ($languageCount > 0) {
$parameters['additionalParams'] = '&L=' . $languageId;
} else {
$parameters['additionalParams'] = '&L=0';
}
}
$function = $contentObjectRenderer->typoLink_URL($parameters);
}
$GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling'] = $function;
......@@ -154,9 +172,9 @@ class RoutingService {
\header($GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling_statheader']);
$htaccessMessage = '';
if(
if (
$exception->getPrevious() instanceof \RuntimeException &&
\strpos($exception->getPrevious()->getMessage(), '401 Unauthorized')!==FALSE
\strpos($exception->getPrevious()->getMessage(), '401 Unauthorized') !== FALSE
) {
$htaccessMessage = ' The error page reported 401 Unauthorized, maybe there is a htaccess protection on it.';
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment