TYPO3 CMS  TYPO3_6-2
DatabaseSelect.php
Go to the documentation of this file.
1 <?php
3 
24 
28  protected $databaseConnection = NULL;
29 
35  public function execute() {
36  $result = array();
38  $postValues = $this->postValues['values'];
39  $localConfigurationPathValuePairs = array();
41  $configurationManager = $this->objectManager->get('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager');
42  if ($postValues['type'] === 'new') {
43  $newDatabaseName = $postValues['new'];
44  if (strlen($newDatabaseName) <= 50) {
45  $createDatabaseResult = $this->databaseConnection->admin_query('CREATE DATABASE ' . $newDatabaseName . ' CHARACTER SET utf8');
46  if ($createDatabaseResult) {
47  $localConfigurationPathValuePairs['DB/database'] = $newDatabaseName;
48  } else {
50  $errorStatus = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\ErrorStatus');
51  $errorStatus->setTitle('Unable to create database');
52  $errorStatus->setMessage(
53  'Database with name ' . $newDatabaseName . ' could not be created.' .
54  ' Either your database name contains special chars (only alphanumeric characters are allowed)' .
55  ' or your database user probably does not have sufficient permissions to create it.' .
56  ' Please choose an existing (empty) database or contact administration.'
57  );
58  $result[] = $errorStatus;
59  }
60  } else {
62  $errorStatus = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\ErrorStatus');
63  $errorStatus->setTitle('Database name not valid');
64  $errorStatus->setMessage('Given database name must be shorter than fifty characters.');
65  $result[] = $errorStatus;
66  }
67  } elseif ($postValues['type'] === 'existing' && !empty($postValues['existing'])) {
68  // Only store database information when it's empty
69  $this->databaseConnection->setDatabaseName($postValues['existing']);
70  $this->databaseConnection->sql_select_db();
71  $existingTables = $this->databaseConnection->admin_get_tables();
72  $isInitialInstallation = $configurationManager->getConfigurationValueByPath('SYS/isInitialInstallationInProgress');
73  if (!$isInitialInstallation || count($existingTables) === 0) {
74  $localConfigurationPathValuePairs['DB/database'] = $postValues['existing'];
75  }
76  } else {
78  $errorStatus = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\ErrorStatus');
79  $errorStatus->setTitle('No Database selected');
80  $errorStatus->setMessage('You must select a database.');
81  $result[] = $errorStatus;
82  }
83 
84  if (!empty($localConfigurationPathValuePairs)) {
85  $configurationManager->setLocalConfigurationValuesByPathValuePairs($localConfigurationPathValuePairs);
86  }
87 
88  return $result;
89  }
90 
97  public function needsExecution() {
99  $result = TRUE;
100  if (strlen($GLOBALS['TYPO3_CONF_VARS']['DB']['database']) > 0) {
101  $this->databaseConnection->setDatabaseName($GLOBALS['TYPO3_CONF_VARS']['DB']['database']);
102  try {
103  $selectResult = $this->databaseConnection->sql_select_db();
104  if ($selectResult === TRUE) {
105  $result = FALSE;
106  }
107  } catch (\RuntimeException $e) {
108  }
109  }
110  return $result;
111  }
112 
118  protected function executeAction() {
120  $configurationManager = $this->objectManager->get('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager');
121  $isInitialInstallationInProgress = $configurationManager->getConfigurationValueByPath('SYS/isInitialInstallationInProgress');
122  $this->view->assign('databaseList', $this->getDatabaseList($isInitialInstallationInProgress));
123  $this->view->assign('isInitialInstallationInProgress', $isInitialInstallationInProgress);
124  $this->assignSteps();
125  return $this->view->render();
126  }
127 
134  protected function getDatabaseList($initialInstallation) {
136  $databaseArray = $this->databaseConnection->admin_get_dbs();
137  // Remove mysql organizational tables from database list
138  $reservedDatabaseNames = array('mysql', 'information_schema', 'performance_schema');
139  $allPossibleDatabases = array_diff($databaseArray, $reservedDatabaseNames);
140 
141  // If we are upgrading we show *all* databases the user has access to
142  if ($initialInstallation === FALSE) {
143  return $allPossibleDatabases;
144  } else {
145  // In first installation we show all databases but disable not empty ones (with tables)
146  $databases = array();
147  foreach ($allPossibleDatabases as $database) {
148  $this->databaseConnection->setDatabaseName($database);
149  $this->databaseConnection->sql_select_db();
150  $existingTables = $this->databaseConnection->admin_get_tables();
151  $databases[] = array(
152  'name' => $database,
153  'tables' => count($existingTables),
154  );
155  }
156  return $databases;
157  }
158  }
159 
165  protected function initializeDatabaseConnection() {
166  $this->databaseConnection = $this->objectManager->get('TYPO3\\CMS\\Core\\Database\\DatabaseConnection');
167  $this->databaseConnection->setDatabaseUsername($GLOBALS['TYPO3_CONF_VARS']['DB']['username']);
168  $this->databaseConnection->setDatabasePassword($GLOBALS['TYPO3_CONF_VARS']['DB']['password']);
169  $this->databaseConnection->setDatabaseHost($GLOBALS['TYPO3_CONF_VARS']['DB']['host']);
170  $this->databaseConnection->setDatabasePort($GLOBALS['TYPO3_CONF_VARS']['DB']['port']);
171  $this->databaseConnection->setDatabaseSocket($GLOBALS['TYPO3_CONF_VARS']['DB']['socket']);
172  $this->databaseConnection->sql_pconnect();
173  }
174 }
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren&#39;t numeric.
$database
Definition: server.php:38
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]