Remove the need for a custom SabreDav server constructor
This commit is contained in:
parent
331fc55e2d
commit
5ef37c28d1
3 changed files with 20 additions and 18 deletions
|
@ -35,7 +35,8 @@ $lockBackend = new OC_Connector_Sabre_Locks();
|
|||
$requestBackend = new OC_Connector_Sabre_Request();
|
||||
|
||||
// Fire up server
|
||||
$server = new OC_Connector_Sabre_Server();
|
||||
$objectTree = new \OC\Connector\Sabre\ObjectTree();
|
||||
$server = new OC_Connector_Sabre_Server($objectTree);
|
||||
$server->httpRequest = $requestBackend;
|
||||
$server->setBaseUri($baseuri);
|
||||
|
||||
|
@ -49,14 +50,13 @@ $server->addPlugin(new OC_Connector_Sabre_MaintenancePlugin());
|
|||
$server->addPlugin(new OC_Connector_Sabre_ExceptionLoggerPlugin('webdav'));
|
||||
|
||||
// wait with registering these until auth is handled and the filesystem is setup
|
||||
$server->subscribeEvent('beforeMethod', function () use ($server) {
|
||||
$server->subscribeEvent('beforeMethod', function () use ($server, $objectTree) {
|
||||
$view = \OC\Files\Filesystem::getView();
|
||||
$rootInfo = $view->getFileInfo('');
|
||||
|
||||
// Create ownCloud Dir
|
||||
$rootDir = new OC_Connector_Sabre_Directory($view, $rootInfo);
|
||||
$objectTree = new \OC\Connector\Sabre\ObjectTree($rootDir, $view);
|
||||
$server->setObjectTree($objectTree);
|
||||
$objectTree->init($rootDir, $view);
|
||||
|
||||
$server->addPlugin(new OC_Connector_Sabre_AbortedUploadDetectionPlugin($view));
|
||||
$server->addPlugin(new OC_Connector_Sabre_QuotaPlugin($view));
|
||||
|
|
|
@ -22,12 +22,16 @@ class ObjectTree extends \Sabre_DAV_ObjectTree {
|
|||
* Creates the object
|
||||
*
|
||||
* This method expects the rootObject to be passed as a parameter
|
||||
*
|
||||
*/
|
||||
public function __construct() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Sabre_DAV_ICollection $rootNode
|
||||
* @param \OC\Files\View $view
|
||||
*/
|
||||
public function __construct(\Sabre_DAV_ICollection $rootNode, $view) {
|
||||
parent::__construct($rootNode);
|
||||
public function init(\Sabre_DAV_ICollection $rootNode, \OC\Files\View $view) {
|
||||
$this->rootNode = $rootNode;
|
||||
$this->fileView = $view;
|
||||
}
|
||||
|
||||
|
@ -39,6 +43,9 @@ class ObjectTree extends \Sabre_DAV_ObjectTree {
|
|||
* @return \Sabre_DAV_INode
|
||||
*/
|
||||
public function getNodeForPath($path) {
|
||||
if (!$this->fileView) {
|
||||
throw new \Sabre_DAV_Exception_ServiceUnavailable('filesystem not setup');
|
||||
}
|
||||
|
||||
$path = trim($path, '/');
|
||||
if (isset($this->cache[$path])) {
|
||||
|
@ -94,6 +101,9 @@ class ObjectTree extends \Sabre_DAV_ObjectTree {
|
|||
* @return int
|
||||
*/
|
||||
public function move($sourcePath, $destinationPath) {
|
||||
if (!$this->fileView) {
|
||||
throw new \Sabre_DAV_Exception_ServiceUnavailable('filesystem not setup');
|
||||
}
|
||||
|
||||
$sourceNode = $this->getNodeForPath($sourcePath);
|
||||
if ($sourceNode instanceof \Sabre_DAV_ICollection and $this->nodeExists($destinationPath)) {
|
||||
|
@ -150,6 +160,9 @@ class ObjectTree extends \Sabre_DAV_ObjectTree {
|
|||
* @return void
|
||||
*/
|
||||
public function copy($source, $destination) {
|
||||
if (!$this->fileView) {
|
||||
throw new \Sabre_DAV_Exception_ServiceUnavailable('filesystem not setup');
|
||||
}
|
||||
|
||||
if ($this->fileView->is_file($source)) {
|
||||
$this->fileView->copy($source, $destination);
|
||||
|
|
|
@ -27,17 +27,6 @@
|
|||
* @see Sabre_DAV_Server
|
||||
*/
|
||||
class OC_Connector_Sabre_Server extends Sabre_DAV_Server {
|
||||
/**
|
||||
* Sets up the server
|
||||
*
|
||||
* Unlike Sabre_DAV_Server's constructor this does not take an INode or ObjectTree as argument,
|
||||
* the object tree needs to be set later with setObjectTree
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->httpResponse = new Sabre_HTTP_Response();
|
||||
$this->httpRequest = new Sabre_HTTP_Request();
|
||||
|
||||
}
|
||||
|
||||
public function setObjectTree($tree) {
|
||||
$this->tree = $tree;
|
||||
|
|
Loading…
Reference in a new issue