Skip to content

Commit f3679b4

Browse files
committed
fix(encryption): Assume boolValue for commands
Signed-off-by: Stephen Cuppett <steve@cuppett.com>
1 parent 60a66e9 commit f3679b4

3 files changed

Lines changed: 10 additions & 46 deletions

File tree

core/Command/Encryption/DecryptAll.php

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
namespace OC\Core\Command\Encryption;
1010

1111
use OCP\App\IAppManager;
12-
use OCP\Exceptions\AppConfigTypeConflictException;
1312
use OCP\IAppConfig;
1413
use OCP\IConfig;
1514
use Symfony\Component\Console\Command\Command;
@@ -92,16 +91,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9291
return 1;
9392
}
9493

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-
}
94+
$originallyEnabled = $this->appConfig->getValueBool('core', 'encryption_enabled', false);
10195
try {
10296
if ($originallyEnabled) {
10397
$output->write('Disable server side encryption... ');
104-
$this->writeEncryptionEnabled(false);
98+
$this->appConfig->setValueBool('core', 'encryption_enabled', false);
10599
$output->writeln('done.');
106100
} else {
107101
$output->writeln('Server side encryption not enabled. Nothing to do.');
@@ -129,37 +123,29 @@ protected function execute(InputInterface $input, OutputInterface $output): int
129123
$output->writeln(' aborted.');
130124
if ($originallyEnabled) {
131125
$output->writeln('Server side encryption remains enabled');
132-
$this->writeEncryptionEnabled(true);
126+
$this->appConfig->setValueBool('core', 'encryption_enabled', true);
133127
}
134128
} elseif (($uid !== '') && $originallyEnabled) {
135129
$output->writeln('Server side encryption remains enabled');
136-
$this->writeEncryptionEnabled(true);
130+
$this->appConfig->setValueBool('core', 'encryption_enabled', true);
137131
}
138132
$this->resetMaintenanceAndTrashbin();
139133
return 0;
140134
}
141135
if ($originallyEnabled) {
142136
$output->write('Enable server side encryption... ');
143-
$this->writeEncryptionEnabled(true);
137+
$this->appConfig->setValueBool('core', 'encryption_enabled', true);
144138
$output->writeln('done.');
145139
}
146140
$output->writeln('aborted');
147141
return 1;
148142
} catch (\Exception $e) {
149143
// enable server side encryption again if something went wrong
150144
if ($originallyEnabled) {
151-
$this->writeEncryptionEnabled(true);
145+
$this->appConfig->setValueBool('core', 'encryption_enabled', true);
152146
}
153147
$this->resetMaintenanceAndTrashbin();
154148
throw $e;
155149
}
156150
}
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-
}
165151
}

core/Command/Encryption/Disable.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
*/
1010
namespace OC\Core\Command\Encryption;
1111

12-
use OCP\Exceptions\AppConfigTypeConflictException;
1312
use OCP\IAppConfig;
1413
use Symfony\Component\Console\Command\Command;
1514
use Symfony\Component\Console\Input\InputInterface;
@@ -32,21 +31,11 @@ protected function configure() {
3231

3332
#[\Override]
3433
protected function execute(InputInterface $input, OutputInterface $output): int {
35-
try {
36-
$isEnabled = $this->appConfig->getValueBool('core', 'encryption_enabled', false);
37-
} catch (AppConfigTypeConflictException) {
38-
$raw = $this->appConfig->getValueString('core', 'encryption_enabled', 'no');
39-
$isEnabled = in_array(strtolower(trim($raw)), ['1', 'true', 'yes', 'on'], true);
40-
}
41-
34+
$isEnabled = $this->appConfig->getValueBool('core', 'encryption_enabled', false);
4235
if (!$isEnabled) {
4336
$output->writeln('Encryption is already disabled');
4437
} else {
45-
try {
46-
$this->appConfig->setValueBool('core', 'encryption_enabled', false);
47-
} catch (AppConfigTypeConflictException) {
48-
$this->appConfig->setValueString('core', 'encryption_enabled', 'no');
49-
}
38+
$this->appConfig->setValueBool('core', 'encryption_enabled', false);
5039
$output->writeln('<info>Encryption disabled</info>');
5140
}
5241
return 0;

core/Command/Encryption/Enable.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
namespace OC\Core\Command\Encryption;
1111

1212
use OCP\Encryption\IManager;
13-
use OCP\Exceptions\AppConfigTypeConflictException;
1413
use OCP\IAppConfig;
1514
use Symfony\Component\Console\Command\Command;
1615
use Symfony\Component\Console\Input\InputInterface;
@@ -34,21 +33,11 @@ protected function configure() {
3433

3534
#[\Override]
3635
protected function execute(InputInterface $input, OutputInterface $output): int {
37-
try {
38-
$isEnabled = $this->appConfig->getValueBool('core', 'encryption_enabled', false);
39-
} catch (AppConfigTypeConflictException) {
40-
$raw = $this->appConfig->getValueString('core', 'encryption_enabled', 'no');
41-
$isEnabled = in_array(strtolower(trim($raw)), ['1', 'true', 'yes', 'on'], true);
42-
}
43-
36+
$isEnabled = $this->appConfig->getValueBool('core', 'encryption_enabled', false);
4437
if ($isEnabled) {
4538
$output->writeln('Encryption is already enabled');
4639
} else {
47-
try {
48-
$this->appConfig->setValueBool('core', 'encryption_enabled', true);
49-
} catch (AppConfigTypeConflictException) {
50-
$this->appConfig->setValueString('core', 'encryption_enabled', 'yes');
51-
}
40+
$this->appConfig->setValueBool('core', 'encryption_enabled', true);
5241
$output->writeln('<info>Encryption enabled</info>');
5342
}
5443
$output->writeln('');

0 commit comments

Comments
 (0)