TYPO3 CMS  TYPO3_6-2
DatabaseUtility.php
Go to the documentation of this file.
1 <?php
3 
22 
26  const MULTI_LINEBREAKS = '
27 
28 
29 ';
36  public function dumpStaticTables($dbFields) {
37  $out = '';
38  // Traverse the table list and dump each:
39  foreach ($dbFields as $table => $fields) {
40  if (is_array($dbFields[$table]['fields'])) {
41  $header = $this->dumpHeader();
42  $tableHeader = $this->dumpTableHeader($table, $dbFields[$table], TRUE);
43  $insertStatements = $this->dumpTableContent($table, $dbFields[$table]['fields']);
44  $out .= $header . self::MULTI_LINEBREAKS . $tableHeader . self::MULTI_LINEBREAKS . $insertStatements . self::MULTI_LINEBREAKS;
45  }
46  }
47  return $out;
48  }
49 
55  protected function dumpHeader() {
56  return trim('
57 # TYPO3 Extension Manager dump 1.1
58 #
59 # Host: ' . TYPO3_db_host . ' Database: ' . TYPO3_db . '
60 #--------------------------------------------------------
61 ');
62  }
63 
72  protected function dumpTableHeader($table, array $fieldKeyInfo, $dropTableIfExists = FALSE) {
73  $lines = array();
74  $dump = '';
75  // Create field definitions
76  if (is_array($fieldKeyInfo['fields'])) {
77  foreach ($fieldKeyInfo['fields'] as $fieldN => $data) {
78  $lines[] = ' ' . $fieldN . ' ' . $data;
79  }
80  }
81  // Create index key definitions
82  if (is_array($fieldKeyInfo['keys'])) {
83  foreach ($fieldKeyInfo['keys'] as $fieldN => $data) {
84  $lines[] = ' ' . $data;
85  }
86  }
87  // Compile final output:
88  if (count($lines)) {
89  $dump = trim('
90 #
91 # Table structure for table "' . $table . '"
92 #
93 ' . ($dropTableIfExists ? 'DROP TABLE IF EXISTS ' . $table . ';
94 ' : '') . 'CREATE TABLE ' . $table . ' (
95 ' . implode((',' . LF), $lines) . '
96 );');
97  }
98  return $dump;
99  }
100 
111  protected function dumpTableContent($table, array $fieldStructure) {
112  // Substitution of certain characters (borrowed from phpMySQL):
113  $search = array('\\', '\'', "\0", "\n", "\r", "\x1A");
114  $replace = array('\\\\', '\\\'', '\\0', '\\n', '\\r', '\\Z');
115  $lines = array();
116  // Select all rows from the table:
117  $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $table, '');
118  // Traverse the selected rows and dump each row as a line in the file:
119  while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
120  $values = array();
121  foreach ($fieldStructure as $field => $structure) {
122  $values[] = isset($row[$field]) ? '\'' . str_replace($search, $replace, $row[$field]) . '\'' : 'NULL';
123  }
124  $lines[] = 'INSERT INTO ' . $table . ' VALUES (' . implode(', ', $values) . ');';
125  }
126  // Free DB result:
127  $GLOBALS['TYPO3_DB']->sql_free_result($result);
128  // Implode lines and return:
129  return implode(LF, $lines);
130  }
131 
132 }
dumpTableHeader($table, array $fieldKeyInfo, $dropTableIfExists=FALSE)
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.
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]