[Pkg-owncloud-commits] [owncloud] 75/215: Make getDefaultModuleId public and get module protected

David Prévot taffit at moszumanska.debian.org
Tue May 5 01:01:25 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch stable8
in repository owncloud.

commit d600955a51a9536ac9ebfa7198ef963679153740
Author: Joas Schilling <nickvergessen at owncloud.com>
Date:   Mon Apr 20 11:11:52 2015 +0200

    Make getDefaultModuleId public and get module protected
---
 core/command/encryption/listmodules.php          | 34 +++++++++---------------
 core/command/encryption/setdefaultmodule.php     | 11 +-------
 lib/private/encryption/manager.php               | 14 ++++------
 lib/private/encryption/update.php                |  2 +-
 lib/private/files/storage/wrapper/encryption.php |  6 ++---
 lib/public/encryption/imanager.php               |  7 +++--
 settings/admin.php                               |  8 ++----
 tests/lib/encryption/managertest.php             | 10 ++++---
 8 files changed, 33 insertions(+), 59 deletions(-)

diff --git a/core/command/encryption/listmodules.php b/core/command/encryption/listmodules.php
index d3fdb2d..a3de26b 100644
--- a/core/command/encryption/listmodules.php
+++ b/core/command/encryption/listmodules.php
@@ -49,16 +49,12 @@ class ListModules extends Base {
 
 	protected function execute(InputInterface $input, OutputInterface $output) {
 		$encryptionModules = $this->encryptionManager->getEncryptionModules();
-		$defaultEncryptionModuleId = '';
-		try {
-			$defaultEncryptionModule = $this->encryptionManager->getDefaultEncryptionModule();
-			$defaultEncryptionModuleId = $defaultEncryptionModule->getId();
-		} catch (\Exception $e) {}
+		$defaultEncryptionModuleId = $this->encryptionManager->getDefaultEncryptionModuleId();
 
 		$encModules = array();
 		foreach ($encryptionModules as $module) {
-			$encModules[$module->getId()]['displayName'] = $module->getDisplayName();
-			$encModules[$module->getId()]['default'] .= $module->getId() === $defaultEncryptionModuleId;
+			$encModules[$module['id']]['displayName'] = $module['displayName'];
+			$encModules[$module['id']]['default'] .= $module['id'] === $defaultEncryptionModuleId;
 		}
 		$this->writeModuleList($input, $output, $encModules);
 	}
@@ -69,20 +65,16 @@ class ListModules extends Base {
 	 * @param array $items
 	 */
 	protected function writeModuleList(InputInterface $input, OutputInterface $output, $items) {
-		switch ($input->getOption('output')) {
-			case 'plain':
-				array_walk($items, function(&$item) {
-					if (!$item['default']) {
-						$item = $item['displayName'];
-					} else {
-						$item = $item['displayName'] . ' [default*]';
-					}
-				});
-				// no break;
-
-			default:
-				parent::writeArrayInOutputFormat($input, $output, $items);
-				break;
+		if ($input->getOption('output') === 'plain') {
+			array_walk($items, function(&$item) {
+				if (!$item['default']) {
+					$item = $item['displayName'];
+				} else {
+					$item = $item['displayName'] . ' [default*]';
+				}
+			});
 		}
+
+		parent::writeArrayInOutputFormat($input, $output, $items);
 	}
 }
diff --git a/core/command/encryption/setdefaultmodule.php b/core/command/encryption/setdefaultmodule.php
index fb82e87..f33762e 100644
--- a/core/command/encryption/setdefaultmodule.php
+++ b/core/command/encryption/setdefaultmodule.php
@@ -56,22 +56,13 @@ class SetDefaultModule extends Command {
 
 	protected function execute(InputInterface $input, OutputInterface $output) {
 		$moduleId = $input->getArgument('module');
-		$currentDefaultModuleId = '';
-		try {
-			$currentDefaultModule = $this->encryptionManager->getDefaultEncryptionModule();
-			$currentDefaultModuleId = $currentDefaultModule->getId();
-		} catch (\Exception $e) {}
 
-		if ($moduleId === $currentDefaultModuleId) {
+		if ($moduleId === $this->encryptionManager->getDefaultEncryptionModuleId()) {
 			$output->writeln('"' . $moduleId . '"" is already the default module');
 		} else if ($this->encryptionManager->setDefaultEncryptionModule($moduleId)) {
 			$output->writeln('Set default module to "' . $moduleId . '"');
 		} else {
 			$output->writeln('The specified module "' . $moduleId . '" does not exist');
 		}
-
-		if ($moduleId === $currentDefaultModuleId) {
-		}
-
 	}
 }
diff --git a/lib/private/encryption/manager.php b/lib/private/encryption/manager.php
index c10867c..1a42646 100644
--- a/lib/private/encryption/manager.php
+++ b/lib/private/encryption/manager.php
@@ -158,7 +158,7 @@ class Manager implements IManager {
 	 * @return \OCP\Encryption\IEncryptionModule
 	 * @throws Exceptions\ModuleDoesNotExistsException
 	 */
-	public function getDefaultEncryptionModule() {
+	protected function getDefaultEncryptionModule() {
 		$defaultModuleId = $this->getDefaultEncryptionModuleId();
 		if (!empty($defaultModuleId)) {
 			if (isset($this->encryptionModules[$defaultModuleId])) {
@@ -183,12 +183,12 @@ class Manager implements IManager {
 	public function setDefaultEncryptionModule($moduleId) {
 		try {
 			$this->getEncryptionModule($moduleId);
-			$this->config->setAppValue('core', 'default_encryption_module', $moduleId);
-			return true;
 		} catch (\Exception $e) {
 			return false;
 		}
 
+		$this->config->setAppValue('core', 'default_encryption_module', $moduleId);
+		return true;
 	}
 
 	/**
@@ -196,12 +196,8 @@ class Manager implements IManager {
 	 *
 	 * @return string
 	 */
-	protected function getDefaultEncryptionModuleId() {
-		try {
-			return $this->config->getAppValue('core', 'default_encryption_module');
-		} catch (\Exception $e) {
-			return '';
-		}
+	public function getDefaultEncryptionModuleId() {
+		return $this->config->getAppValue('core', 'default_encryption_module');
 	}
 
 	public static function setupStorage() {
diff --git a/lib/private/encryption/update.php b/lib/private/encryption/update.php
index f262099..a0b0af9 100644
--- a/lib/private/encryption/update.php
+++ b/lib/private/encryption/update.php
@@ -137,7 +137,7 @@ class Update {
 			$allFiles = array($path);
 		}
 
-		$encryptionModule = $this->encryptionManager->getDefaultEncryptionModule();
+		$encryptionModule = $this->encryptionManager->getEncryptionModule();
 
 		foreach ($allFiles as $file) {
 			$usersSharing = $this->file->getAccessList($file);
diff --git a/lib/private/files/storage/wrapper/encryption.php b/lib/private/files/storage/wrapper/encryption.php
index 0dc59cb..af48d34 100644
--- a/lib/private/files/storage/wrapper/encryption.php
+++ b/lib/private/files/storage/wrapper/encryption.php
@@ -311,12 +311,10 @@ class Encryption extends Wrapper {
 				|| $mode === 'wb'
 				|| $mode === 'wb+'
 			) {
-				if (!empty($encryptionModuleId)) {
+				if ($encryptionEnabled) {
+					// if $encryptionModuleId is empty, the default module will be used
 					$encryptionModule = $this->encryptionManager->getEncryptionModule($encryptionModuleId);
 					$shouldEncrypt = $encryptionModule->shouldEncrypt($fullPath);
-				} elseif ($encryptionEnabled) {
-					$encryptionModule = $this->encryptionManager->getDefaultEncryptionModule();
-					$shouldEncrypt = $encryptionModule->shouldEncrypt($fullPath);
 				}
 			} else {
 				// only get encryption module if we found one in the header
diff --git a/lib/public/encryption/imanager.php b/lib/public/encryption/imanager.php
index 3a37071..3cb30f8 100644
--- a/lib/public/encryption/imanager.php
+++ b/lib/public/encryption/imanager.php
@@ -78,13 +78,12 @@ interface IManager {
 	function getEncryptionModule($moduleId);
 
 	/**
-	 * get default encryption module
+	 * get default encryption module Id
 	 *
-	 * @return \OCP\Encryption\IEncryptionModule
-	 * @throws ModuleDoesNotExistsException
+	 * @return string
 	 * @since 8.1.0
 	 */
-	public function getDefaultEncryptionModule();
+	public function getDefaultEncryptionModuleId();
 
 	/**
 	 * set default encryption module Id
diff --git a/settings/admin.php b/settings/admin.php
index f08c3cd..b8d8c67 100644
--- a/settings/admin.php
+++ b/settings/admin.php
@@ -86,14 +86,10 @@ $backends = \OC::$server->getUserManager()->getBackends();
 $externalBackends = (count($backends) > 1) ? true : false;
 $template->assign('encryptionReady', \OC::$server->getEncryptionManager()->isReady());
 $template->assign('externalBackendsEnabled', $externalBackends);
+
 $encryptionModules = \OC::$server->getEncryptionManager()->getEncryptionModules();
+$defaultEncryptionModuleId = \OC::$server->getEncryptionManager()->getDefaultEncryptionModuleId();
 
-try {
-	$defaultEncryptionModule = \OC::$server->getEncryptionManager()->getDefaultEncryptionModule();
-	$defaultEncryptionModuleId = $defaultEncryptionModule->getId();
-} catch (Exception $e) {
-	$defaultEncryptionModuleId = null;
-}
 $encModulues = array();
 foreach ($encryptionModules as $module) {
 	$encModulues[$module['id']]['displayName'] = $module['displayName'];
diff --git a/tests/lib/encryption/managertest.php b/tests/lib/encryption/managertest.php
index a8c5136..faca647 100644
--- a/tests/lib/encryption/managertest.php
+++ b/tests/lib/encryption/managertest.php
@@ -123,8 +123,10 @@ class ManagerTest extends TestCase {
 		$en0 = $this->manager->getEncryptionModule('ID0');
 		$this->assertEquals('ID0', $en0->getId());
 
-		$en0 = $this->manager->getDefaultEncryptionModule();
+		$en0 = \Test_Helper::invokePrivate($this->manager, 'getDefaultEncryptionModule');
 		$this->assertEquals('ID0', $en0->getId());
+
+		$this->assertEquals('ID0', $this->manager->getDefaultEncryptionModuleId());
 	}
 
 	public function testSetDefaultEncryptionModule() {
@@ -143,7 +145,7 @@ class ManagerTest extends TestCase {
 
 		// Default module is the first we set
 		$defaultId = 'ID0';
-		$this->assertEquals('ID0', \Test_Helper::invokePrivate($this->manager, 'getDefaultEncryptionModuleId'));
+		$this->assertEquals('ID0', $this->manager->getDefaultEncryptionModuleId());
 
 		// Set to an existing module
 		$this->config->expects($this->once())
@@ -151,11 +153,11 @@ class ManagerTest extends TestCase {
 			->with('core', 'default_encryption_module', 'ID1');
 		$this->assertTrue($this->manager->setDefaultEncryptionModule('ID1'));
 		$defaultId = 'ID1';
-		$this->assertEquals('ID1', \Test_Helper::invokePrivate($this->manager, 'getDefaultEncryptionModuleId'));
+		$this->assertEquals('ID1', $this->manager->getDefaultEncryptionModuleId());
 
 		// Set to an unexisting module
 		$this->assertFalse($this->manager->setDefaultEncryptionModule('ID2'));
-		$this->assertEquals('ID1', \Test_Helper::invokePrivate($this->manager, 'getDefaultEncryptionModuleId'));
+		$this->assertEquals('ID1', $this->manager->getDefaultEncryptionModuleId());
 	}
 
 //	/**

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list