summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2014-04-16 17:44:14 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2014-04-16 17:44:14 +0200
commitec594eb53084c62936d47d22757cdbc0fd0dcd5a (patch)
treed02b2bd606ea964cbbd6ed86d9dfa01972365cca
parentc67aaf6688b5ad359da47bde20258db4653e9640 (diff)
parent69644747687bc59ea8db0dec6ac8c51979b03f57 (diff)
downloadnextcloud-server-ec594eb53084c62936d47d22757cdbc0fd0dcd5a.tar.gz
nextcloud-server-ec594eb53084c62936d47d22757cdbc0fd0dcd5a.zip
Merge pull request #8234 from owncloud/backport-fileids-stable5
backport of the FilesPlugin to stable5
-rw-r--r--apps/files/appinfo/remote.php1
-rw-r--r--lib/connector/sabre/filesplugin.php103
-rw-r--r--lib/connector/sabre/node.php16
3 files changed, 120 insertions, 0 deletions
diff --git a/apps/files/appinfo/remote.php b/apps/files/appinfo/remote.php
index 4cecaf207fd..2ab097df50e 100644
--- a/apps/files/appinfo/remote.php
+++ b/apps/files/appinfo/remote.php
@@ -47,6 +47,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_QuotaPlugin());
$server->addPlugin(new OC_Connector_Sabre_MaintenancePlugin());
$server->addPlugin(new OC_Connector_Sabre_ExceptionLoggerPlugin('webdav'));
diff --git a/lib/connector/sabre/filesplugin.php b/lib/connector/sabre/filesplugin.php
new file mode 100644
index 00000000000..65231040fb5
--- /dev/null
+++ b/lib/connector/sabre/filesplugin.php
@@ -0,0 +1,103 @@
+<?php
+
+/**
+ * ownCloud
+ *
+ * @author Thomas Müller
+ * @copyright 2013 Thomas Müller <thomas.mueller@tmit.eu>
+ *
+ * @license AGPL3
+ */
+
+class OC_Connector_Sabre_FilesPlugin extends Sabre_DAV_ServerPlugin
+{
+
+ // namespace
+ const NS_OWNCLOUD = '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'));
+ $this->server->subscribeEvent('afterCreateFile', array($this, 'sendFileIdHeader'));
+ $this->server->subscribeEvent('afterWriteContent', array($this, 'sendFileIdHeader'));
+ }
+
+ /**
+ * 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';
+ if (array_search($fileid_propertyname, $requestedProperties)) {
+ unset($requestedProperties[array_search($fileid_propertyname, $requestedProperties)]);
+ }
+
+ /** @var $node OC_Connector_Sabre_Node */
+ $fileId = $node->getFileId();
+ if (!is_null($fileId)) {
+ $returnedProperties[200][$fileid_propertyname] = $fileId;
+ }
+
+ }
+
+ }
+
+ /**
+ * @param $filePath
+ * @param Sabre_DAV_INode $node
+ * @throws Sabre_DAV_Exception_BadRequest
+ */
+ public function sendFileIdHeader($filePath, Sabre_DAV_INode $node = null) {
+ // chunked upload handling
+ if (isset($_SERVER['HTTP_OC_CHUNKED'])) {
+ list($path, $name) = \Sabre_DAV_URLUtil::splitPath($filePath);
+ $info = OC_FileChunking::decodeName($name);
+ if (!empty($info)) {
+ $filePath = $path . '/' . $info['name'];
+ }
+ }
+
+ // we get the node for the given $filePath here because in case of afterCreateFile $node is the parent folder
+ if (!$this->server->tree->nodeExists($filePath)) {
+ return;
+ }
+ $node = $this->server->tree->getNodeForPath($filePath);
+ if ($node instanceof OC_Connector_Sabre_Node) {
+ $fileId = $node->getFileId();
+ if (!is_null($fileId)) {
+ $this->server->httpResponse->setHeader('OC-FileId', $fileId);
+ }
+ }
+ }
+
+}
diff --git a/lib/connector/sabre/node.php b/lib/connector/sabre/node.php
index cad87eb8582..65fa61f1235 100644
--- a/lib/connector/sabre/node.php
+++ b/lib/connector/sabre/node.php
@@ -238,4 +238,20 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr
return null;
}
+
+ /**
+ * @return string|null
+ */
+ public function getFileId()
+ {
+ $this->getFileinfoCache();
+
+ if (isset($this->fileinfo_cache['fileid'])) {
+ $instanceId = OC_Util::getInstanceId();
+ $id = sprintf('%08d', $this->fileinfo_cache['fileid']);
+ return $id . $instanceId;
+ }
+
+ return null;
+ }
}