[!!!][FEATURE] Streamline Fluid Styled Content and CSS Styled Content
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Updates / MigrateCscStaticTemplateUpdate.php
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
17 use TYPO3\CMS\Core\Database\ConnectionPool;
18 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20
21 /**
22 * Migrate "css_styled_content" static template location
23 */
24 class MigrateCscStaticTemplateUpdate extends AbstractUpdate
25 {
26 /**
27 * @var string
28 */
29 protected $title = 'Migrate "css_styled_content" static template location';
30
31 /**
32 * Checks if an update is needed
33 *
34 * @param string &$description The description for the update
35 * @return bool Whether an update is needed (TRUE) or not (FALSE)
36 */
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
81 /**
82 * Performs the database update
83 *
84 * @param array &$databaseQueries Queries done in this update
85 * @param mixed &$customMessages Custom messages
86 * @return bool
87 */
88 public function performUpdate(array &$databaseQueries, &$customMessages)
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 }