[!!!][FEATURE] Streamline Fluid Styled Content and CSS Styled Content
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Updates / SectionFrameToFrameClassUpdate.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 the field 'section_frame' for all content elements to 'frame_class'
23 */
24 class SectionFrameToFrameClassUpdate extends AbstractUpdate
25 {
26 /**
27 * @var string
28 */
29 protected $title = 'Migrate the field "section_frame" for all content elements to "frame_class"';
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()->gt('section_frame', 0)
48 )
49 ->execute()->fetchColumn(0);
50 if ($elementCount) {
51 $description = 'Section frames were used to control the wrapping of each content element in the frontend '
52 . 'output, stored as integers in the database. To get rid of a nessesary mapping of those values we '
53 . 'are now storing strings you an easily adjust that will simply passed to the rendering.';
54 }
55 return (bool)$elementCount;
56 }
57
58 /**
59 * Performs the database update
60 *
61 * @param array &$databaseQueries Queries done in this update
62 * @param mixed &$customMessages Custom messages
63 * @return bool
64 */
65 public function performUpdate(array &$databaseQueries, &$customMessages)
66 {
67 $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('tt_content');
68 $queryBuilder = $connection->createQueryBuilder();
69 $queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
70 $statement = $queryBuilder->select('uid', 'section_frame')
71 ->from('tt_content')
72 ->where(
73 $queryBuilder->expr()->gt('section_frame', 0)
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('section_frame', 0, false)
86 ->set('frame_class', $this->mapSectionFrame($record['section_frame']));
87 $databaseQueries[] = $queryBuilder->getSQL();
88 $queryBuilder->execute();
89 }
90 $this->markWizardAsDone();
91 return true;
92 }
93
94 /**
95 * Map the old to the new values
96 *
97 * @param int $sectionFrame The content of the FlexForm
98 * @return string The equivalent value frame_class
99 */
100 protected function mapSectionFrame($sectionFrame)
101 {
102 $mapping = [
103 0 => 'default',
104 5 => 'ruler-before',
105 6 => 'ruler-after',
106 10 => 'indent',
107 11 => 'indent-left',
108 12 => 'indent-right',
109 66 => 'none'
110 ];
111 if (array_key_exists($sectionFrame, $mapping)) {
112 return $mapping[$sectionFrame];
113 }
114 return 'custom-' . (int) $sectionFrame;
115 }
116 }