From 25806346c2fb33fb4a82906683ffafd950289b53 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thomas=20M=C3=BCller?= <thomas.mueller@tmit.eu>
Date: Wed, 14 Jan 2015 13:56:49 +0100
Subject: [PATCH] remove deprecated code - fixes #13119

---
 apps/files_sharing/application.php            | 35 +++++++++---------
 .../lib/middleware/sharingcheckmiddleware.php | 30 ++++++++--------
 .../middleware/sharingcheckmiddleware.php     | 36 +++++++++----------
 3 files changed, 51 insertions(+), 50 deletions(-)

diff --git a/apps/files_sharing/application.php b/apps/files_sharing/application.php
index 773831d99b..56ec448d6a 100644
--- a/apps/files_sharing/application.php
+++ b/apps/files_sharing/application.php
@@ -29,21 +29,22 @@ class Application extends App {
 		parent::__construct('files_sharing', $urlParams);
 
 		$container = $this->getContainer();
+		$server = $container->getServer();
 
 		/**
 		 * Controllers
 		 */
-		$container->registerService('ShareController', function(SimpleContainer $c) {
+		$container->registerService('ShareController', function(SimpleContainer $c) use ($server) {
 			return new ShareController(
 				$c->query('AppName'),
 				$c->query('Request'),
 				$c->query('UserSession'),
-				$c->query('ServerContainer')->getAppConfig(),
-				$c->query('ServerContainer')->getConfig(),
+				$server->getAppConfig(),
+				$server->getConfig(),
 				$c->query('URLGenerator'),
-				$c->query('ServerContainer')->getUserManager(),
-				$c->query('ServerContainer')->getLogger(),
-				$c->query('ServerContainer')->getActivityManager()
+				$server->getUserManager(),
+				$server->getLogger(),
+				$server->getActivityManager()
 			);
 		});
 		$container->registerService('ExternalSharesController', function(SimpleContainer $c) {
@@ -58,33 +59,33 @@ class Application extends App {
 		/**
 		 * Core class wrappers
 		 */
-		$container->registerService('UserSession', function(SimpleContainer $c) {
-			return $c->query('ServerContainer')->getUserSession();
+		$container->registerService('UserSession', function(SimpleContainer $c) use ($server) {
+			return $server->getUserSession();
 		});
-		$container->registerService('URLGenerator', function(SimpleContainer $c) {
-			return $c->query('ServerContainer')->getUrlGenerator();
+		$container->registerService('URLGenerator', function(SimpleContainer $c) use ($server){
+			return $server->getUrlGenerator();
 		});
 		$container->registerService('IsIncomingShareEnabled', function(SimpleContainer $c) {
 			return Helper::isIncomingServer2serverShareEnabled();
 		});
-		$container->registerService('ExternalManager', function(SimpleContainer $c) {
+		$container->registerService('ExternalManager', function(SimpleContainer $c) use ($server){
 			return new \OCA\Files_Sharing\External\Manager(
-					\OC::$server->getDatabaseConnection(),
+					$server->getDatabaseConnection(),
 					\OC\Files\Filesystem::getMountManager(),
 					\OC\Files\Filesystem::getLoader(),
-					\OC::$server->getUserSession(),
-					\OC::$server->getHTTPHelper()
+					$server->getUserSession(),
+					$server->getHTTPHelper()
 			);
 		});
 
 		/**
 		 * Middleware
 		 */
-		$container->registerService('SharingCheckMiddleware', function(SimpleContainer $c){
+		$container->registerService('SharingCheckMiddleware', function(SimpleContainer $c) use ($server){
 			return new SharingCheckMiddleware(
 				$c->query('AppName'),
-				$c->query('ServerContainer')->getAppConfig(),
-				$c->getCoreApi()
+				$server->getConfig(),
+				$server->getAppManager()
 			);
 		});
 
diff --git a/apps/files_sharing/lib/middleware/sharingcheckmiddleware.php b/apps/files_sharing/lib/middleware/sharingcheckmiddleware.php
index af79cd9e94..3508407f2a 100644
--- a/apps/files_sharing/lib/middleware/sharingcheckmiddleware.php
+++ b/apps/files_sharing/lib/middleware/sharingcheckmiddleware.php
@@ -10,10 +10,10 @@
 
 namespace OCA\Files_Sharing\Middleware;
 
-use OCP\AppFramework\IApi;
-use \OCP\AppFramework\Middleware;
+use OCP\App\IAppManager;
+use OCP\AppFramework\Middleware;
 use OCP\AppFramework\Http\TemplateResponse;
-use OCP\IAppConfig;
+use OCP\IConfig;
 
 /**
  * Checks whether the "sharing check" is enabled
@@ -24,22 +24,22 @@ class SharingCheckMiddleware extends Middleware {
 
 	/** @var string */
 	protected $appName;
-	/** @var IAppConfig */
-	protected $appConfig;
-	/** @var IApi */
-	protected $api;
+	/** @var IConfig */
+	protected $config;
+	/** @var IAppManager */
+	protected $appManager;
 
 	/***
 	 * @param string $appName
-	 * @param IAppConfig $appConfig
-	 * @param IApi $api
+	 * @param IConfig $config
+	 * @param IAppManager $appManager
 	 */
 	public function __construct($appName,
-								IAppConfig $appConfig,
-								IApi $api) {
+								IConfig $config,
+								IAppManager $appManager) {
 		$this->appName = $appName;
-		$this->appConfig = $appConfig;
-		$this->api = $api;
+		$this->config = $config;
+		$this->appManager = $appManager;
 	}
 
 	/**
@@ -69,12 +69,12 @@ class SharingCheckMiddleware extends Middleware {
 	private function isSharingEnabled() {
 		// FIXME: This check is done here since the route is globally defined and not inside the files_sharing app
 		// Check whether the sharing application is enabled
-		if(!$this->api->isAppEnabled($this->appName)) {
+		if(!$this->appManager->isEnabledForUser($this->appName)) {
 			return false;
 		}
 
 		// Check whether public sharing is enabled
-		if($this->appConfig->getValue('core', 'shareapi_allow_links', 'yes') !== 'yes') {
+		if($this->config->getAppValue('core', 'shareapi_allow_links', 'yes') !== 'yes') {
 			return false;
 		}
 
diff --git a/apps/files_sharing/tests/middleware/sharingcheckmiddleware.php b/apps/files_sharing/tests/middleware/sharingcheckmiddleware.php
index 90c9a7bba1..466904889a 100644
--- a/apps/files_sharing/tests/middleware/sharingcheckmiddleware.php
+++ b/apps/files_sharing/tests/middleware/sharingcheckmiddleware.php
@@ -14,34 +14,34 @@ namespace OCA\Files_Sharing\Middleware;
 /**
  * @package OCA\Files_Sharing\Middleware\SharingCheckMiddleware
  */
-class SharingCheckMiddlewareTest extends \PHPUnit_Framework_TestCase {
+class SharingCheckMiddlewareTest extends \Test\TestCase {
 
-	/** @var \OCP\IAppConfig */
-	private $appConfig;
-	/** @var \OCP\AppFramework\IApi */
-	private $api;
+	/** @var \OCP\IConfig */
+	private $config;
+	/** @var \OCP\App\IAppManager */
+	private $appManager;
 	/** @var SharingCheckMiddleware */
 	private $sharingCheckMiddleware;
 
 	protected function setUp() {
-		$this->appConfig = $this->getMockBuilder('\OCP\IAppConfig')
+		$this->config = $this->getMockBuilder('\OCP\IConfig')
 			->disableOriginalConstructor()->getMock();
-		$this->api = $this->getMockBuilder('\OCP\AppFramework\IApi')
+		$this->appManager = $this->getMockBuilder('\OCP\App\IAppManager')
 			->disableOriginalConstructor()->getMock();
 
-		$this->sharingCheckMiddleware = new SharingCheckMiddleware('files_sharing', $this->appConfig, $this->api);
+		$this->sharingCheckMiddleware = new SharingCheckMiddleware('files_sharing', $this->config, $this->appManager);
 	}
 
 	public function testIsSharingEnabledWithEverythingEnabled() {
-		$this->api
+		$this->appManager
 			->expects($this->once())
-			->method('isAppEnabled')
+			->method('isEnabledForUser')
 			->with('files_sharing')
 			->will($this->returnValue(true));
 
-		$this->appConfig
+		$this->config
 			->expects($this->once())
-			->method('getValue')
+			->method('getAppValue')
 			->with('core', 'shareapi_allow_links', 'yes')
 			->will($this->returnValue('yes'));
 
@@ -49,9 +49,9 @@ class SharingCheckMiddlewareTest extends \PHPUnit_Framework_TestCase {
 	}
 
 	public function testIsSharingEnabledWithAppDisabled() {
-		$this->api
+		$this->appManager
 			->expects($this->once())
-			->method('isAppEnabled')
+			->method('isEnabledForUser')
 			->with('files_sharing')
 			->will($this->returnValue(false));
 
@@ -59,15 +59,15 @@ class SharingCheckMiddlewareTest extends \PHPUnit_Framework_TestCase {
 	}
 
 	public function testIsSharingEnabledWithSharingDisabled() {
-		$this->api
+		$this->appManager
 			->expects($this->once())
-			->method('isAppEnabled')
+			->method('isEnabledForUser')
 			->with('files_sharing')
 			->will($this->returnValue(true));
 
-		$this->appConfig
+		$this->config
 			->expects($this->once())
-			->method('getValue')
+			->method('getAppValue')
 			->with('core', 'shareapi_allow_links', 'yes')
 			->will($this->returnValue('no'));
 
-- 
GitLab