|
9 | 9 | namespace OC\Core\Command\Encryption; |
10 | 10 |
|
11 | 11 | use OCP\App\IAppManager; |
| 12 | +use OCP\Exceptions\AppConfigTypeConflictException; |
12 | 13 | use OCP\IAppConfig; |
13 | 14 | use OCP\IConfig; |
14 | 15 | use Symfony\Component\Console\Command\Command; |
@@ -91,11 +92,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int |
91 | 92 | return 1; |
92 | 93 | } |
93 | 94 |
|
94 | | - $originallyEnabled = $this->appConfig->getValueBool('core', 'encryption_enabled'); |
| 95 | + try { |
| 96 | + $originallyEnabled = $this->appConfig->getValueBool('core', 'encryption_enabled', false); |
| 97 | + } catch (AppConfigTypeConflictException) { |
| 98 | + $raw = $this->appConfig->getValueString('core', 'encryption_enabled', 'no'); |
| 99 | + $originallyEnabled = in_array(strtolower(trim($raw)), ['1', 'true', 'yes', 'on'], true); |
| 100 | + } |
95 | 101 | try { |
96 | 102 | if ($originallyEnabled) { |
97 | 103 | $output->write('Disable server side encryption... '); |
98 | | - $this->appConfig->setValueBool('core', 'encryption_enabled', false); |
| 104 | + $this->writeEncryptionEnabled(false); |
99 | 105 | $output->writeln('done.'); |
100 | 106 | } else { |
101 | 107 | $output->writeln('Server side encryption not enabled. Nothing to do.'); |
@@ -123,29 +129,37 @@ protected function execute(InputInterface $input, OutputInterface $output): int |
123 | 129 | $output->writeln(' aborted.'); |
124 | 130 | if ($originallyEnabled) { |
125 | 131 | $output->writeln('Server side encryption remains enabled'); |
126 | | - $this->appConfig->setValueBool('core', 'encryption_enabled', true); |
| 132 | + $this->writeEncryptionEnabled(true); |
127 | 133 | } |
128 | 134 | } elseif (($uid !== '') && $originallyEnabled) { |
129 | 135 | $output->writeln('Server side encryption remains enabled'); |
130 | | - $this->appConfig->setValueBool('core', 'encryption_enabled', true); |
| 136 | + $this->writeEncryptionEnabled(true); |
131 | 137 | } |
132 | 138 | $this->resetMaintenanceAndTrashbin(); |
133 | 139 | return 0; |
134 | 140 | } |
135 | 141 | if ($originallyEnabled) { |
136 | 142 | $output->write('Enable server side encryption... '); |
137 | | - $this->appConfig->setValueBool('core', 'encryption_enabled', true); |
| 143 | + $this->writeEncryptionEnabled(true); |
138 | 144 | $output->writeln('done.'); |
139 | 145 | } |
140 | 146 | $output->writeln('aborted'); |
141 | 147 | return 1; |
142 | 148 | } catch (\Exception $e) { |
143 | 149 | // enable server side encryption again if something went wrong |
144 | 150 | if ($originallyEnabled) { |
145 | | - $this->appConfig->setValueBool('core', 'encryption_enabled', true); |
| 151 | + $this->writeEncryptionEnabled(true); |
146 | 152 | } |
147 | 153 | $this->resetMaintenanceAndTrashbin(); |
148 | 154 | throw $e; |
149 | 155 | } |
150 | 156 | } |
| 157 | + |
| 158 | + private function writeEncryptionEnabled(bool $enabled): void { |
| 159 | + try { |
| 160 | + $this->appConfig->setValueBool('core', 'encryption_enabled', $enabled); |
| 161 | + } catch (AppConfigTypeConflictException) { |
| 162 | + $this->appConfig->setValueString('core', 'encryption_enabled', $enabled ? 'yes' : 'no'); |
| 163 | + } |
| 164 | + } |
151 | 165 | } |
0 commit comments