@@ -23,12 +23,12 @@ |
||
23 | 23 | namespace OCA\Files_Sharing\External; |
24 | 24 | |
25 | 25 | class Watcher extends \OC\Files\Cache\Watcher { |
26 | - /** |
|
27 | - * remove deleted files in $path from the cache |
|
28 | - * |
|
29 | - * @param string $path |
|
30 | - */ |
|
31 | - public function cleanFolder($path) { |
|
32 | - // not needed, the scanner takes care of this |
|
33 | - } |
|
26 | + /** |
|
27 | + * remove deleted files in $path from the cache |
|
28 | + * |
|
29 | + * @param string $path |
|
30 | + */ |
|
31 | + public function cleanFolder($path) { |
|
32 | + // not needed, the scanner takes care of this |
|
33 | + } |
|
34 | 34 | } |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | */ |
97 | 97 | public function generateTarget($filePath, $shareWith, $exclude = null) { |
98 | 98 | $shareFolder = \OCA\Files_Sharing\Helper::getShareFolder(); |
99 | - $target = \OC\Files\Filesystem::normalizePath($shareFolder . '/' . basename($filePath)); |
|
99 | + $target = \OC\Files\Filesystem::normalizePath($shareFolder.'/'.basename($filePath)); |
|
100 | 100 | |
101 | 101 | // for group shares we return the target right away |
102 | 102 | if ($shareWith === false) { |
@@ -104,13 +104,13 @@ discard block |
||
104 | 104 | } |
105 | 105 | |
106 | 106 | \OC\Files\Filesystem::initMountPoints($shareWith); |
107 | - $view = new \OC\Files\View('/' . $shareWith . '/files'); |
|
107 | + $view = new \OC\Files\View('/'.$shareWith.'/files'); |
|
108 | 108 | |
109 | 109 | if (!$view->is_dir($shareFolder)) { |
110 | 110 | $dir = ''; |
111 | 111 | $subdirs = explode('/', $shareFolder); |
112 | 112 | foreach ($subdirs as $subdir) { |
113 | - $dir = $dir . '/' . $subdir; |
|
113 | + $dir = $dir.'/'.$subdir; |
|
114 | 114 | if (!$view->is_dir($dir)) { |
115 | 115 | $view->mkdir($dir); |
116 | 116 | } |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | if ($share['item_type'] === 'folder' && $target !== '') { |
238 | 238 | // note: in case of ext storage mount points the path might be empty |
239 | 239 | // which would cause a leading slash to appear |
240 | - $share['path'] = ltrim($share['path'] . '/' . $target, '/'); |
|
240 | + $share['path'] = ltrim($share['path'].'/'.$target, '/'); |
|
241 | 241 | } |
242 | 242 | return self::resolveReshares($share); |
243 | 243 | } |
@@ -38,218 +38,218 @@ |
||
38 | 38 | use OCP\Share\IShare; |
39 | 39 | |
40 | 40 | class File implements \OCP\Share_Backend_File_Dependent { |
41 | - public const FORMAT_SHARED_STORAGE = 0; |
|
42 | - public const FORMAT_GET_FOLDER_CONTENTS = 1; |
|
43 | - public const FORMAT_FILE_APP_ROOT = 2; |
|
44 | - public const FORMAT_OPENDIR = 3; |
|
45 | - public const FORMAT_GET_ALL = 4; |
|
46 | - public const FORMAT_PERMISSIONS = 5; |
|
47 | - public const FORMAT_TARGET_NAMES = 6; |
|
48 | - |
|
49 | - private $path; |
|
50 | - |
|
51 | - /** @var FederatedShareProvider */ |
|
52 | - private $federatedShareProvider; |
|
53 | - |
|
54 | - public function __construct(FederatedShareProvider $federatedShareProvider = null) { |
|
55 | - if ($federatedShareProvider) { |
|
56 | - $this->federatedShareProvider = $federatedShareProvider; |
|
57 | - } else { |
|
58 | - $this->federatedShareProvider = \OC::$server->query(FederatedShareProvider::class); |
|
59 | - } |
|
60 | - } |
|
61 | - |
|
62 | - public function isValidSource($itemSource, $uidOwner) { |
|
63 | - try { |
|
64 | - $path = \OC\Files\Filesystem::getPath($itemSource); |
|
65 | - // FIXME: attributes should not be set here, |
|
66 | - // keeping this pattern for now to avoid unexpected |
|
67 | - // regressions |
|
68 | - $this->path = \OC\Files\Filesystem::normalizePath(basename($path)); |
|
69 | - return true; |
|
70 | - } catch (\OCP\Files\NotFoundException $e) { |
|
71 | - return false; |
|
72 | - } |
|
73 | - } |
|
74 | - |
|
75 | - public function getFilePath($itemSource, $uidOwner) { |
|
76 | - if (isset($this->path)) { |
|
77 | - $path = $this->path; |
|
78 | - $this->path = null; |
|
79 | - return $path; |
|
80 | - } else { |
|
81 | - try { |
|
82 | - $path = \OC\Files\Filesystem::getPath($itemSource); |
|
83 | - return $path; |
|
84 | - } catch (\OCP\Files\NotFoundException $e) { |
|
85 | - return false; |
|
86 | - } |
|
87 | - } |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * create unique target |
|
92 | - * @param string $filePath |
|
93 | - * @param string $shareWith |
|
94 | - * @param array $exclude (optional) |
|
95 | - * @return string |
|
96 | - */ |
|
97 | - public function generateTarget($filePath, $shareWith, $exclude = null) { |
|
98 | - $shareFolder = \OCA\Files_Sharing\Helper::getShareFolder(); |
|
99 | - $target = \OC\Files\Filesystem::normalizePath($shareFolder . '/' . basename($filePath)); |
|
100 | - |
|
101 | - // for group shares we return the target right away |
|
102 | - if ($shareWith === false) { |
|
103 | - return $target; |
|
104 | - } |
|
105 | - |
|
106 | - \OC\Files\Filesystem::initMountPoints($shareWith); |
|
107 | - $view = new \OC\Files\View('/' . $shareWith . '/files'); |
|
108 | - |
|
109 | - if (!$view->is_dir($shareFolder)) { |
|
110 | - $dir = ''; |
|
111 | - $subdirs = explode('/', $shareFolder); |
|
112 | - foreach ($subdirs as $subdir) { |
|
113 | - $dir = $dir . '/' . $subdir; |
|
114 | - if (!$view->is_dir($dir)) { |
|
115 | - $view->mkdir($dir); |
|
116 | - } |
|
117 | - } |
|
118 | - } |
|
119 | - |
|
120 | - $excludeList = is_array($exclude) ? $exclude : []; |
|
121 | - |
|
122 | - return \OCA\Files_Sharing\Helper::generateUniqueTarget($target, $excludeList, $view); |
|
123 | - } |
|
124 | - |
|
125 | - public function formatItems($items, $format, $parameters = null) { |
|
126 | - if ($format === self::FORMAT_SHARED_STORAGE) { |
|
127 | - // Only 1 item should come through for this format call |
|
128 | - $item = array_shift($items); |
|
129 | - return [ |
|
130 | - 'parent' => $item['parent'], |
|
131 | - 'path' => $item['path'], |
|
132 | - 'storage' => $item['storage'], |
|
133 | - 'permissions' => $item['permissions'], |
|
134 | - 'uid_owner' => $item['uid_owner'], |
|
135 | - ]; |
|
136 | - } elseif ($format === self::FORMAT_GET_FOLDER_CONTENTS) { |
|
137 | - $files = []; |
|
138 | - foreach ($items as $item) { |
|
139 | - $file = []; |
|
140 | - $file['fileid'] = $item['file_source']; |
|
141 | - $file['storage'] = $item['storage']; |
|
142 | - $file['path'] = $item['file_target']; |
|
143 | - $file['parent'] = $item['file_parent']; |
|
144 | - $file['name'] = basename($item['file_target']); |
|
145 | - $file['mimetype'] = $item['mimetype']; |
|
146 | - $file['mimepart'] = $item['mimepart']; |
|
147 | - $file['mtime'] = $item['mtime']; |
|
148 | - $file['encrypted'] = $item['encrypted']; |
|
149 | - $file['etag'] = $item['etag']; |
|
150 | - $file['uid_owner'] = $item['uid_owner']; |
|
151 | - $file['displayname_owner'] = $item['displayname_owner']; |
|
152 | - |
|
153 | - $storage = \OC\Files\Filesystem::getStorage('/'); |
|
154 | - $cache = $storage->getCache(); |
|
155 | - $file['size'] = $item['size']; |
|
156 | - $files[] = $file; |
|
157 | - } |
|
158 | - return $files; |
|
159 | - } elseif ($format === self::FORMAT_OPENDIR) { |
|
160 | - $files = []; |
|
161 | - foreach ($items as $item) { |
|
162 | - $files[] = basename($item['file_target']); |
|
163 | - } |
|
164 | - return $files; |
|
165 | - } elseif ($format === self::FORMAT_GET_ALL) { |
|
166 | - $ids = []; |
|
167 | - foreach ($items as $item) { |
|
168 | - $ids[] = $item['file_source']; |
|
169 | - } |
|
170 | - return $ids; |
|
171 | - } elseif ($format === self::FORMAT_PERMISSIONS) { |
|
172 | - $filePermissions = []; |
|
173 | - foreach ($items as $item) { |
|
174 | - $filePermissions[$item['file_source']] = $item['permissions']; |
|
175 | - } |
|
176 | - return $filePermissions; |
|
177 | - } elseif ($format === self::FORMAT_TARGET_NAMES) { |
|
178 | - $targets = []; |
|
179 | - foreach ($items as $item) { |
|
180 | - $targets[] = $item['file_target']; |
|
181 | - } |
|
182 | - return $targets; |
|
183 | - } |
|
184 | - return []; |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * check if server2server share is enabled |
|
189 | - * |
|
190 | - * @param int $shareType |
|
191 | - * @return boolean |
|
192 | - */ |
|
193 | - public function isShareTypeAllowed($shareType) { |
|
194 | - if ($shareType === IShare::TYPE_REMOTE) { |
|
195 | - return $this->federatedShareProvider->isOutgoingServer2serverShareEnabled(); |
|
196 | - } |
|
197 | - |
|
198 | - if ($shareType === IShare::TYPE_REMOTE_GROUP) { |
|
199 | - return $this->federatedShareProvider->isOutgoingServer2serverGroupShareEnabled(); |
|
200 | - } |
|
201 | - |
|
202 | - return true; |
|
203 | - } |
|
204 | - |
|
205 | - /** |
|
206 | - * resolve reshares to return the correct source item |
|
207 | - * @param array $source |
|
208 | - * @return array source item |
|
209 | - */ |
|
210 | - protected static function resolveReshares($source) { |
|
211 | - if (isset($source['parent'])) { |
|
212 | - $parent = $source['parent']; |
|
213 | - while (isset($parent)) { |
|
214 | - $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
215 | - $qb->select('parent', 'uid_owner') |
|
216 | - ->from('share') |
|
217 | - ->where( |
|
218 | - $qb->expr()->eq('id', $qb->createNamedParameter($parent)) |
|
219 | - ); |
|
220 | - $result = $qb->execute(); |
|
221 | - $item = $result->fetch(); |
|
222 | - $result->closeCursor(); |
|
223 | - if (isset($item['parent'])) { |
|
224 | - $parent = $item['parent']; |
|
225 | - } else { |
|
226 | - $fileOwner = $item['uid_owner']; |
|
227 | - break; |
|
228 | - } |
|
229 | - } |
|
230 | - } else { |
|
231 | - $fileOwner = $source['uid_owner']; |
|
232 | - } |
|
233 | - if (isset($fileOwner)) { |
|
234 | - $source['fileOwner'] = $fileOwner; |
|
235 | - } else { |
|
236 | - \OC::$server->getLogger()->error('No owner found for reshare', ['app' => 'files_sharing']); |
|
237 | - } |
|
238 | - |
|
239 | - return $source; |
|
240 | - } |
|
241 | - |
|
242 | - /** |
|
243 | - * @param string $target |
|
244 | - * @param array $share |
|
245 | - * @return array|false source item |
|
246 | - */ |
|
247 | - public static function getSource($target, $share) { |
|
248 | - if ($share['item_type'] === 'folder' && $target !== '') { |
|
249 | - // note: in case of ext storage mount points the path might be empty |
|
250 | - // which would cause a leading slash to appear |
|
251 | - $share['path'] = ltrim($share['path'] . '/' . $target, '/'); |
|
252 | - } |
|
253 | - return self::resolveReshares($share); |
|
254 | - } |
|
41 | + public const FORMAT_SHARED_STORAGE = 0; |
|
42 | + public const FORMAT_GET_FOLDER_CONTENTS = 1; |
|
43 | + public const FORMAT_FILE_APP_ROOT = 2; |
|
44 | + public const FORMAT_OPENDIR = 3; |
|
45 | + public const FORMAT_GET_ALL = 4; |
|
46 | + public const FORMAT_PERMISSIONS = 5; |
|
47 | + public const FORMAT_TARGET_NAMES = 6; |
|
48 | + |
|
49 | + private $path; |
|
50 | + |
|
51 | + /** @var FederatedShareProvider */ |
|
52 | + private $federatedShareProvider; |
|
53 | + |
|
54 | + public function __construct(FederatedShareProvider $federatedShareProvider = null) { |
|
55 | + if ($federatedShareProvider) { |
|
56 | + $this->federatedShareProvider = $federatedShareProvider; |
|
57 | + } else { |
|
58 | + $this->federatedShareProvider = \OC::$server->query(FederatedShareProvider::class); |
|
59 | + } |
|
60 | + } |
|
61 | + |
|
62 | + public function isValidSource($itemSource, $uidOwner) { |
|
63 | + try { |
|
64 | + $path = \OC\Files\Filesystem::getPath($itemSource); |
|
65 | + // FIXME: attributes should not be set here, |
|
66 | + // keeping this pattern for now to avoid unexpected |
|
67 | + // regressions |
|
68 | + $this->path = \OC\Files\Filesystem::normalizePath(basename($path)); |
|
69 | + return true; |
|
70 | + } catch (\OCP\Files\NotFoundException $e) { |
|
71 | + return false; |
|
72 | + } |
|
73 | + } |
|
74 | + |
|
75 | + public function getFilePath($itemSource, $uidOwner) { |
|
76 | + if (isset($this->path)) { |
|
77 | + $path = $this->path; |
|
78 | + $this->path = null; |
|
79 | + return $path; |
|
80 | + } else { |
|
81 | + try { |
|
82 | + $path = \OC\Files\Filesystem::getPath($itemSource); |
|
83 | + return $path; |
|
84 | + } catch (\OCP\Files\NotFoundException $e) { |
|
85 | + return false; |
|
86 | + } |
|
87 | + } |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * create unique target |
|
92 | + * @param string $filePath |
|
93 | + * @param string $shareWith |
|
94 | + * @param array $exclude (optional) |
|
95 | + * @return string |
|
96 | + */ |
|
97 | + public function generateTarget($filePath, $shareWith, $exclude = null) { |
|
98 | + $shareFolder = \OCA\Files_Sharing\Helper::getShareFolder(); |
|
99 | + $target = \OC\Files\Filesystem::normalizePath($shareFolder . '/' . basename($filePath)); |
|
100 | + |
|
101 | + // for group shares we return the target right away |
|
102 | + if ($shareWith === false) { |
|
103 | + return $target; |
|
104 | + } |
|
105 | + |
|
106 | + \OC\Files\Filesystem::initMountPoints($shareWith); |
|
107 | + $view = new \OC\Files\View('/' . $shareWith . '/files'); |
|
108 | + |
|
109 | + if (!$view->is_dir($shareFolder)) { |
|
110 | + $dir = ''; |
|
111 | + $subdirs = explode('/', $shareFolder); |
|
112 | + foreach ($subdirs as $subdir) { |
|
113 | + $dir = $dir . '/' . $subdir; |
|
114 | + if (!$view->is_dir($dir)) { |
|
115 | + $view->mkdir($dir); |
|
116 | + } |
|
117 | + } |
|
118 | + } |
|
119 | + |
|
120 | + $excludeList = is_array($exclude) ? $exclude : []; |
|
121 | + |
|
122 | + return \OCA\Files_Sharing\Helper::generateUniqueTarget($target, $excludeList, $view); |
|
123 | + } |
|
124 | + |
|
125 | + public function formatItems($items, $format, $parameters = null) { |
|
126 | + if ($format === self::FORMAT_SHARED_STORAGE) { |
|
127 | + // Only 1 item should come through for this format call |
|
128 | + $item = array_shift($items); |
|
129 | + return [ |
|
130 | + 'parent' => $item['parent'], |
|
131 | + 'path' => $item['path'], |
|
132 | + 'storage' => $item['storage'], |
|
133 | + 'permissions' => $item['permissions'], |
|
134 | + 'uid_owner' => $item['uid_owner'], |
|
135 | + ]; |
|
136 | + } elseif ($format === self::FORMAT_GET_FOLDER_CONTENTS) { |
|
137 | + $files = []; |
|
138 | + foreach ($items as $item) { |
|
139 | + $file = []; |
|
140 | + $file['fileid'] = $item['file_source']; |
|
141 | + $file['storage'] = $item['storage']; |
|
142 | + $file['path'] = $item['file_target']; |
|
143 | + $file['parent'] = $item['file_parent']; |
|
144 | + $file['name'] = basename($item['file_target']); |
|
145 | + $file['mimetype'] = $item['mimetype']; |
|
146 | + $file['mimepart'] = $item['mimepart']; |
|
147 | + $file['mtime'] = $item['mtime']; |
|
148 | + $file['encrypted'] = $item['encrypted']; |
|
149 | + $file['etag'] = $item['etag']; |
|
150 | + $file['uid_owner'] = $item['uid_owner']; |
|
151 | + $file['displayname_owner'] = $item['displayname_owner']; |
|
152 | + |
|
153 | + $storage = \OC\Files\Filesystem::getStorage('/'); |
|
154 | + $cache = $storage->getCache(); |
|
155 | + $file['size'] = $item['size']; |
|
156 | + $files[] = $file; |
|
157 | + } |
|
158 | + return $files; |
|
159 | + } elseif ($format === self::FORMAT_OPENDIR) { |
|
160 | + $files = []; |
|
161 | + foreach ($items as $item) { |
|
162 | + $files[] = basename($item['file_target']); |
|
163 | + } |
|
164 | + return $files; |
|
165 | + } elseif ($format === self::FORMAT_GET_ALL) { |
|
166 | + $ids = []; |
|
167 | + foreach ($items as $item) { |
|
168 | + $ids[] = $item['file_source']; |
|
169 | + } |
|
170 | + return $ids; |
|
171 | + } elseif ($format === self::FORMAT_PERMISSIONS) { |
|
172 | + $filePermissions = []; |
|
173 | + foreach ($items as $item) { |
|
174 | + $filePermissions[$item['file_source']] = $item['permissions']; |
|
175 | + } |
|
176 | + return $filePermissions; |
|
177 | + } elseif ($format === self::FORMAT_TARGET_NAMES) { |
|
178 | + $targets = []; |
|
179 | + foreach ($items as $item) { |
|
180 | + $targets[] = $item['file_target']; |
|
181 | + } |
|
182 | + return $targets; |
|
183 | + } |
|
184 | + return []; |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * check if server2server share is enabled |
|
189 | + * |
|
190 | + * @param int $shareType |
|
191 | + * @return boolean |
|
192 | + */ |
|
193 | + public function isShareTypeAllowed($shareType) { |
|
194 | + if ($shareType === IShare::TYPE_REMOTE) { |
|
195 | + return $this->federatedShareProvider->isOutgoingServer2serverShareEnabled(); |
|
196 | + } |
|
197 | + |
|
198 | + if ($shareType === IShare::TYPE_REMOTE_GROUP) { |
|
199 | + return $this->federatedShareProvider->isOutgoingServer2serverGroupShareEnabled(); |
|
200 | + } |
|
201 | + |
|
202 | + return true; |
|
203 | + } |
|
204 | + |
|
205 | + /** |
|
206 | + * resolve reshares to return the correct source item |
|
207 | + * @param array $source |
|
208 | + * @return array source item |
|
209 | + */ |
|
210 | + protected static function resolveReshares($source) { |
|
211 | + if (isset($source['parent'])) { |
|
212 | + $parent = $source['parent']; |
|
213 | + while (isset($parent)) { |
|
214 | + $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
215 | + $qb->select('parent', 'uid_owner') |
|
216 | + ->from('share') |
|
217 | + ->where( |
|
218 | + $qb->expr()->eq('id', $qb->createNamedParameter($parent)) |
|
219 | + ); |
|
220 | + $result = $qb->execute(); |
|
221 | + $item = $result->fetch(); |
|
222 | + $result->closeCursor(); |
|
223 | + if (isset($item['parent'])) { |
|
224 | + $parent = $item['parent']; |
|
225 | + } else { |
|
226 | + $fileOwner = $item['uid_owner']; |
|
227 | + break; |
|
228 | + } |
|
229 | + } |
|
230 | + } else { |
|
231 | + $fileOwner = $source['uid_owner']; |
|
232 | + } |
|
233 | + if (isset($fileOwner)) { |
|
234 | + $source['fileOwner'] = $fileOwner; |
|
235 | + } else { |
|
236 | + \OC::$server->getLogger()->error('No owner found for reshare', ['app' => 'files_sharing']); |
|
237 | + } |
|
238 | + |
|
239 | + return $source; |
|
240 | + } |
|
241 | + |
|
242 | + /** |
|
243 | + * @param string $target |
|
244 | + * @param array $share |
|
245 | + * @return array|false source item |
|
246 | + */ |
|
247 | + public static function getSource($target, $share) { |
|
248 | + if ($share['item_type'] === 'folder' && $target !== '') { |
|
249 | + // note: in case of ext storage mount points the path might be empty |
|
250 | + // which would cause a leading slash to appear |
|
251 | + $share['path'] = ltrim($share['path'] . '/' . $target, '/'); |
|
252 | + } |
|
253 | + return self::resolveReshares($share); |
|
254 | + } |
|
255 | 255 | } |
@@ -28,55 +28,55 @@ |
||
28 | 28 | use OCP\Settings\IIconSection; |
29 | 29 | |
30 | 30 | class Section implements IIconSection { |
31 | - /** @var IL10N */ |
|
32 | - private $l; |
|
33 | - /** @var IURLGenerator */ |
|
34 | - private $url; |
|
31 | + /** @var IL10N */ |
|
32 | + private $l; |
|
33 | + /** @var IURLGenerator */ |
|
34 | + private $url; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @param IURLGenerator $url |
|
38 | - * @param IL10N $l |
|
39 | - */ |
|
40 | - public function __construct(IURLGenerator $url, IL10N $l) { |
|
41 | - $this->url = $url; |
|
42 | - $this->l = $l; |
|
43 | - } |
|
36 | + /** |
|
37 | + * @param IURLGenerator $url |
|
38 | + * @param IL10N $l |
|
39 | + */ |
|
40 | + public function __construct(IURLGenerator $url, IL10N $l) { |
|
41 | + $this->url = $url; |
|
42 | + $this->l = $l; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * returns the ID of the section. It is supposed to be a lower case string, |
|
47 | - * e.g. 'ldap' |
|
48 | - * |
|
49 | - * @returns string |
|
50 | - */ |
|
51 | - public function getID() { |
|
52 | - return 'theming'; |
|
53 | - } |
|
45 | + /** |
|
46 | + * returns the ID of the section. It is supposed to be a lower case string, |
|
47 | + * e.g. 'ldap' |
|
48 | + * |
|
49 | + * @returns string |
|
50 | + */ |
|
51 | + public function getID() { |
|
52 | + return 'theming'; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * returns the translated name as it should be displayed, e.g. 'LDAP / AD |
|
57 | - * integration'. Use the L10N service to translate it. |
|
58 | - * |
|
59 | - * @return string |
|
60 | - */ |
|
61 | - public function getName() { |
|
62 | - return $this->l->t('Theming'); |
|
63 | - } |
|
55 | + /** |
|
56 | + * returns the translated name as it should be displayed, e.g. 'LDAP / AD |
|
57 | + * integration'. Use the L10N service to translate it. |
|
58 | + * |
|
59 | + * @return string |
|
60 | + */ |
|
61 | + public function getName() { |
|
62 | + return $this->l->t('Theming'); |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * @return int whether the form should be rather on the top or bottom of |
|
67 | - * the settings navigation. The sections are arranged in ascending order of |
|
68 | - * the priority values. It is required to return a value between 0 and 99. |
|
69 | - * |
|
70 | - * E.g.: 70 |
|
71 | - */ |
|
72 | - public function getPriority() { |
|
73 | - return 30; |
|
74 | - } |
|
65 | + /** |
|
66 | + * @return int whether the form should be rather on the top or bottom of |
|
67 | + * the settings navigation. The sections are arranged in ascending order of |
|
68 | + * the priority values. It is required to return a value between 0 and 99. |
|
69 | + * |
|
70 | + * E.g.: 70 |
|
71 | + */ |
|
72 | + public function getPriority() { |
|
73 | + return 30; |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * {@inheritdoc} |
|
78 | - */ |
|
79 | - public function getIcon() { |
|
80 | - return $this->url->imagePath('theming', 'app-dark.svg'); |
|
81 | - } |
|
76 | + /** |
|
77 | + * {@inheritdoc} |
|
78 | + */ |
|
79 | + public function getIcon() { |
|
80 | + return $this->url->imagePath('theming', 'app-dark.svg'); |
|
81 | + } |
|
82 | 82 | } |
@@ -34,13 +34,13 @@ |
||
34 | 34 | */ |
35 | 35 | class BackupCode extends Entity { |
36 | 36 | |
37 | - /** @var string */ |
|
38 | - protected $userId; |
|
37 | + /** @var string */ |
|
38 | + protected $userId; |
|
39 | 39 | |
40 | - /** @var string */ |
|
41 | - protected $code; |
|
40 | + /** @var string */ |
|
41 | + protected $code; |
|
42 | 42 | |
43 | - /** @var int */ |
|
44 | - protected $used; |
|
43 | + /** @var int */ |
|
44 | + protected $used; |
|
45 | 45 | |
46 | 46 | } |
@@ -128,7 +128,7 @@ |
||
128 | 128 | $encryptedKey = $this->crypt->encryptPrivateKey($decryptedKey, $newPassword, $uid); |
129 | 129 | $header = $this->crypt->generateHeader(); |
130 | 130 | if ($encryptedKey) { |
131 | - $this->keyManager->setPrivateKey($uid, $header . $encryptedKey); |
|
131 | + $this->keyManager->setPrivateKey($uid, $header.$encryptedKey); |
|
132 | 132 | $this->session->setPrivateKey($decryptedKey); |
133 | 133 | $result = true; |
134 | 134 | } |
@@ -38,128 +38,128 @@ |
||
38 | 38 | |
39 | 39 | class SettingsController extends Controller { |
40 | 40 | |
41 | - /** @var IL10N */ |
|
42 | - private $l; |
|
43 | - |
|
44 | - /** @var IUserManager */ |
|
45 | - private $userManager; |
|
46 | - |
|
47 | - /** @var IUserSession */ |
|
48 | - private $userSession; |
|
49 | - |
|
50 | - /** @var KeyManager */ |
|
51 | - private $keyManager; |
|
52 | - |
|
53 | - /** @var Crypt */ |
|
54 | - private $crypt; |
|
55 | - |
|
56 | - /** @var Session */ |
|
57 | - private $session; |
|
58 | - |
|
59 | - /** @var ISession */ |
|
60 | - private $ocSession; |
|
61 | - |
|
62 | - /** @var Util */ |
|
63 | - private $util; |
|
64 | - |
|
65 | - /** |
|
66 | - * @param string $AppName |
|
67 | - * @param IRequest $request |
|
68 | - * @param IL10N $l10n |
|
69 | - * @param IUserManager $userManager |
|
70 | - * @param IUserSession $userSession |
|
71 | - * @param KeyManager $keyManager |
|
72 | - * @param Crypt $crypt |
|
73 | - * @param Session $session |
|
74 | - * @param ISession $ocSession |
|
75 | - * @param Util $util |
|
76 | - */ |
|
77 | - public function __construct($AppName, |
|
78 | - IRequest $request, |
|
79 | - IL10N $l10n, |
|
80 | - IUserManager $userManager, |
|
81 | - IUserSession $userSession, |
|
82 | - KeyManager $keyManager, |
|
83 | - Crypt $crypt, |
|
84 | - Session $session, |
|
85 | - ISession $ocSession, |
|
86 | - Util $util |
|
41 | + /** @var IL10N */ |
|
42 | + private $l; |
|
43 | + |
|
44 | + /** @var IUserManager */ |
|
45 | + private $userManager; |
|
46 | + |
|
47 | + /** @var IUserSession */ |
|
48 | + private $userSession; |
|
49 | + |
|
50 | + /** @var KeyManager */ |
|
51 | + private $keyManager; |
|
52 | + |
|
53 | + /** @var Crypt */ |
|
54 | + private $crypt; |
|
55 | + |
|
56 | + /** @var Session */ |
|
57 | + private $session; |
|
58 | + |
|
59 | + /** @var ISession */ |
|
60 | + private $ocSession; |
|
61 | + |
|
62 | + /** @var Util */ |
|
63 | + private $util; |
|
64 | + |
|
65 | + /** |
|
66 | + * @param string $AppName |
|
67 | + * @param IRequest $request |
|
68 | + * @param IL10N $l10n |
|
69 | + * @param IUserManager $userManager |
|
70 | + * @param IUserSession $userSession |
|
71 | + * @param KeyManager $keyManager |
|
72 | + * @param Crypt $crypt |
|
73 | + * @param Session $session |
|
74 | + * @param ISession $ocSession |
|
75 | + * @param Util $util |
|
76 | + */ |
|
77 | + public function __construct($AppName, |
|
78 | + IRequest $request, |
|
79 | + IL10N $l10n, |
|
80 | + IUserManager $userManager, |
|
81 | + IUserSession $userSession, |
|
82 | + KeyManager $keyManager, |
|
83 | + Crypt $crypt, |
|
84 | + Session $session, |
|
85 | + ISession $ocSession, |
|
86 | + Util $util |
|
87 | 87 | ) { |
88 | - parent::__construct($AppName, $request); |
|
89 | - $this->l = $l10n; |
|
90 | - $this->userSession = $userSession; |
|
91 | - $this->userManager = $userManager; |
|
92 | - $this->keyManager = $keyManager; |
|
93 | - $this->crypt = $crypt; |
|
94 | - $this->session = $session; |
|
95 | - $this->ocSession = $ocSession; |
|
96 | - $this->util = $util; |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * @NoAdminRequired |
|
102 | - * @UseSession |
|
103 | - * |
|
104 | - * @param string $oldPassword |
|
105 | - * @param string $newPassword |
|
106 | - * @return DataResponse |
|
107 | - */ |
|
108 | - public function updatePrivateKeyPassword($oldPassword, $newPassword) { |
|
109 | - $result = false; |
|
110 | - $uid = $this->userSession->getUser()->getUID(); |
|
111 | - $errorMessage = $this->l->t('Could not update the private key password.'); |
|
112 | - |
|
113 | - //check if password is correct |
|
114 | - $passwordCorrect = $this->userManager->checkPassword($uid, $newPassword); |
|
115 | - if ($passwordCorrect === false) { |
|
116 | - // if check with uid fails we need to check the password with the login name |
|
117 | - // e.g. in the ldap case. For local user we need to check the password with |
|
118 | - // the uid because in this case the login name is case insensitive |
|
119 | - $loginName = $this->ocSession->get('loginname'); |
|
120 | - $passwordCorrect = $this->userManager->checkPassword($loginName, $newPassword); |
|
121 | - } |
|
122 | - |
|
123 | - if ($passwordCorrect !== false) { |
|
124 | - $encryptedKey = $this->keyManager->getPrivateKey($uid); |
|
125 | - $decryptedKey = $this->crypt->decryptPrivateKey($encryptedKey, $oldPassword, $uid); |
|
126 | - |
|
127 | - if ($decryptedKey) { |
|
128 | - $encryptedKey = $this->crypt->encryptPrivateKey($decryptedKey, $newPassword, $uid); |
|
129 | - $header = $this->crypt->generateHeader(); |
|
130 | - if ($encryptedKey) { |
|
131 | - $this->keyManager->setPrivateKey($uid, $header . $encryptedKey); |
|
132 | - $this->session->setPrivateKey($decryptedKey); |
|
133 | - $result = true; |
|
134 | - } |
|
135 | - } else { |
|
136 | - $errorMessage = $this->l->t('The old password was not correct, please try again.'); |
|
137 | - } |
|
138 | - } else { |
|
139 | - $errorMessage = $this->l->t('The current log-in password was not correct, please try again.'); |
|
140 | - } |
|
141 | - |
|
142 | - if ($result === true) { |
|
143 | - $this->session->setStatus(Session::INIT_SUCCESSFUL); |
|
144 | - return new DataResponse( |
|
145 | - ['message' => (string) $this->l->t('Private key password successfully updated.')] |
|
146 | - ); |
|
147 | - } else { |
|
148 | - return new DataResponse( |
|
149 | - ['message' => (string) $errorMessage], |
|
150 | - Http::STATUS_BAD_REQUEST |
|
151 | - ); |
|
152 | - } |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * @UseSession |
|
157 | - * |
|
158 | - * @param bool $encryptHomeStorage |
|
159 | - * @return DataResponse |
|
160 | - */ |
|
161 | - public function setEncryptHomeStorage($encryptHomeStorage) { |
|
162 | - $this->util->setEncryptHomeStorage($encryptHomeStorage); |
|
163 | - return new DataResponse(); |
|
164 | - } |
|
88 | + parent::__construct($AppName, $request); |
|
89 | + $this->l = $l10n; |
|
90 | + $this->userSession = $userSession; |
|
91 | + $this->userManager = $userManager; |
|
92 | + $this->keyManager = $keyManager; |
|
93 | + $this->crypt = $crypt; |
|
94 | + $this->session = $session; |
|
95 | + $this->ocSession = $ocSession; |
|
96 | + $this->util = $util; |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * @NoAdminRequired |
|
102 | + * @UseSession |
|
103 | + * |
|
104 | + * @param string $oldPassword |
|
105 | + * @param string $newPassword |
|
106 | + * @return DataResponse |
|
107 | + */ |
|
108 | + public function updatePrivateKeyPassword($oldPassword, $newPassword) { |
|
109 | + $result = false; |
|
110 | + $uid = $this->userSession->getUser()->getUID(); |
|
111 | + $errorMessage = $this->l->t('Could not update the private key password.'); |
|
112 | + |
|
113 | + //check if password is correct |
|
114 | + $passwordCorrect = $this->userManager->checkPassword($uid, $newPassword); |
|
115 | + if ($passwordCorrect === false) { |
|
116 | + // if check with uid fails we need to check the password with the login name |
|
117 | + // e.g. in the ldap case. For local user we need to check the password with |
|
118 | + // the uid because in this case the login name is case insensitive |
|
119 | + $loginName = $this->ocSession->get('loginname'); |
|
120 | + $passwordCorrect = $this->userManager->checkPassword($loginName, $newPassword); |
|
121 | + } |
|
122 | + |
|
123 | + if ($passwordCorrect !== false) { |
|
124 | + $encryptedKey = $this->keyManager->getPrivateKey($uid); |
|
125 | + $decryptedKey = $this->crypt->decryptPrivateKey($encryptedKey, $oldPassword, $uid); |
|
126 | + |
|
127 | + if ($decryptedKey) { |
|
128 | + $encryptedKey = $this->crypt->encryptPrivateKey($decryptedKey, $newPassword, $uid); |
|
129 | + $header = $this->crypt->generateHeader(); |
|
130 | + if ($encryptedKey) { |
|
131 | + $this->keyManager->setPrivateKey($uid, $header . $encryptedKey); |
|
132 | + $this->session->setPrivateKey($decryptedKey); |
|
133 | + $result = true; |
|
134 | + } |
|
135 | + } else { |
|
136 | + $errorMessage = $this->l->t('The old password was not correct, please try again.'); |
|
137 | + } |
|
138 | + } else { |
|
139 | + $errorMessage = $this->l->t('The current log-in password was not correct, please try again.'); |
|
140 | + } |
|
141 | + |
|
142 | + if ($result === true) { |
|
143 | + $this->session->setStatus(Session::INIT_SUCCESSFUL); |
|
144 | + return new DataResponse( |
|
145 | + ['message' => (string) $this->l->t('Private key password successfully updated.')] |
|
146 | + ); |
|
147 | + } else { |
|
148 | + return new DataResponse( |
|
149 | + ['message' => (string) $errorMessage], |
|
150 | + Http::STATUS_BAD_REQUEST |
|
151 | + ); |
|
152 | + } |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * @UseSession |
|
157 | + * |
|
158 | + * @param bool $encryptHomeStorage |
|
159 | + * @return DataResponse |
|
160 | + */ |
|
161 | + public function setEncryptHomeStorage($encryptHomeStorage) { |
|
162 | + $this->util->setEncryptHomeStorage($encryptHomeStorage); |
|
163 | + return new DataResponse(); |
|
164 | + } |
|
165 | 165 | } |
@@ -27,72 +27,72 @@ |
||
27 | 27 | |
28 | 28 | class Setting implements ISetting { |
29 | 29 | |
30 | - /** @var IL10N */ |
|
31 | - protected $l; |
|
30 | + /** @var IL10N */ |
|
31 | + protected $l; |
|
32 | 32 | |
33 | - /** |
|
34 | - * @param IL10N $l |
|
35 | - */ |
|
36 | - public function __construct(IL10N $l) { |
|
37 | - $this->l = $l; |
|
38 | - } |
|
33 | + /** |
|
34 | + * @param IL10N $l |
|
35 | + */ |
|
36 | + public function __construct(IL10N $l) { |
|
37 | + $this->l = $l; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @return string Lowercase a-z and underscore only identifier |
|
42 | - * @since 11.0.0 |
|
43 | - */ |
|
44 | - public function getIdentifier() { |
|
45 | - return 'comments'; |
|
46 | - } |
|
40 | + /** |
|
41 | + * @return string Lowercase a-z and underscore only identifier |
|
42 | + * @since 11.0.0 |
|
43 | + */ |
|
44 | + public function getIdentifier() { |
|
45 | + return 'comments'; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @return string A translated string |
|
50 | - * @since 11.0.0 |
|
51 | - */ |
|
52 | - public function getName() { |
|
53 | - return $this->l->t('<strong>Comments</strong> for files'); |
|
54 | - } |
|
48 | + /** |
|
49 | + * @return string A translated string |
|
50 | + * @since 11.0.0 |
|
51 | + */ |
|
52 | + public function getName() { |
|
53 | + return $this->l->t('<strong>Comments</strong> for files'); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * @return int whether the filter should be rather on the top or bottom of |
|
58 | - * the admin section. The filters are arranged in ascending order of the |
|
59 | - * priority values. It is required to return a value between 0 and 100. |
|
60 | - * @since 11.0.0 |
|
61 | - */ |
|
62 | - public function getPriority() { |
|
63 | - return 50; |
|
64 | - } |
|
56 | + /** |
|
57 | + * @return int whether the filter should be rather on the top or bottom of |
|
58 | + * the admin section. The filters are arranged in ascending order of the |
|
59 | + * priority values. It is required to return a value between 0 and 100. |
|
60 | + * @since 11.0.0 |
|
61 | + */ |
|
62 | + public function getPriority() { |
|
63 | + return 50; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @return bool True when the option can be changed for the stream |
|
68 | - * @since 11.0.0 |
|
69 | - */ |
|
70 | - public function canChangeStream() { |
|
71 | - return true; |
|
72 | - } |
|
66 | + /** |
|
67 | + * @return bool True when the option can be changed for the stream |
|
68 | + * @since 11.0.0 |
|
69 | + */ |
|
70 | + public function canChangeStream() { |
|
71 | + return true; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @return bool True when the option can be changed for the stream |
|
76 | - * @since 11.0.0 |
|
77 | - */ |
|
78 | - public function isDefaultEnabledStream() { |
|
79 | - return true; |
|
80 | - } |
|
74 | + /** |
|
75 | + * @return bool True when the option can be changed for the stream |
|
76 | + * @since 11.0.0 |
|
77 | + */ |
|
78 | + public function isDefaultEnabledStream() { |
|
79 | + return true; |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * @return bool True when the option can be changed for the mail |
|
84 | - * @since 11.0.0 |
|
85 | - */ |
|
86 | - public function canChangeMail() { |
|
87 | - return true; |
|
88 | - } |
|
82 | + /** |
|
83 | + * @return bool True when the option can be changed for the mail |
|
84 | + * @since 11.0.0 |
|
85 | + */ |
|
86 | + public function canChangeMail() { |
|
87 | + return true; |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * @return bool True when the option can be changed for the stream |
|
92 | - * @since 11.0.0 |
|
93 | - */ |
|
94 | - public function isDefaultEnabledMail() { |
|
95 | - return false; |
|
96 | - } |
|
90 | + /** |
|
91 | + * @return bool True when the option can be changed for the stream |
|
92 | + * @since 11.0.0 |
|
93 | + */ |
|
94 | + public function isDefaultEnabledMail() { |
|
95 | + return false; |
|
96 | + } |
|
97 | 97 | } |
98 | 98 |
@@ -28,63 +28,63 @@ |
||
28 | 28 | |
29 | 29 | class Filter implements IFilter { |
30 | 30 | |
31 | - /** @var IL10N */ |
|
32 | - protected $l; |
|
31 | + /** @var IL10N */ |
|
32 | + protected $l; |
|
33 | 33 | |
34 | - /** @var IURLGenerator */ |
|
35 | - protected $url; |
|
34 | + /** @var IURLGenerator */ |
|
35 | + protected $url; |
|
36 | 36 | |
37 | - public function __construct(IL10N $l, IURLGenerator $url) { |
|
38 | - $this->l = $l; |
|
39 | - $this->url = $url; |
|
40 | - } |
|
37 | + public function __construct(IL10N $l, IURLGenerator $url) { |
|
38 | + $this->l = $l; |
|
39 | + $this->url = $url; |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * @return string Lowercase a-z only identifier |
|
44 | - * @since 11.0.0 |
|
45 | - */ |
|
46 | - public function getIdentifier() { |
|
47 | - return 'comments'; |
|
48 | - } |
|
42 | + /** |
|
43 | + * @return string Lowercase a-z only identifier |
|
44 | + * @since 11.0.0 |
|
45 | + */ |
|
46 | + public function getIdentifier() { |
|
47 | + return 'comments'; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @return string A translated string |
|
52 | - * @since 11.0.0 |
|
53 | - */ |
|
54 | - public function getName() { |
|
55 | - return $this->l->t('Comments'); |
|
56 | - } |
|
50 | + /** |
|
51 | + * @return string A translated string |
|
52 | + * @since 11.0.0 |
|
53 | + */ |
|
54 | + public function getName() { |
|
55 | + return $this->l->t('Comments'); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * @return int |
|
60 | - * @since 11.0.0 |
|
61 | - */ |
|
62 | - public function getPriority() { |
|
63 | - return 40; |
|
64 | - } |
|
58 | + /** |
|
59 | + * @return int |
|
60 | + * @since 11.0.0 |
|
61 | + */ |
|
62 | + public function getPriority() { |
|
63 | + return 40; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @return string Full URL to an icon, empty string when none is given |
|
68 | - * @since 11.0.0 |
|
69 | - */ |
|
70 | - public function getIcon() { |
|
71 | - return $this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/comment.svg')); |
|
72 | - } |
|
66 | + /** |
|
67 | + * @return string Full URL to an icon, empty string when none is given |
|
68 | + * @since 11.0.0 |
|
69 | + */ |
|
70 | + public function getIcon() { |
|
71 | + return $this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/comment.svg')); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @param string[] $types |
|
76 | - * @return string[] An array of allowed apps from which activities should be displayed |
|
77 | - * @since 11.0.0 |
|
78 | - */ |
|
79 | - public function filterTypes(array $types) { |
|
80 | - return $types; |
|
81 | - } |
|
74 | + /** |
|
75 | + * @param string[] $types |
|
76 | + * @return string[] An array of allowed apps from which activities should be displayed |
|
77 | + * @since 11.0.0 |
|
78 | + */ |
|
79 | + public function filterTypes(array $types) { |
|
80 | + return $types; |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * @return string[] An array of allowed apps from which activities should be displayed |
|
85 | - * @since 11.0.0 |
|
86 | - */ |
|
87 | - public function allowedApps() { |
|
88 | - return ['comments']; |
|
89 | - } |
|
83 | + /** |
|
84 | + * @return string[] An array of allowed apps from which activities should be displayed |
|
85 | + * @since 11.0.0 |
|
86 | + */ |
|
87 | + public function allowedApps() { |
|
88 | + return ['comments']; |
|
89 | + } |
|
90 | 90 | } |
@@ -107,8 +107,8 @@ |
||
107 | 107 | protected function removeDeletedFiles($uid) { |
108 | 108 | \OC_Util::tearDownFS(); |
109 | 109 | \OC_Util::setupFS($uid); |
110 | - if ($this->rootFolder->nodeExists('/' . $uid . '/files_trashbin')) { |
|
111 | - $this->rootFolder->get('/' . $uid . '/files_trashbin')->delete(); |
|
110 | + if ($this->rootFolder->nodeExists('/'.$uid.'/files_trashbin')) { |
|
111 | + $this->rootFolder->get('/'.$uid.'/files_trashbin')->delete(); |
|
112 | 112 | $query = $this->dbConnection->getQueryBuilder(); |
113 | 113 | $query->delete('files_trash') |
114 | 114 | ->where($query->expr()->eq('user', $query->createParameter('uid'))) |
@@ -39,98 +39,98 @@ |
||
39 | 39 | |
40 | 40 | class CleanUp extends Command { |
41 | 41 | |
42 | - /** @var IUserManager */ |
|
43 | - protected $userManager; |
|
42 | + /** @var IUserManager */ |
|
43 | + protected $userManager; |
|
44 | 44 | |
45 | - /** @var IRootFolder */ |
|
46 | - protected $rootFolder; |
|
45 | + /** @var IRootFolder */ |
|
46 | + protected $rootFolder; |
|
47 | 47 | |
48 | - /** @var \OCP\IDBConnection */ |
|
49 | - protected $dbConnection; |
|
48 | + /** @var \OCP\IDBConnection */ |
|
49 | + protected $dbConnection; |
|
50 | 50 | |
51 | - /** |
|
52 | - * @param IRootFolder $rootFolder |
|
53 | - * @param IUserManager $userManager |
|
54 | - * @param IDBConnection $dbConnection |
|
55 | - */ |
|
56 | - public function __construct(IRootFolder $rootFolder, IUserManager $userManager, IDBConnection $dbConnection) { |
|
57 | - parent::__construct(); |
|
58 | - $this->userManager = $userManager; |
|
59 | - $this->rootFolder = $rootFolder; |
|
60 | - $this->dbConnection = $dbConnection; |
|
61 | - } |
|
51 | + /** |
|
52 | + * @param IRootFolder $rootFolder |
|
53 | + * @param IUserManager $userManager |
|
54 | + * @param IDBConnection $dbConnection |
|
55 | + */ |
|
56 | + public function __construct(IRootFolder $rootFolder, IUserManager $userManager, IDBConnection $dbConnection) { |
|
57 | + parent::__construct(); |
|
58 | + $this->userManager = $userManager; |
|
59 | + $this->rootFolder = $rootFolder; |
|
60 | + $this->dbConnection = $dbConnection; |
|
61 | + } |
|
62 | 62 | |
63 | - protected function configure() { |
|
64 | - $this |
|
65 | - ->setName('trashbin:cleanup') |
|
66 | - ->setDescription('Remove deleted files') |
|
67 | - ->addArgument( |
|
68 | - 'user_id', |
|
69 | - InputArgument::OPTIONAL | InputArgument::IS_ARRAY, |
|
70 | - 'remove deleted files of the given user(s)' |
|
71 | - ) |
|
72 | - ->addOption( |
|
73 | - 'all-users', |
|
74 | - null, |
|
75 | - InputOption::VALUE_NONE, |
|
76 | - 'run action on all users' |
|
77 | - ); |
|
78 | - } |
|
63 | + protected function configure() { |
|
64 | + $this |
|
65 | + ->setName('trashbin:cleanup') |
|
66 | + ->setDescription('Remove deleted files') |
|
67 | + ->addArgument( |
|
68 | + 'user_id', |
|
69 | + InputArgument::OPTIONAL | InputArgument::IS_ARRAY, |
|
70 | + 'remove deleted files of the given user(s)' |
|
71 | + ) |
|
72 | + ->addOption( |
|
73 | + 'all-users', |
|
74 | + null, |
|
75 | + InputOption::VALUE_NONE, |
|
76 | + 'run action on all users' |
|
77 | + ); |
|
78 | + } |
|
79 | 79 | |
80 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
81 | - $users = $input->getArgument('user_id'); |
|
82 | - if ((!empty($users)) and ($input->getOption('all-users'))) { |
|
83 | - throw new InvalidOptionException('Either specify a user_id or --all-users'); |
|
84 | - } elseif (!empty($users)) { |
|
85 | - foreach ($users as $user) { |
|
86 | - if ($this->userManager->userExists($user)) { |
|
87 | - $output->writeln("Remove deleted files of <info>$user</info>"); |
|
88 | - $this->removeDeletedFiles($user); |
|
89 | - } else { |
|
90 | - $output->writeln("<error>Unknown user $user</error>"); |
|
91 | - return 1; |
|
92 | - } |
|
93 | - } |
|
94 | - } elseif ($input->getOption('all-users')) { |
|
95 | - $output->writeln('Remove deleted files for all users'); |
|
96 | - foreach ($this->userManager->getBackends() as $backend) { |
|
97 | - $name = get_class($backend); |
|
98 | - if ($backend instanceof IUserBackend) { |
|
99 | - $name = $backend->getBackendName(); |
|
100 | - } |
|
101 | - $output->writeln("Remove deleted files for users on backend <info>$name</info>"); |
|
102 | - $limit = 500; |
|
103 | - $offset = 0; |
|
104 | - do { |
|
105 | - $users = $backend->getUsers('', $limit, $offset); |
|
106 | - foreach ($users as $user) { |
|
107 | - $output->writeln(" <info>$user</info>"); |
|
108 | - $this->removeDeletedFiles($user); |
|
109 | - } |
|
110 | - $offset += $limit; |
|
111 | - } while (count($users) >= $limit); |
|
112 | - } |
|
113 | - } else { |
|
114 | - throw new InvalidOptionException('Either specify a user_id or --all-users'); |
|
115 | - } |
|
116 | - return 0; |
|
117 | - } |
|
80 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
81 | + $users = $input->getArgument('user_id'); |
|
82 | + if ((!empty($users)) and ($input->getOption('all-users'))) { |
|
83 | + throw new InvalidOptionException('Either specify a user_id or --all-users'); |
|
84 | + } elseif (!empty($users)) { |
|
85 | + foreach ($users as $user) { |
|
86 | + if ($this->userManager->userExists($user)) { |
|
87 | + $output->writeln("Remove deleted files of <info>$user</info>"); |
|
88 | + $this->removeDeletedFiles($user); |
|
89 | + } else { |
|
90 | + $output->writeln("<error>Unknown user $user</error>"); |
|
91 | + return 1; |
|
92 | + } |
|
93 | + } |
|
94 | + } elseif ($input->getOption('all-users')) { |
|
95 | + $output->writeln('Remove deleted files for all users'); |
|
96 | + foreach ($this->userManager->getBackends() as $backend) { |
|
97 | + $name = get_class($backend); |
|
98 | + if ($backend instanceof IUserBackend) { |
|
99 | + $name = $backend->getBackendName(); |
|
100 | + } |
|
101 | + $output->writeln("Remove deleted files for users on backend <info>$name</info>"); |
|
102 | + $limit = 500; |
|
103 | + $offset = 0; |
|
104 | + do { |
|
105 | + $users = $backend->getUsers('', $limit, $offset); |
|
106 | + foreach ($users as $user) { |
|
107 | + $output->writeln(" <info>$user</info>"); |
|
108 | + $this->removeDeletedFiles($user); |
|
109 | + } |
|
110 | + $offset += $limit; |
|
111 | + } while (count($users) >= $limit); |
|
112 | + } |
|
113 | + } else { |
|
114 | + throw new InvalidOptionException('Either specify a user_id or --all-users'); |
|
115 | + } |
|
116 | + return 0; |
|
117 | + } |
|
118 | 118 | |
119 | - /** |
|
120 | - * remove deleted files for the given user |
|
121 | - * |
|
122 | - * @param string $uid |
|
123 | - */ |
|
124 | - protected function removeDeletedFiles($uid) { |
|
125 | - \OC_Util::tearDownFS(); |
|
126 | - \OC_Util::setupFS($uid); |
|
127 | - if ($this->rootFolder->nodeExists('/' . $uid . '/files_trashbin')) { |
|
128 | - $this->rootFolder->get('/' . $uid . '/files_trashbin')->delete(); |
|
129 | - $query = $this->dbConnection->getQueryBuilder(); |
|
130 | - $query->delete('files_trash') |
|
131 | - ->where($query->expr()->eq('user', $query->createParameter('uid'))) |
|
132 | - ->setParameter('uid', $uid); |
|
133 | - $query->execute(); |
|
134 | - } |
|
135 | - } |
|
119 | + /** |
|
120 | + * remove deleted files for the given user |
|
121 | + * |
|
122 | + * @param string $uid |
|
123 | + */ |
|
124 | + protected function removeDeletedFiles($uid) { |
|
125 | + \OC_Util::tearDownFS(); |
|
126 | + \OC_Util::setupFS($uid); |
|
127 | + if ($this->rootFolder->nodeExists('/' . $uid . '/files_trashbin')) { |
|
128 | + $this->rootFolder->get('/' . $uid . '/files_trashbin')->delete(); |
|
129 | + $query = $this->dbConnection->getQueryBuilder(); |
|
130 | + $query->delete('files_trash') |
|
131 | + ->where($query->expr()->eq('user', $query->createParameter('uid'))) |
|
132 | + ->setParameter('uid', $uid); |
|
133 | + $query->execute(); |
|
134 | + } |
|
135 | + } |
|
136 | 136 | } |
@@ -33,17 +33,17 @@ |
||
33 | 33 | */ |
34 | 34 | class Capabilities implements ICapability { |
35 | 35 | |
36 | - /** |
|
37 | - * Return this classes capabilities |
|
38 | - * |
|
39 | - * @return array |
|
40 | - */ |
|
41 | - public function getCapabilities() { |
|
42 | - return [ |
|
43 | - 'files' => [ |
|
44 | - 'undelete' => true |
|
45 | - ] |
|
46 | - ]; |
|
47 | - } |
|
36 | + /** |
|
37 | + * Return this classes capabilities |
|
38 | + * |
|
39 | + * @return array |
|
40 | + */ |
|
41 | + public function getCapabilities() { |
|
42 | + return [ |
|
43 | + 'files' => [ |
|
44 | + 'undelete' => true |
|
45 | + ] |
|
46 | + ]; |
|
47 | + } |
|
48 | 48 | |
49 | 49 | } |