‪TYPO3CMS  10.4
SqlSrv.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
25 
30 {
36  protected const ‪SCHEMA_NAME_MAX_LENGTH = 128;
37 
47  protected ‪$databaseCharsetToCheck = [
48  '_UTF8',
49  ];
50 
61  '_UTF8'
62  ];
63 
71  public function ‪getStatus(): ‪FlashMessageQueue
72  {
73  $defaultConnection = GeneralUtility::makeInstance(ConnectionPool::class)
74  ->getConnectionByName(ConnectionPool::DEFAULT_CONNECTION_NAME);
75  if (strpos($defaultConnection->getServerVersion(), 'mssql') !== 0) {
77  }
78 
79  $this->‪checkDefaultDatabaseCharset($defaultConnection);
80  $this->‪checkDefaultDatabaseServerCharset($defaultConnection);
81  $this->‪checkDatabaseName($defaultConnection);
82 
84  }
85 
91  public function ‪checkDefaultDatabaseCharset(‪Connection $connection): void
92  {
93  $defaultDatabaseCharset = $connection->executeQuery(
94  'SELECT DATABASEPROPERTYEX(?,\'collation\')',
95  [$connection->getDatabase()],
96  [\PDO::PARAM_STR]
97  )
98  ->fetch(\PDO::FETCH_NUM);
99 
100  foreach ($this->databaseCharsetToCheck as ‪$databaseCharsetToCheck) {
101  if (!stripos($defaultDatabaseCharset[0], ‪$databaseCharsetToCheck)) {
102  $this->messageQueue->enqueue(new ‪FlashMessage(
103  sprintf(
104  'Checking database character set failed, got key "%s" where "%s" is not part of the collation',
105  $defaultDatabaseCharset[0],
107  ),
108  'SQL Server database character set check failed',
110  ));
111  } else {
112  $this->messageQueue->enqueue(new ‪FlashMessage(
113  '',
114  sprintf('SQL Server database uses %s. All good.', implode(' or ', $this->databaseCharsetToCheck))
115  ));
116  }
117  }
118  }
119 
125  public function ‪checkDefaultDatabaseServerCharset(Connection $connection): void
126  {
127  $defaultServerCharset = $connection->executeQuery('SELECT SERVERPROPERTY(\'Collation\')')
128  ->fetch(\PDO::FETCH_NUM);
129 
130  foreach ($this->databaseServerCharsetToCheck as ‪$databaseServerCharsetToCheck) {
131  // is charset part of collation
132  if (!stripos($defaultServerCharset[0], ‪$databaseServerCharsetToCheck)) {
133  $this->messageQueue->enqueue(new FlashMessage(
134  sprintf(
135  'Checking server character set failed, got key "%s" where "%s" is not part of the collation',
136  $defaultServerCharset[0],
138  ),
139  'SQL Server database character set check failed',
141  ));
142  } else {
143  $this->messageQueue->enqueue(new FlashMessage(
144  '',
145  sprintf('SQL Server server default uses %s. All good.', implode(' or ', $this->databaseCharsetToCheck))
146  ));
147  }
148  }
149  }
150 
171  public static function ‪isValidDatabaseName(string $databaseName): bool
172  {
173  return strlen($databaseName) <= static::SCHEMA_NAME_MAX_LENGTH && preg_match('/^(?!@@)[a-zA-Z0-9\$_@#\p{L}]*$/u', $databaseName);
174  }
175 
176  protected function ‪checkDatabaseName(‪Connection $connection): void
177  {
178  if (static::isValidDatabaseName($connection->getDatabase())) {
179  return;
180  }
181 
182  $this->messageQueue->enqueue(
183  new ‪FlashMessage(
184  'The given database name must not be longer than ' . static::SCHEMA_NAME_MAX_LENGTH . ' characters'
185  . ' and consist solely of basic latin letters (a-z), unicode characters, digits (0-9), dollar signs ($),'
186  . ' symbol @, underscores (_) and does not start with "@@".',
187  'Database name not valid',
189  )
190  );
191  }
192 }
‪TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\Platform\SqlSrv\checkDefaultDatabaseCharset
‪checkDefaultDatabaseCharset(Connection $connection)
Definition: SqlSrv.php:89
‪TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\Platform\SqlSrv\checkDefaultDatabaseServerCharset
‪checkDefaultDatabaseServerCharset(Connection $connection)
Definition: SqlSrv.php:123
‪TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\Platform\AbstractPlatform
Definition: AbstractPlatform.php:28
‪TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\Platform\SqlSrv\getStatus
‪FlashMessageQueue getStatus()
Definition: SqlSrv.php:69
‪TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\Platform
Definition: AbstractPlatform.php:18
‪TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\Platform\SqlSrv\$databaseServerCharsetToCheck
‪array $databaseServerCharsetToCheck
Definition: SqlSrv.php:58
‪TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\Platform\SqlSrv\SCHEMA_NAME_MAX_LENGTH
‪const SCHEMA_NAME_MAX_LENGTH
Definition: SqlSrv.php:36
‪TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\Platform\SqlSrv\checkDatabaseName
‪checkDatabaseName(Connection $connection)
Definition: SqlSrv.php:174
‪TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\Platform\SqlSrv\isValidDatabaseName
‪static bool isValidDatabaseName(string $databaseName)
Definition: SqlSrv.php:169
‪TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\Platform\SqlSrv
Definition: SqlSrv.php:30
‪TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\Platform\AbstractPlatform\$messageQueue
‪FlashMessageQueue $messageQueue
Definition: AbstractPlatform.php:31
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:36
‪TYPO3\CMS\Core\Messaging\AbstractMessage\INFO
‪const INFO
Definition: AbstractMessage.php:28
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:24
‪TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\Platform\SqlSrv\$databaseCharsetToCheck
‪array $databaseCharsetToCheck
Definition: SqlSrv.php:46
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Messaging\FlashMessageQueue
Definition: FlashMessageQueue.php:29
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:31