protected function execute(InputInterface $input, OutputInterface $output) { try { if ($this->encryptionManager->isEnabled() === true) { $output->write('Disable server side encryption... '); $this->config->setAppValue('core', 'encryption_enabled', 'no'); $output->writeln('done.'); } else { $output->writeln('Server side encryption not enabled. Nothing to do.'); return; } $uid = $input->getArgument('user'); if ($uid === '') { $message = 'your ownCloud'; } else { $message = "{$uid}'s account"; } $output->writeln("\n"); $output->writeln("You are about to start to decrypt all files stored in {$message}."); $output->writeln('It will depend on the encryption module and your setup if this is possible.'); $output->writeln('Depending on the number and size of your files this can take some time'); $output->writeln('Please make sure that no user access his files during this process!'); $output->writeln(''); $question = new ConfirmationQuestion('Do you really want to continue? (y/n) ', false); if ($this->questionHelper->ask($input, $output, $question)) { $this->forceSingleUserAndTrashbin(); $user = $input->getArgument('user'); $result = $this->decryptAll->decryptAll($input, $output, $user); if ($result === false) { $output->writeln(' aborted.'); $output->writeln('Server side encryption remains enabled'); $this->config->setAppValue('core', 'encryption_enabled', 'yes'); } else { if ($uid !== '') { $output->writeln('Server side encryption remains enabled'); $this->config->setAppValue('core', 'encryption_enabled', 'yes'); } } $this->resetSingleUserAndTrashbin(); } else { $output->write('Enable server side encryption... '); $this->config->setAppValue('core', 'encryption_enabled', 'yes'); $output->writeln('done.'); $output->writeln('aborted'); } } catch (\Exception $e) { // enable server side encryption again if something went wrong $this->config->setAppValue('core', 'encryption_enabled', 'yes'); $this->resetSingleUserAndTrashbin(); throw $e; } }
/** * test decrypt all call with a user who doesn't exists */ public function testDecryptAllWrongUser() { $this->userManager->expects($this->once())->method('userExists')->willReturn(false); $this->outputInterface->expects($this->once())->method('writeln')->with('User "user1" does not exist. Please check the username and try again'); $this->assertFalse($this->instance->decryptAll($this->inputInterface, $this->outputInterface, 'user1')); }