Skip to content
Snippets Groups Projects
Commit 429176a5 authored by Torsten Oppermann's avatar Torsten Oppermann
Browse files

[TASK] Finish update wizard

parent 2081985b
No related branches found
No related tags found
1 merge request!3New version 4 1
...@@ -51,6 +51,19 @@ class UpdateLanguages extends AbstractUpdate { ...@@ -51,6 +51,19 @@ class UpdateLanguages extends AbstractUpdate {
'tx_sgmail_domain_model_mail', 'tx_sgmail_domain_model_template' '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. * Checks whether updates are required.
* *
...@@ -61,25 +74,27 @@ class UpdateLanguages extends AbstractUpdate { ...@@ -61,25 +74,27 @@ class UpdateLanguages extends AbstractUpdate {
public function checkForUpdate(&$description) { public function checkForUpdate(&$description) {
$upgradeNecessary = FALSE; $upgradeNecessary = FALSE;
$languages = BackendService::getLanguages(); if (count($this->languageMap) > 0) {
$where = 'language NOT IN ('; $languages = BackendService::getLanguages();
foreach ($languages as $language) { $where = 'language NOT IN (';
$where .= '"' . $language['isocode'] . '",'; foreach ($languages as $language) {
} $where .= '"' . $language['isocode'] . '",';
$where = rtrim($where, ','); }
$where .= ')'; $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 */ /** @var DatabaseConnection $databaseConnection */
$databaseConnection = $this->getDatabaseConnection(); $databaseConnection = $this->getDatabaseConnection();
foreach ($this->tables as $table) { foreach ($this->tables as $table) {
/** @var \mysqli_result $result */ /** @var \mysqli_result $result */
$result = $databaseConnection->exec_SELECTquery('distinct language', $table, $where); $result = $databaseConnection->exec_SELECTquery('distinct language', $table, $where);
if ($result->num_rows > 0) { if ($result->num_rows > 0) {
$upgradeNecessary = TRUE; $upgradeNecessary = TRUE;
break; break;
}
} }
} }
...@@ -94,11 +109,19 @@ class UpdateLanguages extends AbstractUpdate { ...@@ -94,11 +109,19 @@ class UpdateLanguages extends AbstractUpdate {
* @return bool Whether everything went smoothly or not * @return bool Whether everything went smoothly or not
*/ */
public function performUpdate(array &$dbQueries, &$customMessages) { public function performUpdate(array &$dbQueries, &$customMessages) {
$dbQueries = [];
/** @var DatabaseConnection $databaseConnection */ /** @var DatabaseConnection $databaseConnection */
$databaseConnection = $this->getDatabaseConnection(); $databaseConnection = $this->getDatabaseConnection();
foreach ($this->tables as $table) { 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(); $this->markWizardAsDone();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment