[TASK] FAL: Hard-coded flexform on storage creation
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_install.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Class to setup values in localconf.php and verify the TYPO3 DB tables/fields
29 *
30 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
31 */
32 /**
33 * Class to setup values in localconf.php and verify the TYPO3 DB tables/fields
34 *
35 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
36 * @package TYPO3
37 * @subpackage t3lib
38 * @deprecated since 6.0, will be removed by 7.0
39 */
40 class t3lib_install {
41
42 // External, Static
43 // Set to string which identifies the script using this class.
44 /**
45 * @deprecated since 6.0, will be removed by 7.0
46 */
47 public $updateIdentity = '';
48
49 // Prefix for checkbox fields when updating database.
50 /**
51 * @deprecated since 6.0, will be removed by 7.0
52 */
53 public $dbUpdateCheckboxPrefix = 'TYPO3_INSTALL[database_update]';
54
55 // If this is set, modifications to localconf.php is done by adding new lines to the array only. If unset, existing values are recognized and changed.
56 /**
57 * @deprecated since 6.0, will be removed by 7.0
58 */
59 public $localconf_addLinesOnly = 0;
60
61 // If set and addLinesOnly is disabled, lines will be change only if they are after this token (on a single line!) in the file
62 protected $localconf_startEditPointToken = '## INSTALL SCRIPT EDIT POINT TOKEN - all lines after this points may be changed by the install script!';
63
64 protected $localconf_endEditPointToken = '## INSTALL SCRIPT EDIT END POINT TOKEN - all lines before this points may be changed by the install script!';
65
66 // If TRUE, this class will allow the user to update the localconf.php file. Is set TRUE in the init.php file.
67 /**
68 * @deprecated since 6.0, will be removed by 7.0
69 */
70 public $allowUpdateLocalConf = 0;
71
72 // Backpath (used for icons etc.)
73 /**
74 * @deprecated since 6.0, will be removed by 7.0
75 */
76 public $backPath = '../';
77
78 // Internal, dynamic:
79 // Used to indicate that a value is change in the line-array of localconf and that it should be written.
80 /**
81 * @deprecated since 6.0, will be removed by 7.0
82 */
83 public $setLocalconf = 0;
84
85 // Used to set (error)messages from the executing functions like mail-sending, writing Localconf and such
86 /**
87 * @deprecated since 6.0, will be removed by 7.0
88 */
89 public $messages = array();
90
91 // Updated with line in localconf.php file that was changed.
92 /**
93 * @deprecated since 6.0, will be removed by 7.0
94 */
95 public $touchedLine = 0;
96
97 /**
98 * @var \TYPO3\CMS\Install\Sql\SchemaMigrator Instance of SQL handler
99 */
100 protected $sqlHandler = NULL;
101
102 /**
103 * Constructor function
104 * @deprecated since 6.0, will be removed by 7.0
105 */
106 public function __construct() {
107 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
108
109 $this->sqlHandler = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Install\\Sql\\SchemaMigrator');
110 }
111
112 /**************************************
113 *
114 * Writing to localconf.php
115 ***************************************/
116 /**
117 * This functions takes an array with lines from localconf.php, finds a variable and inserts the new value.
118 *
119 * @param array $line_array The localconf.php file exploded into an array by linebreaks. (see writeToLocalconf_control())
120 * @param string $variable The variable name to find and substitute. This string must match the first part of a trimmed line in the line-array. Matching is done backwards so the last appearing line will be substituted.
121 * @param string $value Is the value to be insert for the variable
122 * @param boolean $quoteValue Whether the given value should be quoted before being written
123 * @return void
124 * @see writeToLocalconf_control()
125 * @deprecated since 6.0, will be removed by 7.0
126 */
127 public function setValueInLocalconfFile(&$line_array, $variable, $value, $quoteValue = TRUE) {
128 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
129 return;
130 }
131
132 /**
133 * Takes an array with lines from localconf.php, finds a variable and inserts the new array value.
134 *
135 * @param array $lines the localconf.php file exploded into an array by line breaks. {@see writeToLocalconf_control()}
136 * @param string $variable the variable name to find and substitute. This string must match the first part of a trimmed line in the line-array. Matching is done backwards so the last appearing line will be substituted.
137 * @param array $value value to be assigned to the variable
138 * @return void
139 * @see writeToLocalconf_control()
140 * @deprecated since 6.0, will be removed by 7.0
141 */
142 public function setArrayValueInLocalconfFile(array &$lines, $variable, array $value) {
143 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
144 return;
145 }
146
147 /**
148 * Returns a parsable string representation of an array variable. This methods enhances
149 * standard method var_export from PHP to take TYPO3's CGL into account.
150 *
151 * @param array $variable
152 * @return string
153 * @deprecated since 6.0, will be removed by 7.0
154 */
155 protected function array_export(array $variable) {
156 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
157
158 $lines = explode('
159 ', var_export($variable, TRUE));
160 $out = 'array(';
161 $lineCount = count($lines);
162 for ($i = 1; $i < $lineCount; $i++) {
163 $out .= '
164 ';
165 // Make the space-indented declaration tab-indented instead
166 while (substr($lines[$i], 0, 2) === ' ') {
167 $out .= ' ';
168 $lines[$i] = substr($lines[$i], 2);
169 }
170 $out .= $lines[$i];
171 // Array declaration should be next to the assignment and no space between
172 // "array" and its opening parenthesis should exist
173 if (preg_match('/\\s=>\\s$/', $lines[$i])) {
174 $out .= preg_replace('/^\\s*array \\(/', 'array(', $lines[$i + 1]);
175 $i++;
176 }
177 }
178 return $out;
179 }
180
181 /**
182 * Writes or returns lines from localconf.php
183 *
184 * @param mixed $inlines Array of lines to write back to localconf.php. Possibly
185 * @param string $absFullPath Absolute path of alternative file to use (Notice: this path is not validated in terms of being inside 'TYPO3 space')
186 * @return mixed If $inlines is not an array it will return an array with the lines from localconf.php. Otherwise it will return a status string, either "continue" (updated) or "nochange" (not updated)
187 * @see setValueInLocalconfFile()
188 * @deprecated since 6.0, will be removed by 7.0
189 */
190 public function writeToLocalconf_control($inlines = '', $absFullPath = '') {
191 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
192 return 'nochange';
193 }
194
195 /**
196 * Writes lines to localconf.php.
197 *
198 * @param array $lines Array of lines to write back to localconf.php
199 * @param string $absFullPath Absolute path of alternative file to use (Notice: this path is not validated in terms of being inside 'TYPO3 space')
200 * @return boolean TRUE if method succeeded, otherwise FALSE
201 * @deprecated since 6.0, will be removed by 7.0
202 */
203 public function writeToLocalconf(array $lines, $absFullPath = '') {
204 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
205 return FALSE;
206 }
207
208 /**
209 * Checking for linebreaks in the string
210 *
211 * @param string $string String to test
212 * @return boolean Returns TRUE if string is OK
213 * @see setValueInLocalconfFile()
214 * @deprecated since 6.0, will be removed by 7.0
215 */
216 public function checkForBadString($string) {
217 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
218
219 return preg_match('/[' . LF . CR . ']/', $string) ? FALSE : TRUE;
220 }
221
222 /**
223 * Replaces ' with \' and \ with \\
224 *
225 * @param string $value Input value
226 * @return string Output value
227 * @see setValueInLocalconfFile()
228 * @deprecated since 6.0, will be removed by 7.0
229 */
230 public function slashValueForSingleDashes($value) {
231 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
232
233 $value = str_replace('\'.LF.\'', '###INSTALL_TOOL_LINEBREAK###', $value);
234 $value = str_replace('\'', '\\\'', str_replace('\\', '\\\\', $value));
235 $value = str_replace('###INSTALL_TOOL_LINEBREAK###', '\'.LF.\'', $value);
236 return $value;
237 }
238
239 /**
240 * Creates a table which checkboxes for updating database.
241 *
242 * @param array $arr Array of statements (key / value pairs where key is used for the checkboxes)
243 * @param string $label Label for the table.
244 * @param boolean $checked If set, then checkboxes are set by default.
245 * @param boolean $iconDis If set, then icons are shown.
246 * @param array $currentValue Array of "current values" for each key/value pair in $arr. Shown if given.
247 * @param boolean $cVfullMsg If set, will show the prefix "Current value" if $currentValue is given.
248 * @return string HTML table with checkboxes for update. Must be wrapped in a form.
249 * @deprecated since 6.0, will be removed by 7.0
250 */
251 public function generateUpdateDatabaseForm_checkboxes($arr, $label, $checked = TRUE, $iconDis = FALSE, $currentValue = array(), $cVfullMsg = FALSE) {
252 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
253
254 $out = array();
255 if (is_array($arr)) {
256 $tableId = uniqid('table');
257 if (count($arr) > 1) {
258 $out[] = '
259 <tr class="update-db-fields-batch">
260 <td valign="top">
261 <input type="checkbox" id="' . $tableId . '-checkbox"' . ($checked ? ' checked="checked"' : '') . '
262 onclick="$(\'' . $tableId . '\').select(\'input[type=checkbox]\').invoke(\'setValue\', $(this).checked);" />
263 </td>
264 <td nowrap="nowrap"><label for="' . $tableId . '-checkbox" style="cursor:pointer"><strong>select/deselect all</strong></label></td>
265 </tr>';
266 }
267 foreach ($arr as $key => $string) {
268 $ico = '';
269 $warnings = array();
270 if ($iconDis) {
271 if (preg_match('/^TRUNCATE/i', $string)) {
272 $ico .= '<img src="' . $this->backPath . 'gfx/icon_warning.gif" width="18" height="16" align="top" alt="" /><strong> </strong>';
273 $warnings['clear_table_info'] = 'Clearing the table is sometimes neccessary when adding new keys. In case of cache_* tables this should not hurt at all. However, use it with care.';
274 } elseif (stristr($string, ' user_')) {
275 $ico .= '<img src="' . $this->backPath . 'gfx/icon_warning.gif" width="18" height="16" align="top" alt="" /><strong>(USER) </strong>';
276 } elseif (stristr($string, ' app_')) {
277 $ico .= '<img src="' . $this->backPath . 'gfx/icon_warning.gif" width="18" height="16" align="top" alt="" /><strong>(APP) </strong>';
278 } elseif (stristr($string, ' ttx_') || stristr($string, ' tx_')) {
279 $ico .= '<img src="' . $this->backPath . 'gfx/icon_warning.gif" width="18" height="16" align="top" alt="" /><strong>(EXT) </strong>';
280 }
281 }
282 $out[] = '
283 <tr>
284 <td valign="top"><input type="checkbox" id="db-' . $key . '" name="' . $this->dbUpdateCheckboxPrefix . '[' . $key . ']" value="1"' . ($checked ? ' checked="checked"' : '') . ' /></td>
285 <td nowrap="nowrap"><label for="db-' . $key . '">' . nl2br(($ico . htmlspecialchars($string))) . '</label></td>
286 </tr>';
287 if (isset($currentValue[$key])) {
288 $out[] = '
289 <tr>
290 <td valign="top"></td>
291 <td nowrap="nowrap" style="color:#666666;">' . nl2br(((!$cVfullMsg ? 'Current value: ' : '') . '<em>' . $currentValue[$key] . '</em>')) . '</td>
292 </tr>';
293 }
294 }
295 if (count($warnings)) {
296 $out[] = '
297 <tr>
298 <td valign="top"></td>
299 <td style="color:#666666;"><em>' . implode('<br />', $warnings) . '</em></td>
300 </tr>';
301 }
302 // Compile rows:
303 $content = '
304 <!-- Update database fields / tables -->
305 <h3>' . $label . '</h3>
306 <table border="0" cellpadding="2" cellspacing="2" id="' . $tableId . '" class="update-db-fields">' . implode('', $out) . '
307 </table>';
308 }
309 return $content;
310 }
311
312 }
313
314 ?>