Completed
Push — master ( 883574...c5dbe1 )
by Morris
13:12
created
apps/dav/lib/Server.php 1 patch
Indentation   +174 added lines, -174 removed lines patch added patch discarded remove patch
@@ -60,202 +60,202 @@
 block discarded – undo
60 60
 
61 61
 class Server {
62 62
 
63
-	/** @var IRequest */
64
-	private $request;
63
+    /** @var IRequest */
64
+    private $request;
65 65
 
66
-	/** @var  string */
67
-	private $baseUri;
66
+    /** @var  string */
67
+    private $baseUri;
68 68
 
69
-	/** @var Connector\Sabre\Server  */
70
-	private $server;
69
+    /** @var Connector\Sabre\Server  */
70
+    private $server;
71 71
 
72
-	public function __construct(IRequest $request, $baseUri) {
73
-		$this->request = $request;
74
-		$this->baseUri = $baseUri;
75
-		$logger = \OC::$server->getLogger();
76
-		$mailer = \OC::$server->getMailer();
77
-		$dispatcher = \OC::$server->getEventDispatcher();
78
-		$timezone = new TimeFactory();
72
+    public function __construct(IRequest $request, $baseUri) {
73
+        $this->request = $request;
74
+        $this->baseUri = $baseUri;
75
+        $logger = \OC::$server->getLogger();
76
+        $mailer = \OC::$server->getMailer();
77
+        $dispatcher = \OC::$server->getEventDispatcher();
78
+        $timezone = new TimeFactory();
79 79
 
80
-		$root = new RootCollection();
81
-		$this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root));
80
+        $root = new RootCollection();
81
+        $this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root));
82 82
 
83
-		// Add maintenance plugin
84
-		$this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig()));
83
+        // Add maintenance plugin
84
+        $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig()));
85 85
 
86
-		// Backends
87
-		$authBackend = new Auth(
88
-			\OC::$server->getSession(),
89
-			\OC::$server->getUserSession(),
90
-			\OC::$server->getRequest(),
91
-			\OC::$server->getTwoFactorAuthManager(),
92
-			\OC::$server->getBruteForceThrottler()
93
-		);
86
+        // Backends
87
+        $authBackend = new Auth(
88
+            \OC::$server->getSession(),
89
+            \OC::$server->getUserSession(),
90
+            \OC::$server->getRequest(),
91
+            \OC::$server->getTwoFactorAuthManager(),
92
+            \OC::$server->getBruteForceThrottler()
93
+        );
94 94
 
95
-		// Set URL explicitly due to reverse-proxy situations
96
-		$this->server->httpRequest->setUrl($this->request->getRequestUri());
97
-		$this->server->setBaseUri($this->baseUri);
95
+        // Set URL explicitly due to reverse-proxy situations
96
+        $this->server->httpRequest->setUrl($this->request->getRequestUri());
97
+        $this->server->setBaseUri($this->baseUri);
98 98
 
99
-		$this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig()));
100
-		$authPlugin = new Plugin();
101
-		$authPlugin->addBackend(new PublicAuth());
102
-		$this->server->addPlugin($authPlugin);
99
+        $this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig()));
100
+        $authPlugin = new Plugin();
101
+        $authPlugin->addBackend(new PublicAuth());
102
+        $this->server->addPlugin($authPlugin);
103 103
 
104
-		// allow setup of additional auth backends
105
-		$event = new SabrePluginEvent($this->server);
106
-		$dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event);
104
+        // allow setup of additional auth backends
105
+        $event = new SabrePluginEvent($this->server);
106
+        $dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event);
107 107
 
