TYPO3 CMS  TYPO3_7-6
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  */
17 
24 {
28  protected $title = 'Update sys_language records to use new ISO 639-1 letter-code field';
29 
36  public function checkForUpdate(&$description)
37  {
38  if ($this->isWizardDone() || !ExtensionManagementUtility::isLoaded('static_info_tables')) {
39  return false;
40  }
41 
42  $emptyValue = $this->getDatabaseConnection()->fullQuoteStr('', 'sys_language');
43  $migratableLanguageRecords = $this->getDatabaseConnection()->exec_SELECTcountRows('uid', 'sys_language', 'language_isocode=' . $emptyValue . ' AND CAST(static_lang_isocode AS CHAR) != ' . $emptyValue);
44  if ($migratableLanguageRecords === 0) {
45  return false;
46  }
47 
48  $description = 'The sys_language records have a new iso code field which removes the dependency of the TYPO3 CMS Core to the extension "static_info_tables". This upgrade wizard migrates the data of the existing "static_lang_isocode" field to the new DB field.';
49 
50  return true;
51  }
52 
62  public function performUpdate(array &$databaseQueries, &$customMessages)
63  {
64  $emptyValue = $this->getDatabaseConnection()->fullQuoteStr('', 'sys_language');
65  $migrateableLanguageRecords = $this->getDatabaseConnection()->exec_SELECTgetRows('uid,static_lang_isocode', 'sys_language', 'language_isocode=' . $emptyValue . ' AND CAST(static_lang_isocode AS CHAR) != ' . $emptyValue);
66  if (!empty($migrateableLanguageRecords)) {
67  foreach ($migrateableLanguageRecords as $languageRecord) {
68  $staticLanguageRecord = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('*', 'static_languages', 'uid=' . (int)$languageRecord['static_lang_isocode']);
69  if (!empty($staticLanguageRecord['lg_iso_2'])) {
70  $this->getDatabaseConnection()->exec_UPDATEquery(
71  'sys_language',
72  'uid=' . (int)$languageRecord['uid'],
73  [
74  'language_isocode' => strtolower($staticLanguageRecord['lg_iso_2'])
75  ]
76  );
77  $databaseQueries[] = $this->getDatabaseConnection()->debug_lastBuiltQuery;
78  }
79  }
80  }
81 
82  $this->markWizardAsDone();
83  return true;
84  }
85 }
performUpdate(array &$databaseQueries, &$customMessages)