From 12420d08e24a77e6aa484f8f219470b81e5ad20a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Fri, 27 Jun 2014 19:22:10 +0200 Subject: [PATCH 1/3] change order of registering api and capabilities to fix file version previews --- apps/files_versions/appinfo/routes.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/files_versions/appinfo/routes.php b/apps/files_versions/appinfo/routes.php index 80fe0e5d61..b9bb00dae5 100644 --- a/apps/files_versions/appinfo/routes.php +++ b/apps/files_versions/appinfo/routes.php @@ -5,11 +5,11 @@ * See the COPYING-README file. */ -// Register with the capabilities API -OC_API::register('get', '/cloud/capabilities', array('OCA\Files_Versions\Capabilities', 'getCapabilities'), 'files_versions', OC_API::USER_AUTH); - /** @var $this \OCP\Route\IRouter */ $this->create('core_ajax_versions_preview', '/preview')->action( function() { require_once __DIR__ . '/../ajax/preview.php'; }); + +// Register with the capabilities API +OC_API::register('get', '/cloud/capabilities', array('OCA\Files_Versions\Capabilities', 'getCapabilities'), 'files_versions', OC_API::USER_AUTH); From dd20b9f6726db4ddc2d5905705e01544f4f4fd08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Tue, 1 Jul 2014 14:21:20 +0200 Subject: [PATCH 2/3] reset collection to 'root' after adding a route to the api --- lib/private/api.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/private/api.php b/lib/private/api.php index e9c144564f..75d87b333d 100644 --- a/lib/private/api.php +++ b/lib/private/api.php @@ -72,6 +72,7 @@ class OC_API { ->requirements($requirements) ->action('OC_API', 'call'); self::$actions[$name] = array(); + OC::$server->getRouter()->useCollection('root'); } self::$actions[$name][] = array('app' => $app, 'action' => $action, 'authlevel' => $authLevel); } From 5a588333b236519aed449a309be818d0686edb3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Tue, 1 Jul 2014 16:45:00 +0200 Subject: [PATCH 3/3] introduce and use getCurrentConnection() --- lib/private/api.php | 3 ++- lib/private/route/router.php | 16 ++++++++++++++++ lib/public/route/irouter.php | 7 +++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/private/api.php b/lib/private/api.php index 75d87b333d..f5576af2ad 100644 --- a/lib/private/api.php +++ b/lib/private/api.php @@ -65,6 +65,7 @@ class OC_API { $name = strtolower($method).$url; $name = str_replace(array('/', '{', '}'), '_', $name); if(!isset(self::$actions[$name])) { + $oldCollection = OC::$server->getRouter()->getCurrentCollection(); OC::$server->getRouter()->useCollection('ocs'); OC::$server->getRouter()->create($name, $url) ->method($method) @@ -72,7 +73,7 @@ class OC_API { ->requirements($requirements) ->action('OC_API', 'call'); self::$actions[$name] = array(); - OC::$server->getRouter()->useCollection('root'); + OC::$server->getRouter()->useCollection($oldCollection); } self::$actions[$name][] = array('app' => $app, 'action' => $action, 'authlevel' => $authLevel); } diff --git a/lib/private/route/router.php b/lib/private/route/router.php index f3a4bc5f3e..9c973d7ac6 100644 --- a/lib/private/route/router.php +++ b/lib/private/route/router.php @@ -25,6 +25,11 @@ class Router implements IRouter { */ protected $collection = null; + /** + * @var string + */ + protected $collectionName = null; + /** * @var \Symfony\Component\Routing\RouteCollection */ @@ -160,8 +165,19 @@ class Router implements IRouter { */ public function useCollection($name) { $this->collection = $this->getCollection($name); + $this->collectionName = $name; } + /** + * returns the current collection name in use for adding routes + * + * @return string the collection name + */ + public function getCurrentCollection() { + return $this->collectionName; + } + + /** * Create a \OC\Route\Route. * diff --git a/lib/public/route/irouter.php b/lib/public/route/irouter.php index 1c003c7b4b..daa1632e0c 100644 --- a/lib/public/route/irouter.php +++ b/lib/public/route/irouter.php @@ -36,6 +36,13 @@ interface IRouter { */ public function useCollection($name); + /** + * returns the current collection name in use for adding routes + * + * @return string the collection name + */ + public function getCurrentCollection(); + /** * Create a \OCP\Route\IRoute. *