From b60ae11db8b49aa2a06116625de07fa03349a8e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Wed, 23 Oct 2013 16:03:57 +0200 Subject: [PATCH 1/3] introducing new dav property {xmlns:oc="http://owncloud.org/ns}id --- apps/files/appinfo/remote.php | 1 + lib/private/connector/sabre/filesplugin.php | 68 +++++++++++++++++++++ lib/private/connector/sabre/node.php | 18 +++++- 3 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 lib/private/connector/sabre/filesplugin.php diff --git a/apps/files/appinfo/remote.php b/apps/files/appinfo/remote.php index 75c80cd49f..9f29079620 100644 --- a/apps/files/appinfo/remote.php +++ b/apps/files/appinfo/remote.php @@ -48,6 +48,7 @@ $defaults = new OC_Defaults(); $server->addPlugin(new Sabre_DAV_Auth_Plugin($authBackend, $defaults->getName())); $server->addPlugin(new Sabre_DAV_Locks_Plugin($lockBackend)); $server->addPlugin(new Sabre_DAV_Browser_Plugin(false)); // Show something in the Browser, but no upload +$server->addPlugin(new OC_Connector_Sabre_FilesPlugin()); $server->addPlugin(new OC_Connector_Sabre_AbortedUploadDetectionPlugin()); $server->addPlugin(new OC_Connector_Sabre_QuotaPlugin()); $server->addPlugin(new OC_Connector_Sabre_MaintenancePlugin()); diff --git a/lib/private/connector/sabre/filesplugin.php b/lib/private/connector/sabre/filesplugin.php new file mode 100644 index 0000000000..c9d43a038d --- /dev/null +++ b/lib/private/connector/sabre/filesplugin.php @@ -0,0 +1,68 @@ + + * + * @license AGPL3 + */ + +class OC_Connector_Sabre_FilesPlugin extends Sabre_DAV_ServerPlugin +{ + + // namespace + const NS_OWNCLOUD = 'xmlns:oc="http://owncloud.org/ns'; + + /** + * Reference to main server object + * + * @var Sabre_DAV_Server + */ + private $server; + + /** + * This initializes the plugin. + * + * This function is called by Sabre_DAV_Server, after + * addPlugin is called. + * + * This method should set up the required event subscriptions. + * + * @param Sabre_DAV_Server $server + * @return void + */ + public function initialize(Sabre_DAV_Server $server) { + + $server->xmlNamespaces[self::NS_OWNCLOUD] = 'oc'; + $server->protectedProperties[] = '{' . self::NS_OWNCLOUD . '}id'; + + $this->server = $server; + $this->server->subscribeEvent('beforeGetProperties', array($this, 'beforeGetProperties')); + } + + /** + * Adds all ownCloud-specific properties + * + * @param string $path + * @param Sabre_DAV_INode $node + * @param array $requestedProperties + * @param array $returnedProperties + * @return void + */ + public function beforeGetProperties($path, Sabre_DAV_INode $node, array &$requestedProperties, array &$returnedProperties) { + + if ($node instanceof OC_Connector_Sabre_Node) { + + $fileid_propertyname = '{' . self::NS_OWNCLOUD . '}id'; + unset($requestedProperties[array_search($fileid_propertyname, $requestedProperties)]); + + /** @var $node OC_Connector_Sabre_Node */ + $returnedProperties[200][$fileid_propertyname] = $node->getFileId(); + + } + + } + +} diff --git a/lib/private/connector/sabre/node.php b/lib/private/connector/sabre/node.php index 3c2ad60f1d..5c0fd2dcad 100644 --- a/lib/private/connector/sabre/node.php +++ b/lib/private/connector/sabre/node.php @@ -45,6 +45,7 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr * @var string */ protected $path; + /** * node fileinfo cache * @var array @@ -211,6 +212,7 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr * properties should be returned */ public function getProperties($properties) { + if (is_null($this->property_cache)) { $sql = 'SELECT * FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?'; $result = OC_DB::executeAudited( $sql, array( OC_User::getUser(), $this->path ) ); @@ -236,8 +238,11 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr $props = array(); foreach($properties as $property) { - if (isset($this->property_cache[$property])) $props[$property] = $this->property_cache[$property]; + if (isset($this->property_cache[$property])) { + $props[$property] = $this->property_cache[$property]; + } } + return $props; } @@ -260,4 +265,15 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr } return $this->fileView; } + + /** + * @return mixed + */ + public function getFileId() + { + $this->getFileinfoCache(); + $instanceId = OC_Util::getInstanceId(); + $id = sprintf('%08d', $this->fileinfo_cache['fileid']); + return $instanceId . $id; + } } From b02a4857126337688e8ad40d5f74929d005037ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Wed, 23 Oct 2013 16:40:29 +0200 Subject: [PATCH 2/3] handle case where fileid is not set --- lib/private/connector/sabre/filesplugin.php | 5 ++++- lib/private/connector/sabre/node.php | 11 ++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/private/connector/sabre/filesplugin.php b/lib/private/connector/sabre/filesplugin.php index c9d43a038d..46ca14fadc 100644 --- a/lib/private/connector/sabre/filesplugin.php +++ b/lib/private/connector/sabre/filesplugin.php @@ -59,7 +59,10 @@ class OC_Connector_Sabre_FilesPlugin extends Sabre_DAV_ServerPlugin unset($requestedProperties[array_search($fileid_propertyname, $requestedProperties)]); /** @var $node OC_Connector_Sabre_Node */ - $returnedProperties[200][$fileid_propertyname] = $node->getFileId(); + $fileId = $node->getFileId(); + if (!is_null($fileId)) { + $returnedProperties[200][$fileid_propertyname] = $fileId; + } } diff --git a/lib/private/connector/sabre/node.php b/lib/private/connector/sabre/node.php index 5c0fd2dcad..76fbc25110 100644 --- a/lib/private/connector/sabre/node.php +++ b/lib/private/connector/sabre/node.php @@ -272,8 +272,13 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr public function getFileId() { $this->getFileinfoCache(); - $instanceId = OC_Util::getInstanceId(); - $id = sprintf('%08d', $this->fileinfo_cache['fileid']); - return $instanceId . $id; + + if (isset($this->fileinfo_cache['fileid'])) { + $instanceId = OC_Util::getInstanceId(); + $id = sprintf('%08d', $this->fileinfo_cache['fileid']); + return $instanceId . $id; + } + + return null; } } From a22f12cfe0ac6928dea4d5e0d986c10a6b2befc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Thu, 24 Oct 2013 14:40:43 +0200 Subject: [PATCH 3/3] - fixing namespace - remove property only if present --- lib/private/connector/sabre/filesplugin.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/private/connector/sabre/filesplugin.php b/lib/private/connector/sabre/filesplugin.php index 46ca14fadc..ac78182567 100644 --- a/lib/private/connector/sabre/filesplugin.php +++ b/lib/private/connector/sabre/filesplugin.php @@ -13,7 +13,7 @@ class OC_Connector_Sabre_FilesPlugin extends Sabre_DAV_ServerPlugin { // namespace - const NS_OWNCLOUD = 'xmlns:oc="http://owncloud.org/ns'; + const NS_OWNCLOUD = 'http://owncloud.org/ns'; /** * Reference to main server object @@ -56,7 +56,9 @@ class OC_Connector_Sabre_FilesPlugin extends Sabre_DAV_ServerPlugin if ($node instanceof OC_Connector_Sabre_Node) { $fileid_propertyname = '{' . self::NS_OWNCLOUD . '}id'; - unset($requestedProperties[array_search($fileid_propertyname, $requestedProperties)]); + if (array_search($fileid_propertyname, $requestedProperties)) { + unset($requestedProperties[array_search($fileid_propertyname, $requestedProperties)]); + } /** @var $node OC_Connector_Sabre_Node */ $fileId = $node->getFileId();