You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UpdateOutdatedOcsIds.php 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Lukas Reschke <lukas@statuscode.ch>
  6. * @author Thomas Müller <thomas.mueller@tmit.eu>
  7. *
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  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, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OC\Repair;
  24. use OCP\IConfig;
  25. use OCP\Migration\IOutput;
  26. use OCP\Migration\IRepairStep;
  27. /**
  28. * Class UpdateOutdatedOcsIds is used to update invalid outdated OCS IDs, this is
  29. * for example the case when an application has had another OCS ID in the past such
  30. * as for contacts and calendar when apps.owncloud.com migrated to a unified identifier
  31. * for multiple versions.
  32. *
  33. * @package OC\Repair
  34. */
  35. class UpdateOutdatedOcsIds implements IRepairStep {
  36. /** @var IConfig */
  37. private $config;
  38. /**
  39. * @param IConfig $config
  40. */
  41. public function __construct(IConfig $config) {
  42. $this->config = $config;
  43. }
  44. /**
  45. * {@inheritdoc}
  46. */
  47. public function getName() {
  48. return 'Repair outdated OCS IDs';
  49. }
  50. /**
  51. * @param string $appName
  52. * @param string $oldId
  53. * @param string $newId
  54. * @return bool True if updated, false otherwise
  55. */
  56. public function fixOcsId($appName, $oldId, $newId) {
  57. $existingId = $this->config->getAppValue($appName, 'ocsid');
  58. if($existingId === $oldId) {
  59. $this->config->setAppValue($appName, 'ocsid', $newId);
  60. return true;
  61. }
  62. return false;
  63. }
  64. /**
  65. * {@inheritdoc}
  66. */
  67. public function run(IOutput $output) {
  68. $appsToUpdate = [
  69. 'contacts' => [
  70. 'old' => '166044',
  71. 'new' => '168708',
  72. ],
  73. 'calendar' => [
  74. 'old' => '166043',
  75. 'new' => '168707',
  76. ],
  77. 'bookmarks' => [
  78. 'old' => '166042',
  79. 'new' => '168710',
  80. ],
  81. 'search_lucene' => [
  82. 'old' => '166057',
  83. 'new' => '168709',
  84. ],
  85. 'documents' => [
  86. 'old' => '166045',
  87. 'new' => '168711',
  88. ]
  89. ];
  90. foreach($appsToUpdate as $appName => $ids) {
  91. if ($this->fixOcsId($appName, $ids['old'], $ids['new'])) {
  92. $output->info("Fixed invalid $appName OCS id");
  93. }
  94. }
  95. }
  96. }