1
0

SetMasterKeyStatus.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\Encryption\Migration;
  7. use OCP\IConfig;
  8. use OCP\Migration\IOutput;
  9. use OCP\Migration\IRepairStep;
  10. /**
  11. * Class SetPasswordColumn
  12. *
  13. * @package OCA\Files_Sharing\Migration
  14. */
  15. class SetMasterKeyStatus implements IRepairStep {
  16. public function __construct(
  17. private IConfig $config,
  18. ) {
  19. }
  20. /**
  21. * Returns the step's name
  22. *
  23. * @return string
  24. * @since 9.1.0
  25. */
  26. public function getName() {
  27. return 'Write default encryption module configuration to the database';
  28. }
  29. /**
  30. * @param IOutput $output
  31. */
  32. public function run(IOutput $output) {
  33. if (!$this->shouldRun()) {
  34. return;
  35. }
  36. // if no config for the master key is set we set it explicitly to '0' in
  37. // order not to break old installations because the default changed to '1'.
  38. $configAlreadySet = $this->config->getAppValue('encryption', 'useMasterKey', 'not-set');
  39. if ($configAlreadySet === 'not-set') {
  40. $this->config->setAppValue('encryption', 'useMasterKey', '0');
  41. }
  42. }
  43. protected function shouldRun() {
  44. $appVersion = $this->config->getAppValue('encryption', 'installed_version', '0.0.0');
  45. return version_compare($appVersion, '2.0.0', '<');
  46. }
  47. }