‪TYPO3CMS  9.5
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 
27 {
31  public function ‪getIdentifier(): string
32  {
33  return 'sysLanguageSorting';
34  }
35 
39  public function ‪getTitle(): string
40  {
41  return 'Update sorting of sys_language records';
42  }
43 
47  public function ‪getDescription(): string
48  {
49  return 'The sys_language records have unsorted rows. '
50  . ' This upgrade wizard adds values depending on the language title';
51  }
52 
58  public function ‪updateNecessary(): bool
59  {
60  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
61  ->getQueryBuilderForTable('sys_language');
62  return (bool)$queryBuilder->count('uid')
63  ->from('sys_language')
64  ->where(
65  $queryBuilder->expr()->eq('sorting', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)),
66  $queryBuilder->expr()->isNotNull('sorting')
67  )
68  ->execute()
69  ->fetchColumn(0);
70  }
71 
75  public function ‪getPrerequisites(): array
76  {
77  return [
78  DatabaseUpdatedPrerequisite::class
79  ];
80  }
81 
87  public function ‪executeUpdate(): bool
88  {
89  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
90  ->getQueryBuilderForTable('sys_language');
91  $statement = $queryBuilder->select('uid')
92  ->from('sys_language')
93  ->where(
94  $queryBuilder->expr()->eq('sorting', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT))
95  )
96  ->orderBy('title')
97  ->execute();
98  $sortCounter = 10;
99  while ($languageRecord = $statement->fetch()) {
100  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
101  ->getQueryBuilderForTable('sys_language');
102  $queryBuilder->update('sys_language')
103  ->where(
104  $queryBuilder->expr()->eq(
105  'uid',
106  $queryBuilder->createNamedParameter($languageRecord['uid'], \PDO::PARAM_INT)
107  )
108  )
109  ->set('sorting', $sortCounter)
110  ->execute();
111  $sortCounter += 5;
112  }
113  return true;
114  }
115 }
‪TYPO3\CMS\Install\Updates\LanguageSortingUpdate\getTitle
‪string getTitle()
Definition: LanguageSortingUpdate.php:39
‪TYPO3\CMS\Install\Updates\LanguageSortingUpdate
Definition: LanguageSortingUpdate.php:27
‪TYPO3\CMS\Install\Updates
Definition: AbstractDownloadExtensionUpdate.php:3
‪TYPO3\CMS\Install\Updates\LanguageSortingUpdate\getPrerequisites
‪string[] getPrerequisites()
Definition: LanguageSortingUpdate.php:75
‪TYPO3\CMS\Install\Updates\LanguageSortingUpdate\getDescription
‪string getDescription()
Definition: LanguageSortingUpdate.php:47
‪TYPO3\CMS\Install\Updates\LanguageSortingUpdate\executeUpdate
‪bool executeUpdate()
Definition: LanguageSortingUpdate.php:87
‪TYPO3\CMS\Install\Updates\UpgradeWizardInterface
Definition: UpgradeWizardInterface.php:22
‪TYPO3\CMS\Install\Updates\LanguageSortingUpdate\updateNecessary
‪bool updateNecessary()
Definition: LanguageSortingUpdate.php:58
‪TYPO3\CMS\Install\Updates\LanguageSortingUpdate\getIdentifier
‪string getIdentifier()
Definition: LanguageSortingUpdate.php:31
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45