55 * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
66 * SPDX-License-Identifier: AGPL-3.0-only
77 */
8+
89namespace OC \Core \Command \Encryption ;
910
1011use OCP \App \IAppManager ;
11- use OCP \Encryption \ IManager ;
12+ use OCP \IAppConfig ;
1213use OCP \IConfig ;
1314use Symfony \Component \Console \Command \Command ;
1415use Symfony \Component \Console \Helper \QuestionHelper ;
@@ -22,9 +23,9 @@ class DecryptAll extends Command {
2223 protected bool $ wasMaintenanceModeEnabled = false ;
2324
2425 public function __construct (
25- protected IManager $ encryptionManager ,
2626 protected IAppManager $ appManager ,
2727 protected IConfig $ config ,
28+ protected IAppConfig $ appConfig ,
2829 protected \OC \Encryption \DecryptAll $ decryptAll ,
2930 protected QuestionHelper $ questionHelper ,
3031 ) {
@@ -88,14 +89,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8889 return 1 ;
8990 }
9091
92+ $ originallyEnabled = $ this ->appConfig ->getValueBool ('core ' , 'encryption_enabled ' );
9193 try {
92- if ($ this -> encryptionManager -> isEnabled () === true ) {
94+ if ($ originallyEnabled ) {
9395 $ output ->write ('Disable server side encryption... ' );
94- $ this ->config -> setAppValue ('core ' , 'encryption_enabled ' , ' no ' );
96+ $ this ->appConfig -> setValueBool ('core ' , 'encryption_enabled ' , false );
9597 $ output ->writeln ('done. ' );
9698 } else {
9799 $ output ->writeln ('Server side encryption not enabled. Nothing to do. ' );
98- return 0 ;
99100 }
100101
101102 $ uid = $ input ->getArgument ('user ' );
@@ -118,23 +119,29 @@ protected function execute(InputInterface $input, OutputInterface $output): int
118119 $ result = $ this ->decryptAll ->decryptAll ($ input , $ output , $ user );
119120 if ($ result === false ) {
120121 $ output ->writeln (' aborted. ' );
122+ if ($ originallyEnabled ) {
123+ $ output ->writeln ('Server side encryption remains enabled ' );
124+ $ this ->appConfig ->setValueBool ('core ' , 'encryption_enabled ' , true );
125+ }
126+ } elseif (($ uid !== '' ) && $ originallyEnabled ) {
121127 $ output ->writeln ('Server side encryption remains enabled ' );
122- $ this ->config ->setAppValue ('core ' , 'encryption_enabled ' , 'yes ' );
123- } elseif ($ uid !== '' ) {
124- $ output ->writeln ('Server side encryption remains enabled ' );
125- $ this ->config ->setAppValue ('core ' , 'encryption_enabled ' , 'yes ' );
128+ $ this ->appConfig ->setValueBool ('core ' , 'encryption_enabled ' , true );
126129 }
127130 $ this ->resetMaintenanceAndTrashbin ();
128131 return 0 ;
129132 }
130- $ output ->write ('Enable server side encryption... ' );
131- $ this ->config ->setAppValue ('core ' , 'encryption_enabled ' , 'yes ' );
132- $ output ->writeln ('done. ' );
133+ if ($ originallyEnabled ) {
134+ $ output ->write ('Enable server side encryption... ' );
135+ $ this ->appConfig ->setValueBool ('core ' , 'encryption_enabled ' , true );
136+ $ output ->writeln ('done. ' );
137+ }
133138 $ output ->writeln ('aborted ' );
134139 return 1 ;
135140 } catch (\Exception $ e ) {
136141 // enable server side encryption again if something went wrong
137- $ this ->config ->setAppValue ('core ' , 'encryption_enabled ' , 'yes ' );
142+ if ($ originallyEnabled ) {
143+ $ this ->appConfig ->setValueBool ('core ' , 'encryption_enabled ' , true );
144+ }
138145 $ this ->resetMaintenanceAndTrashbin ();
139146 throw $ e ;
140147 }
0 commit comments