Skip to content
Snippets Groups Projects
Commit 36cb9b04 authored by tobiasadolph's avatar tobiasadolph Committed by Benni Mack
Browse files

[TASK] Doctrine: Migrate LanguageIsoCodeUpdate

Resolves: #77461
Releases: master
Change-Id: Icb53997368d031e027f014a5ce7866963211f613
Reviewed-on: https://review.typo3.org/49438


Reviewed-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: default avatarBamboo TYPO3com <info@typo3.com>
Reviewed-by: default avatarBenni Mack <benni@typo3.org>
Tested-by: default avatarBenni Mack <benni@typo3.org>
parent 5e500b8e
Branches
Tags
No related merge requests found
...@@ -13,7 +13,9 @@ namespace TYPO3\CMS\Install\Updates; ...@@ -13,7 +13,9 @@ namespace TYPO3\CMS\Install\Updates;
* *
* The TYPO3 project - inspiring people to share! * The TYPO3 project - inspiring people to share!
*/ */
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/** /**
* Update sys_language records to use the newly created * Update sys_language records to use the newly created
...@@ -39,15 +41,21 @@ class LanguageIsoCodeUpdate extends AbstractUpdate ...@@ -39,15 +41,21 @@ class LanguageIsoCodeUpdate extends AbstractUpdate
return false; return false;
} }
$emptyValue = $this->getDatabaseConnection()->fullQuoteStr('', 'sys_language'); $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_language');
$migratableLanguageRecords = $this->getDatabaseConnection()->exec_SELECTcountRows('uid', 'sys_language', 'language_isocode=' . $emptyValue . ' AND CAST(static_lang_isocode AS CHAR) != ' . $emptyValue); $numberOfAffectedRows = $queryBuilder->count('uid')
if ($migratableLanguageRecords === 0) { ->from('sys_language')
return false; ->where(
$queryBuilder->expr()->eq('language_isocode', $queryBuilder->createNamedParameter('')),
$queryBuilder->expr()->isNotNull('static_lang_isocode')
)
->execute()
->fetchColumn(0);
if ((bool)$numberOfAffectedRows) {
$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.';
} }
return (bool)$numberOfAffectedRows;
$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.';
return true;
} }
/** /**
...@@ -61,24 +69,37 @@ class LanguageIsoCodeUpdate extends AbstractUpdate ...@@ -61,24 +69,37 @@ class LanguageIsoCodeUpdate extends AbstractUpdate
*/ */
public function performUpdate(array &$databaseQueries, &$customMessages) public function performUpdate(array &$databaseQueries, &$customMessages)
{ {
$emptyValue = $this->getDatabaseConnection()->fullQuoteStr('', 'sys_language'); $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_language');
$migrateableLanguageRecords = $this->getDatabaseConnection()->exec_SELECTgetRows('uid,static_lang_isocode', 'sys_language', 'language_isocode=' . $emptyValue . ' AND CAST(static_lang_isocode AS CHAR) != ' . $emptyValue); $statement = $queryBuilder->select('uid', 'language_isocode', 'static_lang_isocode')
if (!empty($migrateableLanguageRecords)) { ->from('sys_language')
foreach ($migrateableLanguageRecords as $languageRecord) { ->where(
$staticLanguageRecord = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('*', 'static_languages', 'uid=' . (int)$languageRecord['static_lang_isocode']); $queryBuilder->expr()->eq('language_isocode', $queryBuilder->createNamedParameter('')),
if (!empty($staticLanguageRecord['lg_iso_2'])) { $queryBuilder->expr()->isNotNull('static_lang_isocode')
$this->getDatabaseConnection()->exec_UPDATEquery( )
'sys_language', ->execute();
'uid=' . (int)$languageRecord['uid'], while ($languageRecord = $statement->fetch()) {
array( $staticLanguageRecord = GeneralUtility::makeInstance(ConnectionPool::class)
'language_isocode' => strtolower($staticLanguageRecord['lg_iso_2']) ->getConnectionForTable('static_languages')
) ->select(
['lg_iso_2'],
'static_languages',
['uid' => (int)$languageRecord['static_lang_isocode']]
)
->fetch();
if (!empty($staticLanguageRecord['lg_iso_2'])) {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('sys_language');
$queryBuilder->update('sys_language')
->where($queryBuilder->expr()->eq('uid', (int)$languageRecord['uid']))
->set(
'language_isocode',
$queryBuilder->quote(strtolower($staticLanguageRecord['lg_iso_2'])),
false
); );
$databaseQueries[] = $this->getDatabaseConnection()->debug_lastBuiltQuery; $databaseQueries[] = $queryBuilder->getSQL();
} $queryBuilder->execute();
} }
} }
$this->markWizardAsDone(); $this->markWizardAsDone();
return true; return true;
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment