[!!!][FEATURE] Streamline Fluid Styled Content and CSS Styled Content
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Updates / SplitMenusUpdate.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 * Split menu types into dedicated content elements
23 */
24 class SplitMenusUpdate extends AbstractUpdate
25 {
26 /**
27 * @var string
28 */
29 protected $title = 'Split menu types into dedicated content elements';
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('menu', \PDO::PARAM_STR))
48 )
49 ->execute()->fetchColumn(0);
50 if ($elementCount) {
51 $description = 'Menus have been splitted into dedicated content elements to provide '
52 . 'a better maintainability and more easy to adjustable template with single '
53 . 'responsibility for 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', 'header', 'menu_type')
71 ->from('tt_content')
72 ->where(
73 $queryBuilder->expr()->eq(
74 'CType',
75 $queryBuilder->createNamedParameter('menu', \PDO::PARAM_STR)
76 )
77 )
78 ->execute();
79 while ($record = $statement->fetch()) {
80 $queryBuilder = $connection->createQueryBuilder();
81 $queryBuilder->update('tt_content')
82 ->where(
83 $queryBuilder->expr()->eq(
84 'uid',
85 $queryBuilder->createNamedParameter($record['uid'], \PDO::PARAM_INT)
86 )
87 )
88 ->set('CType', $this->mapMenuTypes($record['menu_type']));
89 $databaseQueries[] = $queryBuilder->getSQL();
90 $queryBuilder->execute();
91 }
92 $this->markWizardAsDone();
93 return true;
94 }
95
96 /**
97 * Map the old to the new values
98 *
99 * @param string $menuType The content of the FlexForm
100 * @return string The equivalent CType
101 */
102 protected function mapMenuTypes($menuType)
103 {
104 $mapping = [
105 0 => 'menu_pages',
106 1 => 'menu_subpages',
107 2 => 'menu_sitemap',
108 3 => 'menu_section',
109 4 => 'menu_abstract',
110 5 => 'menu_recently_updated',
111 6 => 'menu_related_pages',
112 7 => 'menu_section_pages',
113 8 => 'menu_sitemap_pages',
114 'categorized_pages' => 'menu_categorized_pages',
115 'categorized_content' => 'menu_categorized_content'
116 ];
117 if (array_key_exists($menuType, $mapping)) {
118 return $mapping[$menuType];
119 }
120 return 'menu_' . $menuType;
121 }
122 }