@@ -33,174 +33,174 @@ |
||
33 | 33 | use OCP\Share\IManager; |
34 | 34 | |
35 | 35 | class MountProvider implements IMountProvider { |
36 | - /** |
|
37 | - * @var \OCP\IConfig |
|
38 | - */ |
|
39 | - protected $config; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var IManager |
|
43 | - */ |
|
44 | - protected $shareManager; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var ILogger |
|
48 | - */ |
|
49 | - protected $logger; |
|
50 | - |
|
51 | - /** |
|
52 | - * @param \OCP\IConfig $config |
|
53 | - * @param IManager $shareManager |
|
54 | - * @param ILogger $logger |
|
55 | - */ |
|
56 | - public function __construct(IConfig $config, IManager $shareManager, ILogger $logger) { |
|
57 | - $this->config = $config; |
|
58 | - $this->shareManager = $shareManager; |
|
59 | - $this->logger = $logger; |
|
60 | - } |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * Get all mountpoints applicable for the user and check for shares where we need to update the etags |
|
65 | - * |
|
66 | - * @param \OCP\IUser $user |
|
67 | - * @param \OCP\Files\Storage\IStorageFactory $storageFactory |
|
68 | - * @return \OCP\Files\Mount\IMountPoint[] |
|
69 | - */ |
|
70 | - public function getMountsForUser(IUser $user, IStorageFactory $storageFactory) { |
|
71 | - |
|
72 | - $shares = $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_USER, null, -1); |
|
73 | - $shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_GROUP, null, -1)); |
|
74 | - $shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_CIRCLE, null, -1)); |
|
75 | - |
|
76 | - // filter out excluded shares and group shares that includes self |
|
77 | - $shares = array_filter($shares, function (\OCP\Share\IShare $share) use ($user) { |
|
78 | - return $share->getPermissions() > 0 && $share->getShareOwner() !== $user->getUID(); |
|
79 | - }); |
|
80 | - |
|
81 | - $superShares = $this->buildSuperShares($shares, $user); |
|
82 | - |
|
83 | - $mounts = []; |
|
84 | - foreach ($superShares as $share) { |
|
85 | - try { |
|
86 | - $mounts[] = new SharedMount( |
|
87 | - '\OCA\Files_Sharing\SharedStorage', |
|
88 | - $mounts, |
|
89 | - [ |
|
90 | - 'user' => $user->getUID(), |
|
91 | - // parent share |
|
92 | - 'superShare' => $share[0], |
|
93 | - // children/component of the superShare |
|
94 | - 'groupedShares' => $share[1], |
|
95 | - ], |
|
96 | - $storageFactory |
|
97 | - ); |
|
98 | - } catch (\Exception $e) { |
|
99 | - $this->logger->logException($e); |
|
100 | - $this->logger->error('Error while trying to create shared mount'); |
|
101 | - } |
|
102 | - } |
|
103 | - |
|
104 | - // array_filter removes the null values from the array |
|
105 | - return array_filter($mounts); |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Groups shares by path (nodeId) and target path |
|
110 | - * |
|
111 | - * @param \OCP\Share\IShare[] $shares |
|
112 | - * @return \OCP\Share\IShare[][] array of grouped shares, each element in the |
|
113 | - * array is a group which itself is an array of shares |
|
114 | - */ |
|
115 | - private function groupShares(array $shares) { |
|
116 | - $tmp = []; |
|
117 | - |
|
118 | - foreach ($shares as $share) { |
|
119 | - if (!isset($tmp[$share->getNodeId()])) { |
|
120 | - $tmp[$share->getNodeId()] = []; |
|
121 | - } |
|
122 | - $tmp[$share->getNodeId()][] = $share; |
|
123 | - } |
|
124 | - |
|
125 | - $result = []; |
|
126 | - // sort by stime, the super share will be based on the least recent share |
|
127 | - foreach ($tmp as &$tmp2) { |
|
128 | - @usort($tmp2, function($a, $b) { |
|
129 | - if ($a->getShareTime() <= $b->getShareTime()) { |
|
130 | - return -1; |
|
131 | - } |
|
132 | - return 1; |
|
133 | - }); |
|
134 | - $result[] = $tmp2; |
|
135 | - } |
|
136 | - |
|
137 | - return array_values($result); |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * Build super shares (virtual share) by grouping them by node id and target, |
|
142 | - * then for each group compute the super share and return it along with the matching |
|
143 | - * grouped shares. The most permissive permissions are used based on the permissions |
|
144 | - * of all shares within the group. |
|
145 | - * |
|
146 | - * @param \OCP\Share\IShare[] $allShares |
|
147 | - * @param \OCP\IUser $user user |
|
148 | - * @return array Tuple of [superShare, groupedShares] |
|
149 | - */ |
|
150 | - private function buildSuperShares(array $allShares, \OCP\IUser $user) { |
|
151 | - $result = []; |
|
152 | - |
|
153 | - $groupedShares = $this->groupShares($allShares); |
|
154 | - |
|
155 | - /** @var \OCP\Share\IShare[] $shares */ |
|
156 | - foreach ($groupedShares as $shares) { |
|
157 | - if (count($shares) === 0) { |
|
158 | - continue; |
|
159 | - } |
|
160 | - |
|
161 | - $superShare = $this->shareManager->newShare(); |
|
162 | - |
|
163 | - // compute super share based on first entry of the group |
|
164 | - $superShare->setId($shares[0]->getId()) |
|
165 | - ->setShareOwner($shares[0]->getShareOwner()) |
|
166 | - ->setNodeId($shares[0]->getNodeId()) |
|
167 | - ->setTarget($shares[0]->getTarget()); |
|
168 | - |
|
169 | - // use most permissive permissions |
|
170 | - $permissions = 0; |
|
171 | - foreach ($shares as $share) { |
|
172 | - $permissions |= $share->getPermissions(); |
|
173 | - if ($share->getTarget() !== $superShare->getTarget()) { |
|
174 | - // adjust target, for database consistency |
|
175 | - $share->setTarget($superShare->getTarget()); |
|
176 | - try { |
|
177 | - $this->shareManager->moveShare($share, $user->getUID()); |
|
178 | - } catch (\InvalidArgumentException $e) { |
|
179 | - // ignore as it is not important and we don't want to |
|
180 | - // block FS setup |
|
181 | - |
|
182 | - // the subsequent code anyway only uses the target of the |
|
183 | - // super share |
|
184 | - |
|
185 | - // such issue can usually happen when dealing with |
|
186 | - // null groups which usually appear with group backend |
|
187 | - // caching inconsistencies |
|
188 | - $this->logger->debug( |
|
189 | - 'Could not adjust share target for share ' . $share->getId() . ' to make it consistent: ' . $e->getMessage(), |
|
190 | - ['app' => 'files_sharing'] |
|
191 | - ); |
|
192 | - } |
|
193 | - } |
|
194 | - if (!is_null($share->getNodeCacheEntry())) { |
|
195 | - $superShare->setNodeCacheEntry($share->getNodeCacheEntry()); |
|
196 | - } |
|
197 | - } |
|
198 | - |
|
199 | - $superShare->setPermissions($permissions); |
|
200 | - |
|
201 | - $result[] = [$superShare, $shares]; |
|
202 | - } |
|
203 | - |
|
204 | - return $result; |
|
205 | - } |
|
36 | + /** |
|
37 | + * @var \OCP\IConfig |
|
38 | + */ |
|
39 | + protected $config; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var IManager |
|
43 | + */ |
|
44 | + protected $shareManager; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var ILogger |
|
48 | + */ |
|
49 | + protected $logger; |
|
50 | + |
|
51 | + /** |
|
52 | + * @param \OCP\IConfig $config |
|
53 | + * @param IManager $shareManager |
|
54 | + * @param ILogger $logger |
|
55 | + */ |
|
56 | + public function __construct(IConfig $config, IManager $shareManager, ILogger $logger) { |
|
57 | + $this->config = $config; |
|
58 | + $this->shareManager = $shareManager; |
|
59 | + $this->logger = $logger; |
|
60 | + } |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * Get all mountpoints applicable for the user and check for shares where we need to update the etags |
|
65 | + * |
|
66 | + * @param \OCP\IUser $user |
|
67 | + * @param \OCP\Files\Storage\IStorageFactory $storageFactory |
|
68 | + * @return \OCP\Files\Mount\IMountPoint[] |
|
69 | + */ |
|
70 | + public function getMountsForUser(IUser $user, IStorageFactory $storageFactory) { |
|
71 | + |
|
72 | + $shares = $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_USER, null, -1); |
|
73 | + $shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_GROUP, null, -1)); |
|
74 | + $shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_CIRCLE, null, -1)); |
|
75 | + |
|
76 | + // filter out excluded shares and group shares that includes self |
|
77 | + $shares = array_filter($shares, function (\OCP\Share\IShare $share) use ($user) { |
|
78 | + return $share->getPermissions() > 0 && $share->getShareOwner() !== $user->getUID(); |
|
79 | + }); |
|
80 | + |
|
81 | + $superShares = $this->buildSuperShares($shares, $user); |
|
82 | + |
|
83 | + $mounts = []; |
|
84 | + foreach ($superShares as $share) { |
|
85 | + try { |
|
86 | + $mounts[] = new SharedMount( |
|
87 | + '\OCA\Files_Sharing\SharedStorage', |
|
88 | + $mounts, |
|
89 | + [ |
|
90 | + 'user' => $user->getUID(), |
|
91 | + // parent share |
|
92 | + 'superShare' => $share[0], |
|
93 | + // children/component of the superShare |
|
94 | + 'groupedShares' => $share[1], |
|
95 | + ], |
|
96 | + $storageFactory |
|
97 | + ); |
|
98 | + } catch (\Exception $e) { |
|
99 | + $this->logger->logException($e); |
|
100 | + $this->logger->error('Error while trying to create shared mount'); |
|
101 | + } |
|
102 | + } |
|
103 | + |
|
104 | + // array_filter removes the null values from the array |
|
105 | + return array_filter($mounts); |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Groups shares by path (nodeId) and target path |
|
110 | + * |
|
111 | + * @param \OCP\Share\IShare[] $shares |
|
112 | + * @return \OCP\Share\IShare[][] array of grouped shares, each element in the |
|
113 | + * array is a group which itself is an array of shares |
|
114 | + */ |
|
115 | + private function groupShares(array $shares) { |
|
116 | + $tmp = []; |
|
117 | + |
|
118 | + foreach ($shares as $share) { |
|
119 | + if (!isset($tmp[$share->getNodeId()])) { |
|
120 | + $tmp[$share->getNodeId()] = []; |
|
121 | + } |
|
122 | + $tmp[$share->getNodeId()][] = $share; |
|
123 | + } |
|
124 | + |
|
125 | + $result = []; |
|
126 | + // sort by stime, the super share will be based on the least recent share |
|
127 | + foreach ($tmp as &$tmp2) { |
|
128 | + @usort($tmp2, function($a, $b) { |
|
129 | + if ($a->getShareTime() <= $b->getShareTime()) { |
|
130 | + return -1; |
|
131 | + } |
|
132 | + return 1; |
|
133 | + }); |
|
134 | + $result[] = $tmp2; |
|
135 | + } |
|
136 | + |
|
137 | + return array_values($result); |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * Build super shares (virtual share) by grouping them by node id and target, |
|
142 | + * then for each group compute the super share and return it along with the matching |
|
143 | + * grouped shares. The most permissive permissions are used based on the permissions |
|
144 | + * of all shares within the group. |
|
145 | + * |
|
146 | + * @param \OCP\Share\IShare[] $allShares |
|
147 | + * @param \OCP\IUser $user user |
|
148 | + * @return array Tuple of [superShare, groupedShares] |
|
149 | + */ |
|
150 | + private function buildSuperShares(array $allShares, \OCP\IUser $user) { |
|
151 | + $result = []; |
|
152 | + |
|
153 | + $groupedShares = $this->groupShares($allShares); |
|
154 | + |
|
155 | + /** @var \OCP\Share\IShare[] $shares */ |
|
156 | + foreach ($groupedShares as $shares) { |
|
157 | + if (count($shares) === 0) { |
|
158 | + continue; |
|
159 | + } |
|
160 | + |
|
161 | + $superShare = $this->shareManager->newShare(); |
|
162 | + |
|
163 | + // compute super share based on first entry of the group |
|
164 | + $superShare->setId($shares[0]->getId()) |
|
165 | + ->setShareOwner($shares[0]->getShareOwner()) |
|
166 | + ->setNodeId($shares[0]->getNodeId()) |
|
167 | + ->setTarget($shares[0]->getTarget()); |
|
168 | + |
|
169 | + // use most permissive permissions |
|
170 | + $permissions = 0; |
|
171 | + foreach ($shares as $share) { |
|
172 | + $permissions |= $share->getPermissions(); |
|
173 | + if ($share->getTarget() !== $superShare->getTarget()) { |
|
174 | + // adjust target, for database consistency |
|
175 | + $share->setTarget($superShare->getTarget()); |
|
176 | + try { |
|
177 | + $this->shareManager->moveShare($share, $user->getUID()); |
|
178 | + } catch (\InvalidArgumentException $e) { |
|
179 | + // ignore as it is not important and we don't want to |
|
180 | + // block FS setup |
|
181 | + |
|
182 | + // the subsequent code anyway only uses the target of the |
|
183 | + // super share |
|
184 | + |
|
185 | + // such issue can usually happen when dealing with |
|
186 | + // null groups which usually appear with group backend |
|
187 | + // caching inconsistencies |
|
188 | + $this->logger->debug( |
|
189 | + 'Could not adjust share target for share ' . $share->getId() . ' to make it consistent: ' . $e->getMessage(), |
|
190 | + ['app' => 'files_sharing'] |
|
191 | + ); |
|
192 | + } |
|
193 | + } |
|
194 | + if (!is_null($share->getNodeCacheEntry())) { |
|
195 | + $superShare->setNodeCacheEntry($share->getNodeCacheEntry()); |
|
196 | + } |
|
197 | + } |
|
198 | + |
|
199 | + $superShare->setPermissions($permissions); |
|
200 | + |
|
201 | + $result[] = [$superShare, $shares]; |
|
202 | + } |
|
203 | + |
|
204 | + return $result; |
|
205 | + } |
|
206 | 206 | } |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | $shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_CIRCLE, null, -1)); |
75 | 75 | |
76 | 76 | // filter out excluded shares and group shares that includes self |
77 | - $shares = array_filter($shares, function (\OCP\Share\IShare $share) use ($user) { |
|
77 | + $shares = array_filter($shares, function(\OCP\Share\IShare $share) use ($user) { |
|
78 | 78 | return $share->getPermissions() > 0 && $share->getShareOwner() !== $user->getUID(); |
79 | 79 | }); |
80 | 80 | |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | // null groups which usually appear with group backend |
187 | 187 | // caching inconsistencies |
188 | 188 | $this->logger->debug( |
189 | - 'Could not adjust share target for share ' . $share->getId() . ' to make it consistent: ' . $e->getMessage(), |
|
189 | + 'Could not adjust share target for share '.$share->getId().' to make it consistent: '.$e->getMessage(), |
|
190 | 190 | ['app' => 'files_sharing'] |
191 | 191 | ); |
192 | 192 | } |
@@ -29,141 +29,141 @@ |
||
29 | 29 | |
30 | 30 | class Entry implements IEntry { |
31 | 31 | |
32 | - /** @var string|int|null */ |
|
33 | - private $id = null; |
|
34 | - |
|
35 | - /** @var string */ |
|
36 | - private $fullName = ''; |
|
37 | - |
|
38 | - /** @var string[] */ |
|
39 | - private $emailAddresses = []; |
|
40 | - |
|
41 | - /** @var string|null */ |
|
42 | - private $avatar; |
|
43 | - |
|
44 | - /** @var IAction[] */ |
|
45 | - private $actions = []; |
|
46 | - |
|
47 | - /** @var array */ |
|
48 | - private $properties = []; |
|
49 | - |
|
50 | - /** |
|
51 | - * @param string $id |
|
52 | - */ |
|
53 | - public function setId($id) { |
|
54 | - $this->id = $id; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @param string $displayName |
|
59 | - */ |
|
60 | - public function setFullName($displayName) { |
|
61 | - $this->fullName = $displayName; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - public function getFullName() { |
|
68 | - return $this->fullName; |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * @param string $address |
|
73 | - */ |
|
74 | - public function addEMailAddress($address) { |
|
75 | - $this->emailAddresses[] = $address; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * @return string |
|
80 | - */ |
|
81 | - public function getEMailAddresses() { |
|
82 | - return $this->emailAddresses; |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * @param string $avatar |
|
87 | - */ |
|
88 | - public function setAvatar($avatar) { |
|
89 | - $this->avatar = $avatar; |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * @return string |
|
94 | - */ |
|
95 | - public function getAvatar() { |
|
96 | - return $this->avatar; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * @param IAction $action |
|
101 | - */ |
|
102 | - public function addAction(IAction $action) { |
|
103 | - $this->actions[] = $action; |
|
104 | - $this->sortActions(); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @return IAction[] |
|
109 | - */ |
|
110 | - public function getActions() { |
|
111 | - return $this->actions; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * sort the actions by priority and name |
|
116 | - */ |
|
117 | - private function sortActions() { |
|
118 | - usort($this->actions, function(IAction $action1, IAction $action2) { |
|
119 | - $prio1 = $action1->getPriority(); |
|
120 | - $prio2 = $action2->getPriority(); |
|
121 | - |
|
122 | - if ($prio1 === $prio2) { |
|
123 | - // Ascending order for same priority |
|
124 | - return strcasecmp($action1->getName(), $action2->getName()); |
|
125 | - } |
|
126 | - |
|
127 | - // Descending order when priority differs |
|
128 | - return $prio2 - $prio1; |
|
129 | - }); |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * @param array $contact key-value array containing additional properties |
|
134 | - */ |
|
135 | - public function setProperties(array $contact) { |
|
136 | - $this->properties = $contact; |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * @param string $key |
|
141 | - * @return mixed |
|
142 | - */ |
|
143 | - public function getProperty($key) { |
|
144 | - if (!isset($this->properties[$key])) { |
|
145 | - return null; |
|
146 | - } |
|
147 | - return $this->properties[$key]; |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * @return array |
|
152 | - */ |
|
153 | - public function jsonSerialize() { |
|
154 | - $topAction = !empty($this->actions) ? $this->actions[0]->jsonSerialize() : null; |
|
155 | - $otherActions = array_map(function(IAction $action) { |
|
156 | - return $action->jsonSerialize(); |
|
157 | - }, array_slice($this->actions, 1)); |
|
158 | - |
|
159 | - return [ |
|
160 | - 'id' => $this->id, |
|
161 | - 'fullName' => $this->fullName, |
|
162 | - 'avatar' => $this->getAvatar(), |
|
163 | - 'topAction' => $topAction, |
|
164 | - 'actions' => $otherActions, |
|
165 | - 'lastMessage' => '', |
|
166 | - ]; |
|
167 | - } |
|
32 | + /** @var string|int|null */ |
|
33 | + private $id = null; |
|
34 | + |
|
35 | + /** @var string */ |
|
36 | + private $fullName = ''; |
|
37 | + |
|
38 | + /** @var string[] */ |
|
39 | + private $emailAddresses = []; |
|
40 | + |
|
41 | + /** @var string|null */ |
|
42 | + private $avatar; |
|
43 | + |
|
44 | + /** @var IAction[] */ |
|
45 | + private $actions = []; |
|
46 | + |
|
47 | + /** @var array */ |
|
48 | + private $properties = []; |
|
49 | + |
|
50 | + /** |
|
51 | + * @param string $id |
|
52 | + */ |
|
53 | + public function setId($id) { |
|
54 | + $this->id = $id; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @param string $displayName |
|
59 | + */ |
|
60 | + public function setFullName($displayName) { |
|
61 | + $this->fullName = $displayName; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + public function getFullName() { |
|
68 | + return $this->fullName; |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * @param string $address |
|
73 | + */ |
|
74 | + public function addEMailAddress($address) { |
|
75 | + $this->emailAddresses[] = $address; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * @return string |
|
80 | + */ |
|
81 | + public function getEMailAddresses() { |
|
82 | + return $this->emailAddresses; |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * @param string $avatar |
|
87 | + */ |
|
88 | + public function setAvatar($avatar) { |
|
89 | + $this->avatar = $avatar; |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * @return string |
|
94 | + */ |
|
95 | + public function getAvatar() { |
|
96 | + return $this->avatar; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * @param IAction $action |
|
101 | + */ |
|
102 | + public function addAction(IAction $action) { |
|
103 | + $this->actions[] = $action; |
|
104 | + $this->sortActions(); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @return IAction[] |
|
109 | + */ |
|
110 | + public function getActions() { |
|
111 | + return $this->actions; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * sort the actions by priority and name |
|
116 | + */ |
|
117 | + private function sortActions() { |
|
118 | + usort($this->actions, function(IAction $action1, IAction $action2) { |
|
119 | + $prio1 = $action1->getPriority(); |
|
120 | + $prio2 = $action2->getPriority(); |
|
121 | + |
|
122 | + if ($prio1 === $prio2) { |
|
123 | + // Ascending order for same priority |
|
124 | + return strcasecmp($action1->getName(), $action2->getName()); |
|
125 | + } |
|
126 | + |
|
127 | + // Descending order when priority differs |
|
128 | + return $prio2 - $prio1; |
|
129 | + }); |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * @param array $contact key-value array containing additional properties |
|
134 | + */ |
|
135 | + public function setProperties(array $contact) { |
|
136 | + $this->properties = $contact; |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * @param string $key |
|
141 | + * @return mixed |
|
142 | + */ |
|
143 | + public function getProperty($key) { |
|
144 | + if (!isset($this->properties[$key])) { |
|
145 | + return null; |
|
146 | + } |
|
147 | + return $this->properties[$key]; |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * @return array |
|
152 | + */ |
|
153 | + public function jsonSerialize() { |
|
154 | + $topAction = !empty($this->actions) ? $this->actions[0]->jsonSerialize() : null; |
|
155 | + $otherActions = array_map(function(IAction $action) { |
|
156 | + return $action->jsonSerialize(); |
|
157 | + }, array_slice($this->actions, 1)); |
|
158 | + |
|
159 | + return [ |
|
160 | + 'id' => $this->id, |
|
161 | + 'fullName' => $this->fullName, |
|
162 | + 'avatar' => $this->getAvatar(), |
|
163 | + 'topAction' => $topAction, |
|
164 | + 'actions' => $otherActions, |
|
165 | + 'lastMessage' => '', |
|
166 | + ]; |
|
167 | + } |
|
168 | 168 | |
169 | 169 | } |
@@ -31,36 +31,36 @@ |
||
31 | 31 | */ |
32 | 32 | interface IEntry extends JsonSerializable { |
33 | 33 | |
34 | - /** |
|
35 | - * @since 12.0 |
|
36 | - * @return string |
|
37 | - */ |
|
38 | - public function getFullName(); |
|
34 | + /** |
|
35 | + * @since 12.0 |
|
36 | + * @return string |
|
37 | + */ |
|
38 | + public function getFullName(); |
|
39 | 39 | |
40 | - /** |
|
41 | - * @since 12.0 |
|
42 | - * @return string[] |
|
43 | - */ |
|
44 | - public function getEMailAddresses(); |
|
40 | + /** |
|
41 | + * @since 12.0 |
|
42 | + * @return string[] |
|
43 | + */ |
|
44 | + public function getEMailAddresses(); |
|
45 | 45 | |
46 | - /** |
|
47 | - * @since 12.0 |
|
48 | - * @return string|null image URI |
|
49 | - */ |
|
50 | - public function getAvatar(); |
|
46 | + /** |
|
47 | + * @since 12.0 |
|
48 | + * @return string|null image URI |
|
49 | + */ |
|
50 | + public function getAvatar(); |
|
51 | 51 | |
52 | - /** |
|
53 | - * @since 12.0 |
|
54 | - * @param IAction $action an action to show in the contacts menu |
|
55 | - */ |
|
56 | - public function addAction(IAction $action); |
|
52 | + /** |
|
53 | + * @since 12.0 |
|
54 | + * @param IAction $action an action to show in the contacts menu |
|
55 | + */ |
|
56 | + public function addAction(IAction $action); |
|
57 | 57 | |
58 | - /** |
|
59 | - * Get an arbitrary property from the contact |
|
60 | - * |
|
61 | - * @since 12.0 |
|
62 | - * @param string $key |
|
63 | - * @return mixed the value of the property or null |
|
64 | - */ |
|
65 | - public function getProperty($key); |
|
58 | + /** |
|
59 | + * Get an arbitrary property from the contact |
|
60 | + * |
|
61 | + * @since 12.0 |
|
62 | + * @param string $key |
|
63 | + * @return mixed the value of the property or null |
|
64 | + */ |
|
65 | + public function getProperty($key); |
|
66 | 66 | } |
@@ -47,58 +47,58 @@ |
||
47 | 47 | */ |
48 | 48 | interface IContainer { |
49 | 49 | |
50 | - /** |
|
51 | - * If a parameter is not registered in the container try to instantiate it |
|
52 | - * by using reflection to find out how to build the class |
|
53 | - * @param string $name the class name to resolve |
|
54 | - * @return \stdClass |
|
55 | - * @since 8.2.0 |
|
56 | - * @throws QueryException if the class could not be found or instantiated |
|
57 | - */ |
|
58 | - public function resolve($name); |
|
50 | + /** |
|
51 | + * If a parameter is not registered in the container try to instantiate it |
|
52 | + * by using reflection to find out how to build the class |
|
53 | + * @param string $name the class name to resolve |
|
54 | + * @return \stdClass |
|
55 | + * @since 8.2.0 |
|
56 | + * @throws QueryException if the class could not be found or instantiated |
|
57 | + */ |
|
58 | + public function resolve($name); |
|
59 | 59 | |
60 | - /** |
|
61 | - * Look up a service for a given name in the container. |
|
62 | - * |
|
63 | - * @param string $name |
|
64 | - * @return mixed |
|
65 | - * @throws QueryException if the query could not be resolved |
|
66 | - * @since 6.0.0 |
|
67 | - */ |
|
68 | - public function query($name); |
|
60 | + /** |
|
61 | + * Look up a service for a given name in the container. |
|
62 | + * |
|
63 | + * @param string $name |
|
64 | + * @return mixed |
|
65 | + * @throws QueryException if the query could not be resolved |
|
66 | + * @since 6.0.0 |
|
67 | + */ |
|
68 | + public function query($name); |
|
69 | 69 | |
70 | - /** |
|
71 | - * A value is stored in the container with it's corresponding name |
|
72 | - * |
|
73 | - * @param string $name |
|
74 | - * @param mixed $value |
|
75 | - * @return void |
|
76 | - * @since 6.0.0 |
|
77 | - */ |
|
78 | - public function registerParameter($name, $value); |
|
70 | + /** |
|
71 | + * A value is stored in the container with it's corresponding name |
|
72 | + * |
|
73 | + * @param string $name |
|
74 | + * @param mixed $value |
|
75 | + * @return void |
|
76 | + * @since 6.0.0 |
|
77 | + */ |
|
78 | + public function registerParameter($name, $value); |
|
79 | 79 | |
80 | - /** |
|
81 | - * A service is registered in the container where a closure is passed in which will actually |
|
82 | - * create the service on demand. |
|
83 | - * In case the parameter $shared is set to true (the default usage) the once created service will remain in |
|
84 | - * memory and be reused on subsequent calls. |
|
85 | - * In case the parameter is false the service will be recreated on every call. |
|
86 | - * |
|
87 | - * @param string $name |
|
88 | - * @param \Closure $closure |
|
89 | - * @param bool $shared |
|
90 | - * @return void |
|
91 | - * @since 6.0.0 |
|
92 | - */ |
|
93 | - public function registerService($name, Closure $closure, $shared = true); |
|
80 | + /** |
|
81 | + * A service is registered in the container where a closure is passed in which will actually |
|
82 | + * create the service on demand. |
|
83 | + * In case the parameter $shared is set to true (the default usage) the once created service will remain in |
|
84 | + * memory and be reused on subsequent calls. |
|
85 | + * In case the parameter is false the service will be recreated on every call. |
|
86 | + * |
|
87 | + * @param string $name |
|
88 | + * @param \Closure $closure |
|
89 | + * @param bool $shared |
|
90 | + * @return void |
|
91 | + * @since 6.0.0 |
|
92 | + */ |
|
93 | + public function registerService($name, Closure $closure, $shared = true); |
|
94 | 94 | |
95 | - /** |
|
96 | - * Shortcut for returning a service from a service under a different key, |
|
97 | - * e.g. to tell the container to return a class when queried for an |
|
98 | - * interface |
|
99 | - * @param string $alias the alias that should be registered |
|
100 | - * @param string $target the target that should be resolved instead |
|
101 | - * @since 8.2.0 |
|
102 | - */ |
|
103 | - public function registerAlias($alias, $target); |
|
95 | + /** |
|
96 | + * Shortcut for returning a service from a service under a different key, |
|
97 | + * e.g. to tell the container to return a class when queried for an |
|
98 | + * interface |
|
99 | + * @param string $alias the alias that should be registered |
|
100 | + * @param string $target the target that should be resolved instead |
|
101 | + * @since 8.2.0 |
|
102 | + */ |
|
103 | + public function registerAlias($alias, $target); |
|
104 | 104 | } |
@@ -30,6 +30,9 @@ discard block |
||
30 | 30 | /** @var JSCombiner */ |
31 | 31 | protected $jsCombiner; |
32 | 32 | |
33 | + /** |
|
34 | + * @param string $theme |
|
35 | + */ |
|
33 | 36 | public function __construct(\OCP\ILogger $logger, $theme, array $core_map, array $party_map, JSCombiner $JSCombiner) { |
34 | 37 | parent::__construct($logger, $theme, $core_map, $party_map); |
35 | 38 | |
@@ -91,6 +94,9 @@ discard block |
||
91 | 94 | public function doFindTheme($script) { |
92 | 95 | } |
93 | 96 | |
97 | + /** |
|
98 | + * @param string $file |
|
99 | + */ |
|
94 | 100 | protected function cacheAndAppendCombineJsonIfExist($root, $file, $app = 'core') { |
95 | 101 | if (is_file($root.'/'.$file)) { |
96 | 102 | if ($this->jsCombiner->process($root, $file, $app)) { |
@@ -71,26 +71,26 @@ |
||
71 | 71 | } |
72 | 72 | |
73 | 73 | $app = substr($script, 0, strpos($script, '/')); |
74 | - $script = substr($script, strpos($script, '/')+1); |
|
74 | + $script = substr($script, strpos($script, '/') + 1); |
|
75 | 75 | $app_path = \OC_App::getAppPath($app); |
76 | 76 | $app_url = \OC_App::getAppWebPath($app); |
77 | 77 | |
78 | 78 | // missing translations files fill be ignored |
79 | 79 | if (strpos($script, 'l10n/') === 0) { |
80 | - $this->appendIfExist($app_path, $script . '.js', $app_url); |
|
80 | + $this->appendIfExist($app_path, $script.'.js', $app_url); |
|
81 | 81 | return; |
82 | 82 | } |
83 | 83 | |
84 | 84 | if ($app_path === false && $app_url === false) { |
85 | 85 | $this->logger->error('Could not find resource {resource} to load', [ |
86 | - 'resource' => $app . '/' . $script . '.js', |
|
86 | + 'resource' => $app.'/'.$script.'.js', |
|
87 | 87 | 'app' => 'jsresourceloader', |
88 | 88 | ]); |
89 | 89 | return; |
90 | 90 | } |
91 | 91 | |
92 | 92 | if (!$this->cacheAndAppendCombineJsonIfExist($app_path, $script.'.json', $app)) { |
93 | - $this->append($app_path, $script . '.js', $app_url); |
|
93 | + $this->append($app_path, $script.'.js', $app_url); |
|
94 | 94 | } |
95 | 95 | } |
96 | 96 |
@@ -28,102 +28,102 @@ |
||
28 | 28 | |
29 | 29 | class JSResourceLocator extends ResourceLocator { |
30 | 30 | |
31 | - /** @var JSCombiner */ |
|
32 | - protected $jsCombiner; |
|
33 | - |
|
34 | - public function __construct(\OCP\ILogger $logger, $theme, array $core_map, array $party_map, JSCombiner $JSCombiner) { |
|
35 | - parent::__construct($logger, $theme, $core_map, $party_map); |
|
36 | - |
|
37 | - $this->jsCombiner = $JSCombiner; |
|
38 | - } |
|
39 | - |
|
40 | - /** |
|
41 | - * @param string $script |
|
42 | - */ |
|
43 | - public function doFind($script) { |
|
44 | - $theme_dir = 'themes/'.$this->theme.'/'; |
|
45 | - if (strpos($script, '3rdparty') === 0 |
|
46 | - && $this->appendIfExist($this->thirdpartyroot, $script.'.js')) { |
|
47 | - return; |
|
48 | - } |
|
49 | - |
|
50 | - if (strpos($script, '/l10n/') !== false) { |
|
51 | - // For language files we try to load them all, so themes can overwrite |
|
52 | - // single l10n strings without having to translate all of them. |
|
53 | - $found = 0; |
|
54 | - $found += $this->appendIfExist($this->serverroot, 'core/'.$script.'.js'); |
|
55 | - $found += $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$script.'.js'); |
|
56 | - $found += $this->appendIfExist($this->serverroot, $script.'.js'); |
|
57 | - $found += $this->appendIfExist($this->serverroot, $theme_dir.$script.'.js'); |
|
58 | - $found += $this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$script.'.js'); |
|
59 | - |
|
60 | - if ($found) { |
|
61 | - return; |
|
62 | - } |
|
63 | - } else if ($this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$script.'.js') |
|
64 | - || $this->appendIfExist($this->serverroot, $theme_dir.$script.'.js') |
|
65 | - || $this->appendIfExist($this->serverroot, $script.'.js') |
|
66 | - || $this->cacheAndAppendCombineJsonIfExist($this->serverroot, $script.'.json') |
|
67 | - || $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$script.'.js') |
|
68 | - || $this->appendIfExist($this->serverroot, 'core/'.$script.'.js') |
|
69 | - || $this->cacheAndAppendCombineJsonIfExist($this->serverroot, 'core/'.$script.'.json') |
|
70 | - ) { |
|
71 | - return; |
|
72 | - } |
|
73 | - |
|
74 | - $app = substr($script, 0, strpos($script, '/')); |
|
75 | - $script = substr($script, strpos($script, '/')+1); |
|
76 | - $app_path = \OC_App::getAppPath($app); |
|
77 | - $app_url = \OC_App::getAppWebPath($app); |
|
78 | - |
|
79 | - if ($app_path !== false) { |
|
80 | - // Account for the possibility of having symlinks in app path. Only |
|
81 | - // do this if $app_path is set, because an empty argument to realpath |
|
82 | - // gets turned into cwd. |
|
83 | - $app_path = realpath($app_path); |
|
84 | - } |
|
85 | - |
|
86 | - // missing translations files fill be ignored |
|
87 | - if (strpos($script, 'l10n/') === 0) { |
|
88 | - $this->appendIfExist($app_path, $script . '.js', $app_url); |
|
89 | - return; |
|
90 | - } |
|
91 | - |
|
92 | - if ($app_path === false && $app_url === false) { |
|
93 | - $this->logger->error('Could not find resource {resource} to load', [ |
|
94 | - 'resource' => $app . '/' . $script . '.js', |
|
95 | - 'app' => 'jsresourceloader', |
|
96 | - ]); |
|
97 | - return; |
|
98 | - } |
|
99 | - |
|
100 | - if (!$this->cacheAndAppendCombineJsonIfExist($app_path, $script.'.json', $app)) { |
|
101 | - $this->append($app_path, $script . '.js', $app_url); |
|
102 | - } |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * @param string $script |
|
107 | - */ |
|
108 | - public function doFindTheme($script) { |
|
109 | - } |
|
110 | - |
|
111 | - protected function cacheAndAppendCombineJsonIfExist($root, $file, $app = 'core') { |
|
112 | - if (is_file($root.'/'.$file)) { |
|
113 | - if ($this->jsCombiner->process($root, $file, $app)) { |
|
114 | - $this->append($this->serverroot, $this->jsCombiner->getCachedJS($app, $file), false, false); |
|
115 | - } else { |
|
116 | - // Add all the files from the json |
|
117 | - $files = $this->jsCombiner->getContent($root, $file); |
|
118 | - $app_url = \OC_App::getAppWebPath($app); |
|
119 | - |
|
120 | - foreach ($files as $jsFile) { |
|
121 | - $this->append($root, $jsFile, $app_url); |
|
122 | - } |
|
123 | - } |
|
124 | - return true; |
|
125 | - } |
|
126 | - |
|
127 | - return false; |
|
128 | - } |
|
31 | + /** @var JSCombiner */ |
|
32 | + protected $jsCombiner; |
|
33 | + |
|
34 | + public function __construct(\OCP\ILogger $logger, $theme, array $core_map, array $party_map, JSCombiner $JSCombiner) { |
|
35 | + parent::__construct($logger, $theme, $core_map, $party_map); |
|
36 | + |
|
37 | + $this->jsCombiner = $JSCombiner; |
|
38 | + } |
|
39 | + |
|
40 | + /** |
|
41 | + * @param string $script |
|
42 | + */ |
|
43 | + public function doFind($script) { |
|
44 | + $theme_dir = 'themes/'.$this->theme.'/'; |
|
45 | + if (strpos($script, '3rdparty') === 0 |
|
46 | + && $this->appendIfExist($this->thirdpartyroot, $script.'.js')) { |
|
47 | + return; |
|
48 | + } |
|
49 | + |
|
50 | + if (strpos($script, '/l10n/') !== false) { |
|
51 | + // For language files we try to load them all, so themes can overwrite |
|
52 | + // single l10n strings without having to translate all of them. |
|
53 | + $found = 0; |
|
54 | + $found += $this->appendIfExist($this->serverroot, 'core/'.$script.'.js'); |
|
55 | + $found += $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$script.'.js'); |
|
56 | + $found += $this->appendIfExist($this->serverroot, $script.'.js'); |
|
57 | + $found += $this->appendIfExist($this->serverroot, $theme_dir.$script.'.js'); |
|
58 | + $found += $this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$script.'.js'); |
|
59 | + |
|
60 | + if ($found) { |
|
61 | + return; |
|
62 | + } |
|
63 | + } else if ($this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$script.'.js') |
|
64 | + || $this->appendIfExist($this->serverroot, $theme_dir.$script.'.js') |
|
65 | + || $this->appendIfExist($this->serverroot, $script.'.js') |
|
66 | + || $this->cacheAndAppendCombineJsonIfExist($this->serverroot, $script.'.json') |
|
67 | + || $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$script.'.js') |
|
68 | + || $this->appendIfExist($this->serverroot, 'core/'.$script.'.js') |
|
69 | + || $this->cacheAndAppendCombineJsonIfExist($this->serverroot, 'core/'.$script.'.json') |
|
70 | + ) { |
|
71 | + return; |
|
72 | + } |
|
73 | + |
|
74 | + $app = substr($script, 0, strpos($script, '/')); |
|
75 | + $script = substr($script, strpos($script, '/')+1); |
|
76 | + $app_path = \OC_App::getAppPath($app); |
|
77 | + $app_url = \OC_App::getAppWebPath($app); |
|
78 | + |
|
79 | + if ($app_path !== false) { |
|
80 | + // Account for the possibility of having symlinks in app path. Only |
|
81 | + // do this if $app_path is set, because an empty argument to realpath |
|
82 | + // gets turned into cwd. |
|
83 | + $app_path = realpath($app_path); |
|
84 | + } |
|
85 | + |
|
86 | + // missing translations files fill be ignored |
|
87 | + if (strpos($script, 'l10n/') === 0) { |
|
88 | + $this->appendIfExist($app_path, $script . '.js', $app_url); |
|
89 | + return; |
|
90 | + } |
|
91 | + |
|
92 | + if ($app_path === false && $app_url === false) { |
|
93 | + $this->logger->error('Could not find resource {resource} to load', [ |
|
94 | + 'resource' => $app . '/' . $script . '.js', |
|
95 | + 'app' => 'jsresourceloader', |
|
96 | + ]); |
|
97 | + return; |
|
98 | + } |
|
99 | + |
|
100 | + if (!$this->cacheAndAppendCombineJsonIfExist($app_path, $script.'.json', $app)) { |
|
101 | + $this->append($app_path, $script . '.js', $app_url); |
|
102 | + } |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * @param string $script |
|
107 | + */ |
|
108 | + public function doFindTheme($script) { |
|
109 | + } |
|
110 | + |
|
111 | + protected function cacheAndAppendCombineJsonIfExist($root, $file, $app = 'core') { |
|
112 | + if (is_file($root.'/'.$file)) { |
|
113 | + if ($this->jsCombiner->process($root, $file, $app)) { |
|
114 | + $this->append($this->serverroot, $this->jsCombiner->getCachedJS($app, $file), false, false); |
|
115 | + } else { |
|
116 | + // Add all the files from the json |
|
117 | + $files = $this->jsCombiner->getContent($root, $file); |
|
118 | + $app_url = \OC_App::getAppWebPath($app); |
|
119 | + |
|
120 | + foreach ($files as $jsFile) { |
|
121 | + $this->append($root, $jsFile, $app_url); |
|
122 | + } |
|
123 | + } |
|
124 | + return true; |
|
125 | + } |
|
126 | + |
|
127 | + return false; |
|
128 | + } |
|
129 | 129 | } |
@@ -35,144 +35,144 @@ |
||
35 | 35 | use OCP\IUser; |
36 | 36 | |
37 | 37 | class MountProviderCollection implements IMountProviderCollection, Emitter { |
38 | - use EmitterTrait; |
|
39 | - |
|
40 | - /** |
|
41 | - * @var \OCP\Files\Config\IHomeMountProvider[] |
|
42 | - */ |
|
43 | - private $homeProviders = []; |
|
44 | - |
|
45 | - /** |
|
46 | - * @var \OCP\Files\Config\IMountProvider[] |
|
47 | - */ |
|
48 | - private $providers = array(); |
|
49 | - |
|
50 | - /** |
|
51 | - * @var \OCP\Files\Storage\IStorageFactory |
|
52 | - */ |
|
53 | - private $loader; |
|
54 | - |
|
55 | - /** |
|
56 | - * @var \OCP\Files\Config\IUserMountCache |
|
57 | - */ |
|
58 | - private $mountCache; |
|
59 | - |
|
60 | - /** |
|
61 | - * @param \OCP\Files\Storage\IStorageFactory $loader |
|
62 | - * @param IUserMountCache $mountCache |
|
63 | - */ |
|
64 | - public function __construct(IStorageFactory $loader, IUserMountCache $mountCache) { |
|
65 | - $this->loader = $loader; |
|
66 | - $this->mountCache = $mountCache; |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * Get all configured mount points for the user |
|
71 | - * |
|
72 | - * @param \OCP\IUser $user |
|
73 | - * @return \OCP\Files\Mount\IMountPoint[] |
|
74 | - */ |
|
75 | - public function getMountsForUser(IUser $user) { |
|
76 | - $loader = $this->loader; |
|
77 | - $mounts = array_map(function (IMountProvider $provider) use ($user, $loader) { |
|
78 | - return $provider->getMountsForUser($user, $loader); |
|
79 | - }, $this->providers); |
|
80 | - $mounts = array_filter($mounts, function ($result) { |
|
81 | - return is_array($result); |
|
82 | - }); |
|
83 | - return array_reduce($mounts, function (array $mounts, array $providerMounts) { |
|
84 | - return array_merge($mounts, $providerMounts); |
|
85 | - }, array()); |
|
86 | - } |
|
87 | - |
|
88 | - public function addMountForUser(IUser $user, IMountManager $mountManager) { |
|
89 | - // shared mount provider gets to go last since it needs to know existing files |
|
90 | - // to check for name collisions |
|
91 | - $firstMounts = []; |
|
92 | - $firstProviders = array_filter($this->providers, function (IMountProvider $provider) { |
|
93 | - return (get_class($provider) !== 'OCA\Files_Sharing\MountProvider'); |
|
94 | - }); |
|
95 | - $lastProviders = array_filter($this->providers, function (IMountProvider $provider) { |
|
96 | - return (get_class($provider) === 'OCA\Files_Sharing\MountProvider'); |
|
97 | - }); |
|
98 | - foreach ($firstProviders as $provider) { |
|
99 | - $mounts = $provider->getMountsForUser($user, $this->loader); |
|
100 | - if (is_array($mounts)) { |
|
101 | - $firstMounts = array_merge($firstMounts, $mounts); |
|
102 | - } |
|
103 | - } |
|
104 | - array_walk($firstMounts, [$mountManager, 'addMount']); |
|
105 | - |
|
106 | - $lateMounts = []; |
|
107 | - foreach ($lastProviders as $provider) { |
|
108 | - $mounts = $provider->getMountsForUser($user, $this->loader); |
|
109 | - if (is_array($mounts)) { |
|
110 | - $lateMounts = array_merge($lateMounts, $mounts); |
|
111 | - } |
|
112 | - } |
|
113 | - |
|
114 | - array_walk($lateMounts, [$mountManager, 'addMount']); |
|
115 | - |
|
116 | - return array_merge($lateMounts, $firstMounts); |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Get the configured home mount for this user |
|
121 | - * |
|
122 | - * @param \OCP\IUser $user |
|
123 | - * @return \OCP\Files\Mount\IMountPoint |
|
124 | - * @since 9.1.0 |
|
125 | - */ |
|
126 | - public function getHomeMountForUser(IUser $user) { |
|
127 | - /** @var \OCP\Files\Config\IHomeMountProvider[] $providers */ |
|
128 | - $providers = array_reverse($this->homeProviders); // call the latest registered provider first to give apps an opportunity to overwrite builtin |
|
129 | - foreach ($providers as $homeProvider) { |
|
130 | - if ($mount = $homeProvider->getHomeMountForUser($user, $this->loader)) { |
|
131 | - $mount->setMountPoint('/' . $user->getUID()); //make sure the mountpoint is what we expect |
|
132 | - return $mount; |
|
133 | - } |
|
134 | - } |
|
135 | - throw new \Exception('No home storage configured for user ' . $user); |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * Add a provider for mount points |
|
140 | - * |
|
141 | - * @param \OCP\Files\Config\IMountProvider $provider |
|
142 | - */ |
|
143 | - public function registerProvider(IMountProvider $provider) { |
|
144 | - $this->providers[] = $provider; |
|
145 | - |
|
146 | - $this->emit('\OC\Files\Config', 'registerMountProvider', [$provider]); |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * Add a provider for home mount points |
|
151 | - * |
|
152 | - * @param \OCP\Files\Config\IHomeMountProvider $provider |
|
153 | - * @since 9.1.0 |
|
154 | - */ |
|
155 | - public function registerHomeProvider(IHomeMountProvider $provider) { |
|
156 | - $this->homeProviders[] = $provider; |
|
157 | - $this->emit('\OC\Files\Config', 'registerHomeMountProvider', [$provider]); |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * Cache mounts for user |
|
162 | - * |
|
163 | - * @param IUser $user |
|
164 | - * @param IMountPoint[] $mountPoints |
|
165 | - */ |
|
166 | - public function registerMounts(IUser $user, array $mountPoints) { |
|
167 | - $this->mountCache->registerMounts($user, $mountPoints); |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Get the mount cache which can be used to search for mounts without setting up the filesystem |
|
172 | - * |
|
173 | - * @return IUserMountCache |
|
174 | - */ |
|
175 | - public function getMountCache() { |
|
176 | - return $this->mountCache; |
|
177 | - } |
|
38 | + use EmitterTrait; |
|
39 | + |
|
40 | + /** |
|
41 | + * @var \OCP\Files\Config\IHomeMountProvider[] |
|
42 | + */ |
|
43 | + private $homeProviders = []; |
|
44 | + |
|
45 | + /** |
|
46 | + * @var \OCP\Files\Config\IMountProvider[] |
|
47 | + */ |
|
48 | + private $providers = array(); |
|
49 | + |
|
50 | + /** |
|
51 | + * @var \OCP\Files\Storage\IStorageFactory |
|
52 | + */ |
|
53 | + private $loader; |
|
54 | + |
|
55 | + /** |
|
56 | + * @var \OCP\Files\Config\IUserMountCache |
|
57 | + */ |
|
58 | + private $mountCache; |
|
59 | + |
|
60 | + /** |
|
61 | + * @param \OCP\Files\Storage\IStorageFactory $loader |
|
62 | + * @param IUserMountCache $mountCache |
|
63 | + */ |
|
64 | + public function __construct(IStorageFactory $loader, IUserMountCache $mountCache) { |
|
65 | + $this->loader = $loader; |
|
66 | + $this->mountCache = $mountCache; |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * Get all configured mount points for the user |
|
71 | + * |
|
72 | + * @param \OCP\IUser $user |
|
73 | + * @return \OCP\Files\Mount\IMountPoint[] |
|
74 | + */ |
|
75 | + public function getMountsForUser(IUser $user) { |
|
76 | + $loader = $this->loader; |
|
77 | + $mounts = array_map(function (IMountProvider $provider) use ($user, $loader) { |
|
78 | + return $provider->getMountsForUser($user, $loader); |
|
79 | + }, $this->providers); |
|
80 | + $mounts = array_filter($mounts, function ($result) { |
|
81 | + return is_array($result); |
|
82 | + }); |
|
83 | + return array_reduce($mounts, function (array $mounts, array $providerMounts) { |
|
84 | + return array_merge($mounts, $providerMounts); |
|
85 | + }, array()); |
|
86 | + } |
|
87 | + |
|
88 | + public function addMountForUser(IUser $user, IMountManager $mountManager) { |
|
89 | + // shared mount provider gets to go last since it needs to know existing files |
|
90 | + // to check for name collisions |
|
91 | + $firstMounts = []; |
|
92 | + $firstProviders = array_filter($this->providers, function (IMountProvider $provider) { |
|
93 | + return (get_class($provider) !== 'OCA\Files_Sharing\MountProvider'); |
|
94 | + }); |
|
95 | + $lastProviders = array_filter($this->providers, function (IMountProvider $provider) { |
|
96 | + return (get_class($provider) === 'OCA\Files_Sharing\MountProvider'); |
|
97 | + }); |
|
98 | + foreach ($firstProviders as $provider) { |
|
99 | + $mounts = $provider->getMountsForUser($user, $this->loader); |
|
100 | + if (is_array($mounts)) { |
|
101 | + $firstMounts = array_merge($firstMounts, $mounts); |
|
102 | + } |
|
103 | + } |
|
104 | + array_walk($firstMounts, [$mountManager, 'addMount']); |
|
105 | + |
|
106 | + $lateMounts = []; |
|
107 | + foreach ($lastProviders as $provider) { |
|
108 | + $mounts = $provider->getMountsForUser($user, $this->loader); |
|
109 | + if (is_array($mounts)) { |
|
110 | + $lateMounts = array_merge($lateMounts, $mounts); |
|
111 | + } |
|
112 | + } |
|
113 | + |
|
114 | + array_walk($lateMounts, [$mountManager, 'addMount']); |
|
115 | + |
|
116 | + return array_merge($lateMounts, $firstMounts); |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Get the configured home mount for this user |
|
121 | + * |
|
122 | + * @param \OCP\IUser $user |
|
123 | + * @return \OCP\Files\Mount\IMountPoint |
|
124 | + * @since 9.1.0 |
|
125 | + */ |
|
126 | + public function getHomeMountForUser(IUser $user) { |
|
127 | + /** @var \OCP\Files\Config\IHomeMountProvider[] $providers */ |
|
128 | + $providers = array_reverse($this->homeProviders); // call the latest registered provider first to give apps an opportunity to overwrite builtin |
|
129 | + foreach ($providers as $homeProvider) { |
|
130 | + if ($mount = $homeProvider->getHomeMountForUser($user, $this->loader)) { |
|
131 | + $mount->setMountPoint('/' . $user->getUID()); //make sure the mountpoint is what we expect |
|
132 | + return $mount; |
|
133 | + } |
|
134 | + } |
|
135 | + throw new \Exception('No home storage configured for user ' . $user); |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * Add a provider for mount points |
|
140 | + * |
|
141 | + * @param \OCP\Files\Config\IMountProvider $provider |
|
142 | + */ |
|
143 | + public function registerProvider(IMountProvider $provider) { |
|
144 | + $this->providers[] = $provider; |
|
145 | + |
|
146 | + $this->emit('\OC\Files\Config', 'registerMountProvider', [$provider]); |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * Add a provider for home mount points |
|
151 | + * |
|
152 | + * @param \OCP\Files\Config\IHomeMountProvider $provider |
|
153 | + * @since 9.1.0 |
|
154 | + */ |
|
155 | + public function registerHomeProvider(IHomeMountProvider $provider) { |
|
156 | + $this->homeProviders[] = $provider; |
|
157 | + $this->emit('\OC\Files\Config', 'registerHomeMountProvider', [$provider]); |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * Cache mounts for user |
|
162 | + * |
|
163 | + * @param IUser $user |
|
164 | + * @param IMountPoint[] $mountPoints |
|
165 | + */ |
|
166 | + public function registerMounts(IUser $user, array $mountPoints) { |
|
167 | + $this->mountCache->registerMounts($user, $mountPoints); |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * Get the mount cache which can be used to search for mounts without setting up the filesystem |
|
172 | + * |
|
173 | + * @return IUserMountCache |
|
174 | + */ |
|
175 | + public function getMountCache() { |
|
176 | + return $this->mountCache; |
|
177 | + } |
|
178 | 178 | } |
@@ -74,13 +74,13 @@ discard block |
||
74 | 74 | */ |
75 | 75 | public function getMountsForUser(IUser $user) { |
76 | 76 | $loader = $this->loader; |
77 | - $mounts = array_map(function (IMountProvider $provider) use ($user, $loader) { |
|
77 | + $mounts = array_map(function(IMountProvider $provider) use ($user, $loader) { |
|
78 | 78 | return $provider->getMountsForUser($user, $loader); |
79 | 79 | }, $this->providers); |
80 | - $mounts = array_filter($mounts, function ($result) { |
|
80 | + $mounts = array_filter($mounts, function($result) { |
|
81 | 81 | return is_array($result); |
82 | 82 | }); |
83 | - return array_reduce($mounts, function (array $mounts, array $providerMounts) { |
|
83 | + return array_reduce($mounts, function(array $mounts, array $providerMounts) { |
|
84 | 84 | return array_merge($mounts, $providerMounts); |
85 | 85 | }, array()); |
86 | 86 | } |
@@ -89,10 +89,10 @@ discard block |
||
89 | 89 | // shared mount provider gets to go last since it needs to know existing files |
90 | 90 | // to check for name collisions |
91 | 91 | $firstMounts = []; |
92 | - $firstProviders = array_filter($this->providers, function (IMountProvider $provider) { |
|
92 | + $firstProviders = array_filter($this->providers, function(IMountProvider $provider) { |
|
93 | 93 | return (get_class($provider) !== 'OCA\Files_Sharing\MountProvider'); |
94 | 94 | }); |
95 | - $lastProviders = array_filter($this->providers, function (IMountProvider $provider) { |
|
95 | + $lastProviders = array_filter($this->providers, function(IMountProvider $provider) { |
|
96 | 96 | return (get_class($provider) === 'OCA\Files_Sharing\MountProvider'); |
97 | 97 | }); |
98 | 98 | foreach ($firstProviders as $provider) { |
@@ -128,11 +128,11 @@ discard block |
||
128 | 128 | $providers = array_reverse($this->homeProviders); // call the latest registered provider first to give apps an opportunity to overwrite builtin |
129 | 129 | foreach ($providers as $homeProvider) { |
130 | 130 | if ($mount = $homeProvider->getHomeMountForUser($user, $this->loader)) { |
131 | - $mount->setMountPoint('/' . $user->getUID()); //make sure the mountpoint is what we expect |
|
131 | + $mount->setMountPoint('/'.$user->getUID()); //make sure the mountpoint is what we expect |
|
132 | 132 | return $mount; |
133 | 133 | } |
134 | 134 | } |
135 | - throw new \Exception('No home storage configured for user ' . $user); |
|
135 | + throw new \Exception('No home storage configured for user '.$user); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | $result = array(); |
45 | 45 | $timestamp = null; |
46 | 46 | |
47 | - $view = new \OC\Files\View('/' . $user . '/files_trashbin/files'); |
|
47 | + $view = new \OC\Files\View('/'.$user.'/files_trashbin/files'); |
|
48 | 48 | |
49 | 49 | if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) { |
50 | 50 | throw new \Exception('Directory does not exists'); |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | $timestamp = substr(pathinfo($parts[0], PATHINFO_EXTENSION), 1); |
73 | 73 | } |
74 | 74 | $originalPath = ''; |
75 | - $originalName = substr($entryName, 0, -strlen($timestamp)-2); |
|
75 | + $originalName = substr($entryName, 0, -strlen($timestamp) - 2); |
|
76 | 76 | if (isset($originalLocations[$originalName][$timestamp])) { |
77 | 77 | $originalPath = $originalLocations[$originalName][$timestamp]; |
78 | 78 | if (substr($originalPath, -1) === '/') { |
@@ -92,12 +92,12 @@ discard block |
||
92 | 92 | ); |
93 | 93 | if ($originalPath) { |
94 | 94 | if ($originalPath !== '.') { |
95 | - $i['extraData'] = $originalPath . '/' . $originalName; |
|
95 | + $i['extraData'] = $originalPath.'/'.$originalName; |
|
96 | 96 | } else { |
97 | 97 | $i['extraData'] = $originalName; |
98 | 98 | } |
99 | 99 | } |
100 | - $result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i, $mount); |
|
100 | + $result[] = new FileInfo($absoluteDir.'/'.$i['name'], $storage, $internalPath.'/'.$i['name'], $i, $mount); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | if ($sortAttribute !== '') { |
@@ -33,96 +33,96 @@ |
||
33 | 33 | use OCP\Files\Cache\ICacheEntry; |
34 | 34 | |
35 | 35 | class Helper { |
36 | - /** |
|
37 | - * Retrieves the contents of a trash bin directory. |
|
38 | - * |
|
39 | - * @param string $dir path to the directory inside the trashbin |
|
40 | - * or empty to retrieve the root of the trashbin |
|
41 | - * @param string $user |
|
42 | - * @param string $sortAttribute attribute to sort on or empty to disable sorting |
|
43 | - * @param bool $sortDescending true for descending sort, false otherwise |
|
44 | - * @return \OCP\Files\FileInfo[] |
|
45 | - */ |
|
46 | - public static function getTrashFiles($dir, $user, $sortAttribute = '', $sortDescending = false) { |
|
47 | - $result = array(); |
|
48 | - $timestamp = null; |
|
36 | + /** |
|
37 | + * Retrieves the contents of a trash bin directory. |
|
38 | + * |
|
39 | + * @param string $dir path to the directory inside the trashbin |
|
40 | + * or empty to retrieve the root of the trashbin |
|
41 | + * @param string $user |
|
42 | + * @param string $sortAttribute attribute to sort on or empty to disable sorting |
|
43 | + * @param bool $sortDescending true for descending sort, false otherwise |
|
44 | + * @return \OCP\Files\FileInfo[] |
|
45 | + */ |
|
46 | + public static function getTrashFiles($dir, $user, $sortAttribute = '', $sortDescending = false) { |
|
47 | + $result = array(); |
|
48 | + $timestamp = null; |
|
49 | 49 | |
50 | - $view = new \OC\Files\View('/' . $user . '/files_trashbin/files'); |
|
50 | + $view = new \OC\Files\View('/' . $user . '/files_trashbin/files'); |
|
51 | 51 | |
52 | - if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) { |
|
53 | - throw new \Exception('Directory does not exists'); |
|
54 | - } |
|
52 | + if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) { |
|
53 | + throw new \Exception('Directory does not exists'); |
|
54 | + } |
|
55 | 55 | |
56 | - $mount = $view->getMount($dir); |
|
57 | - $storage = $mount->getStorage(); |
|
58 | - $absoluteDir = $view->getAbsolutePath($dir); |
|
59 | - $internalPath = $mount->getInternalPath($absoluteDir); |
|
56 | + $mount = $view->getMount($dir); |
|
57 | + $storage = $mount->getStorage(); |
|
58 | + $absoluteDir = $view->getAbsolutePath($dir); |
|
59 | + $internalPath = $mount->getInternalPath($absoluteDir); |
|
60 | 60 | |
61 | - $originalLocations = \OCA\Files_Trashbin\Trashbin::getLocations($user); |
|
62 | - $dirContent = $storage->getCache()->getFolderContents($mount->getInternalPath($view->getAbsolutePath($dir))); |
|
63 | - foreach ($dirContent as $entry) { |
|
64 | - $entryName = $entry->getName(); |
|
65 | - $name = $entryName; |
|
66 | - if ($dir === '' || $dir === '/') { |
|
67 | - $pathparts = pathinfo($entryName); |
|
68 | - $timestamp = substr($pathparts['extension'], 1); |
|
69 | - $name = $pathparts['filename']; |
|
61 | + $originalLocations = \OCA\Files_Trashbin\Trashbin::getLocations($user); |
|
62 | + $dirContent = $storage->getCache()->getFolderContents($mount->getInternalPath($view->getAbsolutePath($dir))); |
|
63 | + foreach ($dirContent as $entry) { |
|
64 | + $entryName = $entry->getName(); |
|
65 | + $name = $entryName; |
|
66 | + if ($dir === '' || $dir === '/') { |
|
67 | + $pathparts = pathinfo($entryName); |
|
68 | + $timestamp = substr($pathparts['extension'], 1); |
|
69 | + $name = $pathparts['filename']; |
|
70 | 70 | |
71 | - } else if ($timestamp === null) { |
|
72 | - // for subfolders we need to calculate the timestamp only once |
|
73 | - $parts = explode('/', ltrim($dir, '/')); |
|
74 | - $timestamp = substr(pathinfo($parts[0], PATHINFO_EXTENSION), 1); |
|
75 | - } |
|
76 | - $originalPath = ''; |
|
77 | - $originalName = substr($entryName, 0, -strlen($timestamp)-2); |
|
78 | - if (isset($originalLocations[$originalName][$timestamp])) { |
|
79 | - $originalPath = $originalLocations[$originalName][$timestamp]; |
|
80 | - if (substr($originalPath, -1) === '/') { |
|
81 | - $originalPath = substr($originalPath, 0, -1); |
|
82 | - } |
|
83 | - } |
|
84 | - $type = $entry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE ? 'dir' : 'file'; |
|
85 | - $i = array( |
|
86 | - 'name' => $name, |
|
87 | - 'mtime' => $timestamp, |
|
88 | - 'mimetype' => $type === 'dir' ? 'httpd/unix-directory' : \OC::$server->getMimeTypeDetector()->detectPath($name), |
|
89 | - 'type' => $type, |
|
90 | - 'directory' => ($dir === '/') ? '' : $dir, |
|
91 | - 'size' => $entry->getSize(), |
|
92 | - 'etag' => '', |
|
93 | - 'permissions' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE, |
|
94 | - 'fileid' => $entry->getId(), |
|
95 | - ); |
|
96 | - if ($originalPath) { |
|
97 | - if ($originalPath !== '.') { |
|
98 | - $i['extraData'] = $originalPath . '/' . $originalName; |
|
99 | - } else { |
|
100 | - $i['extraData'] = $originalName; |
|
101 | - } |
|
102 | - } |
|
103 | - $result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i, $mount); |
|
104 | - } |
|
71 | + } else if ($timestamp === null) { |
|
72 | + // for subfolders we need to calculate the timestamp only once |
|
73 | + $parts = explode('/', ltrim($dir, '/')); |
|
74 | + $timestamp = substr(pathinfo($parts[0], PATHINFO_EXTENSION), 1); |
|
75 | + } |
|
76 | + $originalPath = ''; |
|
77 | + $originalName = substr($entryName, 0, -strlen($timestamp)-2); |
|
78 | + if (isset($originalLocations[$originalName][$timestamp])) { |
|
79 | + $originalPath = $originalLocations[$originalName][$timestamp]; |
|
80 | + if (substr($originalPath, -1) === '/') { |
|
81 | + $originalPath = substr($originalPath, 0, -1); |
|
82 | + } |
|
83 | + } |
|
84 | + $type = $entry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE ? 'dir' : 'file'; |
|
85 | + $i = array( |
|
86 | + 'name' => $name, |
|
87 | + 'mtime' => $timestamp, |
|
88 | + 'mimetype' => $type === 'dir' ? 'httpd/unix-directory' : \OC::$server->getMimeTypeDetector()->detectPath($name), |
|
89 | + 'type' => $type, |
|
90 | + 'directory' => ($dir === '/') ? '' : $dir, |
|
91 | + 'size' => $entry->getSize(), |
|
92 | + 'etag' => '', |
|
93 | + 'permissions' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE, |
|
94 | + 'fileid' => $entry->getId(), |
|
95 | + ); |
|
96 | + if ($originalPath) { |
|
97 | + if ($originalPath !== '.') { |
|
98 | + $i['extraData'] = $originalPath . '/' . $originalName; |
|
99 | + } else { |
|
100 | + $i['extraData'] = $originalName; |
|
101 | + } |
|
102 | + } |
|
103 | + $result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i, $mount); |
|
104 | + } |
|
105 | 105 | |
106 | - if ($sortAttribute !== '') { |
|
107 | - return \OCA\Files\Helper::sortFiles($result, $sortAttribute, $sortDescending); |
|
108 | - } |
|
109 | - return $result; |
|
110 | - } |
|
106 | + if ($sortAttribute !== '') { |
|
107 | + return \OCA\Files\Helper::sortFiles($result, $sortAttribute, $sortDescending); |
|
108 | + } |
|
109 | + return $result; |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * Format file infos for JSON |
|
114 | - * |
|
115 | - * @param \OCP\Files\FileInfo[] $fileInfos file infos |
|
116 | - */ |
|
117 | - public static function formatFileInfos($fileInfos) { |
|
118 | - $files = array(); |
|
119 | - foreach ($fileInfos as $i) { |
|
120 | - $entry = \OCA\Files\Helper::formatFileInfo($i); |
|
121 | - $entry['id'] = $i->getId(); |
|
122 | - $entry['etag'] = $entry['mtime']; // add fake etag, it is only needed to identify the preview image |
|
123 | - $entry['permissions'] = \OCP\Constants::PERMISSION_READ; |
|
124 | - $files[] = $entry; |
|
125 | - } |
|
126 | - return $files; |
|
127 | - } |
|
112 | + /** |
|
113 | + * Format file infos for JSON |
|
114 | + * |
|
115 | + * @param \OCP\Files\FileInfo[] $fileInfos file infos |
|
116 | + */ |
|
117 | + public static function formatFileInfos($fileInfos) { |
|
118 | + $files = array(); |
|
119 | + foreach ($fileInfos as $i) { |
|
120 | + $entry = \OCA\Files\Helper::formatFileInfo($i); |
|
121 | + $entry['id'] = $i->getId(); |
|
122 | + $entry['etag'] = $entry['mtime']; // add fake etag, it is only needed to identify the preview image |
|
123 | + $entry['permissions'] = \OCP\Constants::PERMISSION_READ; |
|
124 | + $files[] = $entry; |
|
125 | + } |
|
126 | + return $files; |
|
127 | + } |
|
128 | 128 | } |
@@ -42,248 +42,248 @@ |
||
42 | 42 | |
43 | 43 | class TransferOwnership extends Command { |
44 | 44 | |
45 | - /** @var IUserManager $userManager */ |
|
46 | - private $userManager; |
|
47 | - |
|
48 | - /** @var IManager */ |
|
49 | - private $shareManager; |
|
50 | - |
|
51 | - /** @var IMountManager */ |
|
52 | - private $mountManager; |
|
53 | - |
|
54 | - /** @var FileInfo[] */ |
|
55 | - private $allFiles = []; |
|
56 | - |
|
57 | - /** @var FileInfo[] */ |
|
58 | - private $encryptedFiles = []; |
|
59 | - |
|
60 | - /** @var IShare[] */ |
|
61 | - private $shares = []; |
|
62 | - |
|
63 | - /** @var string */ |
|
64 | - private $sourceUser; |
|
65 | - |
|
66 | - /** @var string */ |
|
67 | - private $destinationUser; |
|
68 | - |
|
69 | - /** @var string */ |
|
70 | - private $sourcePath; |
|
71 | - |
|
72 | - /** @var string */ |
|
73 | - private $finalTarget; |
|
74 | - |
|
75 | - public function __construct(IUserManager $userManager, IManager $shareManager, IMountManager $mountManager) { |
|
76 | - $this->userManager = $userManager; |
|
77 | - $this->shareManager = $shareManager; |
|
78 | - $this->mountManager = $mountManager; |
|
79 | - parent::__construct(); |
|
80 | - } |
|
81 | - |
|
82 | - protected function configure() { |
|
83 | - $this |
|
84 | - ->setName('files:transfer-ownership') |
|
85 | - ->setDescription('All files and folders are moved to another user - shares are moved as well.') |
|
86 | - ->addArgument( |
|
87 | - 'source-user', |
|
88 | - InputArgument::REQUIRED, |
|
89 | - 'owner of files which shall be moved' |
|
90 | - ) |
|
91 | - ->addArgument( |
|
92 | - 'destination-user', |
|
93 | - InputArgument::REQUIRED, |
|
94 | - 'user who will be the new owner of the files' |
|
95 | - ) |
|
96 | - ->addOption( |
|
97 | - 'path', |
|
98 | - null, |
|
99 | - InputOption::VALUE_REQUIRED, |
|
100 | - 'selectively provide the path to transfer. For example --path="folder_name"', |
|
101 | - '' |
|
102 | - ); |
|
103 | - } |
|
104 | - |
|
105 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
106 | - $sourceUserObject = $this->userManager->get($input->getArgument('source-user')); |
|
107 | - $destinationUserObject = $this->userManager->get($input->getArgument('destination-user')); |
|
108 | - |
|
109 | - if (!$sourceUserObject instanceof IUser) { |
|
110 | - $output->writeln("<error>Unknown source user $this->sourceUser</error>"); |
|
111 | - return 1; |
|
112 | - } |
|
113 | - |
|
114 | - if (!$destinationUserObject instanceof IUser) { |
|
115 | - $output->writeln("<error>Unknown destination user $this->destinationUser</error>"); |
|
116 | - return 1; |
|
117 | - } |
|
118 | - |
|
119 | - $this->sourceUser = $sourceUserObject->getUID(); |
|
120 | - $this->destinationUser = $destinationUserObject->getUID(); |
|
121 | - $sourcePathOption = ltrim($input->getOption('path'), '/'); |
|
122 | - $this->sourcePath = rtrim($this->sourceUser . '/files/' . $sourcePathOption, '/'); |
|
123 | - |
|
124 | - // target user has to be ready |
|
125 | - if (!\OC::$server->getEncryptionManager()->isReadyForUser($this->destinationUser)) { |
|
126 | - $output->writeln("<error>The target user is not ready to accept files. The user has at least to be logged in once.</error>"); |
|
127 | - return 2; |
|
128 | - } |
|
129 | - |
|
130 | - $date = date('Y-m-d H-i-s'); |
|
131 | - $this->finalTarget = "$this->destinationUser/files/transferred from $this->sourceUser on $date"; |
|
132 | - |
|
133 | - // setup filesystem |
|
134 | - Filesystem::initMountPoints($this->sourceUser); |
|
135 | - Filesystem::initMountPoints($this->destinationUser); |
|
136 | - |
|
137 | - $view = new View(); |
|
138 | - if (!$view->is_dir($this->sourcePath)) { |
|
139 | - $output->writeln("<error>Unknown path provided: $sourcePathOption</error>"); |
|
140 | - return 1; |
|
141 | - } |
|
142 | - |
|
143 | - // analyse source folder |
|
144 | - $this->analyse($output); |
|
145 | - |
|
146 | - // collect all the shares |
|
147 | - $this->collectUsersShares($output); |
|
148 | - |
|
149 | - // transfer the files |
|
150 | - $this->transfer($output); |
|
151 | - |
|
152 | - // restore the shares |
|
153 | - $this->restoreShares($output); |
|
154 | - } |
|
155 | - |
|
156 | - private function walkFiles(View $view, $path, \Closure $callBack) { |
|
157 | - foreach ($view->getDirectoryContent($path) as $fileInfo) { |
|
158 | - if (!$callBack($fileInfo)) { |
|
159 | - return; |
|
160 | - } |
|
161 | - if ($fileInfo->getType() === FileInfo::TYPE_FOLDER) { |
|
162 | - $this->walkFiles($view, $fileInfo->getPath(), $callBack); |
|
163 | - } |
|
164 | - } |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * @param OutputInterface $output |
|
169 | - * @throws \Exception |
|
170 | - */ |
|
171 | - protected function analyse(OutputInterface $output) { |
|
172 | - $view = new View(); |
|
173 | - $output->writeln("Analysing files of $this->sourceUser ..."); |
|
174 | - $progress = new ProgressBar($output); |
|
175 | - $progress->start(); |
|
176 | - $self = $this; |
|
177 | - |
|
178 | - $this->walkFiles($view, $this->sourcePath, |
|
179 | - function (FileInfo $fileInfo) use ($progress, $self) { |
|
180 | - if ($fileInfo->getType() === FileInfo::TYPE_FOLDER) { |
|
181 | - // only analyze into folders from main storage, |
|
182 | - if (!$fileInfo->getStorage()->instanceOfStorage(IHomeStorage::class)) { |
|
183 | - return false; |
|
184 | - } |
|
185 | - return true; |
|
186 | - } |
|
187 | - $progress->advance(); |
|
188 | - $this->allFiles[] = $fileInfo; |
|
189 | - if ($fileInfo->isEncrypted()) { |
|
190 | - $this->encryptedFiles[] = $fileInfo; |
|
191 | - } |
|
192 | - return true; |
|
193 | - }); |
|
194 | - $progress->finish(); |
|
195 | - $output->writeln(''); |
|
196 | - |
|
197 | - // no file is allowed to be encrypted |
|
198 | - if (!empty($this->encryptedFiles)) { |
|
199 | - $output->writeln("<error>Some files are encrypted - please decrypt them first</error>"); |
|
200 | - foreach($this->encryptedFiles as $encryptedFile) { |
|
201 | - /** @var FileInfo $encryptedFile */ |
|
202 | - $output->writeln(" " . $encryptedFile->getPath()); |
|
203 | - } |
|
204 | - throw new \Exception('Execution terminated.'); |
|
205 | - } |
|
206 | - |
|
207 | - } |
|
208 | - |
|
209 | - /** |
|
210 | - * @param OutputInterface $output |
|
211 | - */ |
|
212 | - private function collectUsersShares(OutputInterface $output) { |
|
213 | - $output->writeln("Collecting all share information for files and folder of $this->sourceUser ..."); |
|
214 | - |
|
215 | - $progress = new ProgressBar($output, count($this->shares)); |
|
216 | - foreach([\OCP\Share::SHARE_TYPE_GROUP, \OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_LINK, \OCP\Share::SHARE_TYPE_REMOTE] as $shareType) { |
|
217 | - $offset = 0; |
|
218 | - while (true) { |
|
219 | - $sharePage = $this->shareManager->getSharesBy($this->sourceUser, $shareType, null, true, 50, $offset); |
|
220 | - $progress->advance(count($sharePage)); |
|
221 | - if (empty($sharePage)) { |
|
222 | - break; |
|
223 | - } |
|
224 | - $this->shares = array_merge($this->shares, $sharePage); |
|
225 | - $offset += 50; |
|
226 | - } |
|
227 | - } |
|
228 | - |
|
229 | - $progress->finish(); |
|
230 | - $output->writeln(''); |
|
231 | - } |
|
232 | - |
|
233 | - /** |
|
234 | - * @param OutputInterface $output |
|
235 | - */ |
|
236 | - protected function transfer(OutputInterface $output) { |
|
237 | - $view = new View(); |
|
238 | - $output->writeln("Transferring files to $this->finalTarget ..."); |
|
239 | - |
|
240 | - // This change will help user to transfer the folder specified using --path option. |
|
241 | - // Else only the content inside folder is transferred which is not correct. |
|
242 | - if($this->sourcePath !== "$this->sourceUser/files") { |
|
243 | - $view->mkdir($this->finalTarget); |
|
244 | - $this->finalTarget = $this->finalTarget . '/' . basename($this->sourcePath); |
|
245 | - } |
|
246 | - $view->rename($this->sourcePath, $this->finalTarget); |
|
247 | - if (!is_dir("$this->sourceUser/files")) { |
|
248 | - // because the files folder is moved away we need to recreate it |
|
249 | - $view->mkdir("$this->sourceUser/files"); |
|
250 | - } |
|
251 | - } |
|
252 | - |
|
253 | - /** |
|
254 | - * @param OutputInterface $output |
|
255 | - */ |
|
256 | - private function restoreShares(OutputInterface $output) { |
|
257 | - $output->writeln("Restoring shares ..."); |
|
258 | - $progress = new ProgressBar($output, count($this->shares)); |
|
259 | - |
|
260 | - foreach($this->shares as $share) { |
|
261 | - try { |
|
262 | - if ($share->getSharedWith() === $this->destinationUser) { |
|
263 | - // Unmount the shares before deleting, so we don't try to get the storage later on. |
|
264 | - $shareMountPoint = $this->mountManager->find('/' . $this->destinationUser . '/files' . $share->getTarget()); |
|
265 | - if ($shareMountPoint) { |
|
266 | - $this->mountManager->removeMount($shareMountPoint->getMountPoint()); |
|
267 | - } |
|
268 | - $this->shareManager->deleteShare($share); |
|
269 | - } else { |
|
270 | - if ($share->getShareOwner() === $this->sourceUser) { |
|
271 | - $share->setShareOwner($this->destinationUser); |
|
272 | - } |
|
273 | - if ($share->getSharedBy() === $this->sourceUser) { |
|
274 | - $share->setSharedBy($this->destinationUser); |
|
275 | - } |
|
276 | - |
|
277 | - $this->shareManager->updateShare($share); |
|
278 | - } |
|
279 | - } catch (\OCP\Files\NotFoundException $e) { |
|
280 | - $output->writeln('<error>Share with id ' . $share->getId() . ' points at deleted file, skipping</error>'); |
|
281 | - } catch (\Exception $e) { |
|
282 | - $output->writeln('<error>Could not restore share with id ' . $share->getId() . ':' . $e->getTraceAsString() . '</error>'); |
|
283 | - } |
|
284 | - $progress->advance(); |
|
285 | - } |
|
286 | - $progress->finish(); |
|
287 | - $output->writeln(''); |
|
288 | - } |
|
45 | + /** @var IUserManager $userManager */ |
|
46 | + private $userManager; |
|
47 | + |
|
48 | + /** @var IManager */ |
|
49 | + private $shareManager; |
|
50 | + |
|
51 | + /** @var IMountManager */ |
|
52 | + private $mountManager; |
|
53 | + |
|
54 | + /** @var FileInfo[] */ |
|
55 | + private $allFiles = []; |
|
56 | + |
|
57 | + /** @var FileInfo[] */ |
|
58 | + private $encryptedFiles = []; |
|
59 | + |
|
60 | + /** @var IShare[] */ |
|
61 | + private $shares = []; |
|
62 | + |
|
63 | + /** @var string */ |
|
64 | + private $sourceUser; |
|
65 | + |
|
66 | + /** @var string */ |
|
67 | + private $destinationUser; |
|
68 | + |
|
69 | + /** @var string */ |
|
70 | + private $sourcePath; |
|
71 | + |
|
72 | + /** @var string */ |
|
73 | + private $finalTarget; |
|
74 | + |
|
75 | + public function __construct(IUserManager $userManager, IManager $shareManager, IMountManager $mountManager) { |
|
76 | + $this->userManager = $userManager; |
|
77 | + $this->shareManager = $shareManager; |
|
78 | + $this->mountManager = $mountManager; |
|
79 | + parent::__construct(); |
|
80 | + } |
|
81 | + |
|
82 | + protected function configure() { |
|
83 | + $this |
|
84 | + ->setName('files:transfer-ownership') |
|
85 | + ->setDescription('All files and folders are moved to another user - shares are moved as well.') |
|
86 | + ->addArgument( |
|
87 | + 'source-user', |
|
88 | + InputArgument::REQUIRED, |
|
89 | + 'owner of files which shall be moved' |
|
90 | + ) |
|
91 | + ->addArgument( |
|
92 | + 'destination-user', |
|
93 | + InputArgument::REQUIRED, |
|
94 | + 'user who will be the new owner of the files' |
|
95 | + ) |
|
96 | + ->addOption( |
|
97 | + 'path', |
|
98 | + null, |
|
99 | + InputOption::VALUE_REQUIRED, |
|
100 | + 'selectively provide the path to transfer. For example --path="folder_name"', |
|
101 | + '' |
|
102 | + ); |
|
103 | + } |
|
104 | + |
|
105 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
106 | + $sourceUserObject = $this->userManager->get($input->getArgument('source-user')); |
|
107 | + $destinationUserObject = $this->userManager->get($input->getArgument('destination-user')); |
|
108 | + |
|
109 | + if (!$sourceUserObject instanceof IUser) { |
|
110 | + $output->writeln("<error>Unknown source user $this->sourceUser</error>"); |
|
111 | + return 1; |
|
112 | + } |
|
113 | + |
|
114 | + if (!$destinationUserObject instanceof IUser) { |
|
115 | + $output->writeln("<error>Unknown destination user $this->destinationUser</error>"); |
|
116 | + return 1; |
|
117 | + } |
|
118 | + |
|
119 | + $this->sourceUser = $sourceUserObject->getUID(); |
|
120 | + $this->destinationUser = $destinationUserObject->getUID(); |
|
121 | + $sourcePathOption = ltrim($input->getOption('path'), '/'); |
|
122 | + $this->sourcePath = rtrim($this->sourceUser . '/files/' . $sourcePathOption, '/'); |
|
123 | + |
|
124 | + // target user has to be ready |
|
125 | + if (!\OC::$server->getEncryptionManager()->isReadyForUser($this->destinationUser)) { |
|
126 | + $output->writeln("<error>The target user is not ready to accept files. The user has at least to be logged in once.</error>"); |
|
127 | + return 2; |
|
128 | + } |
|
129 | + |
|
130 | + $date = date('Y-m-d H-i-s'); |
|
131 | + $this->finalTarget = "$this->destinationUser/files/transferred from $this->sourceUser on $date"; |
|
132 | + |
|
133 | + // setup filesystem |
|
134 | + Filesystem::initMountPoints($this->sourceUser); |
|
135 | + Filesystem::initMountPoints($this->destinationUser); |
|
136 | + |
|
137 | + $view = new View(); |
|
138 | + if (!$view->is_dir($this->sourcePath)) { |
|
139 | + $output->writeln("<error>Unknown path provided: $sourcePathOption</error>"); |
|
140 | + return 1; |
|
141 | + } |
|
142 | + |
|
143 | + // analyse source folder |
|
144 | + $this->analyse($output); |
|
145 | + |
|
146 | + // collect all the shares |
|
147 | + $this->collectUsersShares($output); |
|
148 | + |
|
149 | + // transfer the files |
|
150 | + $this->transfer($output); |
|
151 | + |
|
152 | + // restore the shares |
|
153 | + $this->restoreShares($output); |
|
154 | + } |
|
155 | + |
|
156 | + private function walkFiles(View $view, $path, \Closure $callBack) { |
|
157 | + foreach ($view->getDirectoryContent($path) as $fileInfo) { |
|
158 | + if (!$callBack($fileInfo)) { |
|
159 | + return; |
|
160 | + } |
|
161 | + if ($fileInfo->getType() === FileInfo::TYPE_FOLDER) { |
|
162 | + $this->walkFiles($view, $fileInfo->getPath(), $callBack); |
|
163 | + } |
|
164 | + } |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * @param OutputInterface $output |
|
169 | + * @throws \Exception |
|
170 | + */ |
|
171 | + protected function analyse(OutputInterface $output) { |
|
172 | + $view = new View(); |
|
173 | + $output->writeln("Analysing files of $this->sourceUser ..."); |
|
174 | + $progress = new ProgressBar($output); |
|
175 | + $progress->start(); |
|
176 | + $self = $this; |
|
177 | + |
|
178 | + $this->walkFiles($view, $this->sourcePath, |
|
179 | + function (FileInfo $fileInfo) use ($progress, $self) { |
|
180 | + if ($fileInfo->getType() === FileInfo::TYPE_FOLDER) { |
|
181 | + // only analyze into folders from main storage, |
|
182 | + if (!$fileInfo->getStorage()->instanceOfStorage(IHomeStorage::class)) { |
|
183 | + return false; |
|
184 | + } |
|
185 | + return true; |
|
186 | + } |
|
187 | + $progress->advance(); |
|
188 | + $this->allFiles[] = $fileInfo; |
|
189 | + if ($fileInfo->isEncrypted()) { |
|
190 | + $this->encryptedFiles[] = $fileInfo; |
|
191 | + } |
|
192 | + return true; |
|
193 | + }); |
|
194 | + $progress->finish(); |
|
195 | + $output->writeln(''); |
|
196 | + |
|
197 | + // no file is allowed to be encrypted |
|
198 | + if (!empty($this->encryptedFiles)) { |
|
199 | + $output->writeln("<error>Some files are encrypted - please decrypt them first</error>"); |
|
200 | + foreach($this->encryptedFiles as $encryptedFile) { |
|
201 | + /** @var FileInfo $encryptedFile */ |
|
202 | + $output->writeln(" " . $encryptedFile->getPath()); |
|
203 | + } |
|
204 | + throw new \Exception('Execution terminated.'); |
|
205 | + } |
|
206 | + |
|
207 | + } |
|
208 | + |
|
209 | + /** |
|
210 | + * @param OutputInterface $output |
|
211 | + */ |
|
212 | + private function collectUsersShares(OutputInterface $output) { |
|
213 | + $output->writeln("Collecting all share information for files and folder of $this->sourceUser ..."); |
|
214 | + |
|
215 | + $progress = new ProgressBar($output, count($this->shares)); |
|
216 | + foreach([\OCP\Share::SHARE_TYPE_GROUP, \OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_LINK, \OCP\Share::SHARE_TYPE_REMOTE] as $shareType) { |
|
217 | + $offset = 0; |
|
218 | + while (true) { |
|
219 | + $sharePage = $this->shareManager->getSharesBy($this->sourceUser, $shareType, null, true, 50, $offset); |
|
220 | + $progress->advance(count($sharePage)); |
|
221 | + if (empty($sharePage)) { |
|
222 | + break; |
|
223 | + } |
|
224 | + $this->shares = array_merge($this->shares, $sharePage); |
|
225 | + $offset += 50; |
|
226 | + } |
|
227 | + } |
|
228 | + |
|
229 | + $progress->finish(); |
|
230 | + $output->writeln(''); |
|
231 | + } |
|
232 | + |
|
233 | + /** |
|
234 | + * @param OutputInterface $output |
|
235 | + */ |
|
236 | + protected function transfer(OutputInterface $output) { |
|
237 | + $view = new View(); |
|
238 | + $output->writeln("Transferring files to $this->finalTarget ..."); |
|
239 | + |
|
240 | + // This change will help user to transfer the folder specified using --path option. |
|
241 | + // Else only the content inside folder is transferred which is not correct. |
|
242 | + if($this->sourcePath !== "$this->sourceUser/files") { |
|
243 | + $view->mkdir($this->finalTarget); |
|
244 | + $this->finalTarget = $this->finalTarget . '/' . basename($this->sourcePath); |
|
245 | + } |
|
246 | + $view->rename($this->sourcePath, $this->finalTarget); |
|
247 | + if (!is_dir("$this->sourceUser/files")) { |
|
248 | + // because the files folder is moved away we need to recreate it |
|
249 | + $view->mkdir("$this->sourceUser/files"); |
|
250 | + } |
|
251 | + } |
|
252 | + |
|
253 | + /** |
|
254 | + * @param OutputInterface $output |
|
255 | + */ |
|
256 | + private function restoreShares(OutputInterface $output) { |
|
257 | + $output->writeln("Restoring shares ..."); |
|
258 | + $progress = new ProgressBar($output, count($this->shares)); |
|
259 | + |
|
260 | + foreach($this->shares as $share) { |
|
261 | + try { |
|
262 | + if ($share->getSharedWith() === $this->destinationUser) { |
|
263 | + // Unmount the shares before deleting, so we don't try to get the storage later on. |
|
264 | + $shareMountPoint = $this->mountManager->find('/' . $this->destinationUser . '/files' . $share->getTarget()); |
|
265 | + if ($shareMountPoint) { |
|
266 | + $this->mountManager->removeMount($shareMountPoint->getMountPoint()); |
|
267 | + } |
|
268 | + $this->shareManager->deleteShare($share); |
|
269 | + } else { |
|
270 | + if ($share->getShareOwner() === $this->sourceUser) { |
|
271 | + $share->setShareOwner($this->destinationUser); |
|
272 | + } |
|
273 | + if ($share->getSharedBy() === $this->sourceUser) { |
|
274 | + $share->setSharedBy($this->destinationUser); |
|
275 | + } |
|
276 | + |
|
277 | + $this->shareManager->updateShare($share); |
|
278 | + } |
|
279 | + } catch (\OCP\Files\NotFoundException $e) { |
|
280 | + $output->writeln('<error>Share with id ' . $share->getId() . ' points at deleted file, skipping</error>'); |
|
281 | + } catch (\Exception $e) { |
|
282 | + $output->writeln('<error>Could not restore share with id ' . $share->getId() . ':' . $e->getTraceAsString() . '</error>'); |
|
283 | + } |
|
284 | + $progress->advance(); |
|
285 | + } |
|
286 | + $progress->finish(); |
|
287 | + $output->writeln(''); |
|
288 | + } |
|
289 | 289 | } |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | $this->sourceUser = $sourceUserObject->getUID(); |
120 | 120 | $this->destinationUser = $destinationUserObject->getUID(); |
121 | 121 | $sourcePathOption = ltrim($input->getOption('path'), '/'); |
122 | - $this->sourcePath = rtrim($this->sourceUser . '/files/' . $sourcePathOption, '/'); |
|
122 | + $this->sourcePath = rtrim($this->sourceUser.'/files/'.$sourcePathOption, '/'); |
|
123 | 123 | |
124 | 124 | // target user has to be ready |
125 | 125 | if (!\OC::$server->getEncryptionManager()->isReadyForUser($this->destinationUser)) { |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | $self = $this; |
177 | 177 | |
178 | 178 | $this->walkFiles($view, $this->sourcePath, |
179 | - function (FileInfo $fileInfo) use ($progress, $self) { |
|
179 | + function(FileInfo $fileInfo) use ($progress, $self) { |
|
180 | 180 | if ($fileInfo->getType() === FileInfo::TYPE_FOLDER) { |
181 | 181 | // only analyze into folders from main storage, |
182 | 182 | if (!$fileInfo->getStorage()->instanceOfStorage(IHomeStorage::class)) { |
@@ -197,9 +197,9 @@ discard block |
||
197 | 197 | // no file is allowed to be encrypted |
198 | 198 | if (!empty($this->encryptedFiles)) { |
199 | 199 | $output->writeln("<error>Some files are encrypted - please decrypt them first</error>"); |
200 | - foreach($this->encryptedFiles as $encryptedFile) { |
|
200 | + foreach ($this->encryptedFiles as $encryptedFile) { |
|
201 | 201 | /** @var FileInfo $encryptedFile */ |
202 | - $output->writeln(" " . $encryptedFile->getPath()); |
|
202 | + $output->writeln(" ".$encryptedFile->getPath()); |
|
203 | 203 | } |
204 | 204 | throw new \Exception('Execution terminated.'); |
205 | 205 | } |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | $output->writeln("Collecting all share information for files and folder of $this->sourceUser ..."); |
214 | 214 | |
215 | 215 | $progress = new ProgressBar($output, count($this->shares)); |
216 | - foreach([\OCP\Share::SHARE_TYPE_GROUP, \OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_LINK, \OCP\Share::SHARE_TYPE_REMOTE] as $shareType) { |
|
216 | + foreach ([\OCP\Share::SHARE_TYPE_GROUP, \OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_LINK, \OCP\Share::SHARE_TYPE_REMOTE] as $shareType) { |
|
217 | 217 | $offset = 0; |
218 | 218 | while (true) { |
219 | 219 | $sharePage = $this->shareManager->getSharesBy($this->sourceUser, $shareType, null, true, 50, $offset); |
@@ -239,9 +239,9 @@ discard block |
||
239 | 239 | |
240 | 240 | // This change will help user to transfer the folder specified using --path option. |
241 | 241 | // Else only the content inside folder is transferred which is not correct. |
242 | - if($this->sourcePath !== "$this->sourceUser/files") { |
|
242 | + if ($this->sourcePath !== "$this->sourceUser/files") { |
|
243 | 243 | $view->mkdir($this->finalTarget); |
244 | - $this->finalTarget = $this->finalTarget . '/' . basename($this->sourcePath); |
|
244 | + $this->finalTarget = $this->finalTarget.'/'.basename($this->sourcePath); |
|
245 | 245 | } |
246 | 246 | $view->rename($this->sourcePath, $this->finalTarget); |
247 | 247 | if (!is_dir("$this->sourceUser/files")) { |
@@ -257,11 +257,11 @@ discard block |
||
257 | 257 | $output->writeln("Restoring shares ..."); |
258 | 258 | $progress = new ProgressBar($output, count($this->shares)); |
259 | 259 | |
260 | - foreach($this->shares as $share) { |
|
260 | + foreach ($this->shares as $share) { |
|
261 | 261 | try { |
262 | 262 | if ($share->getSharedWith() === $this->destinationUser) { |
263 | 263 | // Unmount the shares before deleting, so we don't try to get the storage later on. |
264 | - $shareMountPoint = $this->mountManager->find('/' . $this->destinationUser . '/files' . $share->getTarget()); |
|
264 | + $shareMountPoint = $this->mountManager->find('/'.$this->destinationUser.'/files'.$share->getTarget()); |
|
265 | 265 | if ($shareMountPoint) { |
266 | 266 | $this->mountManager->removeMount($shareMountPoint->getMountPoint()); |
267 | 267 | } |
@@ -277,9 +277,9 @@ discard block |
||
277 | 277 | $this->shareManager->updateShare($share); |
278 | 278 | } |
279 | 279 | } catch (\OCP\Files\NotFoundException $e) { |
280 | - $output->writeln('<error>Share with id ' . $share->getId() . ' points at deleted file, skipping</error>'); |
|
280 | + $output->writeln('<error>Share with id '.$share->getId().' points at deleted file, skipping</error>'); |
|
281 | 281 | } catch (\Exception $e) { |
282 | - $output->writeln('<error>Could not restore share with id ' . $share->getId() . ':' . $e->getTraceAsString() . '</error>'); |
|
282 | + $output->writeln('<error>Could not restore share with id '.$share->getId().':'.$e->getTraceAsString().'</error>'); |
|
283 | 283 | } |
284 | 284 | $progress->advance(); |
285 | 285 | } |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | ]); |
111 | 111 | } |
112 | 112 | // password policy app throws exception |
113 | - } catch(HintException $e) { |
|
113 | + } catch (HintException $e) { |
|
114 | 114 | return new JSONResponse([ |
115 | 115 | 'status' => 'error', |
116 | 116 | 'data' => [ |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | 'message' => $this->l->t('Please provide an admin recovery password; otherwise, all user data will be lost.'), |
221 | 221 | ] |
222 | 222 | ]); |
223 | - } elseif ($recoveryEnabledForUser && ! $validRecoveryPassword) { |
|
223 | + } elseif ($recoveryEnabledForUser && !$validRecoveryPassword) { |
|
224 | 224 | return new JSONResponse([ |
225 | 225 | 'status' => 'error', |
226 | 226 | 'data' => [ |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | try { |
232 | 232 | $result = $targetUser->setPassword($password, $recoveryPassword); |
233 | 233 | // password policy app throws exception |
234 | - } catch(HintException $e) { |
|
234 | + } catch (HintException $e) { |
|
235 | 235 | return new JSONResponse([ |
236 | 236 | 'status' => 'error', |
237 | 237 | 'data' => [ |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | ]); |
267 | 267 | } |
268 | 268 | // password policy app throws exception |
269 | - } catch(HintException $e) { |
|
269 | + } catch (HintException $e) { |
|
270 | 270 | return new JSONResponse([ |
271 | 271 | 'status' => 'error', |
272 | 272 | 'data' => [ |
@@ -41,244 +41,244 @@ |
||
41 | 41 | |
42 | 42 | class ChangePasswordController extends Controller { |
43 | 43 | |
44 | - /** @var string */ |
|
45 | - private $userId; |
|
44 | + /** @var string */ |
|
45 | + private $userId; |
|
46 | 46 | |
47 | - /** @var IUserManager */ |
|
48 | - private $userManager; |
|
47 | + /** @var IUserManager */ |
|
48 | + private $userManager; |
|
49 | 49 | |
50 | - /** @var IL10N */ |
|
51 | - private $l; |
|
50 | + /** @var IL10N */ |
|
51 | + private $l; |
|
52 | 52 | |
53 | - /** @var IGroupManager */ |
|
54 | - private $groupManager; |
|
53 | + /** @var IGroupManager */ |
|
54 | + private $groupManager; |
|
55 | 55 | |
56 | - /** @var Session */ |
|
57 | - private $userSession; |
|
56 | + /** @var Session */ |
|
57 | + private $userSession; |
|
58 | 58 | |
59 | - /** @var IAppManager */ |
|
60 | - private $appManager; |
|
59 | + /** @var IAppManager */ |
|
60 | + private $appManager; |
|
61 | 61 | |
62 | - public function __construct(string $appName, |
|
63 | - IRequest $request, |
|
64 | - string $userId, |
|
65 | - IUserManager $userManager, |
|
66 | - IUserSession $userSession, |
|
67 | - IGroupManager $groupManager, |
|
68 | - IAppManager $appManager, |
|
69 | - IL10N $l) { |
|
70 | - parent::__construct($appName, $request); |
|
62 | + public function __construct(string $appName, |
|
63 | + IRequest $request, |
|
64 | + string $userId, |
|
65 | + IUserManager $userManager, |
|
66 | + IUserSession $userSession, |
|
67 | + IGroupManager $groupManager, |
|
68 | + IAppManager $appManager, |
|
69 | + IL10N $l) { |
|
70 | + parent::__construct($appName, $request); |
|
71 | 71 | |
72 | - $this->userId = $userId; |
|
73 | - $this->userManager = $userManager; |
|
74 | - $this->userSession = $userSession; |
|
75 | - $this->groupManager = $groupManager; |
|
76 | - $this->appManager = $appManager; |
|
77 | - $this->l = $l; |
|
78 | - } |
|
72 | + $this->userId = $userId; |
|
73 | + $this->userManager = $userManager; |
|
74 | + $this->userSession = $userSession; |
|
75 | + $this->groupManager = $groupManager; |
|
76 | + $this->appManager = $appManager; |
|
77 | + $this->l = $l; |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * @NoAdminRequired |
|
82 | - * @NoSubadminRequired |
|
83 | - * @BruteForceProtection(action=changePersonalPassword) |
|
84 | - * |
|
85 | - * @param string $oldpassword |
|
86 | - * @param string $newpassword |
|
87 | - * |
|
88 | - * @return JSONResponse |
|
89 | - */ |
|
90 | - public function changePersonalPassword(string $oldpassword = '', string $newpassword = null): JSONResponse { |
|
91 | - /** @var IUser $user */ |
|
92 | - $user = $this->userManager->checkPassword($this->userId, $oldpassword); |
|
93 | - if ($user === false) { |
|
94 | - $response = new JSONResponse([ |
|
95 | - 'status' => 'error', |
|
96 | - 'data' => [ |
|
97 | - 'message' => $this->l->t('Wrong password'), |
|
98 | - ], |
|
99 | - ]); |
|
100 | - $response->throttle(); |
|
101 | - return $response; |
|
102 | - } |
|
80 | + /** |
|
81 | + * @NoAdminRequired |
|
82 | + * @NoSubadminRequired |
|
83 | + * @BruteForceProtection(action=changePersonalPassword) |
|
84 | + * |
|
85 | + * @param string $oldpassword |
|
86 | + * @param string $newpassword |
|
87 | + * |
|
88 | + * @return JSONResponse |
|
89 | + */ |
|
90 | + public function changePersonalPassword(string $oldpassword = '', string $newpassword = null): JSONResponse { |
|
91 | + /** @var IUser $user */ |
|
92 | + $user = $this->userManager->checkPassword($this->userId, $oldpassword); |
|
93 | + if ($user === false) { |
|
94 | + $response = new JSONResponse([ |
|
95 | + 'status' => 'error', |
|
96 | + 'data' => [ |
|
97 | + 'message' => $this->l->t('Wrong password'), |
|
98 | + ], |
|
99 | + ]); |
|
100 | + $response->throttle(); |
|
101 | + return $response; |
|
102 | + } |
|
103 | 103 | |
104 | - try { |
|
105 | - if ($newpassword === null || $user->setPassword($newpassword) === false) { |
|
106 | - return new JSONResponse([ |
|
107 | - 'status' => 'error' |
|
108 | - ]); |
|
109 | - } |
|
110 | - // password policy app throws exception |
|
111 | - } catch(HintException $e) { |
|
112 | - return new JSONResponse([ |
|
113 | - 'status' => 'error', |
|
114 | - 'data' => [ |
|
115 | - 'message' => $e->getHint(), |
|
116 | - ], |
|
117 | - ]); |
|
118 | - } |
|
104 | + try { |
|
105 | + if ($newpassword === null || $user->setPassword($newpassword) === false) { |
|
106 | + return new JSONResponse([ |
|
107 | + 'status' => 'error' |
|
108 | + ]); |
|
109 | + } |
|
110 | + // password policy app throws exception |
|
111 | + } catch(HintException $e) { |
|
112 | + return new JSONResponse([ |
|
113 | + 'status' => 'error', |
|
114 | + 'data' => [ |
|
115 | + 'message' => $e->getHint(), |
|
116 | + ], |
|
117 | + ]); |
|
118 | + } |
|
119 | 119 | |
120 | - $this->userSession->updateSessionTokenPassword($newpassword); |
|
120 | + $this->userSession->updateSessionTokenPassword($newpassword); |
|
121 | 121 | |
122 | - return new JSONResponse([ |
|
123 | - 'status' => 'success', |
|
124 | - 'data' => [ |
|
125 | - 'message' => $this->l->t('Saved'), |
|
126 | - ], |
|
127 | - ]); |
|
128 | - } |
|
122 | + return new JSONResponse([ |
|
123 | + 'status' => 'success', |
|
124 | + 'data' => [ |
|
125 | + 'message' => $this->l->t('Saved'), |
|
126 | + ], |
|
127 | + ]); |
|
128 | + } |
|
129 | 129 | |
130 | - /** |
|
131 | - * @NoAdminRequired |
|
132 | - * @PasswordConfirmationRequired |
|
133 | - * |
|
134 | - * @param string $username |
|
135 | - * @param string $password |
|
136 | - * @param string $recoveryPassword |
|
137 | - * |
|
138 | - * @return JSONResponse |
|
139 | - */ |
|
140 | - public function changeUserPassword(string $username = null, string $password = null, string $recoveryPassword = null): JSONResponse { |
|
141 | - if ($username === null) { |
|
142 | - return new JSONResponse([ |
|
143 | - 'status' => 'error', |
|
144 | - 'data' => [ |
|
145 | - 'message' => $this->l->t('No user supplied'), |
|
146 | - ], |
|
147 | - ]); |
|
148 | - } |
|
130 | + /** |
|
131 | + * @NoAdminRequired |
|
132 | + * @PasswordConfirmationRequired |
|
133 | + * |
|
134 | + * @param string $username |
|
135 | + * @param string $password |
|
136 | + * @param string $recoveryPassword |
|
137 | + * |
|
138 | + * @return JSONResponse |
|
139 | + */ |
|
140 | + public function changeUserPassword(string $username = null, string $password = null, string $recoveryPassword = null): JSONResponse { |
|
141 | + if ($username === null) { |
|
142 | + return new JSONResponse([ |
|
143 | + 'status' => 'error', |
|
144 | + 'data' => [ |
|
145 | + 'message' => $this->l->t('No user supplied'), |
|
146 | + ], |
|
147 | + ]); |
|
148 | + } |
|
149 | 149 | |
150 | - if ($password === null) { |
|
151 | - return new JSONResponse([ |
|
152 | - 'status' => 'error', |
|
153 | - 'data' => [ |
|
154 | - 'message' => $this->l->t('Unable to change password'), |
|
155 | - ], |
|
156 | - ]); |
|
157 | - } |
|
150 | + if ($password === null) { |
|
151 | + return new JSONResponse([ |
|
152 | + 'status' => 'error', |
|
153 | + 'data' => [ |
|
154 | + 'message' => $this->l->t('Unable to change password'), |
|
155 | + ], |
|
156 | + ]); |
|
157 | + } |
|
158 | 158 | |
159 | - $currentUser = $this->userSession->getUser(); |
|
160 | - $targetUser = $this->userManager->get($username); |
|
161 | - if ($currentUser === null || $targetUser === null || |
|
162 | - !($this->groupManager->isAdmin($this->userId) || |
|
163 | - $this->groupManager->getSubAdmin()->isUserAccessible($currentUser, $targetUser)) |
|
164 | - ) { |
|
165 | - return new JSONResponse([ |
|
166 | - 'status' => 'error', |
|
167 | - 'data' => [ |
|
168 | - 'message' => $this->l->t('Authentication error'), |
|
169 | - ], |
|
170 | - ]); |
|
171 | - } |
|
159 | + $currentUser = $this->userSession->getUser(); |
|
160 | + $targetUser = $this->userManager->get($username); |
|
161 | + if ($currentUser === null || $targetUser === null || |
|
162 | + !($this->groupManager->isAdmin($this->userId) || |
|
163 | + $this->groupManager->getSubAdmin()->isUserAccessible($currentUser, $targetUser)) |
|
164 | + ) { |
|
165 | + return new JSONResponse([ |
|
166 | + 'status' => 'error', |
|
167 | + 'data' => [ |
|
168 | + 'message' => $this->l->t('Authentication error'), |
|
169 | + ], |
|
170 | + ]); |
|
171 | + } |
|
172 | 172 | |
173 | - if ($this->appManager->isEnabledForUser('encryption')) { |
|
174 | - //handle the recovery case |
|
175 | - $crypt = new \OCA\Encryption\Crypto\Crypt( |
|
176 | - \OC::$server->getLogger(), |
|
177 | - \OC::$server->getUserSession(), |
|
178 | - \OC::$server->getConfig(), |
|
179 | - \OC::$server->getL10N('encryption')); |
|
180 | - $keyStorage = \OC::$server->getEncryptionKeyStorage(); |
|
181 | - $util = new \OCA\Encryption\Util( |
|
182 | - new \OC\Files\View(), |
|
183 | - $crypt, |
|
184 | - \OC::$server->getLogger(), |
|
185 | - \OC::$server->getUserSession(), |
|
186 | - \OC::$server->getConfig(), |
|
187 | - \OC::$server->getUserManager()); |
|
188 | - $keyManager = new \OCA\Encryption\KeyManager( |
|
189 | - $keyStorage, |
|
190 | - $crypt, |
|
191 | - \OC::$server->getConfig(), |
|
192 | - \OC::$server->getUserSession(), |
|
193 | - new \OCA\Encryption\Session(\OC::$server->getSession()), |
|
194 | - \OC::$server->getLogger(), |
|
195 | - $util); |
|
196 | - $recovery = new \OCA\Encryption\Recovery( |
|
197 | - \OC::$server->getUserSession(), |
|
198 | - $crypt, |
|
199 | - \OC::$server->getSecureRandom(), |
|
200 | - $keyManager, |
|
201 | - \OC::$server->getConfig(), |
|
202 | - $keyStorage, |
|
203 | - \OC::$server->getEncryptionFilesHelper(), |
|
204 | - new \OC\Files\View()); |
|
205 | - $recoveryAdminEnabled = $recovery->isRecoveryKeyEnabled(); |
|
173 | + if ($this->appManager->isEnabledForUser('encryption')) { |
|
174 | + //handle the recovery case |
|
175 | + $crypt = new \OCA\Encryption\Crypto\Crypt( |
|
176 | + \OC::$server->getLogger(), |
|
177 | + \OC::$server->getUserSession(), |
|
178 | + \OC::$server->getConfig(), |
|
179 | + \OC::$server->getL10N('encryption')); |
|
180 | + $keyStorage = \OC::$server->getEncryptionKeyStorage(); |
|
181 | + $util = new \OCA\Encryption\Util( |
|
182 | + new \OC\Files\View(), |
|
183 | + $crypt, |
|
184 | + \OC::$server->getLogger(), |
|
185 | + \OC::$server->getUserSession(), |
|
186 | + \OC::$server->getConfig(), |
|
187 | + \OC::$server->getUserManager()); |
|
188 | + $keyManager = new \OCA\Encryption\KeyManager( |
|
189 | + $keyStorage, |
|
190 | + $crypt, |
|
191 | + \OC::$server->getConfig(), |
|
192 | + \OC::$server->getUserSession(), |
|
193 | + new \OCA\Encryption\Session(\OC::$server->getSession()), |
|
194 | + \OC::$server->getLogger(), |
|
195 | + $util); |
|
196 | + $recovery = new \OCA\Encryption\Recovery( |
|
197 | + \OC::$server->getUserSession(), |
|
198 | + $crypt, |
|
199 | + \OC::$server->getSecureRandom(), |
|
200 | + $keyManager, |
|
201 | + \OC::$server->getConfig(), |
|
202 | + $keyStorage, |
|
203 | + \OC::$server->getEncryptionFilesHelper(), |
|
204 | + new \OC\Files\View()); |
|
205 | + $recoveryAdminEnabled = $recovery->isRecoveryKeyEnabled(); |
|
206 | 206 | |
207 | - $validRecoveryPassword = false; |
|
208 | - $recoveryEnabledForUser = false; |
|
209 | - if ($recoveryAdminEnabled) { |
|
210 | - $validRecoveryPassword = $keyManager->checkRecoveryPassword($recoveryPassword); |
|
211 | - $recoveryEnabledForUser = $recovery->isRecoveryEnabledForUser($username); |
|
212 | - } |
|
207 | + $validRecoveryPassword = false; |
|
208 | + $recoveryEnabledForUser = false; |
|
209 | + if ($recoveryAdminEnabled) { |
|
210 | + $validRecoveryPassword = $keyManager->checkRecoveryPassword($recoveryPassword); |
|
211 | + $recoveryEnabledForUser = $recovery->isRecoveryEnabledForUser($username); |
|
212 | + } |
|
213 | 213 | |
214 | - if ($recoveryEnabledForUser && $recoveryPassword === '') { |
|
215 | - return new JSONResponse([ |
|
216 | - 'status' => 'error', |
|
217 | - 'data' => [ |
|
218 | - 'message' => $this->l->t('Please provide an admin recovery password; otherwise, all user data will be lost.'), |
|
219 | - ] |
|
220 | - ]); |
|
221 | - } elseif ($recoveryEnabledForUser && ! $validRecoveryPassword) { |
|
222 | - return new JSONResponse([ |
|
223 | - 'status' => 'error', |
|
224 | - 'data' => [ |
|
225 | - 'message' => $this->l->t('Wrong admin recovery password. Please check the password and try again.'), |
|
226 | - ] |
|
227 | - ]); |
|
228 | - } else { // now we know that everything is fine regarding the recovery password, let's try to change the password |
|
229 | - try { |
|
230 | - $result = $targetUser->setPassword($password, $recoveryPassword); |
|
231 | - // password policy app throws exception |
|
232 | - } catch(HintException $e) { |
|
233 | - return new JSONResponse([ |
|
234 | - 'status' => 'error', |
|
235 | - 'data' => [ |
|
236 | - 'message' => $e->getHint(), |
|
237 | - ], |
|
238 | - ]); |
|
239 | - } |
|
240 | - if (!$result && $recoveryEnabledForUser) { |
|
241 | - return new JSONResponse([ |
|
242 | - 'status' => 'error', |
|
243 | - 'data' => [ |
|
244 | - 'message' => $this->l->t('Backend doesn\'t support password change, but the user\'s encryption key was updated.'), |
|
245 | - ] |
|
246 | - ]); |
|
247 | - } elseif (!$result && !$recoveryEnabledForUser) { |
|
248 | - return new JSONResponse([ |
|
249 | - 'status' => 'error', |
|
250 | - 'data' => [ |
|
251 | - 'message' => $this->l->t('Unable to change password'), |
|
252 | - ] |
|
253 | - ]); |
|
254 | - } |
|
255 | - } |
|
256 | - } else { |
|
257 | - try { |
|
258 | - if ($targetUser->setPassword($password) === false) { |
|
259 | - return new JSONResponse([ |
|
260 | - 'status' => 'error', |
|
261 | - 'data' => [ |
|
262 | - 'message' => $this->l->t('Unable to change password'), |
|
263 | - ], |
|
264 | - ]); |
|
265 | - } |
|
266 | - // password policy app throws exception |
|
267 | - } catch(HintException $e) { |
|
268 | - return new JSONResponse([ |
|
269 | - 'status' => 'error', |
|
270 | - 'data' => [ |
|
271 | - 'message' => $e->getHint(), |
|
272 | - ], |
|
273 | - ]); |
|
274 | - } |
|
275 | - } |
|
214 | + if ($recoveryEnabledForUser && $recoveryPassword === '') { |
|
215 | + return new JSONResponse([ |
|
216 | + 'status' => 'error', |
|
217 | + 'data' => [ |
|
218 | + 'message' => $this->l->t('Please provide an admin recovery password; otherwise, all user data will be lost.'), |
|
219 | + ] |
|
220 | + ]); |
|
221 | + } elseif ($recoveryEnabledForUser && ! $validRecoveryPassword) { |
|
222 | + return new JSONResponse([ |
|
223 | + 'status' => 'error', |
|
224 | + 'data' => [ |
|
225 | + 'message' => $this->l->t('Wrong admin recovery password. Please check the password and try again.'), |
|
226 | + ] |
|
227 | + ]); |
|
228 | + } else { // now we know that everything is fine regarding the recovery password, let's try to change the password |
|
229 | + try { |
|
230 | + $result = $targetUser->setPassword($password, $recoveryPassword); |
|
231 | + // password policy app throws exception |
|
232 | + } catch(HintException $e) { |
|
233 | + return new JSONResponse([ |
|
234 | + 'status' => 'error', |
|
235 | + 'data' => [ |
|
236 | + 'message' => $e->getHint(), |
|
237 | + ], |
|
238 | + ]); |
|
239 | + } |
|
240 | + if (!$result && $recoveryEnabledForUser) { |
|
241 | + return new JSONResponse([ |
|
242 | + 'status' => 'error', |
|
243 | + 'data' => [ |
|
244 | + 'message' => $this->l->t('Backend doesn\'t support password change, but the user\'s encryption key was updated.'), |
|
245 | + ] |
|
246 | + ]); |
|
247 | + } elseif (!$result && !$recoveryEnabledForUser) { |
|
248 | + return new JSONResponse([ |
|
249 | + 'status' => 'error', |
|
250 | + 'data' => [ |
|
251 | + 'message' => $this->l->t('Unable to change password'), |
|
252 | + ] |
|
253 | + ]); |
|
254 | + } |
|
255 | + } |
|
256 | + } else { |
|
257 | + try { |
|
258 | + if ($targetUser->setPassword($password) === false) { |
|
259 | + return new JSONResponse([ |
|
260 | + 'status' => 'error', |
|
261 | + 'data' => [ |
|
262 | + 'message' => $this->l->t('Unable to change password'), |
|
263 | + ], |
|
264 | + ]); |
|
265 | + } |
|
266 | + // password policy app throws exception |
|
267 | + } catch(HintException $e) { |
|
268 | + return new JSONResponse([ |
|
269 | + 'status' => 'error', |
|
270 | + 'data' => [ |
|
271 | + 'message' => $e->getHint(), |
|
272 | + ], |
|
273 | + ]); |
|
274 | + } |
|
275 | + } |
|
276 | 276 | |
277 | - return new JSONResponse([ |
|
278 | - 'status' => 'success', |
|
279 | - 'data' => [ |
|
280 | - 'username' => $username, |
|
281 | - ], |
|
282 | - ]); |
|
283 | - } |
|
277 | + return new JSONResponse([ |
|
278 | + 'status' => 'success', |
|
279 | + 'data' => [ |
|
280 | + 'username' => $username, |
|
281 | + ], |
|
282 | + ]); |
|
283 | + } |
|
284 | 284 | } |