TYPO3 CMS  TYPO3_7-6
DeprecatedRteProperties.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
18 
24 {
28  protected $title = 'Deprecated RTE properties in Page TSconfig';
29 
37  'disableRightClick' => 'contextMenu.disable',
38  'disableContextMenu' => 'contextMenu.disable',
39  'hidePStyleItems' => 'buttons.formatblock.removeItems',
40  'hideFontFaces' => 'buttons.fontstyle.removeItems',
41  'fontFace' => 'buttons.fontstyle.addItems',
42  'hideFontSizes' => 'buttons.fontsize.removeItems',
43  'classesCharacter' => 'buttons.textstyle.tags.span.allowedClasses',
44  'classesParagraph' => 'buttons.blockstyle.tags.div.allowedClasses',
45  'classesTable' => 'buttons.blockstyle.tags.table.allowedClasses',
46  'classesTD' => 'buttons.blockstyle.tags.td.allowedClasses',
47  'classesImage' => 'buttons.image.properties.class.allowedClasses',
48  'classesLinks' => 'buttons.link.properties.class.allowedClasses',
49  'blindImageOptions' => 'buttons.image.options.removeItems',
50  'blindLinkOptions' => 'buttons.link.options.removeItems',
51  'defaultLinkTarget' => 'buttons.link.properties.target.default'
52  ];
53 
61  'disableTYPO3Browsers' => [
62  'buttons.image.TYPO3Browser.disabled',
63  'buttons.link.TYPO3Browser.disabled'
64  ],
65  'showTagFreeClasses' => [
66  'buttons.blockstyle.showTagFreeClasses',
67  'buttons.textstyle.showTagFreeClasses'
68  ],
69  'disablePCexamples' => [
70  'buttons.blockstyle.disableStyleOnOptionLabel',
71  'buttons.textstyle.disableStyleOnOptionLabel'
72  ]
73  ];
74 
82  'fontSize' => 'buttons.fontsize.addItems',
83  'RTE.default.classesAnchor' => 'RTE.default.buttons.link.properties.class.allowedClasses',
84  'RTE.default.classesAnchor.default.[link-type]' => 'RTE.default.buttons.link.[link-type].properties.class.default',
85  'mainStyleOverride' => 'contentCSS',
86  'mainStyleOverride_add.[key]' => 'contentCSS',
87  'mainStyle_font' => 'contentCSS',
88  'mainStyle_size' => 'contentCSS',
89  'mainStyle_color' => 'contentCSS',
90  'mainStyle_bgcolor' => 'contentCSS',
91  'inlineStyle.[any-keystring]' => 'contentCSS',
92  'ignoreMainStyleOverride' => 'n.a.'
93  ];
94 
101  public function checkForUpdate(&$description)
102  {
103  $result = false;
104 
105  $pages = $this->getPagesWithDeprecatedRteProperties($dbQueries, $customMessages);
106  $pagesCount = count($pages);
107  $deprecatedProperties = '';
108  $deprecatedRteProperties = array_merge($this->replacementRteProperties, $this->useInsteadRteProperties);
109  foreach ($deprecatedRteProperties as $deprecatedProperty => $replacementProperty) {
110  $deprecatedProperties .= '<tr><td>' . $deprecatedProperty . '</td><td>' . $replacementProperty . '</td></tr>' . LF;
111  }
112  foreach ($this->doubleReplacementRteProperties as $deprecatedProperty => $replacementProperties) {
113  $deprecatedProperties .= '<tr><td>' . $deprecatedProperty . '</td><td>' . implode(' and ', $replacementProperties) . '</td></tr>' . LF;
114  }
115  $description = '<p>The following Page TSconfig RTE properties are deprecated since TYPO3 4.6 and have been removed in TYPO3 6.0.</p>' . LF . '<table><thead><tr><th>Deprecated property</th><th>Use instead</th></tr></thead>' . LF . '<tbody>' . $deprecatedProperties . '</tboby></table>' . LF . '<p>You are currently using some of these properties on <strong>' . strval($pagesCount) . '&nbsp;pages</strong> (including deleted and hidden pages).</p>' . LF;
116  if ($pagesCount) {
117  $pagesUids = [];
118  foreach ($pages as $page) {
119  $pagesUids[] = $page['uid'];
120  }
121  $description .= '<p>Pages id\'s: ' . implode(', ', $pagesUids) . '</p>';
122  }
123  $replacementProperties = '';
124  foreach ($this->useInsteadRteProperties as $deprecatedProperty => $replacementProperty) {
125  $replacementProperties .= '<tr><td>' . $deprecatedProperty . '</td><td>' . $replacementProperty . '</td></tr>' . LF;
126  }
127  if ($pagesCount) {
128  $updateablePages = $this->findUpdateablePagesWithDeprecatedRteProperties($pages);
129  if (!empty($updateablePages)) {
130  $replacementProperties = '';
131  foreach ($this->replacementRteProperties as $deprecatedProperty => $replacementProperty) {
132  $replacementProperties .= '<tr><td>' . $deprecatedProperty . '</td><td>' . $replacementProperty . '</td></tr>' . LF;
133  }
134  $description .= '<p>This wizard will perform automatic replacement of the following properties on <strong>' . strval(count($updateablePages)) . '&nbsp;pages</strong> (including deleted and hidden):</p>' . LF . '<table><thead><tr><th>Deprecated property</th><th>Will be replaced by</th></tr></thead><tbody>' . $replacementProperties . '</tboby></table>' . LF . '<p>The Page TSconfig column of the remaining pages will need to be updated manually.</p>' . LF;
135  } else {
136  $replacementProperties = '';
137  foreach ($this->useInsteadRteProperties as $deprecatedProperty => $_) {
138  $replacementProperties .= '<tr><td>' . $deprecatedProperty . '</td></tr>' . LF;
139  }
140  foreach ($this->doubleReplacementRteProperties as $deprecatedProperty => $_) {
141  $replacementProperties .= '<tr><td>' . $deprecatedProperty . '</td></tr>' . LF;
142  }
143  $description .= '<p>This wizard cannot update the following properties, some of which are present on those pages:</p>' . LF . '<table><thead><tr><th>Deprecated property</th></tr></thead><tbody>' . $replacementProperties . '</tboby></table>' . LF . '<p>Therefore, the Page TSconfig column of those pages will need to be updated manually.</p>' . LF;
144  }
145  $result = true;
146  } else {
147  // if we found no occurrence of deprecated settings and wizard was already executed, then
148  // we do not show up anymore
149  if ($this->isWizardDone()) {
150  $result = false;
151  }
152  }
153  $description .= '<p>Only page records are searched for deprecated properties. However, such properties can also be used in BE group and BE user records (prepended with page.). These are not searched nor updated by this wizard.</p>' . LF . '<p>Page TSconfig may also be included from external files. These are not updated by this wizard. If required, the update will need to be done manually.</p>' . LF . '<p>Note also that deprecated properties have been replaced in default configurations provided by htmlArea RTE';
154 
155  return $result;
156  }
157 
165  public function performUpdate(array &$dbQueries, &$customMessages)
166  {
167  $customMessages = '';
168  $pages = $this->getPagesWithDeprecatedRteProperties($dbQueries, $customMessages);
169  if (empty($customMessages)) {
170  $pagesCount = count($pages);
171  if ($pagesCount) {
172  $updateablePages = $this->findUpdateablePagesWithDeprecatedRteProperties($pages);
173  if (!empty($updateablePages)) {
174  $this->updatePages($updateablePages, $dbQueries, $customMessages);
175  // If the update was successful
176  if (empty($customMessages)) {
177  // If all pages were updated, we query again to check if any deprecated properties are still present.
178  if (count($updateablePages) === $pagesCount) {
179  $pagesAfter = $this->getPagesWithDeprecatedRteProperties($dbQueries, $customMessages);
180  if (empty($customMessages)) {
181  if (!empty($pagesAfter)) {
182  $customMessages = 'Some deprecated Page TSconfig properties were found. However, the wizard was unable to automatically replace all the deprecated properties found. Some properties will have to be replaced manually.';
183  }
184  }
185  } else {
186  $customMessages = 'Some deprecated Page TSconfig properties were found. However, the wizard was unable to automatically replace all the deprecated properties found. Some properties will have to be replaced manually.';
187  }
188  }
189  } else {
190  $customMessages = 'Some deprecated Page TSconfig properties were found. However, the wizard was unable to automatically replace any of the deprecated properties found. These properties will have to be replaced manually.';
191  }
192  }
193  }
194  $this->markWizardAsDone();
195  return empty($customMessages);
196  }
197 
205  protected function getPagesWithDeprecatedRteProperties(&$dbQueries, &$customMessages)
206  {
207  $fields = 'uid, TSconfig';
208  $table = 'pages';
209  $where = '';
210  $db = $this->getDatabaseConnection();
211  foreach (array_merge($this->replacementRteProperties, $this->useInsteadRteProperties, $this->doubleReplacementRteProperties) as $deprecatedRteProperty => $_) {
212  $where .= ($where ? ' OR ' : '') . '(TSconfig LIKE BINARY ' . $db->fullQuoteStr('%RTE.%' . $deprecatedRteProperty . '%', 'pages') . ' AND TSconfig NOT LIKE BINARY ' . $db->fullQuoteStr('%RTE.%' . $deprecatedRteProperty . 's%', 'pages') . ')' . LF;
213  }
214  $res = $db->exec_SELECTquery($fields, $table, $where);
215  $dbQueries[] = str_replace(LF, ' ', $db->debug_lastBuiltQuery);
216  if ($db->sql_error()) {
217  $customMessages = 'SQL-ERROR: ' . htmlspecialchars($db->sql_error());
218  }
219  $pages = [];
220  while ($row = $db->sql_fetch_assoc($res)) {
221  $pages[] = $row;
222  }
223  return $pages;
224  }
225 
233  {
234  foreach ($pages as $index => $page) {
235  $deprecatedProperties = explode(',', '/' . implode('/,/((RTE\\.(default\\.|config\\.[a-zA-Z0-9_\\-]*\\.[a-zA-Z0-9_\\-]*\\.))|\\s)', array_keys($this->replacementRteProperties)) . '/');
236  $replacementProperties = explode(',', '$1' . implode(',$1', array_values($this->replacementRteProperties)));
237  $updatedPageTSConfig = preg_replace($deprecatedProperties, $replacementProperties, $page['TSconfig']);
238  if ($updatedPageTSConfig == $page['TSconfig']) {
239  unset($pages[$index]);
240  } else {
241  $pages[$index]['TSconfig'] = $updatedPageTSConfig;
242  }
243  }
244  return $pages;
245  }
246 
254  protected function updatePages($pages, &$dbQueries, &$customMessages)
255  {
256  $db = $this->getDatabaseConnection();
257  foreach ($pages as $page) {
258  $table = 'pages';
259  $where = 'uid =' . $page['uid'];
260  $field_values = [
261  'TSconfig' => $page['TSconfig']
262  ];
263  $db->exec_UPDATEquery($table, $where, $field_values);
264  $dbQueries[] = str_replace(LF, ' ', $db->debug_lastBuiltQuery);
265  if ($db->sql_error()) {
266  $customMessages .= 'SQL-ERROR: ' . htmlspecialchars($db->sql_error()) . LF . LF;
267  }
268  }
269  }
270 }