SetMasterKeyStatus.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. /** @var IConfig */
  17. private $config;
  18. public function __construct(IConfig $config) {
  19. $this->config = $config;
  20. }
  21. /**
  22. * Returns the step's name
  23. *
  24. * @return string
  25. * @since 9.1.0
  26. */
  27. public function getName() {
  28. return 'Write default encryption module configuration to the database';
  29. }
  30. /**
  31. * @param IOutput $output
  32. */
  33. public function run(IOutput $output) {
  34. if (!$this->shouldRun()) {
  35. return;
  36. }
  37. // if no config for the master key is set we set it explicitly to '0' in
  38. // order not to break old installations because the default changed to '1'.
  39. $configAlreadySet = $this->config->getAppValue('encryption', 'useMasterKey', 'not-set');
  40. if ($configAlreadySet === 'not-set') {
  41. $this->config->setAppValue('encryption', 'useMasterKey', '0');
  42. }
  43. }
  44. protected function shouldRun() {
  45. $appVersion = $this->config->getAppValue('encryption', 'installed_version', '0.0.0');
  46. return version_compare($appVersion, '2.0.0', '<');
  47. }
  48. }