108
-		$bearerAuthBackend = new BearerAuth(
109
-			\OC::$server->getUserSession(),
110
-			\OC::$server->getSession(),
111
-			\OC::$server->getRequest()
112
-		);
113
-		$authPlugin->addBackend($bearerAuthBackend);
114
-		// because we are throwing exceptions this plugin has to be the last one
115
-		$authPlugin->addBackend($authBackend);
108
+        $bearerAuthBackend = new BearerAuth(
109
+            \OC::$server->getUserSession(),
110
+            \OC::$server->getSession(),
111
+            \OC::$server->getRequest()
112
+        );
113
+        $authPlugin->addBackend($bearerAuthBackend);
114
+        // because we are throwing exceptions this plugin has to be the last one
115
+        $authPlugin->addBackend($authBackend);
116 116
 
117
-		// debugging
118
-		if(\OC::$server->getConfig()->getSystemValue('debug', false)) {
119
-			$this->server->addPlugin(new \Sabre\DAV\Browser\Plugin());
120
-		} else {
121
-			$this->server->addPlugin(new DummyGetResponsePlugin());
122
-		}
117
+        // debugging
118
+        if(\OC::$server->getConfig()->getSystemValue('debug', false)) {
119
+            $this->server->addPlugin(new \Sabre\DAV\Browser\Plugin());
120
+        } else {
121
+            $this->server->addPlugin(new DummyGetResponsePlugin());
122
+        }
123 123
 
124
-		$this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger));
125
-		$this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin());
126
-		$this->server->addPlugin(new \Sabre\DAV\Sync\Plugin());
124
+        $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger));
125
+        $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin());
126
+        $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin());
127 127
 
128
-		// acl
129
-		$acl = new DavAclPlugin();
130
-		$acl->principalCollectionSet = [
131
-			'principals/users', 'principals/groups'
132
-		];
133
-		$acl->defaultUsernamePath = 'principals/users';
134
-		$this->server->addPlugin($acl);
128
+        // acl
129
+        $acl = new DavAclPlugin();
130
+        $acl->principalCollectionSet = [
131
+            'principals/users', 'principals/groups'
132
+        ];
133
+        $acl->defaultUsernamePath = 'principals/users';
134
+        $this->server->addPlugin($acl);
135 135
 
136
-		// calendar plugins
137
-		$this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin());
138
-		$this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin());
139
-		$this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin());
140
-		$this->server->addPlugin(new IMipPlugin($mailer, $logger, $timezone));
141
-		$this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin());
142
-		$this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin());
143
-		$this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest()));
144
-		$this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin(
145
-			\OC::$server->getConfig(),
146
-			\OC::$server->getURLGenerator()
147
-		));
136
+        // calendar plugins
137
+        $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin());
138
+        $this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin());
139
+        $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin());
140
+        $this->server->addPlugin(new IMipPlugin($mailer, $logger, $timezone));
141
+        $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin());
142
+        $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin());
143
+        $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest()));
144
+        $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin(
145
+            \OC::$server->getConfig(),
146
+            \OC::$server->getURLGenerator()
147
+        ));
148 148
 
149
-		// addressbook plugins
150
-		$this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin());
151
-		$this->server->addPlugin(new VCFExportPlugin());
152
-		$this->server->addPlugin(new ImageExportPlugin(new PhotoCache(\OC::$server->getAppDataDir('dav-photocache'))));
149
+        // addressbook plugins
150
+        $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin());
151
+        $this->server->addPlugin(new VCFExportPlugin());
152
+        $this->server->addPlugin(new ImageExportPlugin(new PhotoCache(\OC::$server->getAppDataDir('dav-photocache'))));
153 153
 
154
-		// system tags plugins
155
-		$this->server->addPlugin(new SystemTagPlugin(
156
-			\OC::$server->getSystemTagManager(),
157
-			\OC::$server->getGroupManager(),
158
-			\OC::$server->getUserSession()
159
-		));
154
+        // system tags plugins
155
+        $this->server->addPlugin(new SystemTagPlugin(
156
+            \OC::$server->getSystemTagManager(),
157
+            \OC::$server->getGroupManager(),
158
+            \OC::$server->getUserSession()
159
+        ));
160 160
 
