[TASK] Re-work/simplify copyright header in PHP files - Part 2
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Controller / Action / Step / DatabaseConnect.php
1 <?php
2 namespace TYPO3\CMS\Install\Controller\Action\Step;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
18
19 /**
20 * Database connect step:
21 * - Needs execution if database credentials are not set or fail to connect
22 * - Renders fields for database connection fields
23 * - Sets database credentials in LocalConfiguration
24 * - Loads / unloads ext:dbal and ext:adodb if requested
25 */
26 class DatabaseConnect extends AbstractStepAction {
27
28 /**
29 * Execute database step:
30 * - Load / unload dbal & adodb
31 * - Set database connect credentials in LocalConfiguration
32 *
33 * @return array<\TYPO3\CMS\Install\Status\StatusInterface>
34 */
35 public function execute() {
36 $result = array();
37
38 /** @var $configurationManager \TYPO3\CMS\Core\Configuration\ConfigurationManager */
39 $configurationManager = $this->objectManager->get('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager');
40
41 $postValues = $this->postValues['values'];
42 if (isset($postValues['loadDbal'])) {
43 $result[] = $this->executeLoadDbalExtension();
44 } elseif ($postValues['unloadDbal']) {
45 $result[] = $this->executeUnloadDbalExtension();
46 } elseif ($postValues['setDbalDriver']) {
47 $driver = $postValues['setDbalDriver'];
48 switch ($driver) {
49 case 'mssql':
50 case 'odbc_mssql':
51 $driverConfig = array(
52 'useNameQuote' => TRUE,
53 'quoteClob' => FALSE,
54 );
55 break;
56 case 'oci8':
57 $driverConfig = array(
58 'driverOptions' => array(
59 'connectSID' => '',
60 ),
61 );
62 break;
63 }
64 $config = array(
65 '_DEFAULT' => array(
66 'type' => 'adodb',
67 'config' => array(
68 'driver' => $driver,
69 )
70 )
71 );
72 if (isset($driverConfig)) {
73 $config['_DEFAULT']['config'] = array_merge($config['_DEFAULT']['config'], $driverConfig);
74 }
75 $configurationManager->setLocalConfigurationValueByPath('EXTCONF/dbal/handlerCfg', $config);
76 } else {
77 $localConfigurationPathValuePairs = array();
78
79 if ($this->isDbalEnabled()) {
80 $config = $configurationManager->getConfigurationValueByPath('EXTCONF/dbal/handlerCfg');
81 $driver = $config['_DEFAULT']['config']['driver'];
82 if ($driver === 'oci8') {
83 $config['_DEFAULT']['config']['driverOptions']['connectSID'] = ($postValues['type'] === 'sid');
84 $localConfigurationPathValuePairs['EXTCONF/dbal/handlerCfg'] = $config;
85 }
86 }
87
88 if (isset($postValues['username'])) {
89 $value = $postValues['username'];
90 if (strlen($value) <= 50) {
91 $localConfigurationPathValuePairs['DB/username'] = $value;
92 } else {
93 /** @var $errorStatus \TYPO3\CMS\Install\Status\ErrorStatus */
94 $errorStatus = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\ErrorStatus');
95 $errorStatus->setTitle('Database username not valid');
96 $errorStatus->setMessage('Given username must be shorter than fifty characters.');
97 $result[] = $errorStatus;
98 }
99 }
100
101 if (isset($postValues['password'])) {
102 $value = $postValues['password'];
103 if (strlen($value) <= 50) {
104 $localConfigurationPathValuePairs['DB/password'] = $value;
105 } else {
106 /** @var $errorStatus \TYPO3\CMS\Install\Status\ErrorStatus */
107 $errorStatus = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\ErrorStatus');
108 $errorStatus->setTitle('Database password not valid');
109 $errorStatus->setMessage('Given password must be shorter than fifty characters.');
110 $result[] = $errorStatus;
111 }
112 }
113
114 if (isset($postValues['host'])) {
115 $value = $postValues['host'];
116 if (preg_match('/^[a-zA-Z0-9_\\.-]+(:.+)?$/', $value) && strlen($value) <= 50) {
117 $localConfigurationPathValuePairs['DB/host'] = $value;
118 } else {
119 /** @var $errorStatus \TYPO3\CMS\Install\Status\ErrorStatus */
120 $errorStatus = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\ErrorStatus');
121 $errorStatus->setTitle('Database host not valid');
122 $errorStatus->setMessage('Given host is not alphanumeric (a-z, A-Z, 0-9 or _-.:) or longer than fifty characters.');
123 $result[] = $errorStatus;
124 }
125 }
126
127 if (isset($postValues['port']) && $postValues['host'] !== 'localhost') {
128 $value = $postValues['port'];
129 if (preg_match('/^[0-9]+(:.+)?$/', $value) && $value > 0 && $value <= 65535) {
130 $localConfigurationPathValuePairs['DB/port'] = (int)$value;
131 } else {
132 /** @var $errorStatus \TYPO3\CMS\Install\Status\ErrorStatus */
133 $errorStatus = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\ErrorStatus');
134 $errorStatus->setTitle('Database port not valid');
135 $errorStatus->setMessage('Given port is not numeric or within range 1 to 65535.');
136 $result[] = $errorStatus;
137 }
138 }
139
140 if (isset($postValues['socket']) && $postValues['socket'] !== '') {
141 if (@file_exists($postValues['socket'])) {
142 $localConfigurationPathValuePairs['DB/socket'] = $postValues['socket'];
143 } else {
144 /** @var $errorStatus \TYPO3\CMS\Install\Status\ErrorStatus */
145 $errorStatus = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\ErrorStatus');
146 $errorStatus->setTitle('Socket does not exist');
147 $errorStatus->setMessage('Given socket location does not exist on server.');
148 $result[] = $errorStatus;
149 }
150 }
151
152 if (isset($postValues['database'])) {
153 $value = $postValues['database'];
154 if (strlen($value) <= 50) {
155 $localConfigurationPathValuePairs['DB/database'] = $value;
156 } else {
157 /** @var $errorStatus \TYPO3\CMS\Install\Status\ErrorStatus */
158 $errorStatus = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\ErrorStatus');
159 $errorStatus->setTitle('Database name not valid');
160 $errorStatus->setMessage('Given database name must be shorter than fifty characters.');
161 $result[] = $errorStatus;
162 }
163 }
164
165 if (!empty($localConfigurationPathValuePairs)) {
166 $configurationManager->setLocalConfigurationValuesByPathValuePairs($localConfigurationPathValuePairs);
167
168 // After setting new credentials, test again and create an error message if connect is not successful
169 // @TODO: This could be simplified, if isConnectSuccessful could be released from TYPO3_CONF_VARS
170 // and fed with connect values directly in order to obsolete the bootstrap reload.
171 \TYPO3\CMS\Core\Core\Bootstrap::getInstance()
172 ->populateLocalConfiguration()
173 ->disableCoreAndClassesCache();
174 if ($this->isDbalEnabled()) {
175 require(ExtensionManagementUtility::extPath('dbal') . 'ext_localconf.php');
176 \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
177 }
178 if (!$this->isConnectSuccessful()) {
179 /** @var $errorStatus \TYPO3\CMS\Install\Status\ErrorStatus */
180 $errorStatus = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\ErrorStatus');
181 $errorStatus->setTitle('Database connect not successful');
182 $errorStatus->setMessage('Connecting to the database with given settings failed. Please check.');
183 $result[] = $errorStatus;
184 }
185 }
186 }
187
188 return $result;
189 }
190
191 /**
192 * Step needs to be executed if database connection is not successful.
193 *
194 * @throws \TYPO3\CMS\Install\Controller\Exception\RedirectException
195 * @return boolean
196 */
197 public function needsExecution() {
198 if ($this->isConnectSuccessful() && $this->isConfigurationComplete()) {
199 return FALSE;
200 }
201 if (!$this->isHostConfigured() && !$this->isDbalEnabled()) {
202 $this->useDefaultValuesForNotConfiguredOptions();
203 throw new \TYPO3\CMS\Install\Controller\Exception\RedirectException(
204 'Wrote default settings to LocalConfiguration.php, redirect needed',
205 1377611168
206 );
207 }
208 return TRUE;
209 }
210
211 /**
212 * Executes the step
213 *
214 * @return string Rendered content
215 */
216 protected function executeAction() {
217 $isDbalEnabled = $this->isDbalEnabled();
218 $this->view
219 ->assign('isDbalEnabled', $isDbalEnabled)
220 ->assign('username', $this->getConfiguredUsername())
221 ->assign('password', $this->getConfiguredPassword())
222 ->assign('host', $this->getConfiguredHost())
223 ->assign('port', $this->getConfiguredOrDefaultPort())
224 ->assign('database', $GLOBALS['TYPO3_CONF_VARS']['DB']['database'] ?: '')
225 ->assign('socket', $GLOBALS['TYPO3_CONF_VARS']['DB']['socket'] ?: '');
226
227 if ($isDbalEnabled) {
228 $this->view->assign('selectedDbalDriver', $this->getSelectedDbalDriver());
229 $this->view->assign('dbalDrivers', $this->getAvailableDbalDrivers());
230 $this->setDbalInputFieldsToRender();
231 } else {
232 $this->view
233 ->assign('renderConnectDetailsUsername', TRUE)
234 ->assign('renderConnectDetailsPassword', TRUE)
235 ->assign('renderConnectDetailsHost', TRUE)
236 ->assign('renderConnectDetailsPort', TRUE)
237 ->assign('renderConnectDetailsSocket', TRUE);
238 }
239 $this->assignSteps();
240
241 return $this->view->render();
242 }
243
244 /**
245 * Render connect port and label
246 *
247 * @return integer Configured or default port
248 */
249 protected function getConfiguredOrDefaultPort() {
250 $configuredPort = (int)$this->getConfiguredPort();
251 if (!$configuredPort) {
252 if ($this->isDbalEnabled()) {
253 $driver = $this->getSelectedDbalDriver();
254 switch ($driver) {
255 case 'postgres':
256 $port = 5432;
257 break;
258 case 'mssql':
259 case 'odbc_mssql':
260 $port = 1433;
261 break;
262 case 'oci8':
263 $port = 1521;
264 break;
265 default:
266 $port = 3306;
267 }
268 } else {
269 $port = 3306;
270 }
271 } else {
272 $port = $configuredPort;
273 }
274 return $port;
275 }
276
277 /**
278 * Test connection with given credentials
279 *
280 * @return boolean TRUE if connect was successful
281 */
282 protected function isConnectSuccessful() {
283 /** @var $databaseConnection \TYPO3\CMS\Core\Database\DatabaseConnection */
284 $databaseConnection = $this->objectManager->get('TYPO3\\CMS\\Core\\Database\\DatabaseConnection');
285 $databaseConnection->initialize();
286
287 if ($this->isDbalEnabled()) {
288 // Set additional connect information based on dbal driver. postgres for example needs
289 // database name already for connect.
290 if (isset($GLOBALS['TYPO3_CONF_VARS']['DB']['database'])) {
291 $databaseConnection->setDatabaseName($GLOBALS['TYPO3_CONF_VARS']['DB']['database']);
292 }
293 }
294
295 $databaseConnection->setDatabaseUsername($this->getConfiguredUsername());
296 $databaseConnection->setDatabasePassword($this->getConfiguredPassword());
297 $databaseConnection->setDatabaseHost($this->getConfiguredHost());
298 $databaseConnection->setDatabasePort($this->getConfiguredPort());
299 $databaseConnection->setDatabaseSocket($this->getConfiguredSocket());
300
301 $result = FALSE;
302 if (@$databaseConnection->sql_pconnect()) {
303 $result = TRUE;
304 }
305 return $result;
306 }
307
308 /**
309 * Check LocalConfiguration.php for required database settings:
310 * - 'host' is mandatory and must not be empty
311 * - 'port' OR 'socket' is mandatory, but may be empty
312 *
313 * @return boolean TRUE if host is set
314 */
315 protected function isHostConfigured() {
316 $hostConfigured = TRUE;
317 if (empty($GLOBALS['TYPO3_CONF_VARS']['DB']['host'])) {
318 $hostConfigured = FALSE;
319 }
320 if (
321 !isset($GLOBALS['TYPO3_CONF_VARS']['DB']['port'])
322 && !isset($GLOBALS['TYPO3_CONF_VARS']['DB']['socket'])
323 ) {
324 $hostConfigured = FALSE;
325 }
326 return $hostConfigured;
327 }
328
329 /**
330 * Check LocalConfiguration.php for required database settings:
331 * - 'host' is mandatory and must not be empty
332 * - 'port' OR 'socket' is mandatory, but may be empty
333 * - 'username' and 'password' are mandatory, but may be empty
334 *
335 * @return boolean TRUE if required settings are present
336 */
337 protected function isConfigurationComplete() {
338 $configurationComplete = $this->isHostConfigured();
339 if (!isset($GLOBALS['TYPO3_CONF_VARS']['DB']['username'])) {
340 $configurationComplete = FALSE;
341 }
342 if (!isset($GLOBALS['TYPO3_CONF_VARS']['DB']['password'])) {
343 $configurationComplete = FALSE;
344 }
345 return $configurationComplete;
346 }
347
348 /**
349 * Write DB settings to LocalConfiguration.php, using default values.
350 * With the switch from mysql to mysqli in 6.1, some mandatory settings were
351 * added. This method tries to add those settings in case of an upgrade, and
352 * pre-configures settings in case of a "new" install process.
353 *
354 * There are two different connection types:
355 * - Unix domain socket. This may be available if mysql is running on localhost
356 * - TCP/IP connection to some mysql system somewhere.
357 *
358 * Unix domain socket connections are quicker than TCP/IP, so it is
359 * tested if a unix domain socket connection to localhost is successful. If not,
360 * a default configuration for TCP/IP is used.
361 *
362 * @return void
363 */
364 protected function useDefaultValuesForNotConfiguredOptions() {
365 $localConfigurationPathValuePairs = array();
366
367 $localConfigurationPathValuePairs['DB/host'] = $this->getConfiguredHost();
368
369 // If host is "local" either by upgrading or by first install, we try a socket
370 // connection first and use TCP/IP as fallback
371 if ($localConfigurationPathValuePairs['DB/host'] === 'localhost'
372 || \TYPO3\CMS\Core\Utility\GeneralUtility::cmpIP($localConfigurationPathValuePairs['DB/host'], '127.*.*.*')
373 || strlen($localConfigurationPathValuePairs['DB/host']) === 0
374 ) {
375 if ($this->isConnectionWithUnixDomainSocketPossible()) {
376 $localConfigurationPathValuePairs['DB/host'] = 'localhost';
377 $localConfigurationPathValuePairs['DB/socket'] = $this->getConfiguredSocket();
378 } else {
379 if (!\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($localConfigurationPathValuePairs['DB/host'], '127.')) {
380 $localConfigurationPathValuePairs['DB/host'] = '127.0.0.1';
381 }
382 }
383 }
384
385 if (!isset($localConfigurationPathValuePairs['DB/socket'])) {
386 // Make sure a default port is set if not configured yet
387 // This is independent from any host configuration
388 $port = $this->getConfiguredPort();
389 if ($port > 0) {
390 $localConfigurationPathValuePairs['DB/port'] = $port;
391 } else {
392 $localConfigurationPathValuePairs['DB/port'] = $this->getConfiguredOrDefaultPort();
393 }
394 }
395
396 /** @var \TYPO3\CMS\Core\Configuration\ConfigurationManager $configurationManager */
397 $configurationManager = $this->objectManager->get('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager');
398 $configurationManager->setLocalConfigurationValuesByPathValuePairs($localConfigurationPathValuePairs);
399 }
400
401 /**
402 * Test if a unix domain socket can be opened. This does not
403 * authenticate but only tests if a connect is successful.
404 *
405 * @return boolean TRUE on success
406 */
407 protected function isConnectionWithUnixDomainSocketPossible() {
408 $result = FALSE;
409 // Use configured socket
410 $socket = $this->getConfiguredSocket();
411 if (!strlen($socket) > 0) {
412 // If no configured socket, use default php socket
413 $defaultSocket = ini_get('mysqli.default_socket');
414 if (strlen($defaultSocket) > 0) {
415 $socket = $defaultSocket;
416 }
417 }
418 if (strlen($socket) > 0) {
419 $socketOpenResult = @fsockopen('unix://' . $socket);
420 if ($socketOpenResult) {
421 fclose($socketOpenResult);
422 $result = TRUE;
423 }
424 }
425 return $result;
426 }
427
428 /**
429 * Render fields required for successful connect based on dbal driver selection.
430 * Hint: There is a code duplication in handle() and this method. This
431 * is done by intention to keep this code area easy to maintain and understand.
432 *
433 * @return void
434 */
435 protected function setDbalInputFieldsToRender() {
436 $driver = $this->getSelectedDbalDriver();
437 switch($driver) {
438 case 'mssql':
439 case 'odbc_mssql':
440 case 'postgres':
441 $this->view
442 ->assign('renderConnectDetailsUsername', TRUE)
443 ->assign('renderConnectDetailsPassword', TRUE)
444 ->assign('renderConnectDetailsHost', TRUE)
445 ->assign('renderConnectDetailsPort', TRUE)
446 ->assign('renderConnectDetailsDatabase', TRUE);
447 break;
448 case 'oci8':
449 $this->view
450 ->assign('renderConnectDetailsUsername', TRUE)
451 ->assign('renderConnectDetailsPassword', TRUE)
452 ->assign('renderConnectDetailsHost', TRUE)
453 ->assign('renderConnectDetailsPort', TRUE)
454 ->assign('renderConnectDetailsDatabase', TRUE)
455 ->assign('renderConnectDetailsOracleSidConnect', TRUE);
456 $type = isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dbal']['handlerCfg']['_DEFAULT']['config']['driverOptions']['connectSID'])
457 ? $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dbal']['handlerCfg']['_DEFAULT']['config']['driverOptions']['connectSID']
458 : '';
459 if ($type === TRUE) {
460 $this->view->assign('oracleSidSelected', TRUE);
461 }
462 break;
463 }
464 }
465
466 /**
467 * Returns a list of database drivers that are available on current server.
468 *
469 * @return array
470 */
471 protected function getAvailableDbalDrivers() {
472 $supportedDrivers = $this->getSupportedDbalDrivers();
473 $availableDrivers = array();
474 $selectedDbalDriver = $this->getSelectedDbalDriver();
475 foreach ($supportedDrivers as $abstractionLayer => $drivers) {
476 foreach ($drivers as $driver => $info) {
477 if (isset($info['combine']) && $info['combine'] === 'OR') {
478 $isAvailable = FALSE;
479 } else {
480 $isAvailable = TRUE;
481 }
482 // Loop through each PHP module dependency to ensure it is loaded
483 foreach ($info['extensions'] as $extension) {
484 if (isset($info['combine']) && $info['combine'] === 'OR') {
485 $isAvailable |= extension_loaded($extension);
486 } else {
487 $isAvailable &= extension_loaded($extension);
488 }
489 }
490 if ($isAvailable) {
491 if (!isset($availableDrivers[$abstractionLayer])) {
492 $availableDrivers[$abstractionLayer] = array();
493 }
494 $availableDrivers[$abstractionLayer][$driver] = array();
495 $availableDrivers[$abstractionLayer][$driver]['driver'] = $driver;
496 $availableDrivers[$abstractionLayer][$driver]['label'] = $info['label'];
497 $availableDrivers[$abstractionLayer][$driver]['selected'] = FALSE;
498 if ($selectedDbalDriver === $driver) {
499 $availableDrivers[$abstractionLayer][$driver]['selected'] = TRUE;
500 }
501 }
502 }
503 }
504 return $availableDrivers;
505 }
506
507 /**
508 * Returns a list of DBAL supported database drivers, with a
509 * user-friendly name and any PHP module dependency.
510 *
511 * @return array
512 */
513 protected function getSupportedDbalDrivers() {
514 $supportedDrivers = array(
515 'Native' => array(
516 'mssql' => array(
517 'label' => 'Microsoft SQL Server',
518 'extensions' => array('mssql')
519 ),
520 'oci8' => array(
521 'label' => 'Oracle OCI8',
522 'extensions' => array('oci8')
523 ),
524 'postgres' => array(
525 'label' => 'PostgreSQL',
526 'extensions' => array('pgsql')
527 )
528 ),
529 'ODBC' => array(
530 'odbc_mssql' => array(
531 'label' => 'Microsoft SQL Server',
532 'extensions' => array('odbc', 'mssql')
533 )
534 )
535 );
536 return $supportedDrivers;
537 }
538
539 /**
540 * Get selected dbal driver if any
541 *
542 * @return string Dbal driver or empty string if not yet selected
543 */
544 protected function getSelectedDbalDriver() {
545 if (isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dbal']['handlerCfg']['_DEFAULT']['config']['driver'])) {
546 return $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dbal']['handlerCfg']['_DEFAULT']['config']['driver'];
547 }
548 return '';
549 }
550
551 /**
552 * Adds dbal and adodb to list of loaded extensions
553 *
554 * @return \TYPO3\CMS\Install\Status\StatusInterface
555 */
556 protected function executeLoadDbalExtension() {
557 if (!ExtensionManagementUtility::isLoaded('adodb')) {
558 ExtensionManagementUtility::loadExtension('adodb');
559 }
560 if (!ExtensionManagementUtility::isLoaded('dbal')) {
561 ExtensionManagementUtility::loadExtension('dbal');
562 }
563 /** @var $errorStatus \TYPO3\CMS\Install\Status\WarningStatus */
564 $warningStatus = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\WarningStatus');
565 $warningStatus->setTitle('Loaded database abstraction layer');
566 return $warningStatus;
567 }
568
569 /**
570 * Remove dbal and adodb from list of loaded extensions
571 *
572 * @return \TYPO3\CMS\Install\Status\StatusInterface
573 */
574 protected function executeUnloadDbalExtension() {
575 if (ExtensionManagementUtility::isLoaded('adodb')) {
576 ExtensionManagementUtility::unloadExtension('adodb');
577 }
578 if (ExtensionManagementUtility::isLoaded('dbal')) {
579 ExtensionManagementUtility::unloadExtension('dbal');
580 }
581 // @TODO: Remove configuration from TYPO3_CONF_VARS['EXTCONF']['dbal']
582 /** @var $errorStatus \TYPO3\CMS\Install\Status\WarningStatus */
583 $warningStatus = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\WarningStatus');
584 $warningStatus->setTitle('Removed database abstraction layer');
585 return $warningStatus;
586 }
587
588 /**
589 * Returns configured username, if set
590 *
591 * @return string
592 */
593 protected function getConfiguredUsername() {
594 $username = isset($GLOBALS['TYPO3_CONF_VARS']['DB']['username']) ? $GLOBALS['TYPO3_CONF_VARS']['DB']['username'] : '';
595 return $username;
596 }
597
598 /**
599 * Returns configured password, if set
600 *
601 * @return string
602 */
603 protected function getConfiguredPassword() {
604 $password = isset($GLOBALS['TYPO3_CONF_VARS']['DB']['password']) ? $GLOBALS['TYPO3_CONF_VARS']['DB']['password'] : '';
605 return $password;
606 }
607
608 /**
609 * Returns configured host with port split off if given
610 *
611 * @return string
612 */
613 protected function getConfiguredHost() {
614 $host = isset($GLOBALS['TYPO3_CONF_VARS']['DB']['host']) ? $GLOBALS['TYPO3_CONF_VARS']['DB']['host'] : '';
615 $port = isset($GLOBALS['TYPO3_CONF_VARS']['DB']['port']) ? $GLOBALS['TYPO3_CONF_VARS']['DB']['port'] : '';
616 if (strlen($port) < 1 && substr_count($host, ':') === 1) {
617 list($host) = explode(':', $host);
618 }
619 return $host;
620 }
621
622 /**
623 * Returns configured port. Gets port from host value if port is not yet set.
624 *
625 * @return integer
626 */
627 protected function getConfiguredPort() {
628 $host = isset($GLOBALS['TYPO3_CONF_VARS']['DB']['host']) ? $GLOBALS['TYPO3_CONF_VARS']['DB']['host'] : '';
629 $port = isset($GLOBALS['TYPO3_CONF_VARS']['DB']['port']) ? $GLOBALS['TYPO3_CONF_VARS']['DB']['port'] : '';
630 if (strlen($port) === 0 && substr_count($host, ':') === 1) {
631 $hostPortArray = explode(':', $host);
632 $port = $hostPortArray[1];
633 }
634 return (int)$port;
635 }
636
637 /**
638 * Returns configured socket, if set
639 *
640 * @return string|NULL
641 */
642 protected function getConfiguredSocket() {
643 $socket = isset($GLOBALS['TYPO3_CONF_VARS']['DB']['socket']) ? $GLOBALS['TYPO3_CONF_VARS']['DB']['socket'] : '';
644 return $socket;
645 }
646 }