TYPO3 CMS  TYPO3_7-6
ContentTypesToTextMediaUpdate.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 
23 {
27  protected $title = 'Migrate CTypes text, image and textpic to textmedia and move file relations from "image" to "asset_references"';
28 
35  public function checkForUpdate(&$description)
36  {
37  $updateNeeded = true;
38 
39  if (
40  !ExtensionManagementUtility::isLoaded('fluid_styled_content')
41  || ExtensionManagementUtility::isLoaded('css_styled_content')
42  || $this->isWizardDone()
43  ) {
44  $updateNeeded = false;
45  } else {
46  $nonTextmediaCount = $this->getDatabaseConnection()->exec_SELECTcountRows(
47  'uid',
48  'tt_content',
49  'CType IN (\'text\', \'image\', \'textpic\')'
50  );
51 
52  if ($nonTextmediaCount === 0) {
53  $updateNeeded = false;
54  }
55  }
56 
57  $description = 'The extension "fluid_styled_content" is using a new CType, textmedia, ' .
58  'which replaces the CTypes text, image and textpic. ' .
59  'This update wizard migrates these old CTypes to the new one in the database. ' .
60  'If backend groups have the explicit deny/allow flag set for any of the old CTypes, ' .
61  'the according flag for the CType textmedia is set as well.';
62 
63  return $updateNeeded;
64  }
65 
73  public function performUpdate(array &$databaseQueries, &$customMessages)
74  {
75  $databaseConnection = $this->getDatabaseConnection();
76  $databaseConnection->store_lastBuiltQuery = true;
77 
78  // Update 'text' records
79  $databaseConnection->exec_UPDATEquery(
80  'tt_content',
81  'tt_content.CType=' . $databaseConnection->fullQuoteStr('text', 'tt_content'),
82  [
83  'CType' => 'textmedia',
84  ]
85  );
86 
87  // Store last executed query
88  $databaseQueries[] = str_replace(chr(10), ' ', $databaseConnection->debug_lastBuiltQuery);
89  // Check for errors
90  if ($databaseConnection->sql_error()) {
91  $customMessages = 'SQL-ERROR: ' . htmlspecialchars($databaseConnection->sql_error());
92  return false;
93  }
94 
95  // Update 'textpic' and 'image' records
96  $query = '
97  UPDATE tt_content
98  LEFT JOIN sys_file_reference
99  ON sys_file_reference.uid_foreign=tt_content.uid
100  AND sys_file_reference.tablenames=' . $databaseConnection->fullQuoteStr('tt_content', 'sys_file_reference')
101  . ' AND sys_file_reference.fieldname=' . $databaseConnection->fullQuoteStr('image', 'sys_file_reference')
102  . ' SET tt_content.CType=' . $databaseConnection->fullQuoteStr('textmedia', 'tt_content')
103  . ', tt_content.assets=tt_content.image,
104  tt_content.image=0,
105  sys_file_reference.fieldname=' . $databaseConnection->fullQuoteStr('assets', 'tt_content')
106  . ' WHERE
107  tt_content.CType=' . $databaseConnection->fullQuoteStr('textpic', 'tt_content')
108  . ' OR tt_content.CType=' . $databaseConnection->fullQuoteStr('image', 'tt_content');
109  $databaseConnection->sql_query($query);
110 
111  // Store last executed query
112  $databaseQueries[] = str_replace(chr(10), ' ', $query);
113  // Check for errors
114  if ($databaseConnection->sql_error()) {
115  $customMessages = 'SQL-ERROR: ' . htmlspecialchars($databaseConnection->sql_error());
116  return false;
117  }
118 
119  // Update explicitDeny - ALLOW
120  $databaseConnection->exec_UPDATEquery(
121  'be_groups',
122  '(explicit_allowdeny LIKE ' . $databaseConnection->fullQuoteStr('%' . $databaseConnection->escapeStrForLike('tt_content:CType:textpic:ALLOW', 'tt_content') . '%', 'tt_content')
123  . ' OR explicit_allowdeny LIKE ' . $databaseConnection->fullQuoteStr('%' . $databaseConnection->escapeStrForLike('tt_content:CType:image:ALLOW', 'tt_content') . '%', 'tt_content')
124  . ' OR explicit_allowdeny LIKE ' . $databaseConnection->fullQuoteStr('%' . $databaseConnection->escapeStrForLike('tt_content:CType:text:ALLOW', 'tt_content') . '%', 'tt_content')
125  . ') AND explicit_allowdeny NOT LIKE ' . $databaseConnection->fullQuoteStr('%' . $databaseConnection->escapeStrForLike('tt_content:CType:textmedia:ALLOW', 'tt_content') . '%', 'tt_content'),
126  [
127  'explicit_allowdeny' => 'CONCAT(explicit_allowdeny,' . $databaseConnection->fullQuoteStr(',tt_content:CType:textmedia:ALLOW', 'tt_content') . ')',
128  ],
129  [
130  'explicit_allowdeny',
131  ]
132  );
133 
134  // Store last executed query
135  $databaseQueries[] = str_replace(chr(10), ' ', $databaseConnection->debug_lastBuiltQuery);
136 
137  // Update explicitDeny - DENY
138  $databaseConnection->exec_UPDATEquery(
139  'be_groups',
140  '(explicit_allowdeny LIKE ' . $databaseConnection->fullQuoteStr('%' . $databaseConnection->escapeStrForLike('tt_content:CType:textpic:DENY', 'tt_content') . '%', 'tt_content')
141  . ' OR explicit_allowdeny LIKE ' . $databaseConnection->fullQuoteStr('%' . $databaseConnection->escapeStrForLike('tt_content:CType:image:DENY', 'tt_content') . '%', 'tt_content')
142  . ' OR explicit_allowdeny LIKE ' . $databaseConnection->fullQuoteStr('%' . $databaseConnection->escapeStrForLike('tt_content:CType:text:DENY', 'tt_content') . '%', 'tt_content')
143  . ') AND explicit_allowdeny NOT LIKE ' . $databaseConnection->fullQuoteStr('%' . $databaseConnection->escapeStrForLike('tt_content:CType:textmedia:DENY', 'tt_content') . '%', 'tt_content'),
144  [
145  'explicit_allowdeny' => 'CONCAT(explicit_allowdeny,' . $databaseConnection->fullQuoteStr(',tt_content:CType:textmedia:DENY', 'tt_content') . ')',
146  ],
147  [
148  'explicit_allowdeny',
149  ]
150  );
151 
152  // Store last executed query
153  $databaseQueries[] = str_replace(chr(10), ' ', $databaseConnection->debug_lastBuiltQuery);
154 
155  $this->markWizardAsDone();
156 
157  return true;
158  }
159 }