Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fs#45038 [BUGFIX] Prevent crash if language not present/disabled on site #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
31 changes: 21 additions & 10 deletions Classes/Backend/Hook/DatamapHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
use TYPO3\CMS\Core\DataHandling\DataHandler;
use TYPO3\CMS\Core\DataHandling\SlugHelper;
use TYPO3\CMS\Core\Exception\SiteNotFoundException;
use TYPO3\CMS\Core\Log\Logger;
use TYPO3\CMS\Core\Log\LogLevel;
use TYPO3\CMS\Core\Log\LogManager;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Messaging\FlashMessageService;
use TYPO3\CMS\Core\Routing\InvalidRouteArgumentsException;
Expand All @@ -39,6 +42,11 @@ class DatamapHook
*/
protected $connection;

/**
* @var Logger
*/
protected $logger;

/**
* @var array
*/
Expand All @@ -48,6 +56,9 @@ public function __construct()
{
$this->connection = GeneralUtility::makeInstance(ConnectionPool::class)
->getConnectionForTable('pages');

$this->logger = GeneralUtility::makeInstance(LogManager::class)
->getLogger(__CLASS__);
}

/**
Expand Down Expand Up @@ -296,7 +307,8 @@ protected function updateRedirect(int $pageId, string $slug, int $languageId): v
$generatedPath = '';
try {
$generatedPath = $pageRouter->generateUri($pageId, ['_language' => $languageId])->getPath();
} catch (InvalidRouteArgumentsException $e) {
} catch (\InvalidArgumentException | InvalidRouteArgumentsException $e) {
$this->logger->log(LogLevel::WARNING, "Failed to generate path for page $pageId and language $languageId.");
}
$variant = null;
// There must be some kind of route enhancer involved
Expand Down Expand Up @@ -572,17 +584,16 @@ protected function getPageOrTranslatedPage(int $pageId, int $languageId): ?array
protected function getBaseByPageId(Site $site, $pageId, $languageId): array
{
$language = null;
// Fetch default language page ID to get the site
if ($languageId > 0) {
$defaultLanguagePageId = BackendUtility::getRecord('pages', $pageId, 'l10n_parent')['l10n_parent'];
if ($defaultLanguagePageId > 0) {
$pageId = $defaultLanguagePageId;
}
}

if ($languageId !== null) {
$language = $site->getLanguageById((int)$languageId);
try {
$language = $site->getLanguageById((int)$languageId);
} catch (\InvalidArgumentException $e){
$this->logger->log(LogLevel::WARNING, "Language $languageId does not exist or disabled on site!");
}
}
if ($language === null) {

if ($languageId === null) {
$language = $site->getDefaultLanguage();
}

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"license": "GPL-3.0",
"description": "The little TYPO3 9 slug helper",
"require": {
"php": ">=7.0.0",
"php": ">=7.1",
"ext-libxml": "*",
"ext-dom": "*"
},
Expand Down