diff --git a/Classes/Updates/UpdateLanguages.php b/Classes/Updates/UpdateLanguages.php index 9051f01f9b62a63e99cde7177510fbce8f0331a0..7bdfdfe50c9f1ec57ebf94308c67c2abb7dd7ba2 100644 --- a/Classes/Updates/UpdateLanguages.php +++ b/Classes/Updates/UpdateLanguages.php @@ -51,6 +51,19 @@ class UpdateLanguages extends AbstractUpdate { 'tx_sgmail_domain_model_mail', 'tx_sgmail_domain_model_template' ]; + /** + * is used to map language codes. If empty the updatewizard will ignore this update + * example: you want to change en-us to en + * [ + * 'en-us' => 'en' + * ] + * + * @var array + */ + protected $languageMap = [ + + ]; + /** * Checks whether updates are required. * @@ -61,25 +74,27 @@ class UpdateLanguages extends AbstractUpdate { public function checkForUpdate(&$description) { $upgradeNecessary = FALSE; - $languages = BackendService::getLanguages(); - $where = 'language NOT IN ('; - foreach ($languages as $language) { - $where .= '"' . $language['isocode'] . '",'; - } - $where = rtrim($where, ','); - $where .= ')'; + if (count($this->languageMap) > 0) { + $languages = BackendService::getLanguages(); + $where = 'language NOT IN ('; + foreach ($languages as $language) { + $where .= '"' . $language['isocode'] . '",'; + } + $where = rtrim($where, ','); + $where .= ')'; - $description = 'Check all the language codes in the database'; + $description = 'Check all the language codes in the database'; - /** @var DatabaseConnection $databaseConnection */ - $databaseConnection = $this->getDatabaseConnection(); + /** @var DatabaseConnection $databaseConnection */ + $databaseConnection = $this->getDatabaseConnection(); - foreach ($this->tables as $table) { - /** @var \mysqli_result $result */ - $result = $databaseConnection->exec_SELECTquery('distinct language', $table, $where); - if ($result->num_rows > 0) { - $upgradeNecessary = TRUE; - break; + foreach ($this->tables as $table) { + /** @var \mysqli_result $result */ + $result = $databaseConnection->exec_SELECTquery('distinct language', $table, $where); + if ($result->num_rows > 0) { + $upgradeNecessary = TRUE; + break; + } } } @@ -94,11 +109,19 @@ class UpdateLanguages extends AbstractUpdate { * @return bool Whether everything went smoothly or not */ public function performUpdate(array &$dbQueries, &$customMessages) { + $dbQueries = []; + /** @var DatabaseConnection $databaseConnection */ $databaseConnection = $this->getDatabaseConnection(); foreach ($this->tables as $table) { - + foreach ($this->languageMap as $origin => $target) { + $where = 'language = ' . $origin; + $databaseConnection->exec_UPDATEquery($table, $where, [ + 'language' => $target + ]); + $dbQueries[] = $databaseConnection->debug_lastBuiltQuery; + } } $this->markWizardAsDone();