‪TYPO3CMS  9.5
UploadContentElementUpdate.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 'uploadContentElementUpdate';
32  }
33 
37  public function ‪getTitle(): string
38  {
39  return 'Migrate upload content element rendering from layout to uploads_type';
40  }
41 
45  public function ‪getDescription(): string
46  {
47  return 'Rendering type field has been streamlined with fluid_styled_content.';
48  }
49 
55  public function ‪updateNecessary(): bool
56  {
57  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_content');
58  $queryBuilder->getRestrictions()->removeAll();
59  $elementCount = $queryBuilder->count('uid')
60  ->from('tt_content')
61  ->where(
62  $queryBuilder->expr()->eq('CType', $queryBuilder->createNamedParameter('uploads', \PDO::PARAM_STR)),
63  $queryBuilder->expr()->in('layout', [1, 2])
64  )
65  ->execute()
66  ->fetchColumn(0);
67  return (bool)$elementCount;
68  }
69 
73  public function ‪getPrerequisites(): array
74  {
75  return [
76  DatabaseUpdatedPrerequisite::class
77  ];
78  }
79 
85  public function ‪executeUpdate(): bool
86  {
87  $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('tt_content');
88  $queryBuilder = $connection->createQueryBuilder();
89  $queryBuilder->getRestrictions()->removeAll();
90  $statement = $queryBuilder->select('uid', 'layout')
91  ->from('tt_content')
92  ->where(
93  $queryBuilder->expr()->eq('CType', $queryBuilder->createNamedParameter('uploads', \PDO::PARAM_STR)),
94  $queryBuilder->expr()->in('layout', [1, 2])
95  )
96  ->execute();
97  while ($record = $statement->fetch()) {
98  $queryBuilder = $connection->createQueryBuilder();
99  $queryBuilder->update('tt_content')
100  ->where(
101  $queryBuilder->expr()->eq(
102  'uid',
103  $queryBuilder->createNamedParameter($record['uid'], \PDO::PARAM_INT)
104  )
105  )
106  ->set('layout', 0, false)
107  ->set('uploads_type', $record['layout'])
108  ->execute();
109  }
110  return true;
111  }
112 }
‪TYPO3\CMS\Install\Updates\UploadContentElementUpdate\getPrerequisites
‪string[] getPrerequisites()
Definition: UploadContentElementUpdate.php:73
‪TYPO3\CMS\Install\Updates\UploadContentElementUpdate
Definition: UploadContentElementUpdate.php:25
‪TYPO3\CMS\Install\Updates
Definition: AbstractDownloadExtensionUpdate.php:3
‪TYPO3\CMS\Install\Updates\UploadContentElementUpdate\getTitle
‪string getTitle()
Definition: UploadContentElementUpdate.php:37
‪TYPO3\CMS\Install\Updates\UploadContentElementUpdate\updateNecessary
‪bool updateNecessary()
Definition: UploadContentElementUpdate.php:55
‪TYPO3\CMS\Install\Updates\UpgradeWizardInterface
Definition: UpgradeWizardInterface.php:22
‪TYPO3\CMS\Install\Updates\UploadContentElementUpdate\getDescription
‪string getDescription()
Definition: UploadContentElementUpdate.php:45
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Install\Updates\UploadContentElementUpdate\executeUpdate
‪bool executeUpdate()
Definition: UploadContentElementUpdate.php:85
‪TYPO3\CMS\Install\Updates\UploadContentElementUpdate\getIdentifier
‪string getIdentifier()
Definition: UploadContentElementUpdate.php:29