TYPO3 CMS  TYPO3_7-6
RteAcronymButtonRenamedToAbbreviation.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 = 'Rte "acronym" button renamed to "abbreviation"';
29 
36  public function checkForUpdate(&$description)
37  {
38  $result = false;
39 
40  $pages = $this->getPagesWithDeprecatedRteProperties($dbQueries, $customMessages);
41  $pagesCount = count($pages);
42  $description = '<p>The RTE "acronym" button is deprecated and replaced by the "abbreviation" button since TYPO3 CMS 7.0.</p>' . LF . '<p>Page TSconfig currently includes the string "acronym" on <strong>' . strval($pagesCount) . '&nbsp;pages</strong> (including deleted and hidden pages).</p>' . LF;
43  if ($pagesCount) {
44  $pagesUids = [];
45  foreach ($pages as $page) {
46  $pagesUids[] = $page['uid'];
47  }
48  $description .= '<p>Pages id\'s: ' . implode(', ', $pagesUids) . '</p>';
49  }
50  if ($pagesCount) {
51  $updateablePages = $this->findUpdateablePagesWithDeprecatedRteProperties($pages);
52  if (!empty($updateablePages)) {
53  $description .= '<p>This wizard will perform automatic replacement of the string "acronym" by the string "abbreviation" on the Page TSconfig of <strong>' . strval(count($updateablePages)) . '&nbsp;pages</strong> (including deleted and hidden):</p>' . LF;
54  }
55  $result = true;
56  } else {
57  // if we found no occurrence of deprecated settings and wizard was already executed, then
58  // we do not show up anymore
59  if ($this->isWizardDone()) {
60  $result = false;
61  }
62  }
63  $description .= '<p>Only page records are searched for the string "acronym". However, such string may also be used in BE group and BE user records. These are not searched nor updated by this wizard.</p>'
64  . 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>'
65  . LF . '<p>Note that this string replacement will apply to all contents of PageTSconfig.</p>'
66  . LF . '<p>Note that the configuration of RTE processing options (RTE.default.proc) may also include the string "acronym".</p>';
67 
68  return $result;
69  }
70 
78  public function performUpdate(array &$dbQueries, &$customMessages)
79  {
80  $customMessages = '';
81  $pages = $this->getPagesWithDeprecatedRteProperties($dbQueries, $customMessages);
82  if (empty($customMessages)) {
83  $pagesCount = count($pages);
84  if ($pagesCount) {
85  $updateablePages = $this->findUpdateablePagesWithDeprecatedRteProperties($pages);
86  if (!empty($updateablePages)) {
87  $this->updatePages($updateablePages, $dbQueries, $customMessages);
88  // If the update was successful
89  if (empty($customMessages)) {
90  if (count($updateablePages) !== $pagesCount) {
91  $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.';
92  }
93  }
94  } else {
95  $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.';
96  }
97  }
98  }
99  $this->markWizardAsDone();
100  return empty($customMessages);
101  }
102 
110  protected function getPagesWithDeprecatedRteProperties(&$dbQueries, &$customMessages)
111  {
112  $db = $this->getDatabaseConnection();
113  $fields = 'uid, TSconfig';
114  $table = 'pages';
115  $where = 'TSconfig LIKE BINARY ' . $db->fullQuoteStr('%acronym%', 'pages');
116  $res = $db->exec_SELECTquery($fields, $table, $where);
117  $dbQueries[] = str_replace(LF, ' ', $db->debug_lastBuiltQuery);
118  if ($db->sql_error()) {
119  $customMessages = 'SQL-ERROR: ' . htmlspecialchars($db->sql_error());
120  }
121  $pages = [];
122  while ($row = $db->sql_fetch_assoc($res)) {
123  $pages[] = $row;
124  }
125  return $pages;
126  }
127 
135  {
136  foreach ($pages as $index => $page) {
137  $updatedPageTSConfig = str_replace('acronym', 'abbreviation', $page['TSconfig']);
138  if ($updatedPageTSConfig == $page['TSconfig']) {
139  unset($pages[$index]);
140  } else {
141  $pages[$index]['TSconfig'] = $updatedPageTSConfig;
142  }
143  }
144  return $pages;
145  }
146 
154  protected function updatePages($pages, &$dbQueries, &$customMessages)
155  {
156  $db = $this->getDatabaseConnection();
157  foreach ($pages as $page) {
158  $table = 'pages';
159  $where = 'uid =' . $page['uid'];
160  $field_values = [
161  'TSconfig' => $page['TSconfig']
162  ];
163  $db->exec_UPDATEquery($table, $where, $field_values);
164  $dbQueries[] = str_replace(LF, ' ', $db->debug_lastBuiltQuery);
165  if ($db->sql_error()) {
166  $customMessages .= 'SQL-ERROR: ' . htmlspecialchars($db->sql_error()) . LF . LF;
167  }
168  }
169  }
170 }