Completed
Pull Request — master (#5550)
by Andreas
16:28
created
apps/dav/lib/Connector/Sabre/Exception/PasswordLoginForbidden.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -29,27 +29,27 @@
 block discarded – undo
29 29
 
30 30
 class PasswordLoginForbidden extends NotAuthenticated {
31 31
 
32
-	const NS_OWNCLOUD = 'http://owncloud.org/ns';
33
-
34
-	public function getHTTPCode() {
35
-		return 401;
36
-	}
37
-
38
-	/**
39
-	 * This method allows the exception to include additional information
40
-	 * into the WebDAV error response
41
-	 *
42
-	 * @param Server $server
43
-	 * @param DOMElement $errorNode
44
-	 * @return void
45
-	 */
46
-	public function serialize(Server $server, DOMElement $errorNode) {
47
-
48
-		// set ownCloud namespace
49
-		$errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD);
50
-
51
-		$error = $errorNode->ownerDocument->createElementNS('o:', 'o:hint', 'password login forbidden');
52
-		$errorNode->appendChild($error);
53
-	}
32
+    const NS_OWNCLOUD = 'http://owncloud.org/ns';
33
+
34
+    public function getHTTPCode() {
35
+        return 401;
36
+    }
37
+
38
+    /**
39
+     * This method allows the exception to include additional information
40
+     * into the WebDAV error response
41
+     *
42
+     * @param Server $server
43
+     * @param DOMElement $errorNode
44
+     * @return void
45
+     */
46
+    public function serialize(Server $server, DOMElement $errorNode) {
47
+
48
+        // set ownCloud namespace
49
+        $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD);
50
+
51
+        $error = $errorNode->ownerDocument->createElementNS('o:', 'o:hint', 'password login forbidden');
52
+        $errorNode->appendChild($error);
53
+    }
54 54
 
55 55
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/Exception/FileLocked.php 2 patches
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -30,20 +30,20 @@
 block discarded – undo
30 30
 
