|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
|
|
4
|
|
|
namespace TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\Platform; |
|
5
|
|
|
|
|
6
|
|
|
/* |
|
7
|
|
|
* This file is part of the TYPO3 CMS project. |
|
8
|
|
|
* |
|
9
|
|
|
* It is free software; you can redistribute it and/or modify it under |
|
10
|
|
|
* the terms of the GNU General Public License, either version 2 |
|
11
|
|
|
* of the License, or any later version. |
|
12
|
|
|
* |
|
13
|
|
|
* For the full copyright and license information, please read the |
|
14
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
15
|
|
|
* |
|
16
|
|
|
* The TYPO3 project - inspiring people to share! |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
use TYPO3\CMS\Core\Database\Connection; |
|
20
|
|
|
use TYPO3\CMS\Core\Database\ConnectionPool; |
|
21
|
|
|
use TYPO3\CMS\Core\Messaging\FlashMessage; |
|
22
|
|
|
use TYPO3\CMS\Core\Messaging\FlashMessageQueue; |
|
23
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @internal This class is only meant to be used within EXT:install and is not part of the TYPO3 Core API. |
|
27
|
|
|
*/ |
|
28
|
|
|
class Sqlite extends AbstractPlatform |
|
29
|
|
|
{ |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Get all status information as array with status objects |
|
33
|
|
|
* |
|
34
|
|
|
* @return FlashMessageQueue |
|
35
|
|
|
* @throws \InvalidArgumentException |
|
36
|
|
|
* @throws \Doctrine\DBAL\DBALException |
|
37
|
|
|
*/ |
|
38
|
|
|
public function getStatus(): FlashMessageQueue |
|
39
|
|
|
{ |
|
40
|
|
|
$defaultConnection = GeneralUtility::makeInstance(ConnectionPool::class) |
|
41
|
|
|
->getConnectionByName(ConnectionPool::DEFAULT_CONNECTION_NAME); |
|
42
|
|
|
if (strpos($defaultConnection->getServerVersion(), 'sqlite') !== 0) { |
|
43
|
|
|
return $this->messageQueue; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
$this->checkDefaultDatabaseCharset($defaultConnection); |
|
47
|
|
|
$this->checkDefaultDatabaseServerCharset($defaultConnection); |
|
48
|
|
|
$this->checkDatabaseName($defaultConnection); |
|
49
|
|
|
|
|
50
|
|
|
return $this->messageQueue; |
|
51
|
|
|
} |
|
52
|
|
|
/** |
|
53
|
|
|
* Checks the character set of the database and reports an error if it is not utf-8. |
|
54
|
|
|
* |
|
55
|
|
|
* @param Connection $connection to the database to be checked |
|
56
|
|
|
*/ |
|
57
|
|
|
public function checkDefaultDatabaseCharset(Connection $connection): void |
|
58
|
|
|
{ |
|
59
|
|
|
// TODO: Implement getDefaultDatabaseCharset() method. |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Checks the character set of the database server and reports an info if it is not utf-8. |
|
64
|
|
|
* |
|
65
|
|
|
* @param Connection $connection to the database to be checked |
|
66
|
|
|
*/ |
|
67
|
|
|
public function checkDefaultDatabaseServerCharset(Connection $connection): void |
|
68
|
|
|
{ |
|
69
|
|
|
// TODO: Implement getDefaultDatabaseServerCharset() method. |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Validate the database name |
|
74
|
|
|
* SQLite does not have any limitation for the length of the database name, |
|
75
|
|
|
* but must start with a letter or _ |
|
76
|
|
|
* |
|
77
|
|
|
* @param string $databaseName |
|
78
|
|
|
* @return bool |
|
79
|
|
|
*/ |
|
80
|
|
|
public static function isValidDatabaseName(string $databaseName): bool |
|
81
|
|
|
{ |
|
82
|
|
|
return (bool)preg_match('/^[A-Za-z_\/][a-zA-Z0-9\$\/_.-]*$/', $databaseName); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
protected function checkDatabaseName(Connection $connection): void |
|
86
|
|
|
{ |
|
87
|
|
|
if (static::isValidDatabaseName($connection->getDatabase())) { |
|
88
|
|
|
return; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
$this->messageQueue->enqueue( |
|
92
|
|
|
new FlashMessage( |
|
93
|
|
|
'The given database name must consist solely of basic latin letters (a-z), digits (0-9)' |
|
94
|
|
|
. ' and underscores (_).', |
|
95
|
|
|
'Database name not valid', |
|
96
|
|
|
FlashMessage::ERROR |
|
97
|
|
|
) |
|
98
|
|
|
); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|