‪TYPO3CMS  9.5
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 
25 {
29  public function ‪getIdentifier(): string
30  {
31  return 'sectionFrameToFrameClassUpdate';
32  }
33 
37  public function ‪getTitle(): string
38  {
39  return 'Migrate the field "section_frame" for all content elements to "frame_class"';
40  }
41 
45  public function ‪getDescription(): string
46  {
47  return 'Section frames were used to control the wrapping of each content element in the frontend '
48  . 'output, stored as integers in the database. To get rid of a nessesary mapping of those values we '
49  . 'are now storing strings you can easily adjust that will simply passed to 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 section_frame field still exists
62  if (!isset($tableColumns['section_frame'])) {
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()->gt('section_frame', 0)
71  )
72  ->execute()
73  ->fetchColumn(0);
74  return (bool)$elementCount;
75  }
76 
80  public function ‪getPrerequisites(): array
81  {
82  return [
83  DatabaseUpdatedPrerequisite::class
84  ];
85  }
86 
92  public function ‪executeUpdate(): bool
93  {
94  $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('tt_content');
95  $queryBuilder = $connection->createQueryBuilder();
96  $queryBuilder->getRestrictions()->removeAll();
97  $statement = $queryBuilder->select('uid', 'section_frame')
98  ->from('tt_content')
99  ->where(
100  $queryBuilder->expr()->gt('section_frame', 0)
101  )
102  ->execute();
103  while ($record = $statement->fetch()) {
104  $queryBuilder = $connection->createQueryBuilder();
105  $queryBuilder->update('tt_content')
106  ->where(
107  $queryBuilder->expr()->eq(
108  'uid',
109  $queryBuilder->createNamedParameter($record['uid'], \PDO::PARAM_INT)
110  )
111  )
112  ->set('section_frame', 0, false)
113  ->set('frame_class', $this->‪mapSectionFrame($record['section_frame']));
114  $queryBuilder->execute();
115  }
116  return true;
117  }
118 
125  protected function ‪mapSectionFrame($sectionFrame)
126  {
127  $mapping = [
128  0 => 'default',
129  5 => 'ruler-before',
130  6 => 'ruler-after',
131  10 => 'indent',
132  11 => 'indent-left',
133  12 => 'indent-right',
134  66 => 'none'
135  ];
136  if (array_key_exists($sectionFrame, $mapping)) {
137  return $mapping[$sectionFrame];
138  }
139  return 'custom-' . (int)$sectionFrame;
140  }
141 }
‪TYPO3\CMS\Install\Updates\SectionFrameToFrameClassUpdate
Definition: SectionFrameToFrameClassUpdate.php:25
‪TYPO3\CMS\Install\Updates\SectionFrameToFrameClassUpdate\getDescription
‪string getDescription()
Definition: SectionFrameToFrameClassUpdate.php:45
‪TYPO3\CMS\Install\Updates
Definition: AbstractDownloadExtensionUpdate.php:3
‪TYPO3\CMS\Install\Updates\SectionFrameToFrameClassUpdate\getTitle
‪string getTitle()
Definition: SectionFrameToFrameClassUpdate.php:37
‪TYPO3\CMS\Install\Updates\SectionFrameToFrameClassUpdate\mapSectionFrame
‪string mapSectionFrame($sectionFrame)
Definition: SectionFrameToFrameClassUpdate.php:125
‪TYPO3\CMS\Install\Updates\UpgradeWizardInterface
Definition: UpgradeWizardInterface.php:22
‪TYPO3\CMS\Install\Updates\SectionFrameToFrameClassUpdate\updateNecessary
‪bool updateNecessary()
Definition: SectionFrameToFrameClassUpdate.php:57
‪TYPO3\CMS\Install\Updates\SectionFrameToFrameClassUpdate\getPrerequisites
‪string[] getPrerequisites()
Definition: SectionFrameToFrameClassUpdate.php:80
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Install\Updates\SectionFrameToFrameClassUpdate\executeUpdate
‪bool executeUpdate()
Definition: SectionFrameToFrameClassUpdate.php:92
‪TYPO3\CMS\Install\Updates\SectionFrameToFrameClassUpdate\getIdentifier
‪string getIdentifier()
Definition: SectionFrameToFrameClassUpdate.php:29