31 31
 class FileLocked extends \Sabre\DAV\Exception {
32 32
 
33
-	public function __construct($message = "", $code = 0, Exception $previous = null) {
34
-		if($previous instanceof \OCP\Files\LockNotAcquiredException) {
35
-			$message = sprintf('Target file %s is locked by another process.', $previous->path);
36
-		}
37
-		parent::__construct($message, $code, $previous);
38
-	}
33
+    public function __construct($message = "", $code = 0, Exception $previous = null) {
34
+        if($previous instanceof \OCP\Files\LockNotAcquiredException) {
35
+            $message = sprintf('Target file %s is locked by another process.', $previous->path);
36
+        }
37
+        parent::__construct($message, $code, $previous);
38
+    }
39 39
 
40
-	/**
41
-	 * Returns the HTTP status code for this exception
42
-	 *
43
-	 * @return int
44
-	 */
45
-	public function getHTTPCode() {
40
+    /**
41
+     * Returns the HTTP status code for this exception
42
+     *
43
+     * @return int
44
+     */
45
+    public function getHTTPCode() {
46 46
 
47
-		return 423;
48
-	}
47
+        return 423;
48
+    }
49 49
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@
 block discarded – undo
31 31
 class FileLocked extends \Sabre\DAV\Exception {
32 32
 
33 33
 	public function __construct($message = "", $code = 0, Exception $previous = null) {
34
-		if($previous instanceof \OCP\Files\LockNotAcquiredException) {
34
+		if ($previous instanceof \OCP\Files\LockNotAcquiredException) {
35 35
 			$message = sprintf('Target file %s is locked by another process.', $previous->path);
36 36
 		}
37 37
 		parent::__construct($message, $code, $previous);
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/Exception/UnsupportedMediaType.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -31,15 +31,15 @@
 block discarded – undo
31 31
  */
32 32
 class UnsupportedMediaType extends \Sabre\DAV\Exception {
33 33
 
34
-	/**
35
-	 * Returns the HTTP status code for this exception
36
-	 *
37
-	 * @return int
38
-	 */
39
-	public function getHTTPCode() {
34
+    /**
35
+     * Returns the HTTP status code for this exception
36
+     *
37
+     * @return int
38
+     */
39
+    public function getHTTPCode() {
40 40
 
41
-		return 415;
41
+        return 415;
42 42
 
43
-	}
43
+    }
44 44
 
45 45
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/Exception/EntityTooLarge.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -31,15 +31,15 @@
 block discarded – undo
31 31
  */
32 32
 class EntityTooLarge extends \Sabre\DAV\Exception {
33 33
 
34
-	/**
35
-	 * Returns the HTTP status code for this exception
36
-	 *
37
-	 * @return int
38
-	 */
39
-	public function getHTTPCode() {
34
+    /**
35
+     * Returns the HTTP status code for this exception
36
+     *
37
+     * @return int
38
+     */
39
+    public function getHTTPCode() {
40 40
 
41
-		return 413;
41
+        return 413;
42 42
 
43
-	}
43
+    }
44 44
 
45 45
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/ServerFactory.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 		$server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin());
118 118
 		// Some WebDAV clients do require Class 2 WebDAV support (locking), since
119 119
 		// we do not provide locking we emulate it using a fake locking plugin.
120
-		if($this->request->isUserAgent([
120
+		if ($this->request->isUserAgent([
121 121
 				'/WebDAVFS/',
122 122
 				'/Microsoft Office OneNote 2013/',
123 123
 				'/Microsoft-WebDAV-MiniRedir/',
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 		}
131 131
 
132 132
 		// wait with registering these until auth is handled and the filesystem is setup
133
-		$server->on('beforeMethod', function () use ($server, $objectTree, $viewCallBack) {
133
+		$server->on('beforeMethod', function() use ($server, $objectTree, $viewCallBack) {
134 134
 			// ensure the skeleton is copied
135 135
 			$userFolder = \OC::$server->getUserFolder();
136 136
 			
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 			);
163 163
 			$server->addPlugin(new \OCA\DAV\Connector\Sabre\QuotaPlugin($view));
164 164
 
165
-			if($this->userSession->isLoggedIn()) {
165
+			if ($this->userSession->isLoggedIn()) {
166 166
 				$server->addPlugin(new \OCA\DAV\Connector\Sabre\TagsPlugin($objectTree, $this->tagManager));
167 167
 				$server->addPlugin(new \OCA\DAV\Connector\Sabre\SharesPlugin(
168 168
 					$objectTree,
Please login to merge, or discard this patch.
Indentation   +145 added lines, -145 removed lines patch added patch discarded remove patch
@@ -43,158 +43,158 @@
 block discarded – undo
43 43
 use Sabre\DAV\Auth\Plugin;
44 44
 
45 45
 class ServerFactory {
46
-	/** @var IConfig */
47
-	private $config;
48
-	/** @var ILogger */
49
-	private $logger;
50
-	/** @var IDBConnection */
51
-	private $databaseConnection;
52
-	/** @var IUserSession */
53
-	private $userSession;
54
-	/** @var IMountManager */
55
-	private $mountManager;
56
-	/** @var ITagManager */
57
-	private $tagManager;
58
-	/** @var IRequest */
59
-	private $request;
60
-	/** @var IPreview  */
61
-	private $previewManager;
46
+    /** @var IConfig */
47
+    private $config;
48
+    /** @var ILogger */
49
+    private $logger;
50
+    /** @var IDBConnection */
51
+    private $databaseConnection;
52
+    /** @var IUserSession */
53
+    private $userSession;
54
+    /** @var IMountManager */
55
+    private $mountManager;
56
+    /** @var ITagManager */
57
+    private $tagManager;
58
+    /** @var IRequest */
59
+    private $request;
60
+    /** @var IPreview  */
61
+    private $previewManager;
62 62
 
63
-	/**
64
-	 * @param IConfig $config
65
-	 * @param ILogger $logger
66
-	 * @param IDBConnection $databaseConnection
67
-	 * @param IUserSession $userSession
68
-	 * @param IMountManager $mountManager
69
-	 * @param ITagManager $tagManager
70
-	 * @param IRequest $request
71
-	 * @param IPreview $previewManager
72
-	 */
73
-	public function __construct(
74
-		IConfig $config,
75
-		ILogger $logger,
76
-		IDBConnection $databaseConnection,
77
-		IUserSession $userSession,
78
-		IMountManager $mountManager,
79
-		ITagManager $tagManager,
80
-		IRequest $request,
81
-		IPreview $previewManager
82
-	) {
83
-		$this->config = $config;
84
-		$this->logger = $logger;
85
-		$this->databaseConnection = $databaseConnection;
86
-		$this->userSession = $userSession;
87
-		$this->mountManager = $mountManager;
88
-		$this->tagManager = $tagManager;
89
-		$this->request = $request;
90
-		$this->previewManager = $previewManager;
91
-	}
63
+    /**
64
+     * @param IConfig $config
65
+     * @param ILogger $logger
66
+     * @param IDBConnection $databaseConnection
67
+     * @param IUserSession $userSession
68
+     * @param IMountManager $mountManager
69
+     * @param ITagManager $tagManager
70
+     * @param IRequest $request
71
+     * @param IPreview $previewManager
72
+     */
73
+    public function __construct(
74
+        IConfig $config,
75
+        ILogger $logger,
76
+        IDBConnection $databaseConnection,
77
+        IUserSession $userSession,
78
+        IMountManager $mountManager,
79
+        ITagManager $tagManager,
80
+        IRequest $request,
81
+        IPreview $previewManager
82
+    ) {
83
+        $this->config = $config;
84
+        $this->logger = $logger;
85
+        $this->databaseConnection = $databaseConnection;
86
+        $this->userSession = $userSession;
87
+        $this->mountManager = $mountManager;
88
+        $this->tagManager = $tagManager;
89
+        $this->request = $request;
90
+        $this->previewManager = $previewManager;
91
+    }
92 92
 
93
-	/**
94
-	 * @param string $baseUri
95
-	 * @param string $requestUri
96
-	 * @param Plugin $authPlugin
97
-	 * @param callable $viewCallBack callback that should return the view for the dav endpoint
98
-	 * @return Server
99
-	 */
100
-	public function createServer($baseUri,
101
-								 $requestUri,
102
-								 Plugin $authPlugin,
103
-								 callable $viewCallBack) {
104
-		// Fire up server
105
-		$objectTree = new \OCA\DAV\Connector\Sabre\ObjectTree();
106
-		$server = new \OCA\DAV\Connector\Sabre\Server($objectTree);
107
-		// Set URL explicitly due to reverse-proxy situations
108
-		$server->httpRequest->setUrl($requestUri);
109
-		$server->setBaseUri($baseUri);
93
+    /**
94
+     * @param string $baseUri
95
+     * @param string $requestUri
96
+     * @param Plugin $authPlugin
97
+     * @param callable $viewCallBack callback that should return the view for the dav endpoint
98
+     * @return Server
99
+     */
100
+    public function createServer($baseUri,
101
+                                    $requestUri,
102
+                                    Plugin $authPlugin,
103
+                                    callable $viewCallBack) {
104
+        // Fire up server
105
+        $objectTree = new \OCA\DAV\Connector\Sabre\ObjectTree();
106
+        $server = new \OCA\DAV\Connector\Sabre\Server($objectTree);
107
+        // Set URL explicitly due to reverse-proxy situations
108
+        $server->httpRequest->setUrl($requestUri);
109
+        $server->setBaseUri($baseUri);
110 110
 
111
-		// Load plugins
112
-		$server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin($this->config));
113
-		$server->addPlugin(new \OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin($this->config));
114
-		$server->addPlugin($authPlugin);
115
-		// FIXME: The following line is a workaround for legacy components relying on being able to send a GET to /
116
-		$server->addPlugin(new \OCA\DAV\Connector\Sabre\DummyGetResponsePlugin());
117
-		$server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $this->logger));
118
-		$server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin());
119
-		// Some WebDAV clients do require Class 2 WebDAV support (locking), since
120
-		// we do not provide locking we emulate it using a fake locking plugin.
121
-		if($this->request->isUserAgent([
122
-				'/WebDAVFS/',
123
-				'/Microsoft Office OneNote 2013/',
124
-				'/Microsoft-WebDAV-MiniRedir/',
125
-		])) {
126
-			$server->addPlugin(new \OCA\DAV\Connector\Sabre\FakeLockerPlugin());
127
-		}
111
+        // Load plugins
112
+        $server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin($this->config));
113
+        $server->addPlugin(new \OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin($this->config));
114
+        $server->addPlugin($authPlugin);
115
+        // FIXME: The following line is a workaround for legacy components relying on being able to send a GET to /
116
+        $server->addPlugin(new \OCA\DAV\Connector\Sabre\DummyGetResponsePlugin());
117
+        $server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $this->logger));
118
+        $server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin());
119
+        // Some WebDAV clients do require Class 2 WebDAV support (locking), since
120
+        // we do not provide locking we emulate it using a fake locking plugin.
121
+        if($this->request->isUserAgent([
122
+                '/WebDAVFS/',
123
+                '/Microsoft Office OneNote 2013/',
124
+                '/Microsoft-WebDAV-MiniRedir/',
125
+        ])) {
126
+            $server->addPlugin(new \OCA\DAV\Connector\Sabre\FakeLockerPlugin());
127
+        }
128 128
 
129
-		if (BrowserErrorPagePlugin::isBrowserRequest($this->request)) {
130
-			$server->addPlugin(new BrowserErrorPagePlugin());
131
-		}
129
+        if (BrowserErrorPagePlugin::isBrowserRequest($this->request)) {
130
+            $server->addPlugin(new BrowserErrorPagePlugin());
131
+        }
132 132
 
133
-		// wait with registering these until auth is handled and the filesystem is setup
134
-		$server->on('beforeMethod', function () use ($server, $objectTree, $viewCallBack) {
135
-			// ensure the skeleton is copied
136
-			$userFolder = \OC::$server->getUserFolder();
133
+        // wait with registering these until auth is handled and the filesystem is setup
134
+        $server->on('beforeMethod', function () use ($server, $objectTree, $viewCallBack) {
135
+            // ensure the skeleton is copied
136
+            $userFolder = \OC::$server->getUserFolder();
137 137
 			
138
-			/** @var \OC\Files\View $view */
139
-			$view = $viewCallBack($server);
140
-			if ($userFolder instanceof Folder && $userFolder->getPath() === $view->getRoot()) {
141
-				$rootInfo = $userFolder;
142
-			} else {
143
-				$rootInfo = $view->getFileInfo('');
144
-			}
138
+            /** @var \OC\Files\View $view */
139
+            $view = $viewCallBack($server);
140
+            if ($userFolder instanceof Folder && $userFolder->getPath() === $view->getRoot()) {
141
+                $rootInfo = $userFolder;
142
+            } else {
143
+                $rootInfo = $view->getFileInfo('');
144
+            }
145 145
 
146
-			// Create Nextcloud Dir
147
-			if ($rootInfo->getType() === 'dir') {
148
-				$root = new \OCA\DAV\Connector\Sabre\Directory($view, $rootInfo, $objectTree);
149
-			} else {
150
-				$root = new \OCA\DAV\Connector\Sabre\File($view, $rootInfo);
151
-			}
152
-			$objectTree->init($root, $view, $this->mountManager);
146
+            // Create Nextcloud Dir
147
+            if ($rootInfo->getType() === 'dir') {
148
+                $root = new \OCA\DAV\Connector\Sabre\Directory($view, $rootInfo, $objectTree);
149
+            } else {
150
+                $root = new \OCA\DAV\Connector\Sabre\File($view, $rootInfo);
151
+            }
152
+            $objectTree->init($root, $view, $this->mountManager);
153 153
 
154
-			$server->addPlugin(
155
-				new \OCA\DAV\Connector\Sabre\FilesPlugin(
156
-					$objectTree,
157
-					$this->config,
158
-					$this->request,
159
-					$this->previewManager,
160
-					false,
161
-					!$this->config->getSystemValue('debug', false)
162
-				)
163
-			);
164
-			$server->addPlugin(new \OCA\DAV\Connector\Sabre\QuotaPlugin($view));
154
+            $server->addPlugin(
155
+                new \OCA\DAV\Connector\Sabre\FilesPlugin(
156
+                    $objectTree,
157
+                    $this->config,
158
+                    $this->request,
159
+                    $this->previewManager,
160
+                    false,
161
+                    !$this->config->getSystemValue('debug', false)
162
+                )
163
+            );
164
+            $server->addPlugin(new \OCA\DAV\Connector\Sabre\QuotaPlugin($view));
165 165
 
166
-			if($this->userSession->isLoggedIn()) {
167
-				$server->addPlugin(new \OCA\DAV\Connector\Sabre\TagsPlugin($objectTree, $this->tagManager));
168
-				$server->addPlugin(new \OCA\DAV\Connector\Sabre\SharesPlugin(
169
-					$objectTree,
170
-					$this->userSession,
171
-					$userFolder,
172
-					\OC::$server->getShareManager()
173
-				));
174
-				$server->addPlugin(new \OCA\DAV\Connector\Sabre\CommentPropertiesPlugin(\OC::$server->getCommentsManager(), $this->userSession));
175
-				$server->addPlugin(new \OCA\DAV\Connector\Sabre\FilesReportPlugin(
176
-					$objectTree,
177
-					$view,
178
-					\OC::$server->getSystemTagManager(),
179
-					\OC::$server->getSystemTagObjectMapper(),
180
-					\OC::$server->getTagManager(),
181
-					$this->userSession,
182
-					\OC::$server->getGroupManager(),
183
-					$userFolder
184
-				));
185
-				// custom properties plugin must be the last one
186
-				$server->addPlugin(
187
-					new \Sabre\DAV\PropertyStorage\Plugin(
188
-						new \OCA\DAV\Connector\Sabre\CustomPropertiesBackend(
189
-							$objectTree,
190
-							$this->databaseConnection,
191
-							$this->userSession->getUser()
192
-						)
193
-					)
194
-				);
195
-			}
196
-			$server->addPlugin(new \OCA\DAV\Connector\Sabre\CopyEtagHeaderPlugin());
197
-		}, 30); // priority 30: after auth (10) and acl(20), before lock(50) and handling the request
198
-		return $server;
199
-	}
166
+            if($this->userSession->isLoggedIn()) {
167
+                $server->addPlugin(new \OCA\DAV\Connector\Sabre\TagsPlugin($objectTree, $this->tagManager));
168
+                $server->addPlugin(new \OCA\DAV\Connector\Sabre\SharesPlugin(
169
+                    $objectTree,
170
+                    $this->userSession,
171
+                    $userFolder,
172
+                    \OC::$server->getShareManager()
173
+                ));
174
+                $server->addPlugin(new \OCA\DAV\Connector\Sabre\CommentPropertiesPlugin(\OC::$server->getCommentsManager(), $this->userSession));
175
+                $server->addPlugin(new \OCA\DAV\Connector\Sabre\FilesReportPlugin(
176
+                    $objectTree,
177
+                    $view,
178
+                    \OC::$server->getSystemTagManager(),
179
+                    \OC::$server->getSystemTagObjectMapper(),
180
+                    \OC::$server->getTagManager(),
181
+                    $this->userSession,
182
+                    \OC::$server->getGroupManager(),
183
+                    $userFolder
184
+                ));
185
+                // custom properties plugin must be the last one
186
+                $server->addPlugin(
187
+                    new \Sabre\DAV\PropertyStorage\Plugin(
188
+                        new \OCA\DAV\Connector\Sabre\CustomPropertiesBackend(
189
+                            $objectTree,
190
+                            $this->databaseConnection,
191
+                            $this->userSession->getUser()
192
+                        )
193
+                    )
194
+                );
195
+            }
196
+            $server->addPlugin(new \OCA\DAV\Connector\Sabre\CopyEtagHeaderPlugin());
197
+        }, 30); // priority 30: after auth (10) and acl(20), before lock(50) and handling the request
198
+        return $server;
199
+    }
200 200
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/Node.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 		// verify path of the target
131 131
 		$this->verifyPath();
132 132
 
133
-		$newPath = $parentPath . '/' . $newName;
133
+		$newPath = $parentPath.'/'.$newName;
134 134
 
135 135
 		$this->fileView->rename($this->path, $newPath);
136 136
 
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 	public function getLastModified() {
152 152
 		$timestamp = $this->info->getMtime();
153 153
 		if (!empty($timestamp)) {
154
-			return (int)$timestamp;
154
+			return (int) $timestamp;
155 155
 		}
156 156
 		return $timestamp;
157 157
 	}
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
 	 * @return string
179 179
 	 */
180 180
 	public function getETag() {
181
-		return '"' . $this->info->getEtag() . '"';
181
+		return '"'.$this->info->getEtag().'"';
182 182
 	}
183 183
 
184 184
 	/**
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
 		if ($this->info->getId()) {
218 218
 			$instanceId = \OC_Util::getInstanceId();
219 219
 			$id = sprintf('%08d', $this->info->getId());
220
-			return $id . $instanceId;
220
+			return $id.$instanceId;
221 221
 		}
222 222
 
223 223
 		return null;
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 
253 253
 		if ($storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) {
254 254
 			/** @var \OCA\Files_Sharing\SharedStorage $storage */
255
-			$permissions = (int)$storage->getShare()->getPermissions();
255
+			$permissions = (int) $storage->getShare()->getPermissions();
256 256
 		} else {
257 257
 			$permissions = $storage->getPermissions($path);
258 258
 		}
Please login to merge, or discard this patch.
Indentation   +306 added lines, -306 removed lines patch added patch discarded remove patch
@@ -43,315 +43,315 @@
 block discarded – undo
43 43
 
44 44
 abstract class Node implements \Sabre\DAV\INode {
45 45
 
46
-	/**
47
-	 * @var \OC\Files\View
48
-	 */
49
-	protected $fileView;
50
-
51
-	/**
52
-	 * The path to the current node
53
-	 *
54
-	 * @var string
55
-	 */
56
-	protected $path;
57
-
58
-	/**
59
-	 * node properties cache
60
-	 *
61
-	 * @var array
62
-	 */
63
-	protected $property_cache = null;
64
-
65
-	/**
66
-	 * @var \OCP\Files\FileInfo
67
-	 */
68
-	protected $info;
69
-
70
-	/**
71
-	 * @var IManager
72
-	 */
73
-	protected $shareManager;
74
-
75
-	/**
76
-	 * Sets up the node, expects a full path name
77
-	 *
78
-	 * @param \OC\Files\View $view
79
-	 * @param \OCP\Files\FileInfo $info
80
-	 * @param IManager $shareManager
81
-	 */
82
-	public function __construct(View $view, FileInfo $info, IManager $shareManager = null) {
83
-		$this->fileView = $view;
84
-		$this->path = $this->fileView->getRelativePath($info->getPath());
85
-		$this->info = $info;
86
-		if ($shareManager) {
87
-			$this->shareManager = $shareManager;
88
-		} else {
89
-			$this->shareManager = \OC::$server->getShareManager();
90
-		}
91
-	}
92
-
93
-	protected function refreshInfo() {
94
-		$this->info = $this->fileView->getFileInfo($this->path);
95
-	}
96
-
97
-	/**
98
-	 *  Returns the name of the node
99
-	 *
100
-	 * @return string
101
-	 */
102
-	public function getName() {
103
-		return $this->info->getName();
104
-	}
105
-
106
-	/**
107
-	 * Returns the full path
108
-	 *
109
-	 * @return string
110
-	 */
111
-	public function getPath() {
112
-		return $this->path;
113
-	}
114
-
115
-	/**
116
-	 * Renames the node
117
-	 *
118
-	 * @param string $name The new name
119
-	 * @throws \Sabre\DAV\Exception\BadRequest
120
-	 * @throws \Sabre\DAV\Exception\Forbidden
121
-	 */
122
-	public function setName($name) {
123
-
124
-		// rename is only allowed if the update privilege is granted
125
-		if (!$this->info->isUpdateable()) {
126
-			throw new \Sabre\DAV\Exception\Forbidden();
127
-		}
128
-
129
-		list($parentPath,) = \Sabre\HTTP\URLUtil::splitPath($this->path);
130
-		list(, $newName) = \Sabre\HTTP\URLUtil::splitPath($name);
131
-
132
-		// verify path of the target
133
-		$this->verifyPath();
134
-
135
-		$newPath = $parentPath . '/' . $newName;
136
-
137
-		$this->fileView->rename($this->path, $newPath);
138
-
139
-		$this->path = $newPath;
140
-
141
-		$this->refreshInfo();
142
-	}
143
-
144
-	public function setPropertyCache($property_cache) {
145
-		$this->property_cache = $property_cache;
146
-	}
147
-
148
-	/**
149
-	 * Returns the last modification time, as a unix timestamp
150
-	 *
151
-	 * @return int timestamp as integer
152
-	 */
153
-	public function getLastModified() {
154
-		$timestamp = $this->info->getMtime();
155
-		if (!empty($timestamp)) {
156
-			return (int)$timestamp;
157
-		}
158
-		return $timestamp;
159
-	}
160
-
161
-	/**
162
-	 *  sets the last modification time of the file (mtime) to the value given
163
-	 *  in the second parameter or to now if the second param is empty.
164
-	 *  Even if the modification time is set to a custom value the access time is set to now.
165
-	 */
166
-	public function touch($mtime) {
167
-		$this->fileView->touch($this->path, $mtime);
168
-		$this->refreshInfo();
169
-	}
170
-
171
-	/**
172
-	 * Returns the ETag for a file
173
-	 *
174
-	 * An ETag is a unique identifier representing the current version of the
175
-	 * file. If the file changes, the ETag MUST change.  The ETag is an
176
-	 * arbitrary string, but MUST be surrounded by double-quotes.
177
-	 *
178
-	 * Return null if the ETag can not effectively be determined
179
-	 *
180
-	 * @return string
181
-	 */
182
-	public function getETag() {
183
-		return '"' . $this->info->getEtag() . '"';
184
-	}
185
-
186
-	/**
187
-	 * Sets the ETag
188
-	 *
189
-	 * @param string $etag
190
-	 *
191
-	 * @return int file id of updated file or -1 on failure
192
-	 */
193
-	public function setETag($etag) {
194
-		return $this->fileView->putFileInfo($this->path, array('etag' => $etag));
195
-	}
196
-
197
-	/**
198
-	 * Returns the size of the node, in bytes
199
-	 *
200
-	 * @return integer
201
-	 */
202
-	public function getSize() {
203
-		return $this->info->getSize();
204
-	}
205
-
206
-	/**
207
-	 * Returns the cache's file id
208
-	 *
209
-	 * @return int
210
-	 */
211
-	public function getId() {
212
-		return $this->info->getId();
213
-	}
214
-
215
-	/**
216
-	 * @return string|null
217
-	 */
218
-	public function getFileId() {
219
-		if ($this->info->getId()) {
220
-			$instanceId = \OC_Util::getInstanceId();
221
-			$id = sprintf('%08d', $this->info->getId());
222
-			return $id . $instanceId;
223
-		}
224
-
225
-		return null;
226
-	}
227
-
228
-	/**
229
-	 * @return integer
230
-	 */
231
-	public function getInternalFileId() {
232
-		return $this->info->getId();
233
-	}
234
-
235
-	/**
236
-	 * @param string $user
237
-	 * @return int
238
-	 */
239
-	public function getSharePermissions($user) {
240
-
241
-		// check of we access a federated share
242
-		if ($user !== null) {
243
-			try {
244
-				$share = $this->shareManager->getShareByToken($user);
245
-				return $share->getPermissions();
246
-			} catch (ShareNotFound $e) {
247
-				// ignore
248
-			}
249
-		}
250
-
251
-		$storage = $this->info->getStorage();
252
-
253
-		$path = $this->info->getInternalPath();
254
-
255
-		if ($storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) {
256
-			/** @var \OCA\Files_Sharing\SharedStorage $storage */
257
-			$permissions = (int)$storage->getShare()->getPermissions();
258
-		} else {
259
-			$permissions = $storage->getPermissions($path);
260
-		}
261
-
262
-		/*
46
+    /**
47
+     * @var \OC\Files\View
48
+     */
49
+    protected $fileView;
50
+
51
+    /**
52
+     * The path to the current node
53
+     *
54
+     * @var string
55
+     */
56
+    protected $path;
57
+
58
+    /**
59
+     * node properties cache
60
+     *
61
+     * @var array
62
+     */
63
+    protected $property_cache = null;
64
+
65
+    /**
66
+     * @var \OCP\Files\FileInfo
67
+     */
68
+    protected $info;
69
+
70
+    /**
71
+     * @var IManager
72
+     */
73
+    protected $shareManager;
74
+
75
+    /**
76
+     * Sets up the node, expects a full path name
77
+     *
78
+     * @param \OC\Files\View $view
79
+     * @param \OCP\Files\FileInfo $info
80
+     * @param IManager $shareManager
81
+     */
82
+    public function __construct(View $view, FileInfo $info, IManager $shareManager = null) {
83
+        $this->fileView = $view;
84
+        $this->path = $this->fileView->getRelativePath($info->getPath());
85
+        $this->info = $info;
86
+        if ($shareManager) {
87
+            $this->shareManager = $shareManager;
88
+        } else {
89
+            $this->shareManager = \OC::$server->getShareManager();
90
+        }
91
+    }
92
+
93
+    protected function refreshInfo() {
94
+        $this->info = $this->fileView->getFileInfo($this->path);
95
+    }
96
+
97
+    /**
98
+     *  Returns the name of the node
99
+     *
100
+     * @return string
101
+     */
102
+    public function getName() {
103
+        return $this->info->getName();
104
+    }
105
+
106
+    /**
107
+     * Returns the full path
108
+     *
109
+     * @return string
110
+     */
111
+    public function getPath() {
112
+        return $this->path;
113
+    }
114
+
115
+    /**
116
+     * Renames the node
117
+     *
118
+     * @param string $name The new name
119
+     * @throws \Sabre\DAV\Exception\BadRequest
120
+     * @throws \Sabre\DAV\Exception\Forbidden
121
+     */
122
+    public function setName($name) {
123
+
124
+        // rename is only allowed if the update privilege is granted
125
+        if (!$this->info->isUpdateable()) {
126
+            throw new \Sabre\DAV\Exception\Forbidden();
127
+        }
128
+
129
+        list($parentPath,) = \Sabre\HTTP\URLUtil::splitPath($this->path);
130
+        list(, $newName) = \Sabre\HTTP\URLUtil::splitPath($name);
131
+
132
+        // verify path of the target
133
+        $this->verifyPath();
134
+
135
+        $newPath = $parentPath . '/' . $newName;
136
+
137
+        $this->fileView->rename($this->path, $newPath);
138
+
139
+        $this->path = $newPath;
140
+
141
+        $this->refreshInfo();
142
+    }
143
+
144
+    public function setPropertyCache($property_cache) {
145
+        $this->property_cache = $property_cache;
146
+    }
147
+
148
+    /**
149
+     * Returns the last modification time, as a unix timestamp
150
+     *
151
+     * @return int timestamp as integer
152
+     */
153
+    public function getLastModified() {
154
+        $timestamp = $this->info->getMtime();
155
+        if (!empty($timestamp)) {
156
+            return (int)$timestamp;
157
+        }
158
+        return $timestamp;
159
+    }
160
+
161
+    /**
162
+     *  sets the last modification time of the file (mtime) to the value given
163
+     *  in the second parameter or to now if the second param is empty.
164
+     *  Even if the modification time is set to a custom value the access time is set to now.
165
+     */
166
+    public function touch($mtime) {
167
+        $this->fileView->touch($this->path, $mtime);
168
+        $this->refreshInfo();
169
+    }
170
+
171
+    /**
172
+     * Returns the ETag for a file
173
+     *
174
+     * An ETag is a unique identifier representing the current version of the
175
+     * file. If the file changes, the ETag MUST change.  The ETag is an
176
+     * arbitrary string, but MUST be surrounded by double-quotes.
177
+     *
178
+     * Return null if the ETag can not effectively be determined
179
+     *
180
+     * @return string
181
+     */
182
+    public function getETag() {
183
+        return '"' . $this->info->getEtag() . '"';
184
+    }
185
+
186
+    /**
187
+     * Sets the ETag
188
+     *
189
+     * @param string $etag
190
+     *
191
+     * @return int file id of updated file or -1 on failure
192
+     */
193
+    public function setETag($etag) {
194
+        return $this->fileView->putFileInfo($this->path, array('etag' => $etag));
195
+    }
196
+
197
+    /**
198
+     * Returns the size of the node, in bytes
199
+     *
200
+     * @return integer
201
+     */
202
+    public function getSize() {
203
+        return $this->info->getSize();
204
+    }
205
+
206
+    /**
207
+     * Returns the cache's file id
208
+     *
209
+     * @return int
210
+     */
211
+    public function getId() {
212
+        return $this->info->getId();
213
+    }
214
+
215
+    /**
216
+     * @return string|null
217
+     */
218
+    public function getFileId() {
219
+        if ($this->info->getId()) {
220
+            $instanceId = \OC_Util::getInstanceId();
221
+            $id = sprintf('%08d', $this->info->getId());
222
+            return $id . $instanceId;
223
+        }
224
+
225
+        return null;
226
+    }
227
+
228
+    /**
229
+     * @return integer
230
+     */
231
+    public function getInternalFileId() {
232
+        return $this->info->getId();
233
+    }
234
+
235
+    /**
236
+     * @param string $user
237
+     * @return int
238
+     */
239
+    public function getSharePermissions($user) {
240
+
241
+        // check of we access a federated share
242
+        if ($user !== null) {
243
+            try {
244
+                $share = $this->shareManager->getShareByToken($user);
245
+                return $share->getPermissions();
246
+            } catch (ShareNotFound $e) {
247
+                // ignore
248
+            }
249
+        }
250
+
251
+        $storage = $this->info->getStorage();
252
+
253
+        $path = $this->info->getInternalPath();
254
+
255
+        if ($storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) {
256
+            /** @var \OCA\Files_Sharing\SharedStorage $storage */
257
+            $permissions = (int)$storage->getShare()->getPermissions();
258
+        } else {
259
+            $permissions = $storage->getPermissions($path);
260
+        }
261
+
262
+        /*
263 263
 		 * We can always share non moveable mount points with DELETE and UPDATE
264 264
 		 * Eventually we need to do this properly
265 265
 		 */
266
-		$mountpoint = $this->info->getMountPoint();
267
-		if (!($mountpoint instanceof MoveableMount)) {
268
-			$mountpointpath = $mountpoint->getMountPoint();
269
-			if (substr($mountpointpath, -1) === '/') {
270
-				$mountpointpath = substr($mountpointpath, 0, -1);
271
-			}
272
-
273
-			if ($mountpointpath === $this->info->getPath()) {
274
-				$permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE;
275
-			}
276
-		}
277
-
278
-		/*
266
+        $mountpoint = $this->info->getMountPoint();
267
+        if (!($mountpoint instanceof MoveableMount)) {
268
+            $mountpointpath = $mountpoint->getMountPoint();
269
+            if (substr($mountpointpath, -1) === '/') {
270
+                $mountpointpath = substr($mountpointpath, 0, -1);
271
+            }
272
+
273
+            if ($mountpointpath === $this->info->getPath()) {
274
+                $permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE;
275
+            }
276
+        }
277
+
278
+        /*
279 279
 		 * Files can't have create or delete permissions
280 280
 		 */
281
-		if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) {
282
-			$permissions &= ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_DELETE);
283
-		}
284
-
285
-		return $permissions;
286
-	}
287
-
288
-	/**
289
-	 * @return string
290
-	 */
291
-	public function getDavPermissions() {
292
-		$p = '';
293
-		if ($this->info->isShared()) {
294
-			$p .= 'S';
295
-		}
296
-		if ($this->info->isShareable()) {
297
-			$p .= 'R';
298
-		}
299
-		if ($this->info->isMounted()) {
300
-			$p .= 'M';
301
-		}
302
-		if ($this->info->isDeletable()) {
303
-			$p .= 'D';
304
-		}
305
-		if ($this->info->isUpdateable()) {
306
-			$p .= 'NV'; // Renameable, Moveable
307
-		}
308
-		if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) {
309
-			if ($this->info->isUpdateable()) {
310
-				$p .= 'W';
311
-			}
312
-		} else {
313
-			if ($this->info->isCreatable()) {
314
-				$p .= 'CK';
315
-			}
316
-		}
317
-		return $p;
318
-	}
319
-
320
-	public function getOwner() {
321
-		return $this->info->getOwner();
322
-	}
323
-
324
-	protected function verifyPath() {
325
-		try {
326
-			$fileName = basename($this->info->getPath());
327
-			$this->fileView->verifyPath($this->path, $fileName);
328
-		} catch (\OCP\Files\InvalidPathException $ex) {
329
-			throw new InvalidPath($ex->getMessage());
330
-		}
331
-	}
332
-
333
-	/**
334
-	 * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
335
-	 */
336
-	public function acquireLock($type) {
337
-		$this->fileView->lockFile($this->path, $type);
338
-	}
339
-
340
-	/**
341
-	 * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
342
-	 */
343
-	public function releaseLock($type) {
344
-		$this->fileView->unlockFile($this->path, $type);
345
-	}
346
-
347
-	/**
348
-	 * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
349
-	 */
350
-	public function changeLock($type) {
351
-		$this->fileView->changeLock($this->path, $type);
352
-	}
353
-
354
-	public function getFileInfo() {
355
-		return $this->info;
356
-	}
281
+        if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) {
282
+            $permissions &= ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_DELETE);
283
+        }
284
+
285
+        return $permissions;
286
+    }
287
+
288
+    /**
289
+     * @return string
290
+     */
291
+    public function getDavPermissions() {
292
+        $p = '';
293
+        if ($this->info->isShared()) {
294
+            $p .= 'S';
295
+        }
296
+        if ($this->info->isShareable()) {
297
+            $p .= 'R';
298
+        }
299
+        if ($this->info->isMounted()) {
300
+            $p .= 'M';
301
+        }
302
+        if ($this->info->isDeletable()) {
303
+            $p .= 'D';
304
+        }
305
+        if ($this->info->isUpdateable()) {
306
+            $p .= 'NV'; // Renameable, Moveable
307
+        }
308
+        if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) {
309
+            if ($this->info->isUpdateable()) {
310
+                $p .= 'W';
311
+            }
312
+        } else {
313
+            if ($this->info->isCreatable()) {
314
+                $p .= 'CK';
315
+            }
316
+        }
317
+        return $p;
318
+    }
319
+
320
+    public function getOwner() {
321
+        return $this->info->getOwner();
322
+    }
323
+
324
+    protected function verifyPath() {
325
+        try {
326
+            $fileName = basename($this->info->getPath());
327
+            $this->fileView->verifyPath($this->path, $fileName);
328
+        } catch (\OCP\Files\InvalidPathException $ex) {
329
+            throw new InvalidPath($ex->getMessage());
330
+        }
331
+    }
332
+
333
+    /**
334
+     * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
335
+     */
336
+    public function acquireLock($type) {
337
+        $this->fileView->lockFile($this->path, $type);
338
+    }
339
+
340
+    /**
341
+     * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
342
+     */
343
+    public function releaseLock($type) {
344
+        $this->fileView->unlockFile($this->path, $type);
345
+    }
346
+
347
+    /**
348
+     * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
349
+     */
350
+    public function changeLock($type) {
351
+        $this->fileView->changeLock($this->path, $type);
352
+    }
353
+
354
+    public function getFileInfo() {
355
+        return $this->info;
356
+    }
357 357
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/ExceptionLoggerPlugin.php 2 patches
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -32,88 +32,88 @@
 block discarded – undo
32 32
 use Sabre\HTTP\Response;
33 33
 
34 34
 class ExceptionLoggerPlugin extends \Sabre\DAV\ServerPlugin {
35
-	protected $nonFatalExceptions = [
36
-		'Sabre\DAV\Exception\NotAuthenticated' => true,
37
-		// If tokenauth can throw this exception (which is basically as
38
-		// NotAuthenticated. So not fatal.
39
-		'OCA\DAV\Connector\Sabre\Exception\PasswordLoginForbidden' => true,
40
-		// the sync client uses this to find out whether files exist,
41
-		// so it is not always an error, log it as debug
42
-		'Sabre\DAV\Exception\NotFound' => true,
43
-		// this one mostly happens when the same file is uploaded at
44
-		// exactly the same time from two clients, only one client
45
-		// wins, the second one gets "Precondition failed"
46
-		'Sabre\DAV\Exception\PreconditionFailed' => true,
47
-		// forbidden can be expected when trying to upload to
48
-		// read-only folders for example
49
-		'Sabre\DAV\Exception\Forbidden' => true,
50
-		// Happens when an external storage or federated share is temporarily
51
-		// not available
52
-		'Sabre\DAV\Exception\StorageNotAvailableException' => true,
53
-	];
35
+    protected $nonFatalExceptions = [
36
+        'Sabre\DAV\Exception\NotAuthenticated' => true,
37
+        // If tokenauth can throw this exception (which is basically as
38
+        // NotAuthenticated. So not fatal.
39
+        'OCA\DAV\Connector\Sabre\Exception\PasswordLoginForbidden' => true,
40
+        // the sync client uses this to find out whether files exist,
41
+        // so it is not always an error, log it as debug
42
+        'Sabre\DAV\Exception\NotFound' => true,
43
+        // this one mostly happens when the same file is uploaded at
44
+        // exactly the same time from two clients, only one client
45
+        // wins, the second one gets "Precondition failed"
46
+        'Sabre\DAV\Exception\PreconditionFailed' => true,
47
+        // forbidden can be expected when trying to upload to
48
+        // read-only folders for example
49
+        'Sabre\DAV\Exception\Forbidden' => true,
50
+        // Happens when an external storage or federated share is temporarily
51
+        // not available
52
+        'Sabre\DAV\Exception\StorageNotAvailableException' => true,
53
+    ];
54 54
 
55
-	/** @var string */
56
-	private $appName;
55
+    /** @var string */
56
+    private $appName;
57 57
 
58
-	/** @var ILogger */
59
-	private $logger;
58
+    /** @var ILogger */
59
+    private $logger;
60 60
 
61
-	/**
62
-	 * @param string $loggerAppName app name to use when logging
63
-	 * @param ILogger $logger
64
-	 */
65
-	public function __construct($loggerAppName, $logger) {
66
-		$this->appName = $loggerAppName;
67
-		$this->logger = $logger;
68
-	}
61
+    /**
62
+     * @param string $loggerAppName app name to use when logging
63
+     * @param ILogger $logger
64
+     */
65
+    public function __construct($loggerAppName, $logger) {
66
+        $this->appName = $loggerAppName;
67
+        $this->logger = $logger;
68
+    }
69 69
 
70
-	/**
71
-	 * This initializes the plugin.
72
-	 *
73
-	 * This function is called by \Sabre\DAV\Server, after
74
-	 * addPlugin is called.
75
-	 *
76
-	 * This method should set up the required event subscriptions.
77
-	 *
78
-	 * @param \Sabre\DAV\Server $server
79
-	 * @return void
80
-	 */
81
-	public function initialize(\Sabre\DAV\Server $server) {
70
+    /**
71
+     * This initializes the plugin.
72
+     *
73
+     * This function is called by \Sabre\DAV\Server, after
74
+     * addPlugin is called.
75
+     *
76
+     * This method should set up the required event subscriptions.
77
+     *
78
+     * @param \Sabre\DAV\Server $server
79
+     * @return void
80
+     */
81
+    public function initialize(\Sabre\DAV\Server $server) {
82 82
 
83
-		$server->on('exception', array($this, 'logException'), 10);
84
-	}
83
+        $server->on('exception', array($this, 'logException'), 10);
84
+    }
85 85
 
86
-	/**
87
-	 * Log exception
88
-	 *
89
-	 */
90
-	public function logException(\Exception $ex) {
91
-		$exceptionClass = get_class($ex);
92
-		$level = \OCP\Util::FATAL;
93
-		if (isset($this->nonFatalExceptions[$exceptionClass])) {
94
-			$level = \OCP\Util::DEBUG;
95
-		}
86
+    /**
87
+     * Log exception
88
+     *
89
+     */
90
+    public function logException(\Exception $ex) {
91
+        $exceptionClass = get_class($ex);
92
+        $level = \OCP\Util::FATAL;
93
+        if (isset($this->nonFatalExceptions[$exceptionClass])) {
94
+            $level = \OCP\Util::DEBUG;
95
+        }
96 96
 
97
-		$message = $ex->getMessage();
98
-		if ($ex instanceof Exception) {
99
-			if (empty($message)) {
100
-				$response = new Response($ex->getHTTPCode());
101
-				$message = $response->getStatusText();
102
-			}
103
-			$message = "HTTP/1.1 {$ex->getHTTPCode()} $message";
104
-		}
97
+        $message = $ex->getMessage();
98
+        if ($ex instanceof Exception) {
99
+            if (empty($message)) {
100
+                $response = new Response($ex->getHTTPCode());
101
+                $message = $response->getStatusText();
102
+            }
103
+            $message = "HTTP/1.1 {$ex->getHTTPCode()} $message";
104
+        }
105 105
 
106
-		$user = \OC_User::getUser();
106
+        $user = \OC_User::getUser();
107 107
 
108
-		$exception = [
109
-			'Message' => $message,
110
-			'Exception' => $exceptionClass,
111
-			'Code' => $ex->getCode(),
112
-			'Trace' => $ex->getTraceAsString(),
113
-			'File' => $ex->getFile(),
114
-			'Line' => $ex->getLine(),
115
-			'User' => $user,
116
-		];
117
-		$this->logger->log($level, 'Exception: ' . json_encode($exception), ['app' => $this->appName]);
118
-	}
108
+        $exception = [
109
+            'Message' => $message,
110
+            'Exception' => $exceptionClass,
111
+            'Code' => $ex->getCode(),
112
+            'Trace' => $ex->getTraceAsString(),
113
+            'File' => $ex->getFile(),
114
+            'Line' => $ex->getLine(),
115
+            'User' => $user,
116
+        ];
117
+        $this->logger->log($level, 'Exception: ' . json_encode($exception), ['app' => $this->appName]);
118
+    }
119 119
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -114,6 +114,6 @@
 block discarded – undo
114 114
 			'Line' => $ex->getLine(),
115 115
 			'User' => $user,
116 116
 		];
117
-		$this->logger->log($level, 'Exception: ' . json_encode($exception), ['app' => $this->appName]);
117
+		$this->logger->log($level, 'Exception: '.json_encode($exception), ['app' => $this->appName]);
118 118
 	}
119 119
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/SharesPlugin.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 
149 149
 		$shareTypesByFileId = [];
150 150
 
151
-		foreach($shares as $fileId => $sharesForFile) {
151
+		foreach ($shares as $fileId => $sharesForFile) {
152 152
 			$types = array_map(function(IShare $share) {
153 153
 				return $share->getShareType();
154 154
 			}, $sharesForFile);
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 			}
190 190
 		}
191 191
 
192
-		$propFind->handle(self::SHARETYPES_PROPERTYNAME, function () use ($sabreNode) {
192
+		$propFind->handle(self::SHARETYPES_PROPERTYNAME, function() use ($sabreNode) {
193 193
 			if (isset($this->cachedShareTypes[$sabreNode->getId()])) {
194 194
 				$shareTypes = $this->cachedShareTypes[$sabreNode->getId()];
195 195
 			} else {
Please login to merge, or discard this patch.
Indentation   +177 added lines, -177 removed lines patch added patch discarded remove patch
@@ -32,181 +32,181 @@
 block discarded – undo
32 32
  */
33 33
 class SharesPlugin extends \Sabre\DAV\ServerPlugin {
34 34
 
35
-	const NS_OWNCLOUD = 'http://owncloud.org/ns';
36
-	const SHARETYPES_PROPERTYNAME = '{http://owncloud.org/ns}share-types';
37
-
38
-	/**
39
-	 * Reference to main server object
40
-	 *
41
-	 * @var \Sabre\DAV\Server
42
-	 */
43
-	private $server;
44
-
45
-	/**
46
-	 * @var \OCP\Share\IManager
47
-	 */
48
-	private $shareManager;
49
-
50
-	/**
51
-	 * @var \Sabre\DAV\Tree
52
-	 */
53
-	private $tree;
54
-
55
-	/**
56
-	 * @var string
57
-	 */
58
-	private $userId;
59
-
60
-	/**
61
-	 * @var \OCP\Files\Folder
62
-	 */
63
-	private $userFolder;
64
-
65
-	/**
66
-	 * @var IShare[]
67
-	 */
68
-	private $cachedShareTypes;
69
-
70
-	private $cachedFolders = [];
71
-
72
-	/**
73
-	 * @param \Sabre\DAV\Tree $tree tree
74
-	 * @param IUserSession $userSession user session
75
-	 * @param \OCP\Files\Folder $userFolder user home folder
76
-	 * @param \OCP\Share\IManager $shareManager share manager
77
-	 */
78
-	public function __construct(
79
-		\Sabre\DAV\Tree $tree,
80
-		IUserSession $userSession,
81
-		\OCP\Files\Folder $userFolder,
82
-		\OCP\Share\IManager $shareManager
83
-	) {
84
-		$this->tree = $tree;
85
-		$this->shareManager = $shareManager;
86
-		$this->userFolder = $userFolder;
87
-		$this->userId = $userSession->getUser()->getUID();
88
-		$this->cachedShareTypes = [];
89
-	}
90
-
91
-	/**
92
-	 * This initializes the plugin.
93
-	 *
94
-	 * This function is called by \Sabre\DAV\Server, after
95
-	 * addPlugin is called.
96
-	 *
97
-	 * This method should set up the required event subscriptions.
98
-	 *
99
-	 * @param \Sabre\DAV\Server $server
100
-	 */
101
-	public function initialize(\Sabre\DAV\Server $server) {
102
-		$server->xml->namespacesMap[self::NS_OWNCLOUD] = 'oc';
103
-		$server->xml->elementMap[self::SHARETYPES_PROPERTYNAME] = 'OCA\\DAV\\Connector\\Sabre\\ShareTypeList';
104
-		$server->protectedProperties[] = self::SHARETYPES_PROPERTYNAME;
105
-
106
-		$this->server = $server;
107
-		$this->server->on('propFind', array($this, 'handleGetProperties'));
108
-	}
109
-
110
-	/**
111
-	 * Return a list of share types for outgoing shares
112
-	 *
113
-	 * @param \OCP\Files\Node $node file node
114
-	 *
115
-	 * @return int[] array of share types
116
-	 */
117
-	private function getShareTypes(\OCP\Files\Node $node) {
118
-		$shareTypes = [];
119
-		$requestedShareTypes = [
120
-			\OCP\Share::SHARE_TYPE_USER,
121
-			\OCP\Share::SHARE_TYPE_GROUP,
122
-			\OCP\Share::SHARE_TYPE_LINK,
123
-			\OCP\Share::SHARE_TYPE_REMOTE,
124
-			\OCP\Share::SHARE_TYPE_EMAIL,
125
-		];
126
-		foreach ($requestedShareTypes as $requestedShareType) {
127
-			// one of each type is enough to find out about the types
128
-			$shares = $this->shareManager->getSharesBy(
129
-				$this->userId,
130
-				$requestedShareType,
131
-				$node,
132
-				false,
133
-				1
134
-			);
135
-			if (!empty($shares)) {
136
-				$shareTypes[] = $requestedShareType;
137
-			}
138
-		}
139
-		return $shareTypes;
140
-	}
141
-
142
-	private function getSharesTypesInFolder(\OCP\Files\Folder $node) {
143
-		$shares = $this->shareManager->getSharesInFolder(
144
-			$this->userId,
145
-			$node,
146
-			true
147
-		);
148
-
149
-		$shareTypesByFileId = [];
150
-
151
-		foreach($shares as $fileId => $sharesForFile) {
152
-			$types = array_map(function(IShare $share) {
153
-				return $share->getShareType();
154
-			}, $sharesForFile);
155
-			$types = array_unique($types);
156
-			sort($types);
157
-			$shareTypesByFileId[$fileId] = $types;
158
-		}
159
-
160
-		return $shareTypesByFileId;
161
-	}
162
-
163
-	/**
164
-	 * Adds shares to propfind response
165
-	 *
166
-	 * @param PropFind $propFind propfind object
167
-	 * @param \Sabre\DAV\INode $sabreNode sabre node
168
-	 */
169
-	public function handleGetProperties(
170
-		PropFind $propFind,
171
-		\Sabre\DAV\INode $sabreNode
172
-	) {
173
-		if (!($sabreNode instanceof \OCA\DAV\Connector\Sabre\Node)) {
174
-			return;
175
-		}
176
-
177
-		// need prefetch ?
178
-		if ($sabreNode instanceof \OCA\DAV\Connector\Sabre\Directory
179
-			&& $propFind->getDepth() !== 0
180
-			&& !is_null($propFind->getStatus(self::SHARETYPES_PROPERTYNAME))
181
-		) {
182
-			$folderNode = $this->userFolder->get($sabreNode->getPath());
183
-
184
-			$childShares = $this->getSharesTypesInFolder($folderNode);
185
-			$this->cachedFolders[] = $sabreNode->getPath();
186
-			$this->cachedShareTypes[$folderNode->getId()] = $this->getShareTypes($folderNode);
187
-			foreach ($childShares as $id => $shares) {
188
-				$this->cachedShareTypes[$id] = $shares;
189
-			}
190
-		}
191
-
192
-		$propFind->handle(self::SHARETYPES_PROPERTYNAME, function () use ($sabreNode) {
193
-			if (isset($this->cachedShareTypes[$sabreNode->getId()])) {
194
-				$shareTypes = $this->cachedShareTypes[$sabreNode->getId()];
195
-			} else {
196
-				list($parentPath,) = \Sabre\Uri\split($sabreNode->getPath());
197
-				if ($parentPath === '') {
198
-					$parentPath = '/';
199
-				}
200
-				// if we already cached the folder this file is in we know there are no shares for this file
201
-				if (array_search($parentPath, $this->cachedFolders) === false) {
202
-					$node = $this->userFolder->get($sabreNode->getPath());
203
-					$shareTypes = $this->getShareTypes($node);
204
-				} else {
205
-					return [];
206
-				}
207
-			}
208
-
209
-			return new ShareTypeList($shareTypes);
210
-		});
211
-	}
35
+    const NS_OWNCLOUD = 'http://owncloud.org/ns';
36
+    const SHARETYPES_PROPERTYNAME = '{http://owncloud.org/ns}share-types';
37
+
38
+    /**
39
+     * Reference to main server object
40
+     *
41
+     * @var \Sabre\DAV\Server
42
+     */
43
+    private $server;
44
+
45
+    /**
46
+     * @var \OCP\Share\IManager
47
+     */
48
+    private $shareManager;
49
+
50
+    /**
51
+     * @var \Sabre\DAV\Tree
52
+     */
53
+    private $tree;
54
+
55
+    /**
56
+     * @var string
57
+     */
58
+    private $userId;
59
+
60
+    /**
61
+     * @var \OCP\Files\Folder
62
+     */
63
+    private $userFolder;
64
+
65
+    /**
66
+     * @var IShare[]
67
+     */
68
+    private $cachedShareTypes;
69
+
70
+    private $cachedFolders = [];
71
+
72
+    /**
73
+     * @param \Sabre\DAV\Tree $tree tree
74
+     * @param IUserSession $userSession user session
75
+     * @param \OCP\Files\Folder $userFolder user home folder
76
+     * @param \OCP\Share\IManager $shareManager share manager
77
+     */
78
+    public function __construct(
79
+        \Sabre\DAV\Tree $tree,
80
+        IUserSession $userSession,
81
+        \OCP\Files\Folder $userFolder,
82
+        \OCP\Share\IManager $shareManager
83
+    ) {
84
+        $this->tree = $tree;
85
+        $this->shareManager = $shareManager;
86
+        $this->userFolder = $userFolder;
87
+        $this->userId = $userSession->getUser()->getUID();
88
+        $this->cachedShareTypes = [];
89
+    }
90
+
91
+    /**
92
+     * This initializes the plugin.
93
+     *
94
+     * This function is called by \Sabre\DAV\Server, after
95
+     * addPlugin is called.
96
+     *
97
+     * This method should set up the required event subscriptions.
98
+     *
99
+     * @param \Sabre\DAV\Server $server
100
+     */
101
+    public function initialize(\Sabre\DAV\Server $server) {
102
+        $server->xml->namespacesMap[self::NS_OWNCLOUD] = 'oc';
103
+        $server->xml->elementMap[self::SHARETYPES_PROPERTYNAME] = 'OCA\\DAV\\Connector\\Sabre\\ShareTypeList';
104
+        $server->protectedProperties[] = self::SHARETYPES_PROPERTYNAME;
105
+
106
+        $this->server = $server;
107
+        $this->server->on('propFind', array($this, 'handleGetProperties'));
108
+    }
109
+
110
+    /**
111
+     * Return a list of share types for outgoing shares
112
+     *
113
+     * @param \OCP\Files\Node $node file node
114
+     *
115
+     * @return int[] array of share types
116
+     */
117
+    private function getShareTypes(\OCP\Files\Node $node) {
118
+        $shareTypes = [];
119
+        $requestedShareTypes = [
120
+            \OCP\Share::SHARE_TYPE_USER,
121
+            \OCP\Share::SHARE_TYPE_GROUP,
122
+            \OCP\Share::SHARE_TYPE_LINK,
123
+            \OCP\Share::SHARE_TYPE_REMOTE,
124
+            \OCP\Share::SHARE_TYPE_EMAIL,
125
+        ];
126
+        foreach ($requestedShareTypes as $requestedShareType) {
127
+            // one of each type is enough to find out about the types
128
+            $shares = $this->shareManager->getSharesBy(
129
+                $this->userId,
130
+                $requestedShareType,
131
+                $node,
132
+                false,
133
+                1
134
+            );
135
+            if (!empty($shares)) {
136
+                $shareTypes[] = $requestedShareType;
137
+            }
138
+        }
139
+        return $shareTypes;
140
+    }
141
+
142
+    private function getSharesTypesInFolder(\OCP\Files\Folder $node) {
143
+        $shares = $this->shareManager->getSharesInFolder(
144
+            $this->userId,
145
+            $node,
146
+            true
147
+        );
148
+
149
+        $shareTypesByFileId = [];
150
+
151
+        foreach($shares as $fileId => $sharesForFile) {
152
+            $types = array_map(function(IShare $share) {
153
+                return $share->getShareType();
154
+            }, $sharesForFile);
155
+            $types = array_unique($types);
156
+            sort($types);
157
+            $shareTypesByFileId[$fileId] = $types;
158
+        }
159
+
160
+        return $shareTypesByFileId;
161
+    }
162
+
163
+    /**
164
+     * Adds shares to propfind response
165
+     *
166
+     * @param PropFind $propFind propfind object
167
+     * @param \Sabre\DAV\INode $sabreNode sabre node
168
+     */
169
+    public function handleGetProperties(
170
+        PropFind $propFind,
171
+        \Sabre\DAV\INode $sabreNode
172
+    ) {
173
+        if (!($sabreNode instanceof \OCA\DAV\Connector\Sabre\Node)) {
174
+            return;
175
+        }
176
+
177
+        // need prefetch ?
178
+        if ($sabreNode instanceof \OCA\DAV\Connector\Sabre\Directory
179
+            && $propFind->getDepth() !== 0
180
+            && !is_null($propFind->getStatus(self::SHARETYPES_PROPERTYNAME))
181
+        ) {
182
+            $folderNode = $this->userFolder->get($sabreNode->getPath());
183
+
184
+            $childShares = $this->getSharesTypesInFolder($folderNode);
185
+            $this->cachedFolders[] = $sabreNode->getPath();
186
+            $this->cachedShareTypes[$folderNode->getId()] = $this->getShareTypes($folderNode);
187
+            foreach ($childShares as $id => $shares) {
188
+                $this->cachedShareTypes[$id] = $shares;
189
+            }
190
+        }
191
+
192
+        $propFind->handle(self::SHARETYPES_PROPERTYNAME, function () use ($sabreNode) {
193
+            if (isset($this->cachedShareTypes[$sabreNode->getId()])) {
194
+                $shareTypes = $this->cachedShareTypes[$sabreNode->getId()];
195
+            } else {
196
+                list($parentPath,) = \Sabre\Uri\split($sabreNode->getPath());
197
+                if ($parentPath === '') {
198
+                    $parentPath = '/';
199
+                }
200
+                // if we already cached the folder this file is in we know there are no shares for this file
201
+                if (array_search($parentPath, $this->cachedFolders) === false) {
202
+                    $node = $this->userFolder->get($sabreNode->getPath());
203
+                    $shareTypes = $this->getShareTypes($node);
204
+                } else {
205
+                    return [];
206
+                }
207
+            }
208
+
209
+            return new ShareTypeList($shareTypes);
210
+        });
211
+    }
212 212
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/FilesPlugin.php 4 patches
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -245,7 +245,9 @@
 block discarded – undo
245 245
 	function httpGet(RequestInterface $request, ResponseInterface $response) {
246 246
 		// Only handle valid files
247 247
 		$node = $this->tree->getNodeForPath($request->getPath());
248
-		if (!($node instanceof IFile)) return;
248
+		if (!($node instanceof IFile)) {
249
+		    return;
250
+		}
249 251
 
250 252
 		// adds a 'Content-Disposition: attachment' header in case no disposition
251 253
 		// header has been set before
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -448,7 +448,7 @@
 block discarded – undo
448 448
 	 *
449 449
 	 * @param string $path source path
450 450
 	 * @param string $destination destination path
451
-	 * @return bool|void false to stop handling, void to skip this handler
451
+	 * @return null|false false to stop handling, void to skip this handler
452 452
 	 */
453 453
 	public function beforeMoveFutureFile($path, $destination) {
454 454
 		$sourceNode = $this->tree->getNodeForPath($path);
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
 		$this->server->on('propPatch', array($this, 'handleUpdateProperties'));
172 172
 		$this->server->on('afterBind', array($this, 'sendFileIdHeader'));
173 173
 		$this->server->on('afterWriteContent', array($this, 'sendFileIdHeader'));
174
-		$this->server->on('afterMethod:GET', [$this,'httpGet']);
174
+		$this->server->on('afterMethod:GET', [$this, 'httpGet']);
175 175
 		$this->server->on('afterMethod:GET', array($this, 'handleDownloadToken'));
176 176
 		$this->server->on('afterResponse', function($request, ResponseInterface $response) {
177 177
 			$body = $response->getBody();
@@ -202,11 +202,11 @@  discard block
 block discarded – undo
202 202
 		if ($sourceDir !== $destinationDir) {
203 203
 			$sourceNodeFileInfo = $sourceNode->getFileInfo();
204 204
 			if (is_null($sourceNodeFileInfo)) {
205
-				throw new NotFound($source . ' does not exist');
205
+				throw new NotFound($source.' does not exist');
206 206
 			}
207 207
 
208 208
 			if (!$sourceNodeFileInfo->isDeletable()) {
209
-				throw new Forbidden($source . " cannot be deleted");
209
+				throw new Forbidden($source." cannot be deleted");
210 210
 			}
211 211
 		}
212 212
 	}
@@ -259,10 +259,10 @@  discard block
 block discarded – undo
259 259
 					\OC\AppFramework\Http\Request::USER_AGENT_ANDROID_MOBILE_CHROME,
260 260
 					\OC\AppFramework\Http\Request::USER_AGENT_FREEBOX,
261 261
 				])) {
262
-				$response->addHeader('Content-Disposition', 'attachment; filename="' . rawurlencode($filename) . '"');
262
+				$response->addHeader('Content-Disposition', 'attachment; filename="'.rawurlencode($filename).'"');
263 263
 			} else {
264
-				$response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\'' . rawurlencode($filename)
265
-													 . '; filename="' . rawurlencode($filename) . '"');
264
+				$response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\''.rawurlencode($filename)
265
+													 . '; filename="'.rawurlencode($filename).'"');
266 266
 			}
267 267
 		}
268 268
 
@@ -337,13 +337,13 @@  discard block
 block discarded – undo
337 337
 				}
338 338
 			});
339 339
 
340
-			$propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) {
340
+			$propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function() use ($node) {
341 341
 				return json_encode($this->previewManager->isAvailable($node->getFileInfo()));
342 342
 			});
343 343
 			$propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) {
344 344
 				return $node->getSize();
345 345
 			});
