TYPO3 CMS  TYPO3_8-7
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 
24 {
28  protected $title = '[Optional] Migrate upload content element rendering from layout to uploads_type';
29 
36  public function checkForUpdate(&$description)
37  {
38  if ($this->isWizardDone()) {
39  return false;
40  }
41  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_content');
42  $queryBuilder->getRestrictions()->removeAll();
43  $elementCount = $queryBuilder->count('uid')
44  ->from('tt_content')
45  ->where(
46  $queryBuilder->expr()->eq('CType', $queryBuilder->createNamedParameter('uploads', \PDO::PARAM_STR)),
47  $queryBuilder->expr()->in('layout', [1, 2])
48  )
49  ->execute()->fetchColumn(0);
50  if ($elementCount) {
51  $description = 'Rendering type field has been streamlined with fluid_styled_content.';
52  }
53  return (bool)$elementCount;
54  }
55 
63  public function performUpdate(array &$databaseQueries, &$customMessage)
64  {
65  $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('tt_content');
66  $queryBuilder = $connection->createQueryBuilder();
67  $queryBuilder->getRestrictions()->removeAll();
68  $statement = $queryBuilder->select('uid', 'layout')
69  ->from('tt_content')
70  ->where(
71  $queryBuilder->expr()->eq('CType', $queryBuilder->createNamedParameter('uploads', \PDO::PARAM_STR)),
72  $queryBuilder->expr()->in('layout', [1, 2])
73  )
74  ->execute();
75  while ($record = $statement->fetch()) {
76  $queryBuilder = $connection->createQueryBuilder();
77  $queryBuilder->update('tt_content')
78  ->where(
79  $queryBuilder->expr()->eq(
80  'uid',
81  $queryBuilder->createNamedParameter($record['uid'], \PDO::PARAM_INT)
82  )
83  )
84  ->set('layout', 0, false)
85  ->set('uploads_type', $record['layout']);
86  $databaseQueries[] = $queryBuilder->getSQL();
87  $queryBuilder->execute();
88  }
89  $this->markWizardAsDone();
90  return true;
91  }
92 }
static makeInstance($className,... $constructorArguments)
performUpdate(array &$databaseQueries, &$customMessage)