diff --git a/core/command/encryption/decryptall.php b/core/command/encryption/decryptall.php
index 696570b7ae6ef2ab4b1682c1a8540386c13abb4f..c71ba5f04c72c60e6448773568d88b8b9fc23d98 100644
--- a/core/command/encryption/decryptall.php
+++ b/core/command/encryption/decryptall.php
@@ -75,14 +75,22 @@ class DecryptAll extends Command {
 		$this->config = $config;
 		$this->decryptAll = $decryptAll;
 		$this->questionHelper = $questionHelper;
+	}
 
+	/**
+	 * Set single user mode and disable the trashbin app
+	 */
+	protected function forceSingleUserAndTrashbin() {
 		$this->wasTrashbinEnabled = $this->appManager->isEnabledForUser('files_trashbin');
 		$this->wasSingleUserModeEnabled = $this->config->getSystemValue('singleuser', false);
 		$this->config->setSystemValue('singleuser', true);
 		$this->appManager->disableApp('files_trashbin');
 	}
 
-	public function __destruct() {
+	/**
+	 * Reset the single user mode and re-enable the trashbin app
+	 */
+	protected function resetSingleUserAndTrashbin() {
 		$this->config->setSystemValue('singleuser', $this->wasSingleUserModeEnabled);
 		if ($this->wasTrashbinEnabled) {
 			$this->appManager->enableApp('files_trashbin');
@@ -115,7 +123,6 @@ class DecryptAll extends Command {
 			} else {
 				$output->writeln('Server side encryption not enabled. Nothing to do.');
 				return;
-
 			}
 
 			$output->writeln("\n");
@@ -126,12 +133,14 @@ class DecryptAll extends Command {
 			$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) {
-					$this->output->writeln(' aborted.');
+					$output->writeln(' aborted.');
 					$this->config->setAppValue('core', 'encryption_enabled', 'yes');
 				}
+				$this->resetSingleUserAndTrashbin();
 			} else {
 				$output->write('Enable server side encryption... ');
 				$this->config->setAppValue('core', 'encryption_enabled', 'yes');
@@ -141,8 +150,9 @@ class DecryptAll extends Command {
 		} catch (\Exception $e) {
 			// enable server side encryption again if something went wrong
 			$this->config->setAppValue('core', 'encryption_enabled', 'yes');
+			$this->resetSingleUserAndTrashbin();
 			throw $e;
 		}
-	}
 
+	}
 }
diff --git a/core/command/encryption/encryptall.php b/core/command/encryption/encryptall.php
index 950ce5166d8dd402690ec8a1030dff9ffd1a29be..4ae6ae4783606e916c3112541c55078922284dd8 100644
--- a/core/command/encryption/encryptall.php
+++ b/core/command/encryption/encryptall.php
@@ -67,13 +67,22 @@ class EncryptAll extends Command {
 		$this->encryptionManager = $encryptionManager;
 		$this->config = $config;
 		$this->questionHelper = $questionHelper;
+	}
+
+	/**
+	 * Set single user mode and disable the trashbin app
+	 */
+	protected function forceSingleUserAndTrashbin() {
 		$this->wasTrashbinEnabled = $this->appManager->isEnabledForUser('files_trashbin');
 		$this->wasSingleUserModeEnabled = $this->config->getSystemValue('singleuser', false);
 		$this->config->setSystemValue('singleuser', true);
 		$this->appManager->disableApp('files_trashbin');
 	}
 
-	public function __destruct() {
+	/**
+	 * Reset the single user mode and re-enable the trashbin app
+	 */
+	protected function resetSingleUserAndTrashbin() {
 		$this->config->setSystemValue('singleuser', $this->wasSingleUserModeEnabled);
 		if ($this->wasTrashbinEnabled) {
 			$this->appManager->enableApp('files_trashbin');
@@ -104,8 +113,17 @@ class EncryptAll extends Command {
 		$output->writeln('');
 		$question = new ConfirmationQuestion('Do you really want to continue? (y/n) ', false);
 		if ($this->questionHelper->ask($input, $output, $question)) {
-			$defaultModule = $this->encryptionManager->getEncryptionModule();
-			$defaultModule->encryptAll($input, $output);
+			$this->forceSingleUserAndTrashbin();
+
+			try {
+				$defaultModule = $this->encryptionManager->getEncryptionModule();
+				$defaultModule->encryptAll($input, $output);
+			} catch (\Exception $ex) {
+				$this->resetSingleUserAndTrashbin();
+				throw $ex;
+			}
+
+			$this->resetSingleUserAndTrashbin();
 		} else {
 			$output->writeln('aborted');
 		}
diff --git a/tests/core/command/encryption/decryptalltest.php b/tests/core/command/encryption/decryptalltest.php
index ef36d6d28274fbda5578c8d7fd7f54f863f4f6fa..972ea03150cd2ffd33e9557babf63841d71a9ba6 100644
--- a/tests/core/command/encryption/decryptalltest.php
+++ b/tests/core/command/encryption/decryptalltest.php
@@ -79,7 +79,8 @@ class DecryptAllTest extends TestCase {
 
 	}
 
-	public function testConstructDesctruct() {
+	public function testSingleUserAndTrashbin() {
+
 		// on construct we enable single-user-mode and disable the trash bin
 		$this->config->expects($this->at(1))
 			->method('setSystemValue')
@@ -103,6 +104,7 @@ class DecryptAllTest extends TestCase {
 			$this->decryptAll,
 			$this->questionHelper
 		);
+		$this->invokePrivate($instance, 'forceSingleUserAndTrashbin');
 
 		$this->assertTrue(
 			$this->invokePrivate($instance, 'wasTrashbinEnabled')
@@ -111,6 +113,7 @@ class DecryptAllTest extends TestCase {
 		$this->assertFalse(
 			$this->invokePrivate($instance, 'wasSingleUserModeEnabled')
 		);
+		$this->invokePrivate($instance, 'resetSingleUserAndTrashbin');
 	}
 
 	/**
@@ -187,7 +190,7 @@ class DecryptAllTest extends TestCase {
 			->with('core', 'encryption_enabled', 'no');
 
 		// make sure that we enable encryption again after a exception was thrown
-		$this->config->expects($this->at(1))
+		$this->config->expects($this->at(3))
 			->method('setAppValue')
 			->with('core', 'encryption_enabled', 'yes');
 
diff --git a/tests/core/command/encryption/encryptalltest.php b/tests/core/command/encryption/encryptalltest.php
index 9f7f737504436bd5c90293c4b399b25e8917a6ff..128b4caa148bfcf5ed9e3491be7ebad10c29d0ab 100644
--- a/tests/core/command/encryption/encryptalltest.php
+++ b/tests/core/command/encryption/encryptalltest.php
@@ -85,7 +85,9 @@ class EncryptAllTest extends TestCase {
 		$this->config->expects($this->at(1))->method('setSystemValue')->with('singleuser', true);
 		$this->config->expects($this->at(2))->method('setSystemValue')->with('singleuser', false);
 
-		new EncryptAll($this->encryptionManager, $this->appManager, $this->config, $this->questionHelper);
+		$instance = new EncryptAll($this->encryptionManager, $this->appManager, $this->config, $this->questionHelper);
+		$this->invokePrivate($instance, 'forceSingleUserAndTrashbin');
+		$this->invokePrivate($instance, 'resetSingleUserAndTrashbin');
 	}
 
 	/**