[!!!][FEATURE] Streamline Fluid Styled Content and CSS Styled Content
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Updates / MigrateFscStaticTemplateUpdate.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 "fluid_styled_content" static template location
23 */
24 class MigrateFscStaticTemplateUpdate extends AbstractUpdate
25 {
26 /**
27 * @var string
28 */
29 protected $title = 'Migrate "fluid_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:fluid_styled_content/Configuration/TypoScript/Static%', \PDO::PARAM_STR)
51 ),
52 $queryBuilder->expr()->like(
53 'config',
54 $queryBuilder->createNamedParameter('%EXT:fluid_styled_content/Configuration/TypoScript/Static%', \PDO::PARAM_STR)
55 ),
56 $queryBuilder->expr()->like(
57 'include_static_file',
58 $queryBuilder->createNamedParameter('%EXT:fluid_styled_content/Configuration/TypoScript/Static%', \PDO::PARAM_STR)
59 )
60 )
61 )
62 ->execute()->fetchColumn(0);
63 if ($elementCount) {
64 $description = 'Static templates have been relocated to EXT:fluid_styled_content/Configuration/TypoScript/';
65 }
66 return (bool)$elementCount;
67 }
68
69 /**
70 * Performs the database update
71 *
72 * @param array &$databaseQueries Queries done in this update
73 * @param mixed &$customMessages Custom messages
74 * @return bool
75 */
76 public function performUpdate(array &$databaseQueries, &$customMessages)
77 {
78 $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('sys_template');
79 $queryBuilder = $connection->createQueryBuilder();
80 $queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
81 $statement = $queryBuilder->select('uid', 'include_static_file', 'constants', 'config')
82 ->from('sys_template')
83 ->where(
84 $queryBuilder->expr()->orX(
85 $queryBuilder->expr()->like(
86 'constants',
87 $queryBuilder->createNamedParameter('%EXT:fluid_styled_content/TypoScript/Static%', \PDO::PARAM_STR)
88 ),
89 $queryBuilder->expr()->like(
90 'config',
91 $queryBuilder->createNamedParameter('%EXT:fluid_styled_content/TypoScript/Static%', \PDO::PARAM_STR)
92 ),
93 $queryBuilder->expr()->like(
94 'include_static_file',
95 $queryBuilder->createNamedParameter('%EXT:fluid_styled_content/TypoScript/Static%', \PDO::PARAM_STR)
96 )
97 )
98 )
99 ->execute();
100 while ($record = $statement->fetch()) {
101 $search = 'EXT:fluid_styled_content/TypoScript/Static';
102 $replace = 'EXT:fluid_styled_content/TypoScript';
103 $record['include_static_file'] = str_replace($search, $replace, $record['include_static_file']);
104 $record['constants'] = str_replace($search, $replace, $record['constants']);
105 $record['config'] = str_replace($search, $replace, $record['config']);
106 $queryBuilder = $connection->createQueryBuilder();
107 $queryBuilder->update('sys_template')
108 ->where(
109 $queryBuilder->expr()->eq(
110 'uid',
111 $queryBuilder->createNamedParameter($record['uid'], \PDO::PARAM_INT)
112 )
113 )
114 ->set('include_static_file', $record['include_static_file'])
115 ->set('constants', $record['constants'])
116 ->set('config', $record['config']);
117 $databaseQueries[] = $queryBuilder->getSQL();
118 $queryBuilder->execute();
119 }
120 $this->markWizardAsDone();
121 return true;
122 }
123 }