1
0

UpdateLanguageCodes.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OC\Repair\Owncloud;
  7. use OCP\DB\QueryBuilder\IQueryBuilder;
  8. use OCP\IConfig;
  9. use OCP\IDBConnection;
  10. use OCP\Migration\IOutput;
  11. use OCP\Migration\IRepairStep;
  12. class UpdateLanguageCodes implements IRepairStep {
  13. /** @var IDBConnection */
  14. private $connection;
  15. /** @var IConfig */
  16. private $config;
  17. /**
  18. * @param IDBConnection $connection
  19. * @param IConfig $config
  20. */
  21. public function __construct(IDBConnection $connection,
  22. IConfig $config) {
  23. $this->connection = $connection;
  24. $this->config = $config;
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function getName() {
  30. return 'Repair language codes';
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. public function run(IOutput $output) {
  36. $versionFromBeforeUpdate = $this->config->getSystemValueString('version', '0.0.0');
  37. if (version_compare($versionFromBeforeUpdate, '12.0.0.13', '>')) {
  38. return;
  39. }
  40. $languages = [
  41. 'bg_BG' => 'bg',
  42. 'cs_CZ' => 'cs',
  43. 'fi_FI' => 'fi',
  44. 'hu_HU' => 'hu',
  45. 'nb_NO' => 'nb',
  46. 'sk_SK' => 'sk',
  47. 'th_TH' => 'th',
  48. ];
  49. foreach ($languages as $oldCode => $newCode) {
  50. $qb = $this->connection->getQueryBuilder();
  51. $affectedRows = $qb->update('preferences')
  52. ->set('configvalue', $qb->createNamedParameter($newCode))
  53. ->where($qb->expr()->eq('appid', $qb->createNamedParameter('core')))
  54. ->andWhere($qb->expr()->eq('configkey', $qb->createNamedParameter('lang')))
  55. ->andWhere($qb->expr()->eq('configvalue', $qb->createNamedParameter($oldCode), IQueryBuilder::PARAM_STR))
  56. ->execute();
  57. $output->info('Changed ' . $affectedRows . ' setting(s) from "' . $oldCode . '" to "' . $newCode . '" in preferences table.');
  58. }
  59. }
  60. }