|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2016 Morris Jobke <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* @author Joas Schilling <[email protected]> |
|
6
|
|
|
* @author Morris Jobke <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* @license GNU AGPL version 3 or any later version |
|
9
|
|
|
* |
|
10
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
11
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
12
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
13
|
|
|
* License, or (at your option) any later version. |
|
14
|
|
|
* |
|
15
|
|
|
* This program is distributed in the hope that it will be useful, |
|
16
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
18
|
|
|
* GNU Affero General Public License for more details. |
|
19
|
|
|
* |
|
20
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
21
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
22
|
|
|
* |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
namespace OC\Repair\Owncloud; |
|
26
|
|
|
|
|
27
|
|
|
use OCP\DB\QueryBuilder\IQueryBuilder; |
|
28
|
|
|
use OCP\IConfig; |
|
29
|
|
|
use OCP\IDBConnection; |
|
30
|
|
|
use OCP\Migration\IOutput; |
|
31
|
|
|
use OCP\Migration\IRepairStep; |
|
32
|
|
|
|
|
33
|
|
|
class UpdateLanguageCodes implements IRepairStep { |
|
34
|
|
|
/** @var IDBConnection */ |
|
35
|
|
|
private $connection; |
|
36
|
|
|
|
|
37
|
|
|
/** @var IConfig */ |
|
38
|
|
|
private $config; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param IDBConnection $connection |
|
42
|
|
|
* @param IConfig $config |
|
43
|
|
|
*/ |
|
44
|
|
|
public function __construct(IDBConnection $connection, |
|
45
|
|
|
IConfig $config) { |
|
46
|
|
|
$this->connection = $connection; |
|
47
|
|
|
$this->config = $config; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* {@inheritdoc} |
|
52
|
|
|
*/ |
|
53
|
|
|
public function getName() { |
|
54
|
|
|
return 'Repair language codes'; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* {@inheritdoc} |
|
59
|
|
|
*/ |
|
60
|
|
|
public function run(IOutput $output) { |
|
61
|
|
|
$versionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0'); |
|
62
|
|
|
|
|
63
|
|
|
if (version_compare($versionFromBeforeUpdate, '12.0.0.13', '>')) { |
|
64
|
|
|
return; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
$languages = [ |
|
68
|
|
|
'bg_BG' => 'bg', |
|
69
|
|
|
'cs_CZ' => 'cs', |
|
70
|
|
|
'fi_FI' => 'fi', |
|
71
|
|
|
'hu_HU' => 'hu', |
|
72
|
|
|
'nb_NO' => 'nb', |
|
73
|
|
|
'sk_SK' => 'sk', |
|
74
|
|
|
'th_TH' => 'th', |
|
75
|
|
|
]; |
|
76
|
|
|
|
|
77
|
|
|
foreach ($languages as $oldCode => $newCode) { |
|
78
|
|
|
$qb = $this->connection->getQueryBuilder(); |
|
79
|
|
|
|
|
80
|
|
|
$affectedRows = $qb->update('preferences') |
|
81
|
|
|
->set('configvalue', $qb->createNamedParameter($newCode)) |
|
82
|
|
|
->where($qb->expr()->eq('appid', $qb->createNamedParameter('core'))) |
|
83
|
|
|
->andWhere($qb->expr()->eq('configkey', $qb->createNamedParameter('lang'))) |
|
84
|
|
|
->andWhere($qb->expr()->eq('configvalue', $qb->createNamedParameter($oldCode), IQueryBuilder::PARAM_STR)) |
|
85
|
|
|
->execute(); |
|
86
|
|
|
|
|
87
|
|
|
$output->info('Changed ' . $affectedRows . ' setting(s) from "' . $oldCode . '" to "' . $newCode . '" in preferences table.'); |
|
|
|
|
|
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|