UpdateLanguageCodes.php 2.5 KB

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