TYPO3 CMS  TYPO3_8-7
MigrateCscStaticTemplateUpdate.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 
20 
25 {
29  protected $title = 'Migrate "css_styled_content" static template location';
30 
37  public function checkForUpdate(&$description)
38  {
39  if ($this->isWizardDone()) {
40  return false;
41  }
42  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_template');
43  $queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
44  $elementCount = $queryBuilder->count('uid')
45  ->from('sys_template')
46  ->where(
47  $queryBuilder->expr()->orX(
48  $queryBuilder->expr()->like(
49  'constants',
50  $queryBuilder->createNamedParameter('%EXT:css_styled_content/static%', \PDO::PARAM_STR)
51  ),
52  $queryBuilder->expr()->like(
53  'constants',
54  $queryBuilder->createNamedParameter('%EXT:css_styled_content/TypoScript/v7%', \PDO::PARAM_STR)
55  ),
56  $queryBuilder->expr()->like(
57  'config',
58  $queryBuilder->createNamedParameter('%EXT:css_styled_content/static%', \PDO::PARAM_STR)
59  ),
60  $queryBuilder->expr()->like(
61  'config',
62  $queryBuilder->createNamedParameter('%EXT:css_styled_content/TypoScript/v7%', \PDO::PARAM_STR)
63  ),
64  $queryBuilder->expr()->like(
65  'include_static_file',
66  $queryBuilder->createNamedParameter('%EXT:css_styled_content/static%', \PDO::PARAM_STR)
67  ),
68  $queryBuilder->expr()->like(
69  'include_static_file',
70  $queryBuilder->createNamedParameter('%EXT:css_styled_content/TypoScript/v7%', \PDO::PARAM_STR)
71  )
72  )
73  )
74  ->execute()->fetchColumn(0);
75  if ($elementCount) {
76  $description = 'Static templates have been relocated to EXT:css_styled_content/Configuration/TypoScript/';
77  }
78  return (bool)$elementCount;
79  }
80 
88  public function performUpdate(array &$databaseQueries, &$customMessage)
89  {
90  $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('sys_template');
91  $queryBuilder = $connection->createQueryBuilder();
92  $queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
93  $statement = $queryBuilder->select('uid', 'include_static_file', 'constants', 'config')
94  ->from('sys_template')
95  ->where(
96  $queryBuilder->expr()->orX(
97  $queryBuilder->expr()->like(
98  'constants',
99  $queryBuilder->createNamedParameter('%EXT:css_styled_content/static%', \PDO::PARAM_STR)
100  ),
101  $queryBuilder->expr()->like(
102  'constants',
103  $queryBuilder->createNamedParameter('%EXT:css_styled_content/Configuration/TypoScript/v7%', \PDO::PARAM_STR)
104  ),
105  $queryBuilder->expr()->like(
106  'config',
107  $queryBuilder->createNamedParameter('%EXT:css_styled_content/static%', \PDO::PARAM_STR)
108  ),
109  $queryBuilder->expr()->like(
110  'config',
111  $queryBuilder->createNamedParameter('%EXT:css_styled_content/Configuration/TypoScript/v7%', \PDO::PARAM_STR)
112  ),
113  $queryBuilder->expr()->like(
114  'include_static_file',
115  $queryBuilder->createNamedParameter('%EXT:css_styled_content/static%', \PDO::PARAM_STR)
116  ),
117  $queryBuilder->expr()->like(
118  'include_static_file',
119  $queryBuilder->createNamedParameter('%EXT:css_styled_content/Configuration/TypoScript/v7%', \PDO::PARAM_STR)
120  )
121  )
122  )
123  ->execute();
124  while ($record = $statement->fetch()) {
125  $search = [
126  'EXT:css_styled_content/static/v4.5',
127  'EXT:css_styled_content/static/v4.6',
128  'EXT:css_styled_content/static/v4.7',
129  'EXT:css_styled_content/static/v6.0',
130  'EXT:css_styled_content/static/v6.1',
131  'EXT:css_styled_content/static/v6.2',
132  'EXT:css_styled_content/static',
133  'EXT:css_styled_content/Configuration/TypoScript/v7'
134  ];
135  $replace = 'EXT:css_styled_content/Configuration/TypoScript';
136  $record['include_static_file'] = str_replace($search, $replace, $record['include_static_file']);
137  $record['constants'] = str_replace($search, $replace, $record['constants']);
138  $record['config'] = str_replace($search, $replace, $record['config']);
139  $queryBuilder = $connection->createQueryBuilder();
140  $queryBuilder->update('sys_template')
141  ->where(
142  $queryBuilder->expr()->eq(
143  'uid',
144  $queryBuilder->createNamedParameter($record['uid'], \PDO::PARAM_INT)
145  )
146  )
147  ->set('include_static_file', $record['include_static_file'])
148  ->set('constants', $record['constants'])
149  ->set('config', $record['config']);
150  $databaseQueries[] = $queryBuilder->getSQL();
151  $queryBuilder->execute();
152  }
153  $this->markWizardAsDone();
154  return true;
155  }
156 }
static makeInstance($className,... $constructorArguments)