2 namespace TYPO3\CMS\Install\Controller\Action\Step;
40 $configurationManager = $this->objectManager->get(\TYPO3\CMS\Core\Configuration\ConfigurationManager::class);
44 $result[] = $this->executeLoadDbalExtension();
46 $result[] = $this->executeUnloadDbalExtension();
52 $driverConfig = array(
53 'useNameQuote' =>
true,
58 $driverConfig = array(
59 'driverOptions' => array(
73 if (isset($driverConfig)) {
74 $config[
'_DEFAULT'][
'config'] = array_merge($config[
'_DEFAULT'][
'config'], $driverConfig);
76 $configurationManager->setLocalConfigurationValueByPath(
'EXTCONF/dbal/handlerCfg', $config);
78 $localConfigurationPathValuePairs = array();
81 $config = $configurationManager->getConfigurationValueByPath(
'EXTCONF/dbal/handlerCfg');
82 $driver = $config[
'_DEFAULT'][
'config'][
'driver'];
83 if ($driver ===
'oci8') {
84 $config[
'_DEFAULT'][
'config'][
'driverOptions'][
'connectSID'] = (
$postValues[
'type'] ===
'sid');
85 $localConfigurationPathValuePairs[
'EXTCONF/dbal/handlerCfg'] = $config;
91 if (strlen($value) <= 50) {
92 $localConfigurationPathValuePairs[
'DB/username'] = $value;
95 $errorStatus = $this->objectManager->get(\TYPO3\CMS\Install\Status\ErrorStatus::class);
96 $errorStatus->setTitle(
'Database username not valid');
97 $errorStatus->setMessage(
'Given username must be shorter than fifty characters.');
98 $result[] = $errorStatus;
104 if (strlen($value) <= 50) {
105 $localConfigurationPathValuePairs[
'DB/password'] = $value;
108 $errorStatus = $this->objectManager->get(\TYPO3\CMS\Install\Status\ErrorStatus::class);
109 $errorStatus->setTitle(
'Database password not valid');
110 $errorStatus->setMessage(
'Given password must be shorter than fifty characters.');
111 $result[] = $errorStatus;
117 if (preg_match(
'/^[a-zA-Z0-9_\\.-]+(:.+)?$/', $value) && strlen($value) <= 50) {
118 $localConfigurationPathValuePairs[
'DB/host'] = $value;
121 $errorStatus = $this->objectManager->get(\TYPO3\CMS\Install\Status\ErrorStatus::class);
122 $errorStatus->setTitle(
'Database host not valid');
123 $errorStatus->setMessage(
'Given host is not alphanumeric (a-z, A-Z, 0-9 or _-.:) or longer than fifty characters.');
124 $result[] = $errorStatus;
130 if (preg_match(
'/^[0-9]+(:.+)?$/', $value) && $value > 0 && $value <= 65535) {
131 $localConfigurationPathValuePairs[
'DB/port'] = (int)$value;
134 $errorStatus = $this->objectManager->get(\TYPO3\CMS\Install\Status\ErrorStatus::class);
135 $errorStatus->setTitle(
'Database port not valid');
136 $errorStatus->setMessage(
'Given port is not numeric or within range 1 to 65535.');
137 $result[] = $errorStatus;
143 $localConfigurationPathValuePairs[
'DB/socket'] =
$postValues[
'socket'];
146 $errorStatus = $this->objectManager->get(\TYPO3\CMS\Install\Status\ErrorStatus::class);
147 $errorStatus->setTitle(
'Socket does not exist');
148 $errorStatus->setMessage(
'Given socket location does not exist on server.');
149 $result[] = $errorStatus;
155 if (strlen($value) <= 50) {
156 $localConfigurationPathValuePairs[
'DB/database'] = $value;
159 $errorStatus = $this->objectManager->get(\TYPO3\CMS\Install\Status\ErrorStatus::class);
160 $errorStatus->setTitle(
'Database name not valid');
161 $errorStatus->setMessage(
'Given database name must be shorter than fifty characters.');
162 $result[] = $errorStatus;
166 if (!empty($localConfigurationPathValuePairs)) {
167 $configurationManager->setLocalConfigurationValuesByPathValuePairs($localConfigurationPathValuePairs);
172 \TYPO3\CMS\Core\Core\Bootstrap::getInstance()
173 ->populateLocalConfiguration()
174 ->disableCoreCache();
177 \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)->setCacheConfigurations(
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'caching'][
'cacheConfigurations']);
179 if (!$this->isConnectSuccessful()) {
181 $errorStatus = $this->objectManager->get(\TYPO3\CMS\Install\Status\ErrorStatus::class);
182 $errorStatus->setTitle(
'Database connect not successful');
183 $errorStatus->setMessage(
'Connecting to the database with given settings failed. Please check.');
184 $result[] = $errorStatus;
204 $this->useDefaultValuesForNotConfiguredOptions();
205 throw new \TYPO3\CMS\Install\Controller\Exception\RedirectException(
206 'Wrote default settings to LocalConfiguration.php, redirect needed',
222 ->assign(
'isDbalEnabled', $isDbalEnabled)
227 ->assign(
'database',
$GLOBALS[
'TYPO3_CONF_VARS'][
'DB'][
'database'] ?:
'')
228 ->assign(
'socket',
$GLOBALS[
'TYPO3_CONF_VARS'][
'DB'][
'socket'] ?:
'');
230 if ($isDbalEnabled) {
236 ->assign(
'renderConnectDetailsUsername',
true)
237 ->assign(
'renderConnectDetailsPassword',
true)
238 ->assign(
'renderConnectDetailsHost',
true)
239 ->assign(
'renderConnectDetailsPort',
true)
240 ->assign(
'renderConnectDetailsSocket',
true);
244 return $this->view->render();
255 if (!$configuredPort) {
276 $port = $configuredPort;
286 protected function isConnectSuccessful()
289 $databaseConnection = $this->objectManager->get(\TYPO3\CMS\Core\Database\DatabaseConnection::class);
294 if (isset(
$GLOBALS[
'TYPO3_CONF_VARS'][
'DB'][
'database'])) {
295 $databaseConnection->setDatabaseName(
$GLOBALS[
'TYPO3_CONF_VARS'][
'DB'][
'database']);
305 $databaseConnection->initialize();
307 return (
bool)@$databaseConnection->sql_pconnect();
319 $hostConfigured =
true;
320 if (empty(
$GLOBALS[
'TYPO3_CONF_VARS'][
'DB'][
'host'])) {
321 $hostConfigured =
false;
324 !isset(
$GLOBALS[
'TYPO3_CONF_VARS'][
'DB'][
'port'])
325 && !isset(
$GLOBALS[
'TYPO3_CONF_VARS'][
'DB'][
'socket'])
327 $hostConfigured =
false;
329 return $hostConfigured;
343 if (!isset(
$GLOBALS[
'TYPO3_CONF_VARS'][
'DB'][
'username'])) {
344 $configurationComplete =
false;
346 if (!isset(
$GLOBALS[
'TYPO3_CONF_VARS'][
'DB'][
'password'])) {
347 $configurationComplete =
false;
349 return $configurationComplete;
368 protected function useDefaultValuesForNotConfiguredOptions()
370 $localConfigurationPathValuePairs = array();
376 if ($localConfigurationPathValuePairs[
'DB/host'] ===
'localhost'
377 || \TYPO3\CMS\Core\Utility\
GeneralUtility::cmpIP($localConfigurationPathValuePairs[
'DB/host'],
'127.*.*.*')
378 || (
string)$localConfigurationPathValuePairs[
'DB/host'] ===
''
381 $localConfigurationPathValuePairs[
'DB/host'] =
'localhost';
385 $localConfigurationPathValuePairs[
'DB/host'] =
'127.0.0.1';
390 if (!isset($localConfigurationPathValuePairs[
'DB/socket'])) {
395 $localConfigurationPathValuePairs[
'DB/port'] = $port;
402 $configurationManager = $this->objectManager->get(\TYPO3\CMS\Core\Configuration\ConfigurationManager::class);
403 $configurationManager->setLocalConfigurationValuesByPathValuePairs($localConfigurationPathValuePairs);
417 if ($socket ===
'') {
419 $defaultSocket = (string)ini_get(
'mysqli.default_socket');
420 if ($defaultSocket !==
'') {
421 $socket = $defaultSocket;
424 if ($socket !==
'') {
425 $socketOpenResult = @fsockopen(
'unix://' . $socket);
426 if ($socketOpenResult) {
427 fclose($socketOpenResult);
449 ->assign(
'renderConnectDetailsUsername',
true)
450 ->assign(
'renderConnectDetailsPassword',
true)
451 ->assign(
'renderConnectDetailsHost',
true)
452 ->assign(
'renderConnectDetailsPort',
true)
453 ->assign(
'renderConnectDetailsDatabase',
true);
457 ->assign(
'renderConnectDetailsUsername',
true)
458 ->assign(
'renderConnectDetailsPassword',
true)
459 ->assign(
'renderConnectDetailsHost',
true)
460 ->assign(
'renderConnectDetailsPort',
true)
461 ->assign(
'renderConnectDetailsDatabase',
true)
462 ->assign(
'renderConnectDetailsOracleSidConnect',
true);
463 $type = isset(
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXTCONF'][
'dbal'][
'handlerCfg'][
'_DEFAULT'][
'config'][
'driverOptions'][
'connectSID'])
464 ?
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXTCONF'][
'dbal'][
'handlerCfg'][
'_DEFAULT'][
'config'][
'driverOptions'][
'connectSID']
466 if ($type ===
true) {
467 $this->view->assign(
'oracleSidSelected',
true);
481 $availableDrivers = array();
483 foreach ($supportedDrivers as $abstractionLayer => $drivers) {
484 foreach ($drivers as $driver => $info) {
485 if (isset($info[
'combine']) && $info[
'combine'] ===
'OR') {
486 $isAvailable =
false;
491 foreach ($info[
'extensions'] as $extension) {
492 if (isset($info[
'combine']) && $info[
'combine'] ===
'OR') {
493 $isAvailable |= extension_loaded($extension);
495 $isAvailable &= extension_loaded($extension);
499 if (!isset($availableDrivers[$abstractionLayer])) {
500 $availableDrivers[$abstractionLayer] = array();
502 $availableDrivers[$abstractionLayer][$driver] = array();
503 $availableDrivers[$abstractionLayer][$driver][
'driver'] = $driver;
504 $availableDrivers[$abstractionLayer][$driver][
'label'] = $info[
'label'];
505 $availableDrivers[$abstractionLayer][$driver][
'selected'] =
false;
506 if ($selectedDbalDriver === $driver) {
507 $availableDrivers[$abstractionLayer][$driver][
'selected'] =
true;
512 return $availableDrivers;
523 $supportedDrivers = array(
526 'label' =>
'Microsoft SQL Server',
527 'extensions' => array(
'mssql')
530 'label' =>
'Oracle OCI8',
531 'extensions' => array(
'oci8')
534 'label' =>
'PostgreSQL',
535 'extensions' => array(
'pgsql')
539 'odbc_mssql' => array(
540 'label' =>
'Microsoft SQL Server',
541 'extensions' => array(
'odbc',
'mssql')
545 return $supportedDrivers;
555 if (isset(
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXTCONF'][
'dbal'][
'handlerCfg'][
'_DEFAULT'][
'config'][
'driver'])) {
556 return $GLOBALS[
'TYPO3_CONF_VARS'][
'EXTCONF'][
'dbal'][
'handlerCfg'][
'_DEFAULT'][
'config'][
'driver'];
566 protected function executeLoadDbalExtension()
575 $warningStatus = $this->objectManager->get(\TYPO3\CMS\Install\Status\WarningStatus::class);
576 $warningStatus->setTitle(
'Loaded database abstraction layer');
577 return $warningStatus;
585 protected function executeUnloadDbalExtension()
595 $warningStatus = $this->objectManager->get(\TYPO3\CMS\Install\Status\WarningStatus::class);
596 $warningStatus->setTitle(
'Removed database abstraction layer');
597 return $warningStatus;
607 $username = isset(
$GLOBALS[
'TYPO3_CONF_VARS'][
'DB'][
'username']) ?
$GLOBALS[
'TYPO3_CONF_VARS'][
'DB'][
'username'] :
'';
618 $password = isset(
$GLOBALS[
'TYPO3_CONF_VARS'][
'DB'][
'password']) ?
$GLOBALS[
'TYPO3_CONF_VARS'][
'DB'][
'password'] :
'';
629 $host = isset(
$GLOBALS[
'TYPO3_CONF_VARS'][
'DB'][
'host']) ?
$GLOBALS[
'TYPO3_CONF_VARS'][
'DB'][
'host'] :
'';
630 $port = isset(
$GLOBALS[
'TYPO3_CONF_VARS'][
'DB'][
'port']) ?
$GLOBALS[
'TYPO3_CONF_VARS'][
'DB'][
'port'] :
'';
631 if (strlen($port) < 1 && substr_count($host,
':') === 1) {
632 list($host) = explode(
':', $host);
644 $host = isset(
$GLOBALS[
'TYPO3_CONF_VARS'][
'DB'][
'host']) ?
$GLOBALS[
'TYPO3_CONF_VARS'][
'DB'][
'host'] :
'';
645 $port = isset(
$GLOBALS[
'TYPO3_CONF_VARS'][
'DB'][
'port']) ?
$GLOBALS[
'TYPO3_CONF_VARS'][
'DB'][
'port'] :
'';
646 if ($port ===
'' && substr_count($host,
':') === 1) {
647 $hostPortArray = explode(
':', $host);
648 $port = $hostPortArray[1];
660 $socket = isset(
$GLOBALS[
'TYPO3_CONF_VARS'][
'DB'][
'socket']) ?
$GLOBALS[
'TYPO3_CONF_VARS'][
'DB'][
'socket'] :
'';