Merge pull request #9269 from owncloud/fix_versions_preview

change order of registering api and capabilities to fix file version previews
This commit is contained in:
Thomas Müller 2014-07-04 15:25:24 +02:00
commit 2327d41b11
4 changed files with 28 additions and 3 deletions

View File

@ -5,11 +5,11 @@
* See the COPYING-README file. * 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 */ /** @var $this \OCP\Route\IRouter */
$this->create('core_ajax_versions_preview', '/preview')->action( $this->create('core_ajax_versions_preview', '/preview')->action(
function() { function() {
require_once __DIR__ . '/../ajax/preview.php'; 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);

View File

@ -65,6 +65,7 @@ class OC_API {
$name = strtolower($method).$url; $name = strtolower($method).$url;
$name = str_replace(array('/', '{', '}'), '_', $name); $name = str_replace(array('/', '{', '}'), '_', $name);
if(!isset(self::$actions[$name])) { if(!isset(self::$actions[$name])) {
$oldCollection = OC::$server->getRouter()->getCurrentCollection();
OC::$server->getRouter()->useCollection('ocs'); OC::$server->getRouter()->useCollection('ocs');
OC::$server->getRouter()->create($name, $url) OC::$server->getRouter()->create($name, $url)
->method($method) ->method($method)
@ -72,6 +73,7 @@ class OC_API {
->requirements($requirements) ->requirements($requirements)
->action('OC_API', 'call'); ->action('OC_API', 'call');
self::$actions[$name] = array(); self::$actions[$name] = array();
OC::$server->getRouter()->useCollection($oldCollection);
} }
self::$actions[$name][] = array('app' => $app, 'action' => $action, 'authlevel' => $authLevel); self::$actions[$name][] = array('app' => $app, 'action' => $action, 'authlevel' => $authLevel);
} }

View File

@ -25,6 +25,11 @@ class Router implements IRouter {
*/ */
protected $collection = null; protected $collection = null;
/**
* @var string
*/
protected $collectionName = null;
/** /**
* @var \Symfony\Component\Routing\RouteCollection * @var \Symfony\Component\Routing\RouteCollection
*/ */
@ -160,8 +165,19 @@ class Router implements IRouter {
*/ */
public function useCollection($name) { public function useCollection($name) {
$this->collection = $this->getCollection($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. * Create a \OC\Route\Route.
* *

View File

@ -36,6 +36,13 @@ interface IRouter {
*/ */
public function useCollection($name); 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. * Create a \OCP\Route\IRoute.
* *