TYPO3 CMS  TYPO3_8-7
MigrateFscStaticTemplateUpdate.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 
19 
24 {
28  protected $title = 'Migrate "fluid_styled_content" static template location';
29 
36  public function checkForUpdate(&$description)
37  {
38  if ($this->isWizardDone()) {
39  return false;
40  }
41  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_template');
42  $queryBuilder->getRestrictions()->removeAll();
43  $elementCount = $queryBuilder->count('uid')
44  ->from('sys_template')
45  ->where(
46  $queryBuilder->expr()->orX(
47  $queryBuilder->expr()->like(
48  'constants',
49  $queryBuilder->createNamedParameter('%EXT:fluid_styled_content/Configuration/TypoScript/Static%', \PDO::PARAM_STR)
50  ),
51  $queryBuilder->expr()->like(
52  'config',
53  $queryBuilder->createNamedParameter('%EXT:fluid_styled_content/Configuration/TypoScript/Static%', \PDO::PARAM_STR)
54  ),
55  $queryBuilder->expr()->like(
56  'include_static_file',
57  $queryBuilder->createNamedParameter('%EXT:fluid_styled_content/Configuration/TypoScript/Static%', \PDO::PARAM_STR)
58  )
59  )
60  )
61  ->execute()->fetchColumn(0);
62  if ($elementCount) {
63  $description = 'Static templates have been relocated to EXT:fluid_styled_content/Configuration/TypoScript/';
64  }
65  return (bool)$elementCount;
66  }
67 
75  public function performUpdate(array &$databaseQueries, &$customMessage)
76  {
77  $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('sys_template');
78  $queryBuilder = $connection->createQueryBuilder();
79  $queryBuilder->getRestrictions()->removeAll();
80  $statement = $queryBuilder->select('uid', 'include_static_file', 'constants', 'config')
81  ->from('sys_template')
82  ->where(
83  $queryBuilder->expr()->orX(
84  $queryBuilder->expr()->like(
85  'constants',
86  $queryBuilder->createNamedParameter('%EXT:fluid_styled_content/Configuration/TypoScript/Static%', \PDO::PARAM_STR)
87  ),
88  $queryBuilder->expr()->like(
89  'config',
90  $queryBuilder->createNamedParameter('%EXT:fluid_styled_content/Configuration/TypoScript/Static%', \PDO::PARAM_STR)
91  ),
92  $queryBuilder->expr()->like(
93  'include_static_file',
94  $queryBuilder->createNamedParameter('%EXT:fluid_styled_content/Configuration/TypoScript/Static%', \PDO::PARAM_STR)
95  )
96  )
97  )
98  ->execute();
99  while ($record = $statement->fetch()) {
100  $search = 'EXT:fluid_styled_content/Configuration/TypoScript/Static';
101  $replace = 'EXT:fluid_styled_content/Configuration/TypoScript';
102  $record['include_static_file'] = str_replace($search, $replace, $record['include_static_file']);
103  $record['constants'] = str_replace($search, $replace, $record['constants']);
104  $record['config'] = str_replace($search, $replace, $record['config']);
105  $queryBuilder = $connection->createQueryBuilder();
106  $queryBuilder->update('sys_template')
107  ->where(
108  $queryBuilder->expr()->eq(
109  'uid',
110  $queryBuilder->createNamedParameter($record['uid'], \PDO::PARAM_INT)
111  )
112  )
113  ->set('include_static_file', $record['include_static_file'])
114  ->set('constants', $record['constants'])
115  ->set('config', $record['config']);
116  $databaseQueries[] = $queryBuilder->getSQL();
117  $queryBuilder->execute();
118  }
119  $this->markWizardAsDone();
120  return true;
121  }
122 }
static makeInstance($className,... $constructorArguments)