diff options
author | Morris Jobke <hey@morrisjobke.de> | 2017-10-23 23:20:50 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2017-10-24 15:52:00 +0200 |
commit | 99934134dc53baaee56740de669c7df549317a2f (patch) | |
tree | 94f970256afdb6ae4b2f383f46b0d463d324b022 /apps/encryption | |
parent | db1096bcfdf2336ccf6aefb70dd902a63ed615db (diff) | |
download | nextcloud-server-99934134dc53baaee56740de669c7df549317a2f.tar.gz nextcloud-server-99934134dc53baaee56740de669c7df549317a2f.zip |
Use DI for IAppManager to encryption migration
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Diffstat (limited to 'apps/encryption')
-rw-r--r-- | apps/encryption/lib/Migration.php | 8 | ||||
-rw-r--r-- | apps/encryption/tests/MigrationTest.php | 16 |
2 files changed, 15 insertions, 9 deletions
diff --git a/apps/encryption/lib/Migration.php b/apps/encryption/lib/Migration.php index 7f4acbb68d4..656cab6a1e1 100644 --- a/apps/encryption/lib/Migration.php +++ b/apps/encryption/lib/Migration.php @@ -26,6 +26,7 @@ namespace OCA\Encryption; use OC\Files\View; +use OCP\App\IAppManager; use OCP\IConfig; use OCP\IDBConnection; use OCP\ILogger; @@ -43,6 +44,8 @@ class Migration { private $logger; /** @var string*/ protected $installedVersion; + /** @var IAppManager */ + protected $appManager; /** * @param IConfig $config @@ -50,7 +53,7 @@ class Migration { * @param IDBConnection $connection * @param ILogger $logger */ - public function __construct(IConfig $config, View $view, IDBConnection $connection, ILogger $logger) { + public function __construct(IConfig $config, View $view, IDBConnection $connection, ILogger $logger, IAppManager $appManager) { $this->view = $view; $this->view->disableCacheUpdate(); $this->connection = $connection; @@ -58,6 +61,7 @@ class Migration { $this->config = $config; $this->logger = $logger; $this->installedVersion = $this->config->getAppValue('files_encryption', 'installed_version', '-1'); + $this->appManager = $appManager; } public function finalCleanUp() { @@ -137,7 +141,7 @@ class Migration { $path = '/files_encryption/keys'; $this->renameFileKeys($user, $path); $trashPath = '/files_trashbin/keys'; - if (\OC_App::isEnabled('files_trashbin') && $this->view->is_dir($user . '/' . $trashPath)) { + if ($this->appManager->isEnabledForUser('files_trashbin') && $this->view->is_dir($user . '/' . $trashPath)) { $this->renameFileKeys($user, $trashPath, true); $this->view->deleteAll($trashPath); } diff --git a/apps/encryption/tests/MigrationTest.php b/apps/encryption/tests/MigrationTest.php index 595d7f12067..8f168e31e4d 100644 --- a/apps/encryption/tests/MigrationTest.php +++ b/apps/encryption/tests/MigrationTest.php @@ -203,13 +203,14 @@ class MigrationTest extends \Test\TestCase { $this->createDummySystemWideKeys(); /** @var \PHPUnit_Framework_MockObject_MockObject|\OCA\Encryption\Migration $m */ - $m = $this->getMockBuilder('OCA\Encryption\Migration') + $m = $this->getMockBuilder(Migration::class) ->setConstructorArgs( [ \OC::$server->getConfig(), new \OC\Files\View(), \OC::$server->getDatabaseConnection(), - $this->logger + $this->logger, + \OC::$server->getAppManager() ] )->setMethods(['getSystemMountPoints'])->getMock(); @@ -366,7 +367,7 @@ class MigrationTest extends \Test\TestCase { public function testUpdateDB() { $this->prepareDB(); - $m = new Migration(\OC::$server->getConfig(), new \OC\Files\View(), \OC::$server->getDatabaseConnection(), $this->logger); + $m = new Migration(\OC::$server->getConfig(), new \OC\Files\View(), \OC::$server->getDatabaseConnection(), $this->logger, \OC::$server->getAppManager()); $this->invokePrivate($m, 'installedVersion', ['0.7']); $m->updateDB(); @@ -386,7 +387,7 @@ class MigrationTest extends \Test\TestCase { $config->setAppValue('encryption', 'publicShareKeyId', 'wrong_share_id'); $config->setUserValue(self::TEST_ENCRYPTION_MIGRATION_USER1, 'encryption', 'recoverKeyEnabled', '9'); - $m = new Migration(\OC::$server->getConfig(), new \OC\Files\View(), \OC::$server->getDatabaseConnection(), $this->logger); + $m = new Migration(\OC::$server->getConfig(), new \OC\Files\View(), \OC::$server->getDatabaseConnection(), $this->logger, \OC::$server->getAppManager()); $this->invokePrivate($m, 'installedVersion', ['0.7']); $m->updateDB(); @@ -455,7 +456,7 @@ class MigrationTest extends \Test\TestCase { */ public function testUpdateFileCache() { $this->prepareFileCache(); - $m = new Migration(\OC::$server->getConfig(), new \OC\Files\View(), \OC::$server->getDatabaseConnection(), $this->logger); + $m = new Migration(\OC::$server->getConfig(), new \OC\Files\View(), \OC::$server->getDatabaseConnection(), $this->logger, \OC::$server->getAppManager()); $this->invokePrivate($m, 'installedVersion', ['0.7']); self::invokePrivate($m, 'updateFileCache'); @@ -527,13 +528,14 @@ class MigrationTest extends \Test\TestCase { ->disableOriginalConstructor()->getMock(); $view->expects($this->any())->method('file_exists')->willReturn(true); - $m = $this->getMockBuilder('OCA\Encryption\Migration') + $m = $this->getMockBuilder(Migration::class) ->setConstructorArgs( [ \OC::$server->getConfig(), $view, \OC::$server->getDatabaseConnection(), - $this->logger + $this->logger, + \OC::$server->getAppManager() ] )->setMethods(['getSystemMountPoints'])->getMock(); |