‪TYPO3CMS  9.5
SplitMenusUpdate.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 
25 {
29  public function ‪getIdentifier(): string
30  {
31  return 'splitMenusUpdate';
32  }
33 
37  public function ‪getTitle(): string
38  {
39  return 'Split menu types into dedicated content elements';
40  }
41 
45  public function ‪getDescription(): string
46  {
47  return 'Menus have been split into dedicated content elements to provide '
48  . 'a better maintainability and more easy to adjustable template with single '
49  . 'responsibility for the rendering.';
50  }
51 
57  public function ‪updateNecessary(): bool
58  {
59  $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('tt_content');
60  $tableColumns = $connection->getSchemaManager()->listTableColumns('tt_content');
61  // Only proceed if menu_type field still exists
62  if (!isset($tableColumns['menu_type'])) {
63  return false;
64  }
65  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_content');
66  $queryBuilder->getRestrictions()->removeAll();
67  $elementCount = $queryBuilder->count('uid')
68  ->from('tt_content')
69  ->where(
70  $queryBuilder->expr()->eq('CType', $queryBuilder->createNamedParameter('menu', \PDO::PARAM_STR))
71  )
72  ->execute()->fetchColumn(0);
73  return (bool)$elementCount;
74  }
75 
79  public function ‪getPrerequisites(): array
80  {
81  return [
82  DatabaseUpdatedPrerequisite::class
83  ];
84  }
85 
91  public function ‪executeUpdate(): bool
92  {
93  $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('tt_content');
94  $queryBuilder = $connection->createQueryBuilder();
95  $queryBuilder->getRestrictions()->removeAll();
96  $statement = $queryBuilder->select('uid', 'header', 'menu_type')
97  ->from('tt_content')
98  ->where(
99  $queryBuilder->expr()->eq(
100  'CType',
101  $queryBuilder->createNamedParameter('menu', \PDO::PARAM_STR)
102  )
103  )
104  ->execute();
105  while ($record = $statement->fetch()) {
106  $queryBuilder = $connection->createQueryBuilder();
107  $queryBuilder->update('tt_content')
108  ->where(
109  $queryBuilder->expr()->eq(
110  'uid',
111  $queryBuilder->createNamedParameter($record['uid'], \PDO::PARAM_INT)
112  )
113  )
114  ->set('CType', $this->‪mapMenuTypes($record['menu_type']));
115  $queryBuilder->execute();
116  }
117  return true;
118  }
119 
126  protected function ‪mapMenuTypes($menuType)
127  {
128  $mapping = [
129  0 => 'menu_pages',
130  1 => 'menu_subpages',
131  2 => 'menu_sitemap',
132  3 => 'menu_section',
133  4 => 'menu_abstract',
134  5 => 'menu_recently_updated',
135  6 => 'menu_related_pages',
136  7 => 'menu_section_pages',
137  8 => 'menu_sitemap_pages',
138  'categorized_pages' => 'menu_categorized_pages',
139  'categorized_content' => 'menu_categorized_content'
140  ];
141  if (array_key_exists($menuType, $mapping)) {
142  return $mapping[$menuType];
143  }
144  return 'menu_' . $menuType;
145  }
146 }
‪TYPO3\CMS\Install\Updates\SplitMenusUpdate\getDescription
‪string getDescription()
Definition: SplitMenusUpdate.php:45
‪TYPO3\CMS\Install\Updates\SplitMenusUpdate\getPrerequisites
‪string[] getPrerequisites()
Definition: SplitMenusUpdate.php:79
‪TYPO3\CMS\Install\Updates\SplitMenusUpdate\getTitle
‪string getTitle()
Definition: SplitMenusUpdate.php:37
‪TYPO3\CMS\Install\Updates
Definition: AbstractDownloadExtensionUpdate.php:3
‪TYPO3\CMS\Install\Updates\SplitMenusUpdate
Definition: SplitMenusUpdate.php:25
‪TYPO3\CMS\Install\Updates\SplitMenusUpdate\executeUpdate
‪bool executeUpdate()
Definition: SplitMenusUpdate.php:91
‪TYPO3\CMS\Install\Updates\UpgradeWizardInterface
Definition: UpgradeWizardInterface.php:22
‪TYPO3\CMS\Install\Updates\SplitMenusUpdate\getIdentifier
‪string getIdentifier()
Definition: SplitMenusUpdate.php:29
‪TYPO3\CMS\Install\Updates\SplitMenusUpdate\mapMenuTypes
‪string mapMenuTypes($menuType)
Definition: SplitMenusUpdate.php:126
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Install\Updates\SplitMenusUpdate\updateNecessary
‪bool updateNecessary()
Definition: SplitMenusUpdate.php:57