SetMasterKeyStatus.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 Bjoern Schiessle <bjoern@schiessle.org>
  4. *
  5. * @author Bjoern Schiessle <bjoern@schiessle.org>
  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 OCA\Encryption\Migration;
  24. use OCP\IConfig;
  25. use OCP\Migration\IOutput;
  26. use OCP\Migration\IRepairStep;
  27. /**
  28. * Class SetPasswordColumn
  29. *
  30. * @package OCA\Files_Sharing\Migration
  31. */
  32. class SetMasterKeyStatus implements IRepairStep {
  33. /** @var IConfig */
  34. private $config;
  35. public function __construct(IConfig $config) {
  36. $this->config = $config;
  37. }
  38. /**
  39. * Returns the step's name
  40. *
  41. * @return string
  42. * @since 9.1.0
  43. */
  44. public function getName() {
  45. return 'Write default encryption module configuration to the database';
  46. }
  47. /**
  48. * @param IOutput $output
  49. */
  50. public function run(IOutput $output) {
  51. if (!$this->shouldRun()) {
  52. return;
  53. }
  54. // if no config for the master key is set we set it explicitly to '0' in
  55. // order not to break old installations because the default changed to '1'.
  56. $configAlreadySet = $this->config->getAppValue('encryption', 'useMasterKey', false);
  57. if ($configAlreadySet === false) {
  58. $this->config->setAppValue('encryption', 'useMasterKey', '0');
  59. }
  60. }
  61. protected function shouldRun() {
  62. $appVersion = $this->config->getAppValue('encryption', 'installed_version', '0.0.0');
  63. return version_compare($appVersion, '2.0.0', '<');
  64. }
  65. }