161
-		// comments plugin
162
-		$this->server->addPlugin(new CommentsPlugin(
163
-			\OC::$server->getCommentsManager(),
164
-			\OC::$server->getUserSession()
165
-		));
161
+        // comments plugin
162
+        $this->server->addPlugin(new CommentsPlugin(
163
+            \OC::$server->getCommentsManager(),
164
+            \OC::$server->getUserSession()
165
+        ));
166 166
 
167
-		$this->server->addPlugin(new CopyEtagHeaderPlugin());
167
+        $this->server->addPlugin(new CopyEtagHeaderPlugin());
168 168
 
169
-		// allow setup of additional plugins
170
-		$dispatcher->dispatch('OCA\DAV\Connector\Sabre::addPlugin', $event);
169
+        // allow setup of additional plugins
170
+        $dispatcher->dispatch('OCA\DAV\Connector\Sabre::addPlugin', $event);
171 171
 
172
-		// Some WebDAV clients do require Class 2 WebDAV support (locking), since
173
-		// we do not provide locking we emulate it using a fake locking plugin.
174
-		if($request->isUserAgent([
175
-			'/WebDAVFS/',
176
-			'/Microsoft Office OneNote 2013/',
177
-			'/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601
178
-		])) {
179
-			$this->server->addPlugin(new FakeLockerPlugin());
180
-		}
172
+        // Some WebDAV clients do require Class 2 WebDAV support (locking), since
173
+        // we do not provide locking we emulate it using a fake locking plugin.
174
+        if($request->isUserAgent([
175
+            '/WebDAVFS/',
176
+            '/Microsoft Office OneNote 2013/',
177
+            '/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601
178
+        ])) {
179
+            $this->server->addPlugin(new FakeLockerPlugin());
180
+        }
181 181
 
182
-		if (BrowserErrorPagePlugin::isBrowserRequest($request)) {
183
-			$this->server->addPlugin(new BrowserErrorPagePlugin());
184
-		}
182
+        if (BrowserErrorPagePlugin::isBrowserRequest($request)) {
183
+            $this->server->addPlugin(new BrowserErrorPagePlugin());
184
+        }
185 185
 
