TYPO3 CMS  TYPO3_8-7
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 
24 {
28  protected $title = 'Split menu types into dedicated content elements';
29 
36  public function checkForUpdate(&$description)
37  {
38  if ($this->isWizardDone()) {
39  return false;
40  }
41  $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('tt_content');
42  $tableColumns = $connection->getSchemaManager()->listTableColumns('tt_content');
43  // Only proceed if menu_type field still exists
44  if (!isset($tableColumns['menu_type'])) {
45  return false;
46  }
47  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_content');
48  $queryBuilder->getRestrictions()->removeAll();
49  $elementCount = $queryBuilder->count('uid')
50  ->from('tt_content')
51  ->where(
52  $queryBuilder->expr()->eq('CType', $queryBuilder->createNamedParameter('menu', \PDO::PARAM_STR))
53  )
54  ->execute()->fetchColumn(0);
55  if ($elementCount) {
56  $description = 'Menus have been splitted into dedicated content elements to provide '
57  . 'a better maintainability and more easy to adjustable template with single '
58  . 'responsibility for the rendering.';
59  }
60  return (bool)$elementCount;
61  }
62 
70  public function performUpdate(array &$databaseQueries, &$customMessage)
71  {
72  $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('tt_content');
73  $queryBuilder = $connection->createQueryBuilder();
74  $queryBuilder->getRestrictions()->removeAll();
75  $statement = $queryBuilder->select('uid', 'header', 'menu_type')
76  ->from('tt_content')
77  ->where(
78  $queryBuilder->expr()->eq(
79  'CType',
80  $queryBuilder->createNamedParameter('menu', \PDO::PARAM_STR)
81  )
82  )
83  ->execute();
84  while ($record = $statement->fetch()) {
85  $queryBuilder = $connection->createQueryBuilder();
86  $queryBuilder->update('tt_content')
87  ->where(
88  $queryBuilder->expr()->eq(
89  'uid',
90  $queryBuilder->createNamedParameter($record['uid'], \PDO::PARAM_INT)
91  )
92  )
93  ->set('CType', $this->mapMenuTypes($record['menu_type']));
94  $databaseQueries[] = $queryBuilder->getSQL();
95  $queryBuilder->execute();
96  }
97  $this->markWizardAsDone();
98  return true;
99  }
100 
107  protected function mapMenuTypes($menuType)
108  {
109  $mapping = [
110  0 => 'menu_pages',
111  1 => 'menu_subpages',
112  2 => 'menu_sitemap',
113  3 => 'menu_section',
114  4 => 'menu_abstract',
115  5 => 'menu_recently_updated',
116  6 => 'menu_related_pages',
117  7 => 'menu_section_pages',
118  8 => 'menu_sitemap_pages',
119  'categorized_pages' => 'menu_categorized_pages',
120  'categorized_content' => 'menu_categorized_content'
121  ];
122  if (array_key_exists($menuType, $mapping)) {
123  return $mapping[$menuType];
124  }
125  return 'menu_' . $menuType;
126  }
127 }
performUpdate(array &$databaseQueries, &$customMessage)
static makeInstance($className,... $constructorArguments)