Skip to content

Commit

Permalink
[TASK] Prefer feature detection over version detection for compat
Browse files Browse the repository at this point in the history
  • Loading branch information
helhum committed Feb 11, 2023
1 parent b41b135 commit 1406aa2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
Expand Up @@ -25,7 +25,6 @@
use TYPO3\CMS\Core\Database\Query\Restriction\EndTimeRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\StartTimeRestriction;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class CreateBackendAdminUserCommand extends Command
Expand Down Expand Up @@ -132,17 +131,11 @@ private function validateUsername(?string $username): ?string
->removeByType(StartTimeRestriction::class)
->removeByType(EndTimeRestriction::class)
->removeByType(HiddenRestriction::class);
$queryBuilder->count('uid')
$userExists = $queryBuilder->count('uid')
->from('be_users')
->where(
$queryBuilder->expr()->eq('username', $queryBuilder->createNamedParameter($username))
);

if ((new Typo3Version())->getMajorVersion() > 11) {
$userExists = $queryBuilder->executeQuery()->fetchOne() > 0;
} else {
$userExists = $queryBuilder->execute()->fetchColumn() > 0;
}
)->execute()->fetchOne() > 0;

if ($userExists) {
return sprintf('A user with username "%s" already exists.', $username);
Expand Down
6 changes: 2 additions & 4 deletions Classes/Console/Core/Booting/Scripts.php
Expand Up @@ -21,7 +21,6 @@
use TYPO3\CMS\Core\Authentication\CommandLineUserAuthentication;
use TYPO3\CMS\Core\Core\BootService;
use TYPO3\CMS\Core\Core\Bootstrap;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Page\PageRenderer;

class Scripts
Expand Down Expand Up @@ -56,10 +55,9 @@ public static function initializeExtensionConfiguration(ContainerInterface $cont
$bootService->makeCurrent($container);
}
$container->get('boot.state')->done = false;
$assetsCache = $container->get('cache.assets');
$coreCache = $container->get('cache.core');
if ((new Typo3Version())->getMajorVersion() < 12) {
PageRenderer::setCache($assetsCache);
if (method_exists(PageRenderer::class, 'setCache')) {
PageRenderer::setCache($container->get('cache.assets'));
}
Bootstrap::loadTypo3LoadedExtAndExtLocalconf(true, $coreCache);
Bootstrap::unsetReservedGlobalVariables();
Expand Down

0 comments on commit 1406aa2

Please sign in to comment.