TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
ContentTypesToTextMediaUpdate.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Install\Updates;
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 
21 
26 {
30  protected $title = 'Migrate CTypes text, image and textpic to textmedia and move file relations from "image" to "asset_references"';
31 
38  public function checkForUpdate(&$description)
39  {
40  if (
41  !ExtensionManagementUtility::isLoaded('fluid_styled_content')
42  || ExtensionManagementUtility::isLoaded('css_styled_content')
43  || $this->isWizardDone()
44  ) {
45  return false;
46  }
47 
48  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
49  ->getQueryBuilderForTable('tt_content');
50  $queryBuilder->getRestrictions()->removeAll();
51  $nonTextmediaCount = $queryBuilder->count('uid')
52  ->from('tt_content')
53  ->where(
54  $queryBuilder->expr()->in(
55  'CType',
56  $queryBuilder->createNamedParameter(
57  ['text', 'image', 'textpic'],
58  Connection::PARAM_STR_ARRAY
59  )
60  )
61  )
62  ->execute()->fetchColumn(0);
63 
64  if ((bool)$nonTextmediaCount) {
65  $description = 'The extension "fluid_styled_content" is using a new CType, textmedia, ' .
66  'which replaces the CTypes text, image and textpic. ' .
67  'This update wizard migrates these old CTypes to the new one in the database. ' .
68  'If backend groups have the explicit deny/allow flag set for any of the old CTypes, ' .
69  'the according flag for the CType textmedia is set as well.';
70  }
71 
72  return (bool)$nonTextmediaCount;
73  }
74 
82  public function performUpdate(array &$databaseQueries, &$customMessages)
83  {
84  $ttContentConnection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('tt_content');
85  $falConnection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('sys_file_reference');
86 
87  // Update text to textmedia
88  $queryBuilder = $ttContentConnection->createQueryBuilder();
89  $queryBuilder->update('tt_content')
90  ->where(
91  $queryBuilder->expr()->eq(
92  'CType',
93  $queryBuilder->createNamedParameter('text', \PDO::PARAM_STR)
94  )
95  )
96  ->set('CType', 'textmedia');
97  $databaseQueries[] = $queryBuilder->getSQL();
98  $queryBuilder->execute();
99 
100  // Update 'textpic' and 'image' records
101  $queryBuilder = $ttContentConnection->createQueryBuilder();
102  $queryBuilder->getRestrictions()->removeAll();
103  $statement = $queryBuilder->select('uid', 'image', 'CType')
104  ->from('tt_content')
105  ->where(
106  $queryBuilder->expr()->orX(
107  $queryBuilder->expr()->eq(
108  'CType',
109  $queryBuilder->createNamedParameter('textpic', \PDO::PARAM_STR)
110  ),
111  $queryBuilder->expr()->eq(
112  'CType',
113  $queryBuilder->createNamedParameter('image', \PDO::PARAM_STR)
114  )
115  )
116  )->execute();
117  while ($ttContentRow = $statement->fetch()) {
118  $falQueryBuilder = $falConnection->createQueryBuilder();
119  $falQueryBuilder->update('sys_file_reference')
120  ->where(
121  $queryBuilder->expr()->eq(
122  'uid_foreign',
123  $falQueryBuilder->createNamedParameter($ttContentRow['uid'], \PDO::PARAM_INT)
124  ),
125  $queryBuilder->expr()->eq(
126  'tablenames',
127  $falQueryBuilder->createNamedParameter('tt_content', \PDO::PARAM_STR)
128  ),
129  $queryBuilder->expr()->eq(
130  'fieldname',
131  $falQueryBuilder->createNamedParameter('image', \PDO::PARAM_STR)
132  )
133  )
134  ->set('fieldname', 'assets');
135  $databaseQueries[] = $falQueryBuilder->getSQL();
136  $falQueryBuilder->execute();
137 
138  $ttContentQueryBuilder = $ttContentConnection->createQueryBuilder();
139  $ttContentQueryBuilder->update('tt_content')
140  ->where(
141  $queryBuilder->expr()->eq(
142  'uid',
143  $ttContentQueryBuilder->createNamedParameter($ttContentRow['uid'], \PDO::PARAM_INT)
144  )
145  )
146  ->set('CType', 'textmedia')
147  ->set('assets', (int)$ttContentRow['image'])
148  ->set('image', 0);
149  $databaseQueries[] = $ttContentQueryBuilder->getSQL();
150  $ttContentQueryBuilder->execute();
151  }
152 
153  // Update explicitDeny - ALLOW
154  $beGroupsConnection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('be_groups');
155  $queryBuilder = $beGroupsConnection->createQueryBuilder();
156  $queryBuilder->getRestrictions()->removeAll();
157  $statement = $queryBuilder->select('uid', 'explicit_allowdeny')
158  ->from('be_groups')
159  ->where(
160  $queryBuilder->expr()->andX(
161  $queryBuilder->expr()->notLike(
162  'explicit_allowdeny',
163  $queryBuilder->createNamedParameter('%tt_content:CType:textmedia:ALLOW%', \PDO::PARAM_STR)
164  ),
165  $queryBuilder->expr()->orX(
166  $queryBuilder->expr()->like(
167  'explicit_allowdeny',
168  $queryBuilder->createNamedParameter('%tt_content:CType:textpic:ALLOW%', \PDO::PARAM_STR)
169  ),
170  $queryBuilder->expr()->like(
171  'explicit_allowdeny',
172  $queryBuilder->createNamedParameter('%tt_content:CType:image:ALLOW%', \PDO::PARAM_STR)
173  ),
174  $queryBuilder->expr()->like(
175  'explicit_allowdeny',
176  $queryBuilder->createNamedParameter('%tt_content:CType:text:ALLOW%', \PDO::PARAM_STR)
177  )
178  )
179  )
180  )->execute();
181  while ($beGroupsRow = $statement->fetch()) {
182  $queryBuilder = $beGroupsConnection->createQueryBuilder();
183  $queryBuilder->update('be_groups')
184  ->where(
185  $queryBuilder->expr()->eq(
186  'uid',
187  $queryBuilder->createNamedParameter($beGroupsRow['uid'], \PDO::PARAM_INT)
188  )
189  )
190  ->set('explicit_allowdeny', $beGroupsRow['explicit_allowdeny'] . ',tt_content:CType:textmedia:ALLOW');
191  $databaseQueries[] = $queryBuilder->getSQL();
192  $queryBuilder->execute();
193  }
194 
195  // Update explicitDeny - DENY
196  $queryBuilder = $beGroupsConnection->createQueryBuilder();
197  $queryBuilder->getRestrictions()->removeAll();
198  $statement = $queryBuilder->select('uid', 'explicit_allowdeny')
199  ->from('be_groups')
200  ->where(
201  $queryBuilder->expr()->andX(
202  $queryBuilder->expr()->notLike(
203  'explicit_allowdeny',
204  $queryBuilder->createNamedParameter('%tt_content:CType:textmedia:DENY%', \PDO::PARAM_STR)
205  ),
206  $queryBuilder->expr()->orX(
207  $queryBuilder->expr()->like(
208  'explicit_allowdeny',
209  $queryBuilder->createNamedParameter('%tt_content:CType:textpic:DENY%', \PDO::PARAM_STR)
210  ),
211  $queryBuilder->expr()->like(
212  'explicit_allowdeny',
213  $queryBuilder->createNamedParameter('%tt_content:CType:image:DENY%', \PDO::PARAM_STR)
214  ),
215  $queryBuilder->expr()->like(
216  'explicit_allowdeny',
217  $queryBuilder->createNamedParameter('%tt_content:CType:text:DENY%', \PDO::PARAM_STR)
218  )
219  )
220  )
221  )->execute();
222  while ($beGroupsRow = $statement->fetch()) {
223  $queryBuilder = $beGroupsConnection->createQueryBuilder();
224  $queryBuilder->update('be_groups')
225  ->where(
226  $queryBuilder->expr()->eq(
227  'uid',
228  $queryBuilder->createNamedParameter($beGroupsRow['uid'], \PDO::PARAM_INT)
229  )
230  )
231  ->set('explicit_allowdeny', $beGroupsRow['explicit_allowdeny'] . ',tt_content:CType:textmedia:DENY');
232  $databaseQueries[] = $queryBuilder->getSQL();
233  $queryBuilder->execute();
234  }
235 
236  $this->markWizardAsDone();
237 
238  return true;
239  }
240 }
static makeInstance($className,...$constructorArguments)