@@ -31,15 +31,15 @@ |
||
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 | } |
@@ -31,15 +31,15 @@ |
||
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 | } |
@@ -117,7 +117,7 @@ discard block |
||
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 |
||
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 |
||
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, |
@@ -42,158 +42,158 @@ |
||
42 | 42 | use Sabre\DAV\Auth\Backend\BackendInterface; |
43 | 43 | |
44 | 44 | class ServerFactory { |
45 | - /** @var IConfig */ |
|
46 | - private $config; |
|
47 | - /** @var ILogger */ |
|
48 | - private $logger; |
|
49 | - /** @var IDBConnection */ |
|
50 | - private $databaseConnection; |
|
51 | - /** @var IUserSession */ |
|
52 | - private $userSession; |
|
53 | - /** @var IMountManager */ |
|
54 | - private $mountManager; |
|
55 | - /** @var ITagManager */ |
|
56 | - private $tagManager; |
|
57 | - /** @var IRequest */ |
|
58 | - private $request; |
|
59 | - /** @var IPreview */ |
|
60 | - private $previewManager; |
|
45 | + /** @var IConfig */ |
|
46 | + private $config; |
|
47 | + /** @var ILogger */ |
|
48 | + private $logger; |
|
49 | + /** @var IDBConnection */ |
|
50 | + private $databaseConnection; |
|
51 | + /** @var IUserSession */ |
|
52 | + private $userSession; |
|
53 | + /** @var IMountManager */ |
|
54 | + private $mountManager; |
|
55 | + /** @var ITagManager */ |
|
56 | + private $tagManager; |
|
57 | + /** @var IRequest */ |
|
58 | + private $request; |
|
59 | + /** @var IPreview */ |
|
60 | + private $previewManager; |
|
61 | 61 | |
62 | - /** |
|
63 | - * @param IConfig $config |
|
64 | - * @param ILogger $logger |
|
65 | - * @param IDBConnection $databaseConnection |
|
66 | - * @param IUserSession $userSession |
|
67 | - * @param IMountManager $mountManager |
|
68 | - * @param ITagManager $tagManager |
|
69 | - * @param IRequest $request |
|
70 | - * @param IPreview $previewManager |
|
71 | - */ |
|
72 | - public function __construct( |
|
73 | - IConfig $config, |
|
74 | - ILogger $logger, |
|
75 | - IDBConnection $databaseConnection, |
|
76 | - IUserSession $userSession, |
|
77 | - IMountManager $mountManager, |
|
78 | - ITagManager $tagManager, |
|
79 | - IRequest $request, |
|
80 | - IPreview $previewManager |
|
81 | - ) { |
|
82 | - $this->config = $config; |
|
83 | - $this->logger = $logger; |
|
84 | - $this->databaseConnection = $databaseConnection; |
|
85 | - $this->userSession = $userSession; |
|
86 | - $this->mountManager = $mountManager; |
|
87 | - $this->tagManager = $tagManager; |
|
88 | - $this->request = $request; |
|
89 | - $this->previewManager = $previewManager; |
|
90 | - } |
|
62 | + /** |
|
63 | + * @param IConfig $config |
|
64 | + * @param ILogger $logger |
|
65 | + * @param IDBConnection $databaseConnection |
|
66 | + * @param IUserSession $userSession |
|
67 | + * @param IMountManager $mountManager |
|
68 | + * @param ITagManager $tagManager |
|
69 | + * @param IRequest $request |
|
70 | + * @param IPreview $previewManager |
|
71 | + */ |
|
72 | + public function __construct( |
|
73 | + IConfig $config, |
|
74 | + ILogger $logger, |
|
75 | + IDBConnection $databaseConnection, |
|
76 | + IUserSession $userSession, |
|
77 | + IMountManager $mountManager, |
|
78 | + ITagManager $tagManager, |
|
79 | + IRequest $request, |
|
80 | + IPreview $previewManager |
|
81 | + ) { |
|
82 | + $this->config = $config; |
|
83 | + $this->logger = $logger; |
|
84 | + $this->databaseConnection = $databaseConnection; |
|
85 | + $this->userSession = $userSession; |
|
86 | + $this->mountManager = $mountManager; |
|
87 | + $this->tagManager = $tagManager; |
|
88 | + $this->request = $request; |
|
89 | + $this->previewManager = $previewManager; |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * @param string $baseUri |
|
94 | - * @param string $requestUri |
|
95 | - * @param BackendInterface $authBackend |
|
96 | - * @param callable $viewCallBack callback that should return the view for the dav endpoint |
|
97 | - * @return Server |
|
98 | - */ |
|
99 | - public function createServer($baseUri, |
|
100 | - $requestUri, |
|
101 | - BackendInterface $authBackend, |
|
102 | - callable $viewCallBack) { |
|
103 | - // Fire up server |
|
104 | - $objectTree = new \OCA\DAV\Connector\Sabre\ObjectTree(); |
|
105 | - $server = new \OCA\DAV\Connector\Sabre\Server($objectTree); |
|
106 | - // Set URL explicitly due to reverse-proxy situations |
|
107 | - $server->httpRequest->setUrl($requestUri); |
|
108 | - $server->setBaseUri($baseUri); |
|
92 | + /** |
|
93 | + * @param string $baseUri |
|
94 | + * @param string $requestUri |
|
95 | + * @param BackendInterface $authBackend |
|
96 | + * @param callable $viewCallBack callback that should return the view for the dav endpoint |
|
97 | + * @return Server |
|
98 | + */ |
|
99 | + public function createServer($baseUri, |
|
100 | + $requestUri, |
|
101 | + BackendInterface $authBackend, |
|
102 | + callable $viewCallBack) { |
|
103 | + // Fire up server |
|
104 | + $objectTree = new \OCA\DAV\Connector\Sabre\ObjectTree(); |
|
105 | + $server = new \OCA\DAV\Connector\Sabre\Server($objectTree); |
|
106 | + // Set URL explicitly due to reverse-proxy situations |
|
107 | + $server->httpRequest->setUrl($requestUri); |
|
108 | + $server->setBaseUri($baseUri); |
|
109 | 109 | |
110 | - // Load plugins |
|
111 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin($this->config)); |
|
112 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin($this->config)); |
|
113 | - $server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend)); |
|
114 | - // FIXME: The following line is a workaround for legacy components relying on being able to send a GET to / |
|
115 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\DummyGetResponsePlugin()); |
|
116 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $this->logger)); |
|
117 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
118 | - // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
119 | - // we do not provide locking we emulate it using a fake locking plugin. |
|
120 | - if($this->request->isUserAgent([ |
|
121 | - '/WebDAVFS/', |
|
122 | - '/Microsoft Office OneNote 2013/', |
|
123 | - '/Microsoft-WebDAV-MiniRedir/', |
|
124 | - ])) { |
|
125 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\FakeLockerPlugin()); |
|
126 | - } |
|
110 | + // Load plugins |
|
111 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin($this->config)); |
|
112 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin($this->config)); |
|
113 | + $server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend)); |
|
114 | + // FIXME: The following line is a workaround for legacy components relying on being able to send a GET to / |
|
115 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\DummyGetResponsePlugin()); |
|
116 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $this->logger)); |
|
117 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
118 | + // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
119 | + // we do not provide locking we emulate it using a fake locking plugin. |
|
120 | + if($this->request->isUserAgent([ |
|
121 | + '/WebDAVFS/', |
|
122 | + '/Microsoft Office OneNote 2013/', |
|
123 | + '/Microsoft-WebDAV-MiniRedir/', |
|
124 | + ])) { |
|
125 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\FakeLockerPlugin()); |
|
126 | + } |
|
127 | 127 | |
128 | - if (BrowserErrorPagePlugin::isBrowserRequest($this->request)) { |
|
129 | - $server->addPlugin(new BrowserErrorPagePlugin()); |
|
130 | - } |
|
128 | + if (BrowserErrorPagePlugin::isBrowserRequest($this->request)) { |
|
129 | + $server->addPlugin(new BrowserErrorPagePlugin()); |
|
130 | + } |
|
131 | 131 | |
132 | - // wait with registering these until auth is handled and the filesystem is setup |
|
133 | - $server->on('beforeMethod', function () use ($server, $objectTree, $viewCallBack) { |
|
134 | - // ensure the skeleton is copied |
|
135 | - $userFolder = \OC::$server->getUserFolder(); |
|
132 | + // wait with registering these until auth is handled and the filesystem is setup |
|
133 | + $server->on('beforeMethod', function () use ($server, $objectTree, $viewCallBack) { |
|
134 | + // ensure the skeleton is copied |
|
135 | + $userFolder = \OC::$server->getUserFolder(); |
|
136 | 136 | |
137 | - /** @var \OC\Files\View $view */ |
|
138 | - $view = $viewCallBack($server); |
|
139 | - if ($userFolder instanceof Folder && $userFolder->getPath() === $view->getRoot()) { |
|
140 | - $rootInfo = $userFolder; |
|
141 | - } else { |
|
142 | - $rootInfo = $view->getFileInfo(''); |
|
143 | - } |
|
137 | + /** @var \OC\Files\View $view */ |
|
138 | + $view = $viewCallBack($server); |
|
139 | + if ($userFolder instanceof Folder && $userFolder->getPath() === $view->getRoot()) { |
|
140 | + $rootInfo = $userFolder; |
|
141 | + } else { |
|
142 | + $rootInfo = $view->getFileInfo(''); |
|
143 | + } |
|
144 | 144 | |
145 | - // Create Nextcloud Dir |
|
146 | - if ($rootInfo->getType() === 'dir') { |
|
147 | - $root = new \OCA\DAV\Connector\Sabre\Directory($view, $rootInfo, $objectTree); |
|
148 | - } else { |
|
149 | - $root = new \OCA\DAV\Connector\Sabre\File($view, $rootInfo); |
|
150 | - } |
|
151 | - $objectTree->init($root, $view, $this->mountManager); |
|
145 | + // Create Nextcloud Dir |
|
146 | + if ($rootInfo->getType() === 'dir') { |
|
147 | + $root = new \OCA\DAV\Connector\Sabre\Directory($view, $rootInfo, $objectTree); |
|
148 | + } else { |
|
149 | + $root = new \OCA\DAV\Connector\Sabre\File($view, $rootInfo); |
|
150 | + } |
|
151 | + $objectTree->init($root, $view, $this->mountManager); |
|
152 | 152 | |
153 | - $server->addPlugin( |
|
154 | - new \OCA\DAV\Connector\Sabre\FilesPlugin( |
|
155 | - $objectTree, |
|
156 | - $this->config, |
|
157 | - $this->request, |
|
158 | - $this->previewManager, |
|
159 | - false, |
|
160 | - !$this->config->getSystemValue('debug', false) |
|
161 | - ) |
|
162 | - ); |
|
163 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\QuotaPlugin($view)); |
|
153 | + $server->addPlugin( |
|
154 | + new \OCA\DAV\Connector\Sabre\FilesPlugin( |
|
155 | + $objectTree, |
|
156 | + $this->config, |
|
157 | + $this->request, |
|
158 | + $this->previewManager, |
|
159 | + false, |
|
160 | + !$this->config->getSystemValue('debug', false) |
|
161 | + ) |
|
162 | + ); |
|
163 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\QuotaPlugin($view)); |
|
164 | 164 | |
165 | - if($this->userSession->isLoggedIn()) { |
|
166 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\TagsPlugin($objectTree, $this->tagManager)); |
|
167 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\SharesPlugin( |
|
168 | - $objectTree, |
|
169 | - $this->userSession, |
|
170 | - $userFolder, |
|
171 | - \OC::$server->getShareManager() |
|
172 | - )); |
|
173 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\CommentPropertiesPlugin(\OC::$server->getCommentsManager(), $this->userSession)); |
|
174 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\FilesReportPlugin( |
|
175 | - $objectTree, |
|
176 | - $view, |
|
177 | - \OC::$server->getSystemTagManager(), |
|
178 | - \OC::$server->getSystemTagObjectMapper(), |
|
179 | - \OC::$server->getTagManager(), |
|
180 | - $this->userSession, |
|
181 | - \OC::$server->getGroupManager(), |
|
182 | - $userFolder |
|
183 | - )); |
|
184 | - // custom properties plugin must be the last one |
|
185 | - $server->addPlugin( |
|
186 | - new \Sabre\DAV\PropertyStorage\Plugin( |
|
187 | - new \OCA\DAV\Connector\Sabre\CustomPropertiesBackend( |
|
188 | - $objectTree, |
|
189 | - $this->databaseConnection, |
|
190 | - $this->userSession->getUser() |
|
191 | - ) |
|
192 | - ) |
|
193 | - ); |
|
194 | - } |
|
195 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\CopyEtagHeaderPlugin()); |
|
196 | - }, 30); // priority 30: after auth (10) and acl(20), before lock(50) and handling the request |
|
197 | - return $server; |
|
198 | - } |
|
165 | + if($this->userSession->isLoggedIn()) { |
|
166 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\TagsPlugin($objectTree, $this->tagManager)); |
|
167 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\SharesPlugin( |
|
168 | + $objectTree, |
|
169 | + $this->userSession, |
|
170 | + $userFolder, |
|
171 | + \OC::$server->getShareManager() |
|
172 | + )); |
|
173 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\CommentPropertiesPlugin(\OC::$server->getCommentsManager(), $this->userSession)); |
|
174 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\FilesReportPlugin( |
|
175 | + $objectTree, |
|
176 | + $view, |
|
177 | + \OC::$server->getSystemTagManager(), |
|
178 | + \OC::$server->getSystemTagObjectMapper(), |
|
179 | + \OC::$server->getTagManager(), |
|
180 | + $this->userSession, |
|
181 | + \OC::$server->getGroupManager(), |
|
182 | + $userFolder |
|
183 | + )); |
|
184 | + // custom properties plugin must be the last one |
|
185 | + $server->addPlugin( |
|
186 | + new \Sabre\DAV\PropertyStorage\Plugin( |
|
187 | + new \OCA\DAV\Connector\Sabre\CustomPropertiesBackend( |
|
188 | + $objectTree, |
|
189 | + $this->databaseConnection, |
|
190 | + $this->userSession->getUser() |
|
191 | + ) |
|
192 | + ) |
|
193 | + ); |
|
194 | + } |
|
195 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\CopyEtagHeaderPlugin()); |
|
196 | + }, 30); // priority 30: after auth (10) and acl(20), before lock(50) and handling the request |
|
197 | + return $server; |
|
198 | + } |
|
199 | 199 | } |
@@ -41,315 +41,315 @@ |
||
41 | 41 | |
42 | 42 | abstract class Node implements \Sabre\DAV\INode { |
43 | 43 | |
44 | - /** |
|
45 | - * @var \OC\Files\View |
|
46 | - */ |
|
47 | - protected $fileView; |
|
48 | - |
|
49 | - /** |
|
50 | - * The path to the current node |
|
51 | - * |
|
52 | - * @var string |
|
53 | - */ |
|
54 | - protected $path; |
|
55 | - |
|
56 | - /** |
|
57 | - * node properties cache |
|
58 | - * |
|
59 | - * @var array |
|
60 | - */ |
|
61 | - protected $property_cache = null; |
|
62 | - |
|
63 | - /** |
|
64 | - * @var \OCP\Files\FileInfo |
|
65 | - */ |
|
66 | - protected $info; |
|
67 | - |
|
68 | - /** |
|
69 | - * @var IManager |
|
70 | - */ |
|
71 | - protected $shareManager; |
|
72 | - |
|
73 | - /** |
|
74 | - * Sets up the node, expects a full path name |
|
75 | - * |
|
76 | - * @param \OC\Files\View $view |
|
77 | - * @param \OCP\Files\FileInfo $info |
|
78 | - * @param IManager $shareManager |
|
79 | - */ |
|
80 | - public function __construct($view, $info, IManager $shareManager = null) { |
|
81 | - $this->fileView = $view; |
|
82 | - $this->path = $this->fileView->getRelativePath($info->getPath()); |
|
83 | - $this->info = $info; |
|
84 | - if ($shareManager) { |
|
85 | - $this->shareManager = $shareManager; |
|
86 | - } else { |
|
87 | - $this->shareManager = \OC::$server->getShareManager(); |
|
88 | - } |
|
89 | - } |
|
90 | - |
|
91 | - protected function refreshInfo() { |
|
92 | - $this->info = $this->fileView->getFileInfo($this->path); |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Returns the name of the node |
|
97 | - * |
|
98 | - * @return string |
|
99 | - */ |
|
100 | - public function getName() { |
|
101 | - return $this->info->getName(); |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Returns the full path |
|
106 | - * |
|
107 | - * @return string |
|
108 | - */ |
|
109 | - public function getPath() { |
|
110 | - return $this->path; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Renames the node |
|
115 | - * |
|
116 | - * @param string $name The new name |
|
117 | - * @throws \Sabre\DAV\Exception\BadRequest |
|
118 | - * @throws \Sabre\DAV\Exception\Forbidden |
|
119 | - */ |
|
120 | - public function setName($name) { |
|
121 | - |
|
122 | - // rename is only allowed if the update privilege is granted |
|
123 | - if (!$this->info->isUpdateable()) { |
|
124 | - throw new \Sabre\DAV\Exception\Forbidden(); |
|
125 | - } |
|
126 | - |
|
127 | - list($parentPath,) = \Sabre\HTTP\URLUtil::splitPath($this->path); |
|
128 | - list(, $newName) = \Sabre\HTTP\URLUtil::splitPath($name); |
|
129 | - |
|
130 | - // verify path of the target |
|
131 | - $this->verifyPath(); |
|
132 | - |
|
133 | - $newPath = $parentPath . '/' . $newName; |
|
134 | - |
|
135 | - $this->fileView->rename($this->path, $newPath); |
|
136 | - |
|
137 | - $this->path = $newPath; |
|
138 | - |
|
139 | - $this->refreshInfo(); |
|
140 | - } |
|
141 | - |
|
142 | - public function setPropertyCache($property_cache) { |
|
143 | - $this->property_cache = $property_cache; |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * Returns the last modification time, as a unix timestamp |
|
148 | - * |
|
149 | - * @return int timestamp as integer |
|
150 | - */ |
|
151 | - public function getLastModified() { |
|
152 | - $timestamp = $this->info->getMtime(); |
|
153 | - if (!empty($timestamp)) { |
|
154 | - return (int)$timestamp; |
|
155 | - } |
|
156 | - return $timestamp; |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * sets the last modification time of the file (mtime) to the value given |
|
161 | - * in the second parameter or to now if the second param is empty. |
|
162 | - * Even if the modification time is set to a custom value the access time is set to now. |
|
163 | - */ |
|
164 | - public function touch($mtime) { |
|
165 | - $this->fileView->touch($this->path, $mtime); |
|
166 | - $this->refreshInfo(); |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * Returns the ETag for a file |
|
171 | - * |
|
172 | - * An ETag is a unique identifier representing the current version of the |
|
173 | - * file. If the file changes, the ETag MUST change. The ETag is an |
|
174 | - * arbitrary string, but MUST be surrounded by double-quotes. |
|
175 | - * |
|
176 | - * Return null if the ETag can not effectively be determined |
|
177 | - * |
|
178 | - * @return string |
|
179 | - */ |
|
180 | - public function getETag() { |
|
181 | - return '"' . $this->info->getEtag() . '"'; |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * Sets the ETag |
|
186 | - * |
|
187 | - * @param string $etag |
|
188 | - * |
|
189 | - * @return int file id of updated file or -1 on failure |
|
190 | - */ |
|
191 | - public function setETag($etag) { |
|
192 | - return $this->fileView->putFileInfo($this->path, array('etag' => $etag)); |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * Returns the size of the node, in bytes |
|
197 | - * |
|
198 | - * @return integer |
|
199 | - */ |
|
200 | - public function getSize() { |
|
201 | - return $this->info->getSize(); |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Returns the cache's file id |
|
206 | - * |
|
207 | - * @return int |
|
208 | - */ |
|
209 | - public function getId() { |
|
210 | - return $this->info->getId(); |
|
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * @return string|null |
|
215 | - */ |
|
216 | - public function getFileId() { |
|
217 | - if ($this->info->getId()) { |
|
218 | - $instanceId = \OC_Util::getInstanceId(); |
|
219 | - $id = sprintf('%08d', $this->info->getId()); |
|
220 | - return $id . $instanceId; |
|
221 | - } |
|
222 | - |
|
223 | - return null; |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * @return integer |
|
228 | - */ |
|
229 | - public function getInternalFileId() { |
|
230 | - return $this->info->getId(); |
|
231 | - } |
|
232 | - |
|
233 | - /** |
|
234 | - * @param string $user |
|
235 | - * @return int |
|
236 | - */ |
|
237 | - public function getSharePermissions($user) { |
|
238 | - |
|
239 | - // check of we access a federated share |
|
240 | - if ($user !== null) { |
|
241 | - try { |
|
242 | - $share = $this->shareManager->getShareByToken($user); |
|
243 | - return $share->getPermissions(); |
|
244 | - } catch (ShareNotFound $e) { |
|
245 | - // ignore |
|
246 | - } |
|
247 | - } |
|
248 | - |
|
249 | - $storage = $this->info->getStorage(); |
|
250 | - |
|
251 | - $path = $this->info->getInternalPath(); |
|
252 | - |
|
253 | - if ($storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) { |
|
254 | - /** @var \OCA\Files_Sharing\SharedStorage $storage */ |
|
255 | - $permissions = (int)$storage->getShare()->getPermissions(); |
|
256 | - } else { |
|
257 | - $permissions = $storage->getPermissions($path); |
|
258 | - } |
|
259 | - |
|
260 | - /* |
|
44 | + /** |
|
45 | + * @var \OC\Files\View |
|
46 | + */ |
|
47 | + protected $fileView; |
|
48 | + |
|
49 | + /** |
|
50 | + * The path to the current node |
|
51 | + * |
|
52 | + * @var string |
|
53 | + */ |
|
54 | + protected $path; |
|
55 | + |
|
56 | + /** |
|
57 | + * node properties cache |
|
58 | + * |
|
59 | + * @var array |
|
60 | + */ |
|
61 | + protected $property_cache = null; |
|
62 | + |
|
63 | + /** |
|
64 | + * @var \OCP\Files\FileInfo |
|
65 | + */ |
|
66 | + protected $info; |
|
67 | + |
|
68 | + /** |
|
69 | + * @var IManager |
|
70 | + */ |
|
71 | + protected $shareManager; |
|
72 | + |
|
73 | + /** |
|
74 | + * Sets up the node, expects a full path name |
|
75 | + * |
|
76 | + * @param \OC\Files\View $view |
|
77 | + * @param \OCP\Files\FileInfo $info |
|
78 | + * @param IManager $shareManager |
|
79 | + */ |
|
80 | + public function __construct($view, $info, IManager $shareManager = null) { |
|
81 | + $this->fileView = $view; |
|
82 | + $this->path = $this->fileView->getRelativePath($info->getPath()); |
|
83 | + $this->info = $info; |
|
84 | + if ($shareManager) { |
|
85 | + $this->shareManager = $shareManager; |
|
86 | + } else { |
|
87 | + $this->shareManager = \OC::$server->getShareManager(); |
|
88 | + } |
|
89 | + } |
|
90 | + |
|
91 | + protected function refreshInfo() { |
|
92 | + $this->info = $this->fileView->getFileInfo($this->path); |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Returns the name of the node |
|
97 | + * |
|
98 | + * @return string |
|
99 | + */ |
|
100 | + public function getName() { |
|
101 | + return $this->info->getName(); |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Returns the full path |
|
106 | + * |
|
107 | + * @return string |
|
108 | + */ |
|
109 | + public function getPath() { |
|
110 | + return $this->path; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Renames the node |
|
115 | + * |
|
116 | + * @param string $name The new name |
|
117 | + * @throws \Sabre\DAV\Exception\BadRequest |
|
118 | + * @throws \Sabre\DAV\Exception\Forbidden |
|
119 | + */ |
|
120 | + public function setName($name) { |
|
121 | + |
|
122 | + // rename is only allowed if the update privilege is granted |
|
123 | + if (!$this->info->isUpdateable()) { |
|
124 | + throw new \Sabre\DAV\Exception\Forbidden(); |
|
125 | + } |
|
126 | + |
|
127 | + list($parentPath,) = \Sabre\HTTP\URLUtil::splitPath($this->path); |
|
128 | + list(, $newName) = \Sabre\HTTP\URLUtil::splitPath($name); |
|
129 | + |
|
130 | + // verify path of the target |
|
131 | + $this->verifyPath(); |
|
132 | + |
|
133 | + $newPath = $parentPath . '/' . $newName; |
|
134 | + |
|
135 | + $this->fileView->rename($this->path, $newPath); |
|
136 | + |
|
137 | + $this->path = $newPath; |
|
138 | + |
|
139 | + $this->refreshInfo(); |
|
140 | + } |
|
141 | + |
|
142 | + public function setPropertyCache($property_cache) { |
|
143 | + $this->property_cache = $property_cache; |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * Returns the last modification time, as a unix timestamp |
|
148 | + * |
|
149 | + * @return int timestamp as integer |
|
150 | + */ |
|
151 | + public function getLastModified() { |
|
152 | + $timestamp = $this->info->getMtime(); |
|
153 | + if (!empty($timestamp)) { |
|
154 | + return (int)$timestamp; |
|
155 | + } |
|
156 | + return $timestamp; |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * sets the last modification time of the file (mtime) to the value given |
|
161 | + * in the second parameter or to now if the second param is empty. |
|
162 | + * Even if the modification time is set to a custom value the access time is set to now. |
|
163 | + */ |
|
164 | + public function touch($mtime) { |
|
165 | + $this->fileView->touch($this->path, $mtime); |
|
166 | + $this->refreshInfo(); |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * Returns the ETag for a file |
|
171 | + * |
|
172 | + * An ETag is a unique identifier representing the current version of the |
|
173 | + * file. If the file changes, the ETag MUST change. The ETag is an |
|
174 | + * arbitrary string, but MUST be surrounded by double-quotes. |
|
175 | + * |
|
176 | + * Return null if the ETag can not effectively be determined |
|
177 | + * |
|
178 | + * @return string |
|
179 | + */ |
|
180 | + public function getETag() { |
|
181 | + return '"' . $this->info->getEtag() . '"'; |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * Sets the ETag |
|
186 | + * |
|
187 | + * @param string $etag |
|
188 | + * |
|
189 | + * @return int file id of updated file or -1 on failure |
|
190 | + */ |
|
191 | + public function setETag($etag) { |
|
192 | + return $this->fileView->putFileInfo($this->path, array('etag' => $etag)); |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * Returns the size of the node, in bytes |
|
197 | + * |
|
198 | + * @return integer |
|
199 | + */ |
|
200 | + public function getSize() { |
|
201 | + return $this->info->getSize(); |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Returns the cache's file id |
|
206 | + * |
|
207 | + * @return int |
|
208 | + */ |
|
209 | + public function getId() { |
|
210 | + return $this->info->getId(); |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * @return string|null |
|
215 | + */ |
|
216 | + public function getFileId() { |
|
217 | + if ($this->info->getId()) { |
|
218 | + $instanceId = \OC_Util::getInstanceId(); |
|
219 | + $id = sprintf('%08d', $this->info->getId()); |
|
220 | + return $id . $instanceId; |
|
221 | + } |
|
222 | + |
|
223 | + return null; |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * @return integer |
|
228 | + */ |
|
229 | + public function getInternalFileId() { |
|
230 | + return $this->info->getId(); |
|
231 | + } |
|
232 | + |
|
233 | + /** |
|
234 | + * @param string $user |
|
235 | + * @return int |
|
236 | + */ |
|
237 | + public function getSharePermissions($user) { |
|
238 | + |
|
239 | + // check of we access a federated share |
|
240 | + if ($user !== null) { |
|
241 | + try { |
|
242 | + $share = $this->shareManager->getShareByToken($user); |
|
243 | + return $share->getPermissions(); |
|
244 | + } catch (ShareNotFound $e) { |
|
245 | + // ignore |
|
246 | + } |
|
247 | + } |
|
248 | + |
|
249 | + $storage = $this->info->getStorage(); |
|
250 | + |
|
251 | + $path = $this->info->getInternalPath(); |
|
252 | + |
|
253 | + if ($storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) { |
|
254 | + /** @var \OCA\Files_Sharing\SharedStorage $storage */ |
|
255 | + $permissions = (int)$storage->getShare()->getPermissions(); |
|
256 | + } else { |
|
257 | + $permissions = $storage->getPermissions($path); |
|
258 | + } |
|
259 | + |
|
260 | + /* |
|
261 | 261 | * We can always share non moveable mount points with DELETE and UPDATE |
262 | 262 | * Eventually we need to do this properly |
263 | 263 | */ |
264 | - $mountpoint = $this->info->getMountPoint(); |
|
265 | - if (!($mountpoint instanceof MoveableMount)) { |
|
266 | - $mountpointpath = $mountpoint->getMountPoint(); |
|
267 | - if (substr($mountpointpath, -1) === '/') { |
|
268 | - $mountpointpath = substr($mountpointpath, 0, -1); |
|
269 | - } |
|
270 | - |
|
271 | - if ($mountpointpath === $this->info->getPath()) { |
|
272 | - $permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE; |
|
273 | - } |
|
274 | - } |
|
275 | - |
|
276 | - /* |
|
264 | + $mountpoint = $this->info->getMountPoint(); |
|
265 | + if (!($mountpoint instanceof MoveableMount)) { |
|
266 | + $mountpointpath = $mountpoint->getMountPoint(); |
|
267 | + if (substr($mountpointpath, -1) === '/') { |
|
268 | + $mountpointpath = substr($mountpointpath, 0, -1); |
|
269 | + } |
|
270 | + |
|
271 | + if ($mountpointpath === $this->info->getPath()) { |
|
272 | + $permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE; |
|
273 | + } |
|
274 | + } |
|
275 | + |
|
276 | + /* |
|
277 | 277 | * Files can't have create or delete permissions |
278 | 278 | */ |
279 | - if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) { |
|
280 | - $permissions &= ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_DELETE); |
|
281 | - } |
|
282 | - |
|
283 | - return $permissions; |
|
284 | - } |
|
285 | - |
|
286 | - /** |
|
287 | - * @return string |
|
288 | - */ |
|
289 | - public function getDavPermissions() { |
|
290 | - $p = ''; |
|
291 | - if ($this->info->isShared()) { |
|
292 | - $p .= 'S'; |
|
293 | - } |
|
294 | - if ($this->info->isShareable()) { |
|
295 | - $p .= 'R'; |
|
296 | - } |
|
297 | - if ($this->info->isMounted()) { |
|
298 | - $p .= 'M'; |
|
299 | - } |
|
300 | - if ($this->info->isDeletable()) { |
|
301 | - $p .= 'D'; |
|
302 | - } |
|
303 | - if ($this->info->isUpdateable()) { |
|
304 | - $p .= 'NV'; // Renameable, Moveable |
|
305 | - } |
|
306 | - if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) { |
|
307 | - if ($this->info->isUpdateable()) { |
|
308 | - $p .= 'W'; |
|
309 | - } |
|
310 | - } else { |
|
311 | - if ($this->info->isCreatable()) { |
|
312 | - $p .= 'CK'; |
|
313 | - } |
|
314 | - } |
|
315 | - return $p; |
|
316 | - } |
|
317 | - |
|
318 | - public function getOwner() { |
|
319 | - return $this->info->getOwner(); |
|
320 | - } |
|
321 | - |
|
322 | - protected function verifyPath() { |
|
323 | - try { |
|
324 | - $fileName = basename($this->info->getPath()); |
|
325 | - $this->fileView->verifyPath($this->path, $fileName); |
|
326 | - } catch (\OCP\Files\InvalidPathException $ex) { |
|
327 | - throw new InvalidPath($ex->getMessage()); |
|
328 | - } |
|
329 | - } |
|
330 | - |
|
331 | - /** |
|
332 | - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
333 | - */ |
|
334 | - public function acquireLock($type) { |
|
335 | - $this->fileView->lockFile($this->path, $type); |
|
336 | - } |
|
337 | - |
|
338 | - /** |
|
339 | - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
340 | - */ |
|
341 | - public function releaseLock($type) { |
|
342 | - $this->fileView->unlockFile($this->path, $type); |
|
343 | - } |
|
344 | - |
|
345 | - /** |
|
346 | - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
347 | - */ |
|
348 | - public function changeLock($type) { |
|
349 | - $this->fileView->changeLock($this->path, $type); |
|
350 | - } |
|
351 | - |
|
352 | - public function getFileInfo() { |
|
353 | - return $this->info; |
|
354 | - } |
|
279 | + if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) { |
|
280 | + $permissions &= ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_DELETE); |
|
281 | + } |
|
282 | + |
|
283 | + return $permissions; |
|
284 | + } |
|
285 | + |
|
286 | + /** |
|
287 | + * @return string |
|
288 | + */ |
|
289 | + public function getDavPermissions() { |
|
290 | + $p = ''; |
|
291 | + if ($this->info->isShared()) { |
|
292 | + $p .= 'S'; |
|
293 | + } |
|
294 | + if ($this->info->isShareable()) { |
|
295 | + $p .= 'R'; |
|
296 | + } |
|
297 | + if ($this->info->isMounted()) { |
|
298 | + $p .= 'M'; |
|
299 | + } |
|
300 | + if ($this->info->isDeletable()) { |
|
301 | + $p .= 'D'; |
|
302 | + } |
|
303 | + if ($this->info->isUpdateable()) { |
|
304 | + $p .= 'NV'; // Renameable, Moveable |
|
305 | + } |
|
306 | + if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) { |
|
307 | + if ($this->info->isUpdateable()) { |
|
308 | + $p .= 'W'; |
|
309 | + } |
|
310 | + } else { |
|
311 | + if ($this->info->isCreatable()) { |
|
312 | + $p .= 'CK'; |
|
313 | + } |
|
314 | + } |
|
315 | + return $p; |
|
316 | + } |
|
317 | + |
|
318 | + public function getOwner() { |
|
319 | + return $this->info->getOwner(); |
|
320 | + } |
|
321 | + |
|
322 | + protected function verifyPath() { |
|
323 | + try { |
|
324 | + $fileName = basename($this->info->getPath()); |
|
325 | + $this->fileView->verifyPath($this->path, $fileName); |
|
326 | + } catch (\OCP\Files\InvalidPathException $ex) { |
|
327 | + throw new InvalidPath($ex->getMessage()); |
|
328 | + } |
|
329 | + } |
|
330 | + |
|
331 | + /** |
|
332 | + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
333 | + */ |
|
334 | + public function acquireLock($type) { |
|
335 | + $this->fileView->lockFile($this->path, $type); |
|
336 | + } |
|
337 | + |
|
338 | + /** |
|
339 | + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
340 | + */ |
|
341 | + public function releaseLock($type) { |
|
342 | + $this->fileView->unlockFile($this->path, $type); |
|
343 | + } |
|
344 | + |
|
345 | + /** |
|
346 | + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
347 | + */ |
|
348 | + public function changeLock($type) { |
|
349 | + $this->fileView->changeLock($this->path, $type); |
|
350 | + } |
|
351 | + |
|
352 | + public function getFileInfo() { |
|
353 | + return $this->info; |
|
354 | + } |
|
355 | 355 | } |
@@ -130,7 +130,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -32,88 +32,88 @@ |
||
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 | } |
@@ -114,6 +114,6 @@ |
||
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 | } |
@@ -148,7 +148,7 @@ discard block |
||
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 |
||
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 { |
@@ -32,181 +32,181 @@ |
||
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 | } |
@@ -32,42 +32,42 @@ |
||
32 | 32 | |
33 | 33 | class LegacyDAVACL extends DavAclPlugin { |
34 | 34 | |
35 | - /** |
|
36 | - * @inheritdoc |
|
37 | - */ |
|
38 | - public function getCurrentUserPrincipals() { |
|
39 | - $principalV2 = $this->getCurrentUserPrincipal(); |
|
35 | + /** |
|
36 | + * @inheritdoc |
|
37 | + */ |
|
38 | + public function getCurrentUserPrincipals() { |
|
39 | + $principalV2 = $this->getCurrentUserPrincipal(); |
|
40 | 40 | |
41 | - if (is_null($principalV2)) return []; |
|
41 | + if (is_null($principalV2)) return []; |
|
42 | 42 | |
43 | - $principalV1 = $this->convertPrincipal($principalV2, false); |
|
44 | - return array_merge( |
|
45 | - [ |
|
46 | - $principalV2, |
|
47 | - $principalV1 |
|
48 | - ], |
|
49 | - $this->getPrincipalMembership($principalV1) |
|
50 | - ); |
|
51 | - } |
|
43 | + $principalV1 = $this->convertPrincipal($principalV2, false); |
|
44 | + return array_merge( |
|
45 | + [ |
|
46 | + $principalV2, |
|
47 | + $principalV1 |
|
48 | + ], |
|
49 | + $this->getPrincipalMembership($principalV1) |
|
50 | + ); |
|
51 | + } |
|
52 | 52 | |
53 | - private function convertPrincipal($principal, $toV2) { |
|
54 | - list(, $name) = URLUtil::splitPath($principal); |
|
55 | - if ($toV2) { |
|
56 | - return "principals/users/$name"; |
|
57 | - } |
|
58 | - return "principals/$name"; |
|
59 | - } |
|
53 | + private function convertPrincipal($principal, $toV2) { |
|
54 | + list(, $name) = URLUtil::splitPath($principal); |
|
55 | + if ($toV2) { |
|
56 | + return "principals/users/$name"; |
|
57 | + } |
|
58 | + return "principals/$name"; |
|
59 | + } |
|
60 | 60 | |
61 | - public function propFind(PropFind $propFind, INode $node) { |
|
62 | - /* Overload current-user-principal */ |
|
63 | - $propFind->handle('{DAV:}current-user-principal', function () { |
|
64 | - if ($url = parent::getCurrentUserPrincipal()) { |
|
65 | - return new Principal(Principal::HREF, $url . '/'); |
|
66 | - } else { |
|
67 | - return new Principal(Principal::UNAUTHENTICATED); |
|
68 | - } |
|
69 | - }); |
|
61 | + public function propFind(PropFind $propFind, INode $node) { |
|
62 | + /* Overload current-user-principal */ |
|
63 | + $propFind->handle('{DAV:}current-user-principal', function () { |
|
64 | + if ($url = parent::getCurrentUserPrincipal()) { |
|
65 | + return new Principal(Principal::HREF, $url . '/'); |
|
66 | + } else { |
|
67 | + return new Principal(Principal::UNAUTHENTICATED); |
|
68 | + } |
|
69 | + }); |
|
70 | 70 | |
71 | - return parent::propFind($propFind, $node); |
|
72 | - } |
|
71 | + return parent::propFind($propFind, $node); |
|
72 | + } |
|
73 | 73 | } |
@@ -60,9 +60,9 @@ |
||
60 | 60 | |
61 | 61 | public function propFind(PropFind $propFind, INode $node) { |
62 | 62 | /* Overload current-user-principal */ |
63 | - $propFind->handle('{DAV:}current-user-principal', function () { |
|
63 | + $propFind->handle('{DAV:}current-user-principal', function() { |
|
64 | 64 | if ($url = parent::getCurrentUserPrincipal()) { |
65 | - return new Principal(Principal::HREF, $url . '/'); |
|
65 | + return new Principal(Principal::HREF, $url.'/'); |
|
66 | 66 | } else { |
67 | 67 | return new Principal(Principal::UNAUTHENTICATED); |
68 | 68 | } |
@@ -38,7 +38,9 @@ |
||
38 | 38 | public function getCurrentUserPrincipals() { |
39 | 39 | $principalV2 = $this->getCurrentUserPrincipal(); |
40 | 40 | |
41 | - if (is_null($principalV2)) return []; |
|
41 | + if (is_null($principalV2)) { |
|
42 | + return []; |
|
43 | + } |
|
42 | 44 | |
43 | 45 | $principalV1 = $this->convertPrincipal($principalV2, false); |
44 | 46 | return array_merge( |
@@ -28,35 +28,35 @@ |
||
28 | 28 | |
29 | 29 | class FixBirthdayCalendarComponent implements IRepairStep { |
30 | 30 | |
31 | - /** @var IDBConnection */ |
|
32 | - private $connection; |
|
33 | - |
|
34 | - /** |
|
35 | - * FixBirthdayCalendarComponent constructor. |
|
36 | - * |
|
37 | - * @param IDBConnection $connection |
|
38 | - */ |
|
39 | - public function __construct(IDBConnection $connection) { |
|
40 | - $this->connection = $connection; |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * @inheritdoc |
|
45 | - */ |
|
46 | - public function getName() { |
|
47 | - return 'Fix component of birthday calendars'; |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * @inheritdoc |
|
52 | - */ |
|
53 | - public function run(IOutput $output) { |
|
54 | - $query = $this->connection->getQueryBuilder(); |
|
55 | - $updated = $query->update('calendars') |
|
56 | - ->set('components', $query->createNamedParameter('VEVENT')) |
|
57 | - ->where($query->expr()->eq('uri', $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI))) |
|
58 | - ->execute(); |
|
59 | - |
|
60 | - $output->info("$updated birthday calendars updated."); |
|
61 | - } |
|
31 | + /** @var IDBConnection */ |
|
32 | + private $connection; |
|
33 | + |
|
34 | + /** |
|
35 | + * FixBirthdayCalendarComponent constructor. |
|
36 | + * |
|
37 | + * @param IDBConnection $connection |
|
38 | + */ |
|
39 | + public function __construct(IDBConnection $connection) { |
|
40 | + $this->connection = $connection; |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * @inheritdoc |
|
45 | + */ |
|
46 | + public function getName() { |
|
47 | + return 'Fix component of birthday calendars'; |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * @inheritdoc |
|
52 | + */ |
|
53 | + public function run(IOutput $output) { |
|
54 | + $query = $this->connection->getQueryBuilder(); |
|
55 | + $updated = $query->update('calendars') |
|
56 | + ->set('components', $query->createNamedParameter('VEVENT')) |
|
57 | + ->where($query->expr()->eq('uri', $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI))) |
|
58 | + ->execute(); |
|
59 | + |
|
60 | + $output->info("$updated birthday calendars updated."); |
|
61 | + } |
|
62 | 62 | } |
@@ -33,55 +33,55 @@ |
||
33 | 33 | |
34 | 34 | class SyncBirthdayCalendar extends Command { |
35 | 35 | |
36 | - /** @var BirthdayService */ |
|
37 | - private $birthdayService; |
|
36 | + /** @var BirthdayService */ |
|
37 | + private $birthdayService; |
|
38 | 38 | |
39 | - /** @var IUserManager */ |
|
40 | - private $userManager; |
|
39 | + /** @var IUserManager */ |
|
40 | + private $userManager; |
|
41 | 41 | |
42 | - /** |
|
43 | - * @param IUserManager $userManager |
|
44 | - * @param BirthdayService $birthdayService |
|
45 | - */ |
|
46 | - function __construct(IUserManager $userManager, BirthdayService $birthdayService) { |
|
47 | - parent::__construct(); |
|
48 | - $this->birthdayService = $birthdayService; |
|
49 | - $this->userManager = $userManager; |
|
50 | - } |
|
42 | + /** |
|
43 | + * @param IUserManager $userManager |
|
44 | + * @param BirthdayService $birthdayService |
|
45 | + */ |
|
46 | + function __construct(IUserManager $userManager, BirthdayService $birthdayService) { |
|
47 | + parent::__construct(); |
|
48 | + $this->birthdayService = $birthdayService; |
|
49 | + $this->userManager = $userManager; |
|
50 | + } |
|
51 | 51 | |
52 | - protected function configure() { |
|
53 | - $this |
|
54 | - ->setName('dav:sync-birthday-calendar') |
|
55 | - ->setDescription('Synchronizes the birthday calendar') |
|
56 | - ->addArgument('user', |
|
57 | - InputArgument::OPTIONAL, |
|
58 | - 'User for whom the birthday calendar will be synchronized'); |
|
59 | - } |
|
52 | + protected function configure() { |
|
53 | + $this |
|
54 | + ->setName('dav:sync-birthday-calendar') |
|
55 | + ->setDescription('Synchronizes the birthday calendar') |
|
56 | + ->addArgument('user', |
|
57 | + InputArgument::OPTIONAL, |
|
58 | + 'User for whom the birthday calendar will be synchronized'); |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @param InputInterface $input |
|
63 | - * @param OutputInterface $output |
|
64 | - */ |
|
65 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
66 | - $user = $input->getArgument('user'); |
|
67 | - if (!is_null($user)) { |
|
68 | - if (!$this->userManager->userExists($user)) { |
|
69 | - throw new \InvalidArgumentException("User <$user> in unknown."); |
|
70 | - } |
|
71 | - $output->writeln("Start birthday calendar sync for $user"); |
|
72 | - $this->birthdayService->syncUser($user); |
|
73 | - return; |
|
74 | - } |
|
75 | - $output->writeln("Start birthday calendar sync for all users ..."); |
|
76 | - $p = new ProgressBar($output); |
|
77 | - $p->start(); |
|
78 | - $this->userManager->callForAllUsers(function($user) use ($p) { |
|
79 | - $p->advance(); |
|
80 | - /** @var IUser $user */ |
|
81 | - $this->birthdayService->syncUser($user->getUID()); |
|
82 | - }); |
|
61 | + /** |
|
62 | + * @param InputInterface $input |
|
63 | + * @param OutputInterface $output |
|
64 | + */ |
|
65 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
66 | + $user = $input->getArgument('user'); |
|
67 | + if (!is_null($user)) { |
|
68 | + if (!$this->userManager->userExists($user)) { |
|
69 | + throw new \InvalidArgumentException("User <$user> in unknown."); |
|
70 | + } |
|
71 | + $output->writeln("Start birthday calendar sync for $user"); |
|
72 | + $this->birthdayService->syncUser($user); |
|
73 | + return; |
|
74 | + } |
|
75 | + $output->writeln("Start birthday calendar sync for all users ..."); |
|
76 | + $p = new ProgressBar($output); |
|
77 | + $p->start(); |
|
78 | + $this->userManager->callForAllUsers(function($user) use ($p) { |
|
79 | + $p->advance(); |
|
80 | + /** @var IUser $user */ |
|
81 | + $this->birthdayService->syncUser($user->getUID()); |
|
82 | + }); |
|
83 | 83 | |
84 | - $p->finish(); |
|
85 | - $output->writeln(''); |
|
86 | - } |
|
84 | + $p->finish(); |
|
85 | + $output->writeln(''); |
|
86 | + } |
|
87 | 87 | } |