TYPO3 CMS  TYPO3_8-7
LanguageSortingUpdate.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
20 
26 {
30  protected $title = 'Update sorting of sys_language records';
31 
39  public function checkForUpdate(&$description): bool
40  {
41  if ($this->isWizardDone()) {
42  $this->markWizardAsDone();
43 
44  return false;
45  }
46 
47  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
48  ->getQueryBuilderForTable('sys_language');
49  $hasAffectedRows = (bool)$queryBuilder->count('uid')
50  ->from('sys_language')
51  ->where(
52  $queryBuilder->expr()->eq('sorting', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)),
53  $queryBuilder->expr()->isNotNull('sorting')
54  )
55  ->execute()
56  ->fetchColumn(0);
57 
58  if ($hasAffectedRows === true) {
59  $description = 'The sys_language records have unsorted rows. '
60  . ' This upgrade wizard adds values depending on the language title';
61  }
62 
63  return $hasAffectedRows;
64  }
65 
74  public function performUpdate(array &$databaseQueries, &$customMessage): bool
75  {
76  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
77  ->getQueryBuilderForTable('sys_language');
78  $statement = $queryBuilder->select('uid')
79  ->from('sys_language')
80  ->where(
81  $queryBuilder->expr()->eq('sorting', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT))
82  )
83  ->orderBy('title')
84  ->execute();
85  $sortCounter = 128;
86  while ($languageRecord = $statement->fetch()) {
87  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
88  ->getQueryBuilderForTable('sys_language');
89  $queryBuilder->update('sys_language')
90  ->where(
91  $queryBuilder->expr()->eq(
92  'uid',
93  $queryBuilder->createNamedParameter($languageRecord['uid'], \PDO::PARAM_INT)
94  )
95  )
96  ->set('sorting', $sortCounter);
97  $databaseQueries[] = $queryBuilder->getSQL();
98  $queryBuilder->execute();
99  $sortCounter *= 2;
100  }
101  $this->markWizardAsDone();
102 
103  return true;
104  }
105 }
performUpdate(array &$databaseQueries, &$customMessage)
static makeInstance($className,... $constructorArguments)