Skip to content

Commit

Permalink
[BUGFIX] Avoid unnecessary DB queries to sys_language
Browse files Browse the repository at this point in the history
Since site handling, finding the correct languages and the amount of languages in a page can be simplified.

NewRecordController->checkIfLanguagesExist() is never in use, and can be removed completely.

Resolves: #89125
Releases: master
Change-Id: I523bf8ecdf0598d7acb062200710c4fae2935cc5
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/61656
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Susanne Moog <look@susi.dev>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Susanne Moog <look@susi.dev>
  • Loading branch information
bmack authored and susannemoog committed Sep 11, 2019
1 parent b55e146 commit f329f0c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 40 deletions.
19 changes: 0 additions & 19 deletions typo3/sysext/backend/Classes/Controller/NewRecordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -771,25 +771,6 @@ protected function isRecordCreationAllowedForTable(string $table, array $allowed
return !in_array($table, $deniedNewTables) && (empty($allowedNewTables) || in_array($table, $allowedNewTables));
}

/**
* Checks if sys_language records are present
*
* @return bool
*/
protected function checkIfLanguagesExist(): bool
{
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('sys_language');
$queryBuilder->getRestrictions()->removeAll();

$count = $queryBuilder
->count('uid')
->from('sys_language')
->execute()
->fetchColumn(0);
return (bool)$count;
}

/**
* @return LanguageService
*/
Expand Down
37 changes: 16 additions & 21 deletions typo3/sysext/backend/Classes/Controller/PageLayoutController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Site\Entity\SiteInterface;
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
use TYPO3\CMS\Core\Type\Bitmask\Permission;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
Expand Down Expand Up @@ -246,6 +247,11 @@ class PageLayoutController
*/
protected $searchContent;

/**
* @var SiteLanguage[]
*/
protected $availableLanguages;

/**
* Injects the request object for the current request or subrequest
* As this controller goes only through the main() method, it is rather simple for now
Expand Down Expand Up @@ -317,7 +323,7 @@ protected function menuConfig(ServerRequestInterface $request): void

/** @var SiteInterface $currentSite */
$currentSite = $request->getAttribute('site');
$availableLanguages = $currentSite->getAvailableLanguages($this->getBackendUser(), false, $this->id);
$this->availableLanguages = $currentSite->getAvailableLanguages($this->getBackendUser(), false, $this->id);

$lang = $this->getLanguageService();
// MENU-ITEMS:
Expand Down Expand Up @@ -355,13 +361,13 @@ protected function menuConfig(ServerRequestInterface $request): void
)->execute();
while ($pageTranslation = $statement->fetch()) {
$languageId = $pageTranslation[$GLOBALS['TCA']['pages']['ctrl']['languageField']];
if (isset($availableLanguages[$languageId])) {
$this->MOD_MENU['language'][$languageId] = $availableLanguages[$languageId]->getTitle();
if (isset($this->availableLanguages[$languageId])) {
$this->MOD_MENU['language'][$languageId] = $this->availableLanguages[$languageId]->getTitle();
}
}
// Override the label
if (isset($availableLanguages[0])) {
$this->MOD_MENU['language'][0] = $availableLanguages[0]->getTitle();
if (isset($this->availableLanguages[0])) {
$this->MOD_MENU['language'][0] = $this->availableLanguages[0]->getTitle();
}
}
// Initialize the available actions
Expand All @@ -387,24 +393,13 @@ protected function menuConfig(ServerRequestInterface $request): void
protected function initActions(): array
{
$actions = [
1 => $this->getLanguageService()->getLL('m_function_1'),
2 => $this->getLanguageService()->getLL('m_function_2')
1 => $this->getLanguageService()->getLL('m_function_1')
];
// Find if there are ANY languages at all (and if not, remove the language option from function menu).
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_language');
if ($this->getBackendUser()->isAdmin()) {
$queryBuilder->getRestrictions()->removeAll();
}

$count = $queryBuilder
->count('uid')
->from('sys_language')
->execute()
->fetchColumn(0);

if (!$count) {
unset($actions['2']);
// Find if there are ANY languages at all (and if not, do not show the language option from function menu).
if (count($this->availableLanguages) > 1) {
$actions[2] = $this->getLanguageService()->getLL('m_function_2');
}
$this->makeLanguageMenu();
// Page / user TSconfig blinding of menu-items
$blindActions = $this->modTSconfig['properties']['menu.']['functions.'] ?? [];
foreach ($blindActions as $key => $value) {
Expand Down

0 comments on commit f329f0c

Please sign in to comment.