TYPO3 CMS  TYPO3_8-7
LanguageIsoCodeUpdate.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 
20 
27 {
31  protected $title = 'Update sys_language records to use new ISO 639-1 letter-code field';
32 
39  public function checkForUpdate(&$description)
40  {
41  if ($this->isWizardDone() || !ExtensionManagementUtility::isLoaded('static_info_tables')) {
42  return false;
43  }
44 
45  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_language');
46  $numberOfAffectedRows = $queryBuilder->count('uid')
47  ->from('sys_language')
48  ->where(
49  $queryBuilder->expr()->eq('language_isocode', $queryBuilder->createNamedParameter('', \PDO::PARAM_STR)),
50  $queryBuilder->expr()->isNotNull('static_lang_isocode')
51  )
52  ->execute()
53  ->fetchColumn(0);
54  if ((bool)$numberOfAffectedRows) {
55  $description = 'The sys_language records have a new iso code field which removes the dependency of the'
56  . ' TYPO3 CMS Core to the extension "static_info_tables". This upgrade wizard migrates the data of the'
57  . ' existing "static_lang_isocode" field to the new DB field.';
58  }
59  return (bool)$numberOfAffectedRows;
60  }
61 
71  public function performUpdate(array &$databaseQueries, &$customMessage)
72  {
73  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_language');
74  $statement = $queryBuilder->select('uid', 'language_isocode', 'static_lang_isocode')
75  ->from('sys_language')
76  ->where(
77  $queryBuilder->expr()->eq('language_isocode', $queryBuilder->createNamedParameter('', \PDO::PARAM_STR)),
78  $queryBuilder->expr()->isNotNull('static_lang_isocode')
79  )
80  ->execute();
81  while ($languageRecord = $statement->fetch()) {
82  $staticLanguageRecord = GeneralUtility::makeInstance(ConnectionPool::class)
83  ->getConnectionForTable('static_languages')
84  ->select(
85  ['lg_iso_2'],
86  'static_languages',
87  ['uid' => (int)$languageRecord['static_lang_isocode']]
88  )
89  ->fetch();
90  if (!empty($staticLanguageRecord['lg_iso_2'])) {
91  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
92  ->getQueryBuilderForTable('sys_language');
93  $queryBuilder->update('sys_language')
94  ->where(
95  $queryBuilder->expr()->eq(
96  'uid',
97  $queryBuilder->createNamedParameter($languageRecord['uid'], \PDO::PARAM_INT)
98  )
99  )
100  ->set('language_isocode', strtolower($staticLanguageRecord['lg_iso_2']));
101  $databaseQueries[] = $queryBuilder->getSQL();
102  $queryBuilder->execute();
103  }
104  }
105  $this->markWizardAsDone();
106  return true;
107  }
108 }
static makeInstance($className,... $constructorArguments)
performUpdate(array &$databaseQueries, &$customMessage)