186
-		// wait with registering these until auth is handled and the filesystem is setup
187
-		$this->server->on('beforeMethod', function () {
188
-			// custom properties plugin must be the last one
189
-			$userSession = \OC::$server->getUserSession();
190
-			$user = $userSession->getUser();
191
-			if ($user !== null) {
192
-				$view = \OC\Files\Filesystem::getView();
193
-				$this->server->addPlugin(
194
-					new FilesPlugin(
195
-						$this->server->tree,
196
-						\OC::$server->getConfig(),
197
-						$this->request,
198
-						\OC::$server->getPreviewManager(),
199
-						false,
200
-						!\OC::$server->getConfig()->getSystemValue('debug', false)
201
-					)
202
-				);
186
+        // wait with registering these until auth is handled and the filesystem is setup
187
+        $this->server->on('beforeMethod', function () {
188
+            // custom properties plugin must be the last one
189
+            $userSession = \OC::$server->getUserSession();
190
+            $user = $userSession->getUser();
191
+            if ($user !== null) {
192
+                $view = \OC\Files\Filesystem::getView();
193
+                $this->server->addPlugin(
194
+                    new FilesPlugin(
195
+                        $this->server->tree,
196
+                        \OC::$server->getConfig(),
197
+                        $this->request,
198
+                        \OC::$server->getPreviewManager(),
199
+                        false,
200
+                        !\OC::$server->getConfig()->getSystemValue('debug', false)
201
+                    )
202
+                );
203 203
 
204
-				$this->server->addPlugin(
205
-					new \Sabre\DAV\PropertyStorage\Plugin(
206
-						new CustomPropertiesBackend(
207
-							$this->server->tree,
208
-							\OC::$server->getDatabaseConnection(),
209
-							\OC::$server->getUserSession()->getUser()
210
-						)
211
-					)
212
-				);
213
-				if ($view !== null) {
214
-					$this->server->addPlugin(
215
-						new QuotaPlugin($view, false));
216
-				}
217
-				$this->server->addPlugin(
218
-					new TagsPlugin(
219
-						$this->server->tree, \OC::$server->getTagManager()
220
-					)
221
-				);
222
-				// TODO: switch to LazyUserFolder
223
-				$userFolder = \OC::$server->getUserFolder();
224
-				$this->server->addPlugin(new SharesPlugin(
225
-					$this->server->tree,
226
-					$userSession,
227
-					$userFolder,
228
-					\OC::$server->getShareManager()
229
-				));
230
-				$this->server->addPlugin(new CommentPropertiesPlugin(
231
-					\OC::$server->getCommentsManager(),
232
-					$userSession
233
-				));
234
-				$this->server->addPlugin(new \OCA\DAV\CalDAV\Search\SearchPlugin());
235
-				if ($view !== null) {
236
-					$this->server->addPlugin(new FilesReportPlugin(
237
-						$this->server->tree,
238
-						$view,
239
-						\OC::$server->getSystemTagManager(),
240
-						\OC::$server->getSystemTagObjectMapper(),
241
-						\OC::$server->getTagManager(),
242
-						$userSession,
243
-						\OC::$server->getGroupManager(),
244
-						$userFolder
245
-					));
246
-					$this->server->addPlugin(new SearchPlugin(new \OCA\DAV\Files\FileSearchBackend(
247
-						$this->server->tree,
248
-						$user,
249
-						\OC::$server->getRootFolder(),
250
-						\OC::$server->getShareManager(),
251
-						$view
252
-					)));
253
-				}
254
-			}
255
-		});
256
-	}
204
+                $this->server->addPlugin(
205
+                    new \Sabre\DAV\PropertyStorage\Plugin(
206
+                        new CustomPropertiesBackend(
207
+                            $this->server->tree,
208
+                            \OC::$server->getDatabaseConnection(),
209
+                            \OC::$server->getUserSession()->getUser()
210
+                        )
211
+                    )
212
+                );
213
+                if ($view !== null) {
214
+                    $this->server->addPlugin(
215
+                        new QuotaPlugin($view, false));
216
+                }
217
+                $this->server->addPlugin(
218
+                    new TagsPlugin(
219
+                        $this->server->tree, \OC::$server->getTagManager()
220
+                    )
221
+                );
222
+                // TODO: switch to LazyUserFolder
223
+                $userFolder = \OC::$server->getUserFolder();
224
+                $this->server->addPlugin(new SharesPlugin(
225
+                    $this->server->tree,
226
+                    $userSession,
227
+                    $userFolder,
228
+                    \OC::$server->getShareManager()
229
+                ));
230
+                $this->server->addPlugin(new CommentPropertiesPlugin(
231
+                    \OC::$server->getCommentsManager(),
232
+                    $userSession
233
+                ));
234
+                $this->server->addPlugin(new \OCA\DAV\CalDAV\Search\SearchPlugin());
235
+                if ($view !== null) {
236
+                    $this->server->addPlugin(new FilesReportPlugin(
237
+                        $this->server->tree,
238
+                        $view,
239
+                        \OC::$server->getSystemTagManager(),
240
+                        \OC::$server->getSystemTagObjectMapper(),
241
+                        \OC::$server->getTagManager(),
242
+                        $userSession,
243
+                        \OC::$server->getGroupManager(),
244
+                        $userFolder
245
+                    ));
246
+                    $this->server->addPlugin(new SearchPlugin(new \OCA\DAV\Files\FileSearchBackend(
247
+                        $this->server->tree,
248
+                        $user,
249
+                        \OC::$server->getRootFolder(),
250
+                        \OC::$server->getShareManager(),
251
+                        $view
252
+                    )));
253
+                }
254
+            }
255
+        });
256
+    }
257 257
 
