4aff4d1f7c9267cc35244f3b41f8bde43b29f5aa
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_install.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2013 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 * @deprecated since 6.0, will be removed with 6.2
37 */
38 class t3lib_install {
39
40 // External, Static
41 // Set to string which identifies the script using this class.
42 /**
43 * @deprecated since 6.0, will be removed with 6.2
44 */
45 public $updateIdentity = '';
46
47 // Prefix for checkbox fields when updating database.
48 /**
49 * @deprecated since 6.0, will be removed with 6.2
50 */
51 public $dbUpdateCheckboxPrefix = 'TYPO3_INSTALL[database_update]';
52
53 // 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.
54 /**
55 * @deprecated since 6.0, will be removed with 6.2
56 */
57 public $localconf_addLinesOnly = 0;
58
59 // If set and addLinesOnly is disabled, lines will be change only if they are after this token (on a single line!) in the file
60 protected $localconf_startEditPointToken = '## INSTALL SCRIPT EDIT POINT TOKEN - all lines after this points may be changed by the install script!';
61
62 protected $localconf_endEditPointToken = '## INSTALL SCRIPT EDIT END POINT TOKEN - all lines before this points may be changed by the install script!';
63
64 // If TRUE, this class will allow the user to update the localconf.php file. Is set TRUE in the init.php file.
65 /**
66 * @deprecated since 6.0, will be removed with 6.2
67 */
68 public $allowUpdateLocalConf = 0;
69
70 // Backpath (used for icons etc.)
71 /**
72 * @deprecated since 6.0, will be removed with 6.2
73 */
74 public $backPath = '../';
75
76 // Internal, dynamic:
77 // Used to indicate that a value is change in the line-array of localconf and that it should be written.
78 /**
79 * @deprecated since 6.0, will be removed with 6.2
80 */
81 public $setLocalconf = 0;
82
83 // Used to set (error)messages from the executing functions like mail-sending, writing Localconf and such
84 /**
85 * @deprecated since 6.0, will be removed with 6.2
86 */
87 public $messages = array();
88
89 // Updated with line in localconf.php file that was changed.
90 /**
91 * @deprecated since 6.0, will be removed with 6.2
92 */
93 public $touchedLine = 0;
94
95 /**
96 * @var \TYPO3\CMS\Install\Sql\SchemaMigrator Instance of SQL handler
97 */
98 protected $sqlHandler = NULL;
99
100 /**
101 * Constructor function
102 * @deprecated since 6.0, will be removed with 6.2
103 */
104 public function __construct() {
105 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
106
107 $this->sqlHandler = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Install\\Sql\\SchemaMigrator');
108 }
109
110 /**************************************
111 *
112 * Writing to localconf.php
113 ***************************************/
114 /**
115 * This functions takes an array with lines from localconf.php, finds a variable and inserts the new value.
116 *
117 * @param array $line_array The localconf.php file exploded into an array by linebreaks. (see writeToLocalconf_control())
118 * @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.
119 * @param string $value Is the value to be insert for the variable
120 * @param boolean $quoteValue Whether the given value should be quoted before being written
121 * @return void
122 * @see writeToLocalconf_control()
123 * @deprecated since 6.0, will be removed with 6.2
124 */
125 public function setValueInLocalconfFile(&$line_array, $variable, $value, $quoteValue = TRUE) {
126 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
127 return;
128 }
129
130 /**
131 * Takes an array with lines from localconf.php, finds a variable and inserts the new array value.
132 *
133 * @param array $lines the localconf.php file exploded into an array by line breaks. {@see writeToLocalconf_control()}
134 * @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.
135 * @param array $value value to be assigned to the variable
136 * @return void
137 * @see writeToLocalconf_control()
138 * @deprecated since 6.0, will be removed with 6.2
139 */
140 public function setArrayValueInLocalconfFile(array &$lines, $variable, array $value) {
141 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
142 return;
143 }
144
145 /**
146 * Returns a parsable string representation of an array variable. This methods enhances
147 * standard method var_export from PHP to take TYPO3's CGL into account.
148 *
149 * @param array $variable
150 * @return string
151 * @deprecated since 6.0, will be removed with 6.2
152 */
153 protected function array_export(array $variable) {
154 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
155
156 $lines = explode('
157 ', var_export($variable, TRUE));
158 $out = 'array(';
159 $lineCount = count($lines);
160 for ($i = 1; $i < $lineCount; $i++) {
161 $out .= '
162 ';
163 // Make the space-indented declaration tab-indented instead
164 while (substr($lines[$i], 0, 2) === ' ') {
165 $out .= ' ';
166 $lines[$i] = substr($lines[$i], 2);
167 }
168 $out .= $lines[$i];
169 // Array declaration should be next to the assignment and no space between
170 // "array" and its opening parenthesis should exist
171 if (preg_match('/\\s=>\\s$/', $lines[$i])) {
172 $out .= preg_replace('/^\\s*array \\(/', 'array(', $lines[$i + 1]);
173 $i++;
174 }
175 }
176 return $out;
177 }
178
179 /**
180 * Writes or returns lines from localconf.php
181 *
182 * @param mixed $inlines Array of lines to write back to localconf.php. Possibly
183 * @param string $absFullPath Absolute path of alternative file to use (Notice: this path is not validated in terms of being inside 'TYPO3 space')
184 * @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)
185 * @see setValueInLocalconfFile()
186 * @deprecated since 6.0, will be removed with 6.2
187 */
188 public function writeToLocalconf_control($inlines = '', $absFullPath = '') {
189 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
190 return 'nochange';
191 }
192
193 /**
194 * Writes lines to localconf.php.
195 *
196 * @param array $lines Array of lines to write back to localconf.php
197 * @param string $absFullPath Absolute path of alternative file to use (Notice: this path is not validated in terms of being inside 'TYPO3 space')
198 * @return boolean TRUE if method succeeded, otherwise FALSE
199 * @deprecated since 6.0, will be removed with 6.2
200 */
201 public function writeToLocalconf(array $lines, $absFullPath = '') {
202 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
203 return FALSE;
204 }
205
206 /**
207 * Checking for linebreaks in the string
208 *
209 * @param string $string String to test
210 * @return boolean Returns TRUE if string is OK
211 * @see setValueInLocalconfFile()
212 * @deprecated since 6.0, will be removed with 6.2
213 */
214 public function checkForBadString($string) {
215 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
216
217 return preg_match('/[' . LF . CR . ']/', $string) ? FALSE : TRUE;
218 }
219
220 /**
221 * Replaces ' with \' and \ with \\
222 *
223 * @param string $value Input value
224 * @return string Output value
225 * @see setValueInLocalconfFile()
226 * @deprecated since 6.0, will be removed with 6.2
227 */
228 public function slashValueForSingleDashes($value) {
229 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
230
231 $value = str_replace('\'.LF.\'', '###INSTALL_TOOL_LINEBREAK###', $value);
232 $value = str_replace('\'', '\\\'', str_replace('\\', '\\\\', $value));
233 $value = str_replace('###INSTALL_TOOL_LINEBREAK###', '\'.LF.\'', $value);
234 return $value;
235 }
236
237 /**
238 * Creates a table which checkboxes for updating database.
239 *
240 * @param array $arr Array of statements (key / value pairs where key is used for the checkboxes)
241 * @param string $label Label for the table.
242 * @param boolean $checked If set, then checkboxes are set by default.
243 * @param boolean $iconDis If set, then icons are shown.
244 * @param array $currentValue Array of "current values" for each key/value pair in $arr. Shown if given.
245 * @param boolean $cVfullMsg If set, will show the prefix "Current value" if $currentValue is given.
246 * @return string HTML table with checkboxes for update. Must be wrapped in a form.
247 * @deprecated since 6.0, will be removed with 6.2
248 */
249 public function generateUpdateDatabaseForm_checkboxes($arr, $label, $checked = TRUE, $iconDis = FALSE, $currentValue = array(), $cVfullMsg = FALSE) {
250 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
251
252 $out = array();
253 if (is_array($arr)) {
254 $tableId = uniqid('table');
255 if (count($arr) > 1) {
256 $out[] = '
257 <tr class="update-db-fields-batch">
258 <td valign="top">
259 <input type="checkbox" id="' . $tableId . '-checkbox"' . ($checked ? ' checked="checked"' : '') . '
260 onclick="$(\'' . $tableId . '\').select(\'input[type=checkbox]\').invoke(\'setValue\', $(this).checked);" />
261 </td>
262 <td nowrap="nowrap"><label for="' . $tableId . '-checkbox" style="cursor:pointer"><strong>select/deselect all</strong></label></td>
263 </tr>';
264 }
265 foreach ($arr as $key => $string) {
266 $ico = '';
267 $warnings = array();
268 if ($iconDis) {
269 if (preg_match('/^TRUNCATE/i', $string)) {
270 $ico .= '<img src="' . $this->backPath . 'gfx/icon_warning.gif" width="18" height="16" align="top" alt="" /><strong> </strong>';
271 $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.';
272 } elseif (stristr($string, ' user_')) {
273 $ico .= '<img src="' . $this->backPath . 'gfx/icon_warning.gif" width="18" height="16" align="top" alt="" /><strong>(USER) </strong>';
274 } elseif (stristr($string, ' app_')) {
275 $ico .= '<img src="' . $this->backPath . 'gfx/icon_warning.gif" width="18" height="16" align="top" alt="" /><strong>(APP) </strong>';
276 } elseif (stristr($string, ' ttx_') || stristr($string, ' tx_')) {
277 $ico .= '<img src="' . $this->backPath . 'gfx/icon_warning.gif" width="18" height="16" align="top" alt="" /><strong>(EXT) </strong>';
278 }
279 }
280 $out[] = '
281 <tr>
282 <td valign="top"><input type="checkbox" id="db-' . $key . '" name="' . $this->dbUpdateCheckboxPrefix . '[' . $key . ']" value="1"' . ($checked ? ' checked="checked"' : '') . ' /></td>
283 <td nowrap="nowrap"><label for="db-' . $key . '">' . nl2br(($ico . htmlspecialchars($string))) . '</label></td>
284 </tr>';
285 if (isset($currentValue[$key])) {
286 $out[] = '
287 <tr>
288 <td valign="top"></td>
289 <td nowrap="nowrap" style="color:#666666;">' . nl2br(((!$cVfullMsg ? 'Current value: ' : '') . '<em>' . $currentValue[$key] . '</em>')) . '</td>
290 </tr>';
291 }
292 }
293 if (count($warnings)) {
294 $out[] = '
295 <tr>
296 <td valign="top"></td>
297 <td style="color:#666666;"><em>' . implode('<br />', $warnings) . '</em></td>
298 </tr>';
299 }
300 // Compile rows:
301 $content = '
302 <!-- Update database fields / tables -->
303 <h3>' . $label . '</h3>
304 <table border="0" cellpadding="2" cellspacing="2" id="' . $tableId . '" class="update-db-fields">' . implode('', $out) . '
305 </table>';
306 }
307 return $content;
308 }
309
310 }
311
312 ?>