TYPO3 CMS  TYPO3_8-7
SectionFrameToFrameClassUpdate.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 = 'Migrate the field "section_frame" for all content elements to "frame_class"';
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 section_frame field still exists
44  if (!isset($tableColumns['section_frame'])) {
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()->gt('section_frame', 0)
53  )
54  ->execute()->fetchColumn(0);
55  if ($elementCount) {
56  $description = 'Section frames were used to control the wrapping of each content element in the frontend '
57  . 'output, stored as integers in the database. To get rid of a nessesary mapping of those values we '
58  . 'are now storing strings you an easily adjust that will simply passed to 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', 'section_frame')
76  ->from('tt_content')
77  ->where(
78  $queryBuilder->expr()->gt('section_frame', 0)
79  )
80  ->execute();
81  while ($record = $statement->fetch()) {
82  $queryBuilder = $connection->createQueryBuilder();
83  $queryBuilder->update('tt_content')
84  ->where(
85  $queryBuilder->expr()->eq(
86  'uid',
87  $queryBuilder->createNamedParameter($record['uid'], \PDO::PARAM_INT)
88  )
89  )
90  ->set('section_frame', 0, false)
91  ->set('frame_class', $this->mapSectionFrame($record['section_frame']));
92  $databaseQueries[] = $queryBuilder->getSQL();
93  $queryBuilder->execute();
94  }
95  $this->markWizardAsDone();
96  return true;
97  }
98 
105  protected function mapSectionFrame($sectionFrame)
106  {
107  $mapping = [
108  0 => 'default',
109  5 => 'ruler-before',
110  6 => 'ruler-after',
111  10 => 'indent',
112  11 => 'indent-left',
113  12 => 'indent-right',
114  66 => 'none'
115  ];
116  if (array_key_exists($sectionFrame, $mapping)) {
117  return $mapping[$sectionFrame];
118  }
119  return 'custom-' . (int)$sectionFrame;
120  }
121 }
static makeInstance($className,... $constructorArguments)