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 {
'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();
......
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