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