346
-			$propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) {
346
+			$propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function() use ($node) {
347 347
 				return $node->getFileInfo()->getMountPoint()->getMountType();
348 348
 			});
349 349
 		}
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
 			list($path, $name) = \Sabre\HTTP\URLUtil::splitPath($filePath);
432 432
 			$info = \OC_FileChunking::decodeName($name);
433 433
 			if (!empty($info)) {
434
-				$filePath = $path . '/' . $info['name'];
434
+				$filePath = $path.'/'.$info['name'];
435 435
 			}
436 436
 		}
437 437
 
Please login to merge, or discard this patch.
Indentation   +438 added lines, -438 removed lines patch added patch discarded remove patch
@@ -49,447 +49,447 @@
 block discarded – undo
49 49
 
50 50
 class FilesPlugin extends ServerPlugin {
51 51
 
52
-	// namespace
53
-	const NS_OWNCLOUD = 'http://owncloud.org/ns';
54
-	const NS_NEXTCLOUD = 'http://nextcloud.org/ns';
55
-	const FILEID_PROPERTYNAME = '{http://owncloud.org/ns}id';
56
-	const INTERNAL_FILEID_PROPERTYNAME = '{http://owncloud.org/ns}fileid';
57
-	const PERMISSIONS_PROPERTYNAME = '{http://owncloud.org/ns}permissions';
58
-	const SHARE_PERMISSIONS_PROPERTYNAME = '{http://open-collaboration-services.org/ns}share-permissions';
59
-	const DOWNLOADURL_PROPERTYNAME = '{http://owncloud.org/ns}downloadURL';
60
-	const SIZE_PROPERTYNAME = '{http://owncloud.org/ns}size';
61
-	const GETETAG_PROPERTYNAME = '{DAV:}getetag';
62
-	const LASTMODIFIED_PROPERTYNAME = '{DAV:}lastmodified';
63
-	const OWNER_ID_PROPERTYNAME = '{http://owncloud.org/ns}owner-id';
64
-	const OWNER_DISPLAY_NAME_PROPERTYNAME = '{http://owncloud.org/ns}owner-display-name';
65
-	const CHECKSUMS_PROPERTYNAME = '{http://owncloud.org/ns}checksums';
66
-	const DATA_FINGERPRINT_PROPERTYNAME = '{http://owncloud.org/ns}data-fingerprint';
67
-	const HAS_PREVIEW_PROPERTYNAME = '{http://nextcloud.org/ns}has-preview';
68
-	const MOUNT_TYPE_PROPERTYNAME = '{http://nextcloud.org/ns}mount-type';
69
-
70
-	/**
71
-	 * Reference to main server object
72
-	 *
73
-	 * @var \Sabre\DAV\Server
74
-	 */
75
-	private $server;
76
-
77
-	/**
78
-	 * @var Tree
79
-	 */
80
-	private $tree;
81
-
82
-	/**
83
-	 * Whether this is public webdav.
84
-	 * If true, some returned information will be stripped off.
85
-	 *
86
-	 * @var bool
87
-	 */
88
-	private $isPublic;
89
-
90
-	/**
91
-	 * @var View
92
-	 */
93
-	private $fileView;
94
-
95
-	/**
96
-	 * @var bool
97
-	 */
98
-	private $downloadAttachment;
99
-
100
-	/**
101
-	 * @var IConfig
102
-	 */
103
-	private $config;
104
-
105
-	/**
106
-	 * @var IRequest
107
-	 */
108
-	private $request;
109
-
110
-	/**
111
-	 * @var IPreview
112
-	 */
113
-	private $previewManager;
114
-
115
-	/**
116
-	 * @param Tree $tree
117
-	 * @param IConfig $config
118
-	 * @param IRequest $request
119
-	 * @param IPreview $previewManager
120
-	 * @param bool $isPublic
121
-	 * @param bool $downloadAttachment
122
-	 */
123
-	public function __construct(Tree $tree,
124
-								IConfig $config,
125
-								IRequest $request,
126
-								IPreview $previewManager,
127
-								$isPublic = false,
128
-								$downloadAttachment = true) {
129
-		$this->tree = $tree;
130
-		$this->config = $config;
131
-		$this->request = $request;
132
-		$this->isPublic = $isPublic;
133
-		$this->downloadAttachment = $downloadAttachment;
134
-		$this->previewManager = $previewManager;
135
-	}
136
-
137
-	/**
138
-	 * This initializes the plugin.
139
-	 *
140
-	 * This function is called by \Sabre\DAV\Server, after
141
-	 * addPlugin is called.
142
-	 *
143
-	 * This method should set up the required event subscriptions.
144
-	 *
145
-	 * @param \Sabre\DAV\Server $server
146
-	 * @return void
147
-	 */
148
-	public function initialize(\Sabre\DAV\Server $server) {
149
-
150
-		$server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc';
151
-		$server->xml->namespaceMap[self::NS_NEXTCLOUD] = 'nc';
152
-		$server->protectedProperties[] = self::FILEID_PROPERTYNAME;
153
-		$server->protectedProperties[] = self::INTERNAL_FILEID_PROPERTYNAME;
154
-		$server->protectedProperties[] = self::PERMISSIONS_PROPERTYNAME;
155
-		$server->protectedProperties[] = self::SHARE_PERMISSIONS_PROPERTYNAME;
156
-		$server->protectedProperties[] = self::SIZE_PROPERTYNAME;
157
-		$server->protectedProperties[] = self::DOWNLOADURL_PROPERTYNAME;
158
-		$server->protectedProperties[] = self::OWNER_ID_PROPERTYNAME;
159
-		$server->protectedProperties[] = self::OWNER_DISPLAY_NAME_PROPERTYNAME;
160
-		$server->protectedProperties[] = self::CHECKSUMS_PROPERTYNAME;
161
-		$server->protectedProperties[] = self::DATA_FINGERPRINT_PROPERTYNAME;
162
-		$server->protectedProperties[] = self::HAS_PREVIEW_PROPERTYNAME;
163
-		$server->protectedProperties[] = self::MOUNT_TYPE_PROPERTYNAME;
164
-
165
-		// normally these cannot be changed (RFC4918), but we want them modifiable through PROPPATCH
166
-		$allowedProperties = ['{DAV:}getetag'];
167
-		$server->protectedProperties = array_diff($server->protectedProperties, $allowedProperties);
168
-
169
-		$this->server = $server;
170
-		$this->server->on('propFind', array($this, 'handleGetProperties'));
171
-		$this->server->on('propPatch', array($this, 'handleUpdateProperties'));
172
-		$this->server->on('afterBind', array($this, 'sendFileIdHeader'));
173
-		$this->server->on('afterWriteContent', array($this, 'sendFileIdHeader'));
174
-		$this->server->on('afterMethod:GET', [$this,'httpGet']);
175
-		$this->server->on('afterMethod:GET', array($this, 'handleDownloadToken'));
176
-		$this->server->on('afterResponse', function($request, ResponseInterface $response) {
177
-			$body = $response->getBody();
178
-			if (is_resource($body)) {
179
-				fclose($body);
180
-			}
181
-		});
182
-		$this->server->on('beforeMove', [$this, 'checkMove']);
183
-		$this->server->on('beforeMove', [$this, 'beforeMoveFutureFile']);
184
-	}
185
-
186
-	/**
187
-	 * Plugin that checks if a move can actually be performed.
188
-	 *
189
-	 * @param string $source source path
190
-	 * @param string $destination destination path
191
-	 * @throws Forbidden
192
-	 * @throws NotFound
193
-	 */
194
-	function checkMove($source, $destination) {
195
-		$sourceNode = $this->tree->getNodeForPath($source);
196
-		if (!$sourceNode instanceof Node) {
197
-			return;
198
-		}
199
-		list($sourceDir,) = \Sabre\HTTP\URLUtil::splitPath($source);
200
-		list($destinationDir,) = \Sabre\HTTP\URLUtil::splitPath($destination);
201
-
202
-		if ($sourceDir !== $destinationDir) {
203
-			$sourceNodeFileInfo = $sourceNode->getFileInfo();
204
-			if (is_null($sourceNodeFileInfo)) {
205
-				throw new NotFound($source . ' does not exist');
206
-			}
207
-
208
-			if (!$sourceNodeFileInfo->isDeletable()) {
209
-				throw new Forbidden($source . " cannot be deleted");
210
-			}
211
-		}
212
-	}
213
-
214
-	/**
215
-	 * This sets a cookie to be able to recognize the start of the download
216
-	 * the content must not be longer than 32 characters and must only contain
217
-	 * alphanumeric characters
218
-	 *
219
-	 * @param RequestInterface $request
220
-	 * @param ResponseInterface $response
221
-	 */
222
-	function handleDownloadToken(RequestInterface $request, ResponseInterface $response) {
223
-		$queryParams = $request->getQueryParameters();
224
-
225
-		/**
226
-		 * this sets a cookie to be able to recognize the start of the download
227
-		 * the content must not be longer than 32 characters and must only contain
228
-		 * alphanumeric characters
229
-		 */
230
-		if (isset($queryParams['downloadStartSecret'])) {
231
-			$token = $queryParams['downloadStartSecret'];
232
-			if (!isset($token[32])
233
-				&& preg_match('!^[a-zA-Z0-9]+$!', $token) === 1) {
234
-				// FIXME: use $response->setHeader() instead
235
-				setcookie('ocDownloadStarted', $token, time() + 20, '/');
236
-			}
237
-		}
238
-	}
239
-
240
-	/**
241
-	 * Add headers to file download
242
-	 *
243
-	 * @param RequestInterface $request
244
-	 * @param ResponseInterface $response
245
-	 */
246
-	function httpGet(RequestInterface $request, ResponseInterface $response) {
247
-		// Only handle valid files
248
-		$node = $this->tree->getNodeForPath($request->getPath());
249
-		if (!($node instanceof IFile)) return;
250
-
251
-		// adds a 'Content-Disposition: attachment' header in case no disposition
252
-		// header has been set before
253
-		if ($this->downloadAttachment &&
254
-			$response->getHeader('Content-Disposition') === null) {
255
-			$filename = $node->getName();
256
-			if ($this->request->isUserAgent(
257
-				[
258
-					\OC\AppFramework\Http\Request::USER_AGENT_IE,
259
-					\OC\AppFramework\Http\Request::USER_AGENT_ANDROID_MOBILE_CHROME,
260
-					\OC\AppFramework\Http\Request::USER_AGENT_FREEBOX,
261
-				])) {
262
-				$response->addHeader('Content-Disposition', 'attachment; filename="' . rawurlencode($filename) . '"');
263
-			} else {
264
-				$response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\'' . rawurlencode($filename)
265
-													 . '; filename="' . rawurlencode($filename) . '"');
266
-			}
267
-		}
268
-
269
-		if ($node instanceof \OCA\DAV\Connector\Sabre\File) {
270
-			//Add OC-Checksum header
271
-			/** @var $node File */
272
-			$checksum = $node->getChecksum();
273
-			if ($checksum !== null && $checksum !== '') {
274
-				$response->addHeader('OC-Checksum', $checksum);
275
-			}
276
-		}
277
-	}
278
-
279
-	/**
280
-	 * Adds all ownCloud-specific properties
281
-	 *
282
-	 * @param PropFind $propFind
283
-	 * @param \Sabre\DAV\INode $node
284
-	 * @return void
285
-	 */
286
-	public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node) {
287
-
288
-		$httpRequest = $this->server->httpRequest;
289
-
290
-		if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
291
-			/**
292
-			 * This was disabled, because it made dir listing throw an exception,
293
-			 * so users were unable to navigate into folders where one subitem
294
-			 * is blocked by the files_accesscontrol app, see:
295
-			 * https://github.com/nextcloud/files_accesscontrol/issues/65
52
+    // namespace
53
+    const NS_OWNCLOUD = 'http://owncloud.org/ns';
54
+    const NS_NEXTCLOUD = 'http://nextcloud.org/ns';
55
+    const FILEID_PROPERTYNAME = '{http://owncloud.org/ns}id';
56
+    const INTERNAL_FILEID_PROPERTYNAME = '{http://owncloud.org/ns}fileid';
57
+    const PERMISSIONS_PROPERTYNAME = '{http://owncloud.org/ns}permissions';
58
+    const SHARE_PERMISSIONS_PROPERTYNAME = '{http://open-collaboration-services.org/ns}share-permissions';
59
+    const DOWNLOADURL_PROPERTYNAME = '{http://owncloud.org/ns}downloadURL';
60
+    const SIZE_PROPERTYNAME = '{http://owncloud.org/ns}size';
61
+    const GETETAG_PROPERTYNAME = '{DAV:}getetag';
62
+    const LASTMODIFIED_PROPERTYNAME = '{DAV:}lastmodified';
63
+    const OWNER_ID_PROPERTYNAME = '{http://owncloud.org/ns}owner-id';
64
+    const OWNER_DISPLAY_NAME_PROPERTYNAME = '{http://owncloud.org/ns}owner-display-name';
65
+    const CHECKSUMS_PROPERTYNAME = '{http://owncloud.org/ns}checksums';
66
+    const DATA_FINGERPRINT_PROPERTYNAME = '{http://owncloud.org/ns}data-fingerprint';
67
+    const HAS_PREVIEW_PROPERTYNAME = '{http://nextcloud.org/ns}has-preview';
68
+    const MOUNT_TYPE_PROPERTYNAME = '{http://nextcloud.org/ns}mount-type';
69
+
70
+    /**
71
+     * Reference to main server object
72
+     *
73
+     * @var \Sabre\DAV\Server
74
+     */
75
+    private $server;
76
+
77
+    /**
78
+     * @var Tree
79
+     */
80
+    private $tree;
81
+
82
+    /**
83
+     * Whether this is public webdav.
84
+     * If true, some returned information will be stripped off.
85
+     *
86
+     * @var bool
87
+     */
88
+    private $isPublic;
89
+
90
+    /**
91
+     * @var View
92
+     */
93
+    private $fileView;
94
+
95
+    /**
96
+     * @var bool
97
+     */
98
+    private $downloadAttachment;
99
+
100
+    /**
101
+     * @var IConfig
102
+     */
103
+    private $config;
104
+
105
+    /**
106
+     * @var IRequest
107
+     */
108
+    private $request;
109
+
110
+    /**
111
+     * @var IPreview
112
+     */
113
+    private $previewManager;
114
+
115
+    /**
116
+     * @param Tree $tree
117
+     * @param IConfig $config
118
+     * @param IRequest $request
119
+     * @param IPreview $previewManager
120
+     * @param bool $isPublic
121
+     * @param bool $downloadAttachment
122
+     */
123
+    public function __construct(Tree $tree,
124
+                                IConfig $config,
125
+                                IRequest $request,
126
+                                IPreview $previewManager,
127
+                                $isPublic = false,
128
+                                $downloadAttachment = true) {
129
+        $this->tree = $tree;
130
+        $this->config = $config;
131
+        $this->request = $request;
132
+        $this->isPublic = $isPublic;
133
+        $this->downloadAttachment = $downloadAttachment;
134
+        $this->previewManager = $previewManager;
135
+    }
136
+
137
+    /**
138
+     * This initializes the plugin.
139
+     *
140
+     * This function is called by \Sabre\DAV\Server, after
141
+     * addPlugin is called.
142
+     *
143
+     * This method should set up the required event subscriptions.
144
+     *
145
+     * @param \Sabre\DAV\Server $server
146
+     * @return void
147
+     */
148
+    public function initialize(\Sabre\DAV\Server $server) {
149
+
150
+        $server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc';
151
+        $server->xml->namespaceMap[self::NS_NEXTCLOUD] = 'nc';
152
+        $server->protectedProperties[] = self::FILEID_PROPERTYNAME;
153
+        $server->protectedProperties[] = self::INTERNAL_FILEID_PROPERTYNAME;
154
+        $server->protectedProperties[] = self::PERMISSIONS_PROPERTYNAME;
155
+        $server->protectedProperties[] = self::SHARE_PERMISSIONS_PROPERTYNAME;
156
+        $server->protectedProperties[] = self::SIZE_PROPERTYNAME;
157
+        $server->protectedProperties[] = self::DOWNLOADURL_PROPERTYNAME;
158
+        $server->protectedProperties[] = self::OWNER_ID_PROPERTYNAME;
159
+        $server->protectedProperties[] = self::OWNER_DISPLAY_NAME_PROPERTYNAME;
160
+        $server->protectedProperties[] = self::CHECKSUMS_PROPERTYNAME;
161
+        $server->protectedProperties[] = self::DATA_FINGERPRINT_PROPERTYNAME;
162
+        $server->protectedProperties[] = self::HAS_PREVIEW_PROPERTYNAME;
163
+        $server->protectedProperties[] = self::MOUNT_TYPE_PROPERTYNAME;
164
+
165
+        // normally these cannot be changed (RFC4918), but we want them modifiable through PROPPATCH
166
+        $allowedProperties = ['{DAV:}getetag'];
167
+        $server->protectedProperties = array_diff($server->protectedProperties, $allowedProperties);
168
+
169
+        $this->server = $server;
170
+        $this->server->on('propFind', array($this, 'handleGetProperties'));
171
+        $this->server->on('propPatch', array($this, 'handleUpdateProperties'));
172
+        $this->server->on('afterBind', array($this, 'sendFileIdHeader'));
173
+        $this->server->on('afterWriteContent', array($this, 'sendFileIdHeader'));
174
+        $this->server->on('afterMethod:GET', [$this,'httpGet']);
175
+        $this->server->on('afterMethod:GET', array($this, 'handleDownloadToken'));
176
+        $this->server->on('afterResponse', function($request, ResponseInterface $response) {
177
+            $body = $response->getBody();
178
+            if (is_resource($body)) {
179
+                fclose($body);
180
+            }
181
+        });
182
+        $this->server->on('beforeMove', [$this, 'checkMove']);
183
+        $this->server->on('beforeMove', [$this, 'beforeMoveFutureFile']);
184
+    }
185
+
186
+    /**
187
+     * Plugin that checks if a move can actually be performed.
188
+     *
189
+     * @param string $source source path
190
+     * @param string $destination destination path
191
+     * @throws Forbidden
192
+     * @throws NotFound
193
+     */
194
+    function checkMove($source, $destination) {
195
+        $sourceNode = $this->tree->getNodeForPath($source);
196
+        if (!$sourceNode instanceof Node) {
197
+            return;
198
+        }
199
+        list($sourceDir,) = \Sabre\HTTP\URLUtil::splitPath($source);
200
+        list($destinationDir,) = \Sabre\HTTP\URLUtil::splitPath($destination);
201
+
202
+        if ($sourceDir !== $destinationDir) {
203
+            $sourceNodeFileInfo = $sourceNode->getFileInfo();
204
+            if (is_null($sourceNodeFileInfo)) {
205
+                throw new NotFound($source . ' does not exist');
206
+            }
207
+
208
+            if (!$sourceNodeFileInfo->isDeletable()) {
209
+                throw new Forbidden($source . " cannot be deleted");
210
+            }
211
+        }
212
+    }
213
+
214
+    /**
215
+     * This sets a cookie to be able to recognize the start of the download
216
+     * the content must not be longer than 32 characters and must only contain
217
+     * alphanumeric characters
218
+     *
219
+     * @param RequestInterface $request
220
+     * @param ResponseInterface $response
221
+     */
222
+    function handleDownloadToken(RequestInterface $request, ResponseInterface $response) {
223
+        $queryParams = $request->getQueryParameters();
224
+
225
+        /**
226
+         * this sets a cookie to be able to recognize the start of the download
227
+         * the content must not be longer than 32 characters and must only contain
228
+         * alphanumeric characters
229
+         */
230
+        if (isset($queryParams['downloadStartSecret'])) {
231
+            $token = $queryParams['downloadStartSecret'];
232
+            if (!isset($token[32])
233
+                && preg_match('!^[a-zA-Z0-9]+$!', $token) === 1) {
234
+                // FIXME: use $response->setHeader() instead
235
+                setcookie('ocDownloadStarted', $token, time() + 20, '/');
236
+            }
237
+        }
238
+    }
239
+
240
+    /**
241
+     * Add headers to file download
242
+     *
243
+     * @param RequestInterface $request
244
+     * @param ResponseInterface $response
245
+     */
246
+    function httpGet(RequestInterface $request, ResponseInterface $response) {
247
+        // Only handle valid files
248
+        $node = $this->tree->getNodeForPath($request->getPath());
249
+        if (!($node instanceof IFile)) return;
250
+
251
+        // adds a 'Content-Disposition: attachment' header in case no disposition
252
+        // header has been set before
253
+        if ($this->downloadAttachment &&
254
+            $response->getHeader('Content-Disposition') === null) {
255
+            $filename = $node->getName();
256
+            if ($this->request->isUserAgent(
257
+                [
258
+                    \OC\AppFramework\Http\Request::USER_AGENT_IE,
259
+                    \OC\AppFramework\Http\Request::USER_AGENT_ANDROID_MOBILE_CHROME,
260
+                    \OC\AppFramework\Http\Request::USER_AGENT_FREEBOX,
261
+                ])) {
262
+                $response->addHeader('Content-Disposition', 'attachment; filename="' . rawurlencode($filename) . '"');
263
+            } else {
264
+                $response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\'' . rawurlencode($filename)
265
+                                                        . '; filename="' . rawurlencode($filename) . '"');
266
+            }
267
+        }
268
+
269
+        if ($node instanceof \OCA\DAV\Connector\Sabre\File) {
270
+            //Add OC-Checksum header
271
+            /** @var $node File */
272
+            $checksum = $node->getChecksum();
273
+            if ($checksum !== null && $checksum !== '') {
274
+                $response->addHeader('OC-Checksum', $checksum);
275
+            }
276
+        }
277
+    }
278
+
279
+    /**
280
+     * Adds all ownCloud-specific properties
281
+     *
282
+     * @param PropFind $propFind
283
+     * @param \Sabre\DAV\INode $node
284
+     * @return void
285
+     */
286
+    public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node) {
287
+
288
+        $httpRequest = $this->server->httpRequest;
289
+
290
+        if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
291
+            /**
292
+             * This was disabled, because it made dir listing throw an exception,
293
+             * so users were unable to navigate into folders where one subitem
294
+             * is blocked by the files_accesscontrol app, see:
295
+             * https://github.com/nextcloud/files_accesscontrol/issues/65
296 296
 			if (!$node->getFileInfo()->isReadable()) {
297 297
 				// avoid detecting files through this means
298 298
 				throw new NotFound();
299 299
 			}
300
-			 */
301
-
302
-			$propFind->handle(self::FILEID_PROPERTYNAME, function() use ($node) {
303
-				return $node->getFileId();
304
-			});
305
-
306
-			$propFind->handle(self::INTERNAL_FILEID_PROPERTYNAME, function() use ($node) {
307
-				return $node->getInternalFileId();
308
-			});
309
-
310
-			$propFind->handle(self::PERMISSIONS_PROPERTYNAME, function() use ($node) {
311
-				$perms = $node->getDavPermissions();
312
-				if ($this->isPublic) {
313
-					// remove mount information
314
-					$perms = str_replace(['S', 'M'], '', $perms);
315
-				}
316
-				return $perms;
317
-			});
318
-
319
-			$propFind->handle(self::SHARE_PERMISSIONS_PROPERTYNAME, function() use ($node, $httpRequest) {
320
-				return $node->getSharePermissions(
321
-					$httpRequest->getRawServerValue('PHP_AUTH_USER')
322
-				);
323
-			});
324
-
325
-			$propFind->handle(self::GETETAG_PROPERTYNAME, function() use ($node) {
326
-				return $node->getETag();
327
-			});
328
-
329
-			$propFind->handle(self::OWNER_ID_PROPERTYNAME, function() use ($node) {
330
-				$owner = $node->getOwner();
331
-				if (!$owner) {
332
-					return null;
333
-				} else {
334
-					return $owner->getUID();
335
-				}
336
-			});
337
-			$propFind->handle(self::OWNER_DISPLAY_NAME_PROPERTYNAME, function() use ($node) {
338
-				$owner = $node->getOwner();
339
-				if (!$owner) {
340
-					return null;
341
-				} else {
342
-					return $owner->getDisplayName();
343
-				}
344
-			});
345
-
346
-			$propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) {
347
-				return json_encode($this->previewManager->isAvailable($node->getFileInfo()));
348
-			});
349
-			$propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) {
350
-				return $node->getSize();
351
-			});
352
-			$propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) {
353
-				return $node->getFileInfo()->getMountPoint()->getMountType();
354
-			});
355
-		}
356
-
357
-		if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
358
-			$propFind->handle(self::DATA_FINGERPRINT_PROPERTYNAME, function() use ($node) {
359
-				return $this->config->getSystemValue('data-fingerprint', '');
360
-			});
361
-		}
362
-
363
-		if ($node instanceof \OCA\DAV\Connector\Sabre\File) {
364
-			$propFind->handle(self::DOWNLOADURL_PROPERTYNAME, function() use ($node) {
365
-				/** @var $node \OCA\DAV\Connector\Sabre\File */
366
-				try {
367
-					$directDownloadUrl = $node->getDirectDownload();
368
-					if (isset($directDownloadUrl['url'])) {
369
-						return $directDownloadUrl['url'];
370
-					}
371
-				} catch (StorageNotAvailableException $e) {
372
-					return false;
373
-				} catch (ForbiddenException $e) {
374
-					return false;
375
-				}
376
-				return false;
377
-			});
378
-
379
-			$propFind->handle(self::CHECKSUMS_PROPERTYNAME, function() use ($node) {
380
-				$checksum = $node->getChecksum();
381
-				if ($checksum === NULL || $checksum === '') {
382
-					return null;
383
-				}
384
-
385
-				return new ChecksumList($checksum);
386
-			});
387
-
388
-		}
389
-
390
-		if ($node instanceof \OCA\DAV\Connector\Sabre\Directory) {
391
-			$propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) {
392
-				return $node->getSize();
393
-			});
394
-		}
395
-	}
396
-
397
-	/**
398
-	 * Update ownCloud-specific properties
399
-	 *
400
-	 * @param string $path
401
-	 * @param PropPatch $propPatch
402
-	 *
403
-	 * @return void
404
-	 */
405
-	public function handleUpdateProperties($path, PropPatch $propPatch) {
406
-		$node = $this->tree->getNodeForPath($path);
407
-		if (!($node instanceof \OCA\DAV\Connector\Sabre\Node)) {
408
-			return;
409
-		}
410
-
411
-		$propPatch->handle(self::LASTMODIFIED_PROPERTYNAME, function($time) use ($node) {
412
-			if (empty($time)) {
413
-				return false;
414
-			}
415
-			$node->touch($time);
416
-			return true;
417
-		});
418
-		$propPatch->handle(self::GETETAG_PROPERTYNAME, function($etag) use ($node) {
419
-			if (empty($etag)) {
420
-				return false;
421
-			}
422
-			if ($node->setEtag($etag) !== -1) {
423
-				return true;
424
-			}
425
-			return false;
426
-		});
427
-	}
428
-
429
-	/**
430
-	 * @param string $filePath
431
-	 * @param \Sabre\DAV\INode $node
432
-	 * @throws \Sabre\DAV\Exception\BadRequest
433
-	 */
434
-	public function sendFileIdHeader($filePath, \Sabre\DAV\INode $node = null) {
435
-		// chunked upload handling
436
-		if (isset($_SERVER['HTTP_OC_CHUNKED'])) {
437
-			list($path, $name) = \Sabre\HTTP\URLUtil::splitPath($filePath);
438
-			$info = \OC_FileChunking::decodeName($name);
439
-			if (!empty($info)) {
440
-				$filePath = $path . '/' . $info['name'];
441
-			}
442
-		}
443
-
444
-		// we get the node for the given $filePath here because in case of afterCreateFile $node is the parent folder
445
-		if (!$this->server->tree->nodeExists($filePath)) {
446
-			return;
447
-		}
448
-		$node = $this->server->tree->getNodeForPath($filePath);
449
-		if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
450
-			$fileId = $node->getFileId();
451
-			if (!is_null($fileId)) {
452
-				$this->server->httpResponse->setHeader('OC-FileId', $fileId);
453
-			}
454
-		}
455
-	}
456
-
457
-	/**
458
-	 * Move handler for future file.
459
-	 *
460
-	 * This overrides the default move behavior to prevent Sabre
461
-	 * to delete the target file before moving. Because deleting would
462
-	 * lose the file id and metadata.
463
-	 *
464
-	 * @param string $path source path
465
-	 * @param string $destination destination path
466
-	 * @return bool|void false to stop handling, void to skip this handler
467
-	 */
468
-	public function beforeMoveFutureFile($path, $destination) {
469
-		$sourceNode = $this->tree->getNodeForPath($path);
470
-		if (!$sourceNode instanceof FutureFile) {
471
-			// skip handling as the source is not a chunked FutureFile
472
-			return;
473
-		}
474
-
475
-		if (!$this->tree->nodeExists($destination)) {
476
-			// skip and let the default handler do its work
477
-			return;
478
-		}
479
-
480
-		// do a move manually, skipping Sabre's default "delete" for existing nodes
481
-		$this->tree->move($path, $destination);
482
-
483
-		// trigger all default events (copied from CorePlugin::move)
484
-		$this->server->emit('afterMove', [$path, $destination]);
485
-		$this->server->emit('afterUnbind', [$path]);
486
-		$this->server->emit('afterBind', [$destination]);
487
-
488
-		$response = $this->server->httpResponse;
489
-		$response->setHeader('Content-Length', '0');
490
-		$response->setStatus(204);
491
-
492
-		return false;
493
-	}
300
+             */
301
+
302
+            $propFind->handle(self::FILEID_PROPERTYNAME, function() use ($node) {
303
+                return $node->getFileId();
304
+            });
305
+
306
+            $propFind->handle(self::INTERNAL_FILEID_PROPERTYNAME, function() use ($node) {
307
+                return $node->getInternalFileId();
308
+            });
309
+
310
+            $propFind->handle(self::PERMISSIONS_PROPERTYNAME, function() use ($node) {
311
+                $perms = $node->getDavPermissions();
312
+                if ($this->isPublic) {
313
+                    // remove mount information
314
+                    $perms = str_replace(['S', 'M'], '', $perms);
315
+                }
316
+                return $perms;
317
+            });
318
+
319
+            $propFind->handle(self::SHARE_PERMISSIONS_PROPERTYNAME, function() use ($node, $httpRequest) {
320
+                return $node->getSharePermissions(
321
+                    $httpRequest->getRawServerValue('PHP_AUTH_USER')
322
+                );
323
+            });
324
+
325
+            $propFind->handle(self::GETETAG_PROPERTYNAME, function() use ($node) {
326
+                return $node->getETag();
327
+            });
328
+
329
+            $propFind->handle(self::OWNER_ID_PROPERTYNAME, function() use ($node) {
330
+                $owner = $node->getOwner();
331
+                if (!$owner) {
332
+                    return null;
333
+                } else {
334
+                    return $owner->getUID();
335
+                }
336
+            });
337
+            $propFind->handle(self::OWNER_DISPLAY_NAME_PROPERTYNAME, function() use ($node) {
338
+                $owner = $node->getOwner();
339
+                if (!$owner) {
340
+                    return null;
341
+                } else {
342
+                    return $owner->getDisplayName();
343
+                }
344
+            });
345
+
346
+            $propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) {
347
+                return json_encode($this->previewManager->isAvailable($node->getFileInfo()));
348
+            });
349
+            $propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) {
350
+                return $node->getSize();
351
+            });
352
+            $propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) {
353
+                return $node->getFileInfo()->getMountPoint()->getMountType();
354
+            });
355
+        }
356
+
357
+        if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
358
+            $propFind->handle(self::DATA_FINGERPRINT_PROPERTYNAME, function() use ($node) {
359
+                return $this->config->getSystemValue('data-fingerprint', '');
360
+            });
361
+        }
362
+
363
+        if ($node instanceof \OCA\DAV\Connector\Sabre\File) {
364
+            $propFind->handle(self::DOWNLOADURL_PROPERTYNAME, function() use ($node) {
365
+                /** @var $node \OCA\DAV\Connector\Sabre\File */
366
+                try {
367
+                    $directDownloadUrl = $node->getDirectDownload();
368
+                    if (isset($directDownloadUrl['url'])) {
369
+                        return $directDownloadUrl['url'];
370
+                    }
371
+                } catch (StorageNotAvailableException $e) {
372
+                    return false;
373
+                } catch (ForbiddenException $e) {
374
+                    return false;
375
+                }
376
+                return false;
377
+            });
378
+
379
+            $propFind->handle(self::CHECKSUMS_PROPERTYNAME, function() use ($node) {
380
+                $checksum = $node->getChecksum();
381
+                if ($checksum === NULL || $checksum === '') {
382
+                    return null;
383
+                }
384
+
385
+                return new ChecksumList($checksum);
386
+            });
387
+
388
+        }
389
+
390
+        if ($node instanceof \OCA\DAV\Connector\Sabre\Directory) {
391
+            $propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) {
392
+                return $node->getSize();
393
+            });
394
+        }
395
+    }
396
+
397
+    /**
398
+     * Update ownCloud-specific properties
399
+     *
400
+     * @param string $path
401
+     * @param PropPatch $propPatch
402
+     *
403
+     * @return void
404
+     */
405
+    public function handleUpdateProperties($path, PropPatch $propPatch) {
406
+        $node = $this->tree->getNodeForPath($path);
407
+        if (!($node instanceof \OCA\DAV\Connector\Sabre\Node)) {
408
+            return;
409
+        }
410
+
411
+        $propPatch->handle(self::LASTMODIFIED_PROPERTYNAME, function($time) use ($node) {
412
+            if (empty($time)) {
413
+                return false;
414
+            }
415
+            $node->touch($time);
416
+            return true;
417
+        });
418
+        $propPatch->handle(self::GETETAG_PROPERTYNAME, function($etag) use ($node) {
419
+            if (empty($etag)) {
420
+                return false;
421
+            }
422
+            if ($node->setEtag($etag) !== -1) {
423
+                return true;
424
+            }
425
+            return false;
426
+        });
427
+    }
428
+
429
+    /**
430
+     * @param string $filePath
431
+     * @param \Sabre\DAV\INode $node
432
+     * @throws \Sabre\DAV\Exception\BadRequest
433
+     */
434
+    public function sendFileIdHeader($filePath, \Sabre\DAV\INode $node = null) {
435
+        // chunked upload handling
436
+        if (isset($_SERVER['HTTP_OC_CHUNKED'])) {
437
+            list($path, $name) = \Sabre\HTTP\URLUtil::splitPath($filePath);
438
+            $info = \OC_FileChunking::decodeName($name);
439
+            if (!empty($info)) {
440
+                $filePath = $path . '/' . $info['name'];
441
+            }
442
+        }
443
+
444
+        // we get the node for the given $filePath here because in case of afterCreateFile $node is the parent folder
445
+        if (!$this->server->tree->nodeExists($filePath)) {
446
+            return;
447
+        }
448
+        $node = $this->server->tree->getNodeForPath($filePath);
449
+        if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
450
+            $fileId = $node->getFileId();
451
+            if (!is_null($fileId)) {
452
+                $this->server->httpResponse->setHeader('OC-FileId', $fileId);
453
+            }
454
+        }
455
+    }
456
+
457
+    /**
458
+     * Move handler for future file.
459
+     *
460
+     * This overrides the default move behavior to prevent Sabre
461
+     * to delete the target file before moving. Because deleting would
462
+     * lose the file id and metadata.
463
+     *
464
+     * @param string $path source path
465
+     * @param string $destination destination path
466
+     * @return bool|void false to stop handling, void to skip this handler
467
+     */
468
+    public function beforeMoveFutureFile($path, $destination) {
469
+        $sourceNode = $this->tree->getNodeForPath($path);
470
+        if (!$sourceNode instanceof FutureFile) {
471
+            // skip handling as the source is not a chunked FutureFile
472
+            return;
473
+        }
474
+
475
+        if (!$this->tree->nodeExists($destination)) {
476
+            // skip and let the default handler do its work
477
+            return;
478
+        }
479
+
480
+        // do a move manually, skipping Sabre's default "delete" for existing nodes
481
+        $this->tree->move($path, $destination);
482
+
483
+        // trigger all default events (copied from CorePlugin::move)
484
+        $this->server->emit('afterMove', [$path, $destination]);
485
+        $this->server->emit('afterUnbind', [$path]);
486
+        $this->server->emit('afterBind', [$destination]);
487
+
488
+        $response = $this->server->httpResponse;
489
+        $response->setHeader('Content-Length', '0');
490
+        $response->setStatus(204);
491
+
492
+        return false;
493
+    }
494 494
 
495 495
 }
Please login to merge, or discard this patch.