[!!!][FEATURE] Streamline Fluid Styled Content and CSS Styled Content
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Updates / BulletContentElementUpdate.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 bullet content element rendering from layout to bullets_type
23 */
24 class BulletContentElementUpdate extends AbstractUpdate
25 {
26 /**
27 * @var string
28 */
29 protected $title = '[Optional] Migrate bullet content element rendering selector from layout to bullets_type';
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('tt_content');
43 $queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
44 $elementCount = $queryBuilder->count('uid')
45 ->from('tt_content')
46 ->where(
47 $queryBuilder->expr()->eq('CType', $queryBuilder->createNamedParameter('bullets', \PDO::PARAM_STR)),
48 $queryBuilder->expr()->in('layout', [1, 2])
49 )
50 ->execute()->fetchColumn(0);
51 if ($elementCount) {
52 $description = 'Rendering type field has been streamlined with fluid_styled_content.';
53 }
54 return (bool)$elementCount;
55 }
56
57 /**
58 * Performs the database update
59 *
60 * @param array &$databaseQueries Queries done in this update
61 * @param mixed &$customMessages Custom messages
62 * @return bool
63 */
64 public function performUpdate(array &$databaseQueries, &$customMessages)
65 {
66 $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('tt_content');
67 $queryBuilder = $connection->createQueryBuilder();
68 $queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
69 $statement = $queryBuilder->select('uid', 'layout')
70 ->from('tt_content')
71 ->where(
72 $queryBuilder->expr()->eq('CType', $queryBuilder->createNamedParameter('bullets', \PDO::PARAM_STR)),
73 $queryBuilder->expr()->in('layout', [1, 2])
74 )
75 ->execute();
76 while ($record = $statement->fetch()) {
77 $queryBuilder = $connection->createQueryBuilder();
78 $queryBuilder->update('tt_content')
79 ->where(
80 $queryBuilder->expr()->eq(
81 'uid',
82 $queryBuilder->createNamedParameter($record['uid'], \PDO::PARAM_INT)
83 )
84 )
85 ->set('layout', 0, false)
86 ->set('bullets_type', $record['layout']);
87 $databaseQueries[] = $queryBuilder->getSQL();
88 $queryBuilder->execute();
89 }
90 $this->markWizardAsDone();
91 return true;
92 }
93 }