258
-	public function exec() {
259
-		$this->server->exec();
260
-	}
258
+    public function exec() {
259
+        $this->server->exec();
260
+    }
261 261
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/ServerFactory.php 2 patches
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, true));
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, true));
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.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 		$server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin());
119 119
 		// Some WebDAV clients do require Class 2 WebDAV support (locking), since
120 120
 		// we do not provide locking we emulate it using a fake locking plugin.
121
-		if($this->request->isUserAgent([
121
+		if ($this->request->isUserAgent([
122 122
 				'/WebDAVFS/',
123 123
 				'/Microsoft Office OneNote 2013/',
124 124
 				'/Microsoft-WebDAV-MiniRedir/',
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
 		}
132 132
 
133 133
 		// wait with registering these until auth is handled and the filesystem is setup
134
-		$server->on('beforeMethod', function () use ($server, $objectTree, $viewCallBack) {
134
+		$server->on('beforeMethod', function() use ($server, $objectTree, $viewCallBack) {
135 135
 			// ensure the skeleton is copied
136 136
 			$userFolder = \OC::$server->getUserFolder();
137 137
 			
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
 			);
164 164
 			$server->addPlugin(new \OCA\DAV\Connector\Sabre\QuotaPlugin($view, true));
165 165
 
166
-			if($this->userSession->isLoggedIn()) {
166
+			if ($this->userSession->isLoggedIn()) {
167 167
 				$server->addPlugin(new \OCA\DAV\Connector\Sabre\TagsPlugin($objectTree, $this->tagManager));
168 168
 				$server->addPlugin(new \OCA\DAV\Connector\Sabre\SharesPlugin(
169 169
 					$objectTree,
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/QuotaPlugin.php 2 patches
Indentation   +168 added lines, -168 removed lines patch added patch discarded remove patch
@@ -44,172 +44,172 @@
 block discarded – undo
44 44
  */
45 45
 class QuotaPlugin extends \Sabre\DAV\ServerPlugin {
46 46
 
47
-	/** @var \OC\Files\View */
48
-	private $view;
49
-
50
-	/**
51
-	 * Reference to main server object
52
-	 *
53
-	 * @var \Sabre\DAV\Server
54
-	 */
55
-	private $server;
56
-
57
-	/**
58
-	 * @param \OC\Files\View $view
59
-	 */
60
-	public function __construct($view) {
61
-		$this->view = $view;
62
-	}
63
-
64
-	/**
65
-	 * This initializes the plugin.
66
-	 *
67
-	 * This function is called by \Sabre\DAV\Server, after
68
-	 * addPlugin is called.
69
-	 *
70
-	 * This method should set up the requires event subscriptions.
71
-	 *
72
-	 * @param \Sabre\DAV\Server $server
73
-	 * @return void
74
-	 */
75
-	public function initialize(\Sabre\DAV\Server $server) {
76
-
77
-		$this->server = $server;
78
-
79
-		$server->on('beforeWriteContent', [$this, 'beforeWriteContent'], 10);
80
-		$server->on('beforeCreateFile', [$this, 'beforeCreateFile'], 10);
81
-		$server->on('beforeMove', [$this, 'beforeMove'], 10);
82
-	}
83
-
84
-	/**
85
-	 * Check quota before creating file
86
-	 *
87
-	 * @param string $uri target file URI
88
-	 * @param resource $data data
89
-	 * @param INode $parent Sabre Node
90
-	 * @param bool $modified modified
91
-	 */
92
-	public function beforeCreateFile($uri, $data, INode $parent, $modified) {
93
-		if (!$parent instanceof Node) {
94
-			return;
95
-		}
96
-
97
-		return $this->checkQuota($parent->getPath() . '/' . basename($uri));
98
-	}
99
-
100
-	/**
101
-	 * Check quota before writing content
102
-	 *
103
-	 * @param string $uri target file URI
104
-	 * @param INode $node Sabre Node
105
-	 * @param resource $data data
106
-	 * @param bool $modified modified
107
-	 */
108
-	public function beforeWriteContent($uri, INode $node, $data, $modified) {
109
-		if (!$node instanceof Node) {
110
-			return;
111
-		}
112
-
113
-		return $this->checkQuota($node->getPath());
114
-	}
115
-
116
-	/**
117
-	 * Check if we're moving a Futurefile in which case we need to check
118
-	 * the quota on the target destination.
119
-	 *
120
-	 * @param string $source source path
121
-	 * @param string $destination destination path
122
-	 */
123
-	public function beforeMove($source, $destination) {
124
-		$sourceNode = $this->server->tree->getNodeForPath($source);
125
-		if (!$sourceNode instanceof FutureFile) {
126
-			return;
127
-		}
128
-
129
-		// get target node for proper path conversion
130
-		if ($this->server->tree->nodeExists($destination)) {
131
-			$destinationNode = $this->server->tree->getNodeForPath($destination);
132
-			$path = $destinationNode->getPath();
133
-		} else {
134
-			$parentNode = $this->server->tree->getNodeForPath(dirname($destination));
135
-			$path = $parentNode->getPath();
136
-		}
137
-
138
-		return $this->checkQuota($path, $sourceNode->getSize());
139
-	}
140
-
141
-
142
-	/**
143
-	 * This method is called before any HTTP method and validates there is enough free space to store the file
144
-	 *
145
-	 * @param string $path relative to the users home
146
-	 * @param int $length
147
-	 * @throws InsufficientStorage
148
-	 * @return bool
149
-	 */
150
-	public function checkQuota($path, $length = null) {
151
-		if ($length === null) {
152
-			$length = $this->getLength();
153
-		}
154
-
155
-		if ($length) {
156
-			list($parentPath, $newName) = \Sabre\Uri\split($path);
157
-			if(is_null($parentPath)) {
158
-				$parentPath = '';
159
-			}
160
-			$req = $this->server->httpRequest;
161
-			if ($req->getHeader('OC-Chunked')) {
162
-				$info = \OC_FileChunking::decodeName($newName);
163
-				$chunkHandler = $this->getFileChunking($info);
164
-				// subtract the already uploaded size to see whether
165
-				// there is still enough space for the remaining chunks
166
-				$length -= $chunkHandler->getCurrentSize();
167
-				// use target file name for free space check in case of shared files
168
-				$path = rtrim($parentPath, '/') . '/' . $info['name'];
169
-			}
170
-			$freeSpace = $this->getFreeSpace($path);
171
-			if ($freeSpace !== FileInfo::SPACE_UNKNOWN && $freeSpace !== FileInfo::SPACE_UNLIMITED && $length > $freeSpace) {
172
-				if (isset($chunkHandler)) {
173
-					$chunkHandler->cleanup();
174
-				}
175
-				throw new InsufficientStorage();
176
-			}
177
-		}
178
-		return true;
179
-	}
180
-
181
-	public function getFileChunking($info) {
182
-		// FIXME: need a factory for better mocking support
183
-		return new \OC_FileChunking($info);
184
-	}
185
-
186
-	public function getLength() {
187
-		$req = $this->server->httpRequest;
188
-		$length = $req->getHeader('X-Expected-Entity-Length');
189
-		if (!is_numeric($length)) {
190
-			$length = $req->getHeader('Content-Length');
191
-			$length = is_numeric($length) ? $length : null;
192
-		}
193
-
194
-		$ocLength = $req->getHeader('OC-Total-Length');
195
-		if (is_numeric($length) && is_numeric($ocLength)) {
196
-			return max($length, $ocLength);
197
-		}
198
-
199
-		return $length;
200
-	}
201
-
202
-	/**
203
-	 * @param string $uri
204
-	 * @return mixed
205
-	 * @throws ServiceUnavailable
206
-	 */
207
-	public function getFreeSpace($uri) {
208
-		try {
209
-			$freeSpace = $this->view->free_space(ltrim($uri, '/'));
210
-			return $freeSpace;
211
-		} catch (StorageNotAvailableException $e) {
212
-			throw new ServiceUnavailable($e->getMessage());
213
-		}
214
-	}
47
+    /** @var \OC\Files\View */
48
+    private $view;
49
+
50
+    /**
51
+     * Reference to main server object
52
+     *
53
+     * @var \Sabre\DAV\Server
54
+     */
55
+    private $server;
56
+
57
+    /**
58
+     * @param \OC\Files\View $view
59
+     */
60
+    public function __construct($view) {
61
+        $this->view = $view;
62
+    }
63
+
64
+    /**
65
+     * This initializes the plugin.
66
+     *
67
+     * This function is called by \Sabre\DAV\Server, after
68
+     * addPlugin is called.
69
+     *
70
+     * This method should set up the requires event subscriptions.
71
+     *
72
+     * @param \Sabre\DAV\Server $server
73
+     * @return void
74
+     */
75
+    public function initialize(\Sabre\DAV\Server $server) {
76
+
77
+        $this->server = $server;
78
+
79
+        $server->on('beforeWriteContent', [$this, 'beforeWriteContent'], 10);
80
+        $server->on('beforeCreateFile', [$this, 'beforeCreateFile'], 10);
81
+        $server->on('beforeMove', [$this, 'beforeMove'], 10);
82
+    }
83
+
84
+    /**
85
+     * Check quota before creating file
86
+     *
87
+     * @param string $uri target file URI
88
+     * @param resource $data data
89
+     * @param INode $parent Sabre Node
90
+     * @param bool $modified modified
91
+     */
92
+    public function beforeCreateFile($uri, $data, INode $parent, $modified) {
93
+        if (!$parent instanceof Node) {
94
+            return;
95
+        }
96
+
97
+        return $this->checkQuota($parent->getPath() . '/' . basename($uri));
98
+    }
99
+
100
+    /**
101
+     * Check quota before writing content
102
+     *
103
+     * @param string $uri target file URI
104
+     * @param INode $node Sabre Node
105
+     * @param resource $data data
106
+     * @param bool $modified modified
107
+     */
108
+    public function beforeWriteContent($uri, INode $node, $data, $modified) {
109
+        if (!$node instanceof Node) {
110
+            return;
111
+        }
112
+
113
+        return $this->checkQuota($node->getPath());
114
+    }
115
+
116
+    /**
117
+     * Check if we're moving a Futurefile in which case we need to check
118
+     * the quota on the target destination.
119
+     *
120
+     * @param string $source source path
121
+     * @param string $destination destination path
122
+     */
123
+    public function beforeMove($source, $destination) {
124
+        $sourceNode = $this->server->tree->getNodeForPath($source);
125
+        if (!$sourceNode instanceof FutureFile) {
126
+            return;
127
+        }
128
+
129
+        // get target node for proper path conversion
130
+        if ($this->server->tree->nodeExists($destination)) {
131
+            $destinationNode = $this->server->tree->getNodeForPath($destination);
132
+            $path = $destinationNode->getPath();
133
+        } else {
134
+            $parentNode = $this->server->tree->getNodeForPath(dirname($destination));
135
+            $path = $parentNode->getPath();
136
+        }
137
+
138
+        return $this->checkQuota($path, $sourceNode->getSize());
139
+    }
140
+
141
+
142
+    /**
143
+     * This method is called before any HTTP method and validates there is enough free space to store the file
144
+     *
145
+     * @param string $path relative to the users home
146
+     * @param int $length
147
+     * @throws InsufficientStorage
148
+     * @return bool
149
+     */
150
+    public function checkQuota($path, $length = null) {
151
+        if ($length === null) {
152
+            $length = $this->getLength();
153
+        }
154
+
155
+        if ($length) {
156
+            list($parentPath, $newName) = \Sabre\Uri\split($path);
157
+            if(is_null($parentPath)) {
158
+                $parentPath = '';
159
+            }
160
+            $req = $this->server->httpRequest;
161
+            if ($req->getHeader('OC-Chunked')) {
162
+                $info = \OC_FileChunking::decodeName($newName);
163
+                $chunkHandler = $this->getFileChunking($info);
164
+                // subtract the already uploaded size to see whether
165
+                // there is still enough space for the remaining chunks
166
+                $length -= $chunkHandler->getCurrentSize();
167
+                // use target file name for free space check in case of shared files
168
+                $path = rtrim($parentPath, '/') . '/' . $info['name'];
169
+            }
170
+            $freeSpace = $this->getFreeSpace($path);
171
+            if ($freeSpace !== FileInfo::SPACE_UNKNOWN && $freeSpace !== FileInfo::SPACE_UNLIMITED && $length > $freeSpace) {
172
+                if (isset($chunkHandler)) {
173
+                    $chunkHandler->cleanup();
174
+                }
175
+                throw new InsufficientStorage();
176
+            }
177
+        }
178
+        return true;
179
+    }
180
+
181
+    public function getFileChunking($info) {
182
+        // FIXME: need a factory for better mocking support
183
+        return new \OC_FileChunking($info);
184
+    }
185
+
186
+    public function getLength() {
187
+        $req = $this->server->httpRequest;
188
+        $length = $req->getHeader('X-Expected-Entity-Length');
189
+        if (!is_numeric($length)) {
190
+            $length = $req->getHeader('Content-Length');
191
+            $length = is_numeric($length) ? $length : null;
192
+        }
193
+
194
+        $ocLength = $req->getHeader('OC-Total-Length');
195
+        if (is_numeric($length) && is_numeric($ocLength)) {
196
+            return max($length, $ocLength);
197
+        }
198
+
199
+        return $length;
200
+    }
201
+
202
+    /**
203
+     * @param string $uri
204
+     * @return mixed
205
+     * @throws ServiceUnavailable
206
+     */
207
+    public function getFreeSpace($uri) {
208
+        try {
209
+            $freeSpace = $this->view->free_space(ltrim($uri, '/'));
210
+            return $freeSpace;
211
+        } catch (StorageNotAvailableException $e) {
212
+            throw new ServiceUnavailable($e->getMessage());
213
+        }
214
+    }
215 215
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 			return;
95 95
 		}
96 96
 
97
-		return $this->checkQuota($parent->getPath() . '/' . basename($uri));
97
+		return $this->checkQuota($parent->getPath().'/'.basename($uri));
98 98
 	}
99 99
 
100 100
 	/**
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 
155 155
 		if ($length) {
156 156
 			list($parentPath, $newName) = \Sabre\Uri\split($path);
157
-			if(is_null($parentPath)) {
157
+			if (is_null($parentPath)) {
158 158
 				$parentPath = '';
159 159
 			}
160 160
 			$req = $this->server->httpRequest;
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 				// there is still enough space for the remaining chunks
166 166
 				$length -= $chunkHandler->getCurrentSize();
167 167
 				// use target file name for free space check in case of shared files
168
-				$path = rtrim($parentPath, '/') . '/' . $info['name'];
168
+				$path = rtrim($parentPath, '/').'/'.$info['name'];
169 169
 			}
170 170
 			$freeSpace = $this->getFreeSpace($path);
171 171
 			if ($freeSpace !== FileInfo::SPACE_UNKNOWN && $freeSpace !== FileInfo::SPACE_UNLIMITED && $length > $freeSpace) {
Please login to merge, or discard this patch.