@@ -171,14 +171,14 @@ |
||
171 | 171 | protected function deleteOrphanEntries(IOutput $output, $repairInfo, $deleteTable, $deleteId, $sourceTable, $sourceId, $sourceNullColumn) { |
172 | 172 | $qb = $this->connection->getQueryBuilder(); |
173 | 173 | |
174 | - $qb->select('d.' . $deleteId) |
|
174 | + $qb->select('d.'.$deleteId) |
|
175 | 175 | ->from($deleteTable, 'd') |
176 | - ->leftJoin('d', $sourceTable, 's', $qb->expr()->eq('d.' . $deleteId, 's.' . $sourceId)) |
|
176 | + ->leftJoin('d', $sourceTable, 's', $qb->expr()->eq('d.'.$deleteId, 's.'.$sourceId)) |
|
177 | 177 | ->where( |
178 | 178 | $qb->expr()->eq('d.type', $qb->expr()->literal('files')) |
179 | 179 | ) |
180 | 180 | ->andWhere( |
181 | - $qb->expr()->isNull('s.' . $sourceNullColumn) |
|
181 | + $qb->expr()->isNull('s.'.$sourceNullColumn) |
|
182 | 182 | ); |
183 | 183 | $result = $qb->execute(); |
184 | 184 |
@@ -38,171 +38,171 @@ |
||
38 | 38 | * @package OC\Repair |
39 | 39 | */ |
40 | 40 | class CleanTags implements IRepairStep { |
41 | - /** @var IDBConnection */ |
|
42 | - protected $connection; |
|
43 | - |
|
44 | - /** @var IUserManager */ |
|
45 | - protected $userManager; |
|
46 | - |
|
47 | - protected $deletedTags = 0; |
|
48 | - |
|
49 | - /** |
|
50 | - * @param IDBConnection $connection |
|
51 | - * @param IUserManager $userManager |
|
52 | - */ |
|
53 | - public function __construct(IDBConnection $connection, IUserManager $userManager) { |
|
54 | - $this->connection = $connection; |
|
55 | - $this->userManager = $userManager; |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * @return string |
|
60 | - */ |
|
61 | - public function getName() { |
|
62 | - return 'Clean tags and favorites'; |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * Updates the configuration after running an update |
|
67 | - */ |
|
68 | - public function run(IOutput $output) { |
|
69 | - $this->deleteOrphanTags($output); |
|
70 | - $this->deleteOrphanFileEntries($output); |
|
71 | - $this->deleteOrphanTagEntries($output); |
|
72 | - $this->deleteOrphanCategoryEntries($output); |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Delete tags for deleted users |
|
77 | - */ |
|
78 | - protected function deleteOrphanTags(IOutput $output) { |
|
79 | - $offset = 0; |
|
80 | - while ($this->checkTags($offset)) { |
|
81 | - $offset += 50; |
|
82 | - } |
|
83 | - |
|
84 | - $output->info(sprintf('%d tags of deleted users have been removed.', $this->deletedTags)); |
|
85 | - } |
|
86 | - |
|
87 | - protected function checkTags($offset) { |
|
88 | - $query = $this->connection->getQueryBuilder(); |
|
89 | - $query->select('uid') |
|
90 | - ->from('vcategory') |
|
91 | - ->groupBy('uid') |
|
92 | - ->orderBy('uid') |
|
93 | - ->setMaxResults(50) |
|
94 | - ->setFirstResult($offset); |
|
95 | - $result = $query->execute(); |
|
96 | - |
|
97 | - $users = []; |
|
98 | - $hadResults = false; |
|
99 | - while ($row = $result->fetch()) { |
|
100 | - $hadResults = true; |
|
101 | - if (!$this->userManager->userExists($row['uid'])) { |
|
102 | - $users[] = $row['uid']; |
|
103 | - } |
|
104 | - } |
|
105 | - $result->closeCursor(); |
|
106 | - |
|
107 | - if (!$hadResults) { |
|
108 | - // No more tags, stop looping |
|
109 | - return false; |
|
110 | - } |
|
111 | - |
|
112 | - if (!empty($users)) { |
|
113 | - $query = $this->connection->getQueryBuilder(); |
|
114 | - $query->delete('vcategory') |
|
115 | - ->where($query->expr()->in('uid', $query->createNamedParameter($users, IQueryBuilder::PARAM_STR_ARRAY))); |
|
116 | - $this->deletedTags += $query->execute(); |
|
117 | - } |
|
118 | - return true; |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * Delete tag entries for deleted files |
|
123 | - */ |
|
124 | - protected function deleteOrphanFileEntries(IOutput $output) { |
|
125 | - $this->deleteOrphanEntries( |
|
126 | - $output, |
|
127 | - '%d tags for delete files have been removed.', |
|
128 | - 'vcategory_to_object', 'objid', |
|
129 | - 'filecache', 'fileid', 'path_hash' |
|
130 | - ); |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Delete tag entries for deleted tags |
|
135 | - */ |
|
136 | - protected function deleteOrphanTagEntries(IOutput $output) { |
|
137 | - $this->deleteOrphanEntries( |
|
138 | - $output, |
|
139 | - '%d tag entries for deleted tags have been removed.', |
|
140 | - 'vcategory_to_object', 'categoryid', |
|
141 | - 'vcategory', 'id', 'uid' |
|
142 | - ); |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * Delete tags that have no entries |
|
147 | - */ |
|
148 | - protected function deleteOrphanCategoryEntries(IOutput $output) { |
|
149 | - $this->deleteOrphanEntries( |
|
150 | - $output, |
|
151 | - '%d tags with no entries have been removed.', |
|
152 | - 'vcategory', 'id', |
|
153 | - 'vcategory_to_object', 'categoryid', 'type' |
|
154 | - ); |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * Deletes all entries from $deleteTable that do not have a matching entry in $sourceTable |
|
159 | - * |
|
160 | - * A query joins $deleteTable.$deleteId = $sourceTable.$sourceId and checks |
|
161 | - * whether $sourceNullColumn is null. If it is null, the entry in $deleteTable |
|
162 | - * is being deleted. |
|
163 | - * |
|
164 | - * @param string $repairInfo |
|
165 | - * @param string $deleteTable |
|
166 | - * @param string $deleteId |
|
167 | - * @param string $sourceTable |
|
168 | - * @param string $sourceId |
|
169 | - * @param string $sourceNullColumn If this column is null in the source table, |
|
170 | - * the entry is deleted in the $deleteTable |
|
171 | - */ |
|
172 | - protected function deleteOrphanEntries(IOutput $output, $repairInfo, $deleteTable, $deleteId, $sourceTable, $sourceId, $sourceNullColumn) { |
|
173 | - $qb = $this->connection->getQueryBuilder(); |
|
174 | - |
|
175 | - $qb->select('d.' . $deleteId) |
|
176 | - ->from($deleteTable, 'd') |
|
177 | - ->leftJoin('d', $sourceTable, 's', $qb->expr()->eq('d.' . $deleteId, 's.' . $sourceId)) |
|
178 | - ->where( |
|
179 | - $qb->expr()->eq('d.type', $qb->expr()->literal('files')) |
|
180 | - ) |
|
181 | - ->andWhere( |
|
182 | - $qb->expr()->isNull('s.' . $sourceNullColumn) |
|
183 | - ); |
|
184 | - $result = $qb->execute(); |
|
185 | - |
|
186 | - $orphanItems = []; |
|
187 | - while ($row = $result->fetch()) { |
|
188 | - $orphanItems[] = (int) $row[$deleteId]; |
|
189 | - } |
|
190 | - |
|
191 | - if (!empty($orphanItems)) { |
|
192 | - $orphanItemsBatch = array_chunk($orphanItems, 200); |
|
193 | - foreach ($orphanItemsBatch as $items) { |
|
194 | - $qb->delete($deleteTable) |
|
195 | - ->where( |
|
196 | - $qb->expr()->eq('type', $qb->expr()->literal('files')) |
|
197 | - ) |
|
198 | - ->andWhere($qb->expr()->in($deleteId, $qb->createParameter('ids'))); |
|
199 | - $qb->setParameter('ids', $items, IQueryBuilder::PARAM_INT_ARRAY); |
|
200 | - $qb->execute(); |
|
201 | - } |
|
202 | - } |
|
203 | - |
|
204 | - if ($repairInfo) { |
|
205 | - $output->info(sprintf($repairInfo, count($orphanItems))); |
|
206 | - } |
|
207 | - } |
|
41 | + /** @var IDBConnection */ |
|
42 | + protected $connection; |
|
43 | + |
|
44 | + /** @var IUserManager */ |
|
45 | + protected $userManager; |
|
46 | + |
|
47 | + protected $deletedTags = 0; |
|
48 | + |
|
49 | + /** |
|
50 | + * @param IDBConnection $connection |
|
51 | + * @param IUserManager $userManager |
|
52 | + */ |
|
53 | + public function __construct(IDBConnection $connection, IUserManager $userManager) { |
|
54 | + $this->connection = $connection; |
|
55 | + $this->userManager = $userManager; |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * @return string |
|
60 | + */ |
|
61 | + public function getName() { |
|
62 | + return 'Clean tags and favorites'; |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * Updates the configuration after running an update |
|
67 | + */ |
|
68 | + public function run(IOutput $output) { |
|
69 | + $this->deleteOrphanTags($output); |
|
70 | + $this->deleteOrphanFileEntries($output); |
|
71 | + $this->deleteOrphanTagEntries($output); |
|
72 | + $this->deleteOrphanCategoryEntries($output); |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Delete tags for deleted users |
|
77 | + */ |
|
78 | + protected function deleteOrphanTags(IOutput $output) { |
|
79 | + $offset = 0; |
|
80 | + while ($this->checkTags($offset)) { |
|
81 | + $offset += 50; |
|
82 | + } |
|
83 | + |
|
84 | + $output->info(sprintf('%d tags of deleted users have been removed.', $this->deletedTags)); |
|
85 | + } |
|
86 | + |
|
87 | + protected function checkTags($offset) { |
|
88 | + $query = $this->connection->getQueryBuilder(); |
|
89 | + $query->select('uid') |
|
90 | + ->from('vcategory') |
|
91 | + ->groupBy('uid') |
|
92 | + ->orderBy('uid') |
|
93 | + ->setMaxResults(50) |
|
94 | + ->setFirstResult($offset); |
|
95 | + $result = $query->execute(); |
|
96 | + |
|
97 | + $users = []; |
|
98 | + $hadResults = false; |
|
99 | + while ($row = $result->fetch()) { |
|
100 | + $hadResults = true; |
|
101 | + if (!$this->userManager->userExists($row['uid'])) { |
|
102 | + $users[] = $row['uid']; |
|
103 | + } |
|
104 | + } |
|
105 | + $result->closeCursor(); |
|
106 | + |
|
107 | + if (!$hadResults) { |
|
108 | + // No more tags, stop looping |
|
109 | + return false; |
|
110 | + } |
|
111 | + |
|
112 | + if (!empty($users)) { |
|
113 | + $query = $this->connection->getQueryBuilder(); |
|
114 | + $query->delete('vcategory') |
|
115 | + ->where($query->expr()->in('uid', $query->createNamedParameter($users, IQueryBuilder::PARAM_STR_ARRAY))); |
|
116 | + $this->deletedTags += $query->execute(); |
|
117 | + } |
|
118 | + return true; |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * Delete tag entries for deleted files |
|
123 | + */ |
|
124 | + protected function deleteOrphanFileEntries(IOutput $output) { |
|
125 | + $this->deleteOrphanEntries( |
|
126 | + $output, |
|
127 | + '%d tags for delete files have been removed.', |
|
128 | + 'vcategory_to_object', 'objid', |
|
129 | + 'filecache', 'fileid', 'path_hash' |
|
130 | + ); |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Delete tag entries for deleted tags |
|
135 | + */ |
|
136 | + protected function deleteOrphanTagEntries(IOutput $output) { |
|
137 | + $this->deleteOrphanEntries( |
|
138 | + $output, |
|
139 | + '%d tag entries for deleted tags have been removed.', |
|
140 | + 'vcategory_to_object', 'categoryid', |
|
141 | + 'vcategory', 'id', 'uid' |
|
142 | + ); |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * Delete tags that have no entries |
|
147 | + */ |
|
148 | + protected function deleteOrphanCategoryEntries(IOutput $output) { |
|
149 | + $this->deleteOrphanEntries( |
|
150 | + $output, |
|
151 | + '%d tags with no entries have been removed.', |
|
152 | + 'vcategory', 'id', |
|
153 | + 'vcategory_to_object', 'categoryid', 'type' |
|
154 | + ); |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * Deletes all entries from $deleteTable that do not have a matching entry in $sourceTable |
|
159 | + * |
|
160 | + * A query joins $deleteTable.$deleteId = $sourceTable.$sourceId and checks |
|
161 | + * whether $sourceNullColumn is null. If it is null, the entry in $deleteTable |
|
162 | + * is being deleted. |
|
163 | + * |
|
164 | + * @param string $repairInfo |
|
165 | + * @param string $deleteTable |
|
166 | + * @param string $deleteId |
|
167 | + * @param string $sourceTable |
|
168 | + * @param string $sourceId |
|
169 | + * @param string $sourceNullColumn If this column is null in the source table, |
|
170 | + * the entry is deleted in the $deleteTable |
|
171 | + */ |
|
172 | + protected function deleteOrphanEntries(IOutput $output, $repairInfo, $deleteTable, $deleteId, $sourceTable, $sourceId, $sourceNullColumn) { |
|
173 | + $qb = $this->connection->getQueryBuilder(); |
|
174 | + |
|
175 | + $qb->select('d.' . $deleteId) |
|
176 | + ->from($deleteTable, 'd') |
|
177 | + ->leftJoin('d', $sourceTable, 's', $qb->expr()->eq('d.' . $deleteId, 's.' . $sourceId)) |
|
178 | + ->where( |
|
179 | + $qb->expr()->eq('d.type', $qb->expr()->literal('files')) |
|
180 | + ) |
|
181 | + ->andWhere( |
|
182 | + $qb->expr()->isNull('s.' . $sourceNullColumn) |
|
183 | + ); |
|
184 | + $result = $qb->execute(); |
|
185 | + |
|
186 | + $orphanItems = []; |
|
187 | + while ($row = $result->fetch()) { |
|
188 | + $orphanItems[] = (int) $row[$deleteId]; |
|
189 | + } |
|
190 | + |
|
191 | + if (!empty($orphanItems)) { |
|
192 | + $orphanItemsBatch = array_chunk($orphanItems, 200); |
|
193 | + foreach ($orphanItemsBatch as $items) { |
|
194 | + $qb->delete($deleteTable) |
|
195 | + ->where( |
|
196 | + $qb->expr()->eq('type', $qb->expr()->literal('files')) |
|
197 | + ) |
|
198 | + ->andWhere($qb->expr()->in($deleteId, $qb->createParameter('ids'))); |
|
199 | + $qb->setParameter('ids', $items, IQueryBuilder::PARAM_INT_ARRAY); |
|
200 | + $qb->execute(); |
|
201 | + } |
|
202 | + } |
|
203 | + |
|
204 | + if ($repairInfo) { |
|
205 | + $output->info(sprintf($repairInfo, count($orphanItems))); |
|
206 | + } |
|
207 | + } |
|
208 | 208 | } |
@@ -24,56 +24,56 @@ |
||
24 | 24 | use OCP\Lockdown\ILockdownManager; |
25 | 25 | |
26 | 26 | class LockdownManager implements ILockdownManager { |
27 | - /** @var ISession */ |
|
28 | - private $sessionCallback; |
|
27 | + /** @var ISession */ |
|
28 | + private $sessionCallback; |
|
29 | 29 | |
30 | - private $enabled = false; |
|
30 | + private $enabled = false; |
|
31 | 31 | |
32 | - /** @var array|null */ |
|
33 | - private $scope; |
|
32 | + /** @var array|null */ |
|
33 | + private $scope; |
|
34 | 34 | |
35 | - /** |
|
36 | - * LockdownManager constructor. |
|
37 | - * |
|
38 | - * @param callable $sessionCallback we need to inject the session lazily to avoid dependency loops |
|
39 | - */ |
|
40 | - public function __construct(callable $sessionCallback) { |
|
41 | - $this->sessionCallback = $sessionCallback; |
|
42 | - } |
|
35 | + /** |
|
36 | + * LockdownManager constructor. |
|
37 | + * |
|
38 | + * @param callable $sessionCallback we need to inject the session lazily to avoid dependency loops |
|
39 | + */ |
|
40 | + public function __construct(callable $sessionCallback) { |
|
41 | + $this->sessionCallback = $sessionCallback; |
|
42 | + } |
|
43 | 43 | |
44 | 44 | |
45 | - public function enable() { |
|
46 | - $this->enabled = true; |
|
47 | - } |
|
45 | + public function enable() { |
|
46 | + $this->enabled = true; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @return ISession |
|
51 | - */ |
|
52 | - private function getSession() { |
|
53 | - $callback = $this->sessionCallback; |
|
54 | - return $callback(); |
|
55 | - } |
|
49 | + /** |
|
50 | + * @return ISession |
|
51 | + */ |
|
52 | + private function getSession() { |
|
53 | + $callback = $this->sessionCallback; |
|
54 | + return $callback(); |
|
55 | + } |
|
56 | 56 | |
57 | - private function getScopeAsArray() { |
|
58 | - if (!$this->scope) { |
|
59 | - $session = $this->getSession(); |
|
60 | - $sessionScope = $session->get('token_scope'); |
|
61 | - if ($sessionScope) { |
|
62 | - $this->scope = $sessionScope; |
|
63 | - } |
|
64 | - } |
|
65 | - return $this->scope; |
|
66 | - } |
|
57 | + private function getScopeAsArray() { |
|
58 | + if (!$this->scope) { |
|
59 | + $session = $this->getSession(); |
|
60 | + $sessionScope = $session->get('token_scope'); |
|
61 | + if ($sessionScope) { |
|
62 | + $this->scope = $sessionScope; |
|
63 | + } |
|
64 | + } |
|
65 | + return $this->scope; |
|
66 | + } |
|
67 | 67 | |
68 | - public function setToken(IToken $token) { |
|
69 | - $this->scope = $token->getScopeAsArray(); |
|
70 | - $session = $this->getSession(); |
|
71 | - $session->set('token_scope', $this->scope); |
|
72 | - $this->enable(); |
|
73 | - } |
|
68 | + public function setToken(IToken $token) { |
|
69 | + $this->scope = $token->getScopeAsArray(); |
|
70 | + $session = $this->getSession(); |
|
71 | + $session->set('token_scope', $this->scope); |
|
72 | + $this->enable(); |
|
73 | + } |
|
74 | 74 | |
75 | - public function canAccessFilesystem() { |
|
76 | - $scope = $this->getScopeAsArray(); |
|
77 | - return !$scope || $scope['filesystem']; |
|
78 | - } |
|
75 | + public function canAccessFilesystem() { |
|
76 | + $scope = $this->getScopeAsArray(); |
|
77 | + return !$scope || $scope['filesystem']; |
|
78 | + } |
|
79 | 79 | } |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | } |
115 | 115 | |
116 | 116 | $item = $node; |
117 | - $appendix = '/' . $node->getName(); |
|
117 | + $appendix = '/'.$node->getName(); |
|
118 | 118 | while (!empty($byId)) { |
119 | 119 | try { |
120 | 120 | /** @var Node $item */ |
@@ -122,12 +122,12 @@ discard block |
||
122 | 122 | |
123 | 123 | if (!empty($byId[$item->getId()])) { |
124 | 124 | foreach ($byId[$item->getId()] as $uid => $path) { |
125 | - $results[$uid] = $path . $appendix; |
|
125 | + $results[$uid] = $path.$appendix; |
|
126 | 126 | } |
127 | 127 | unset($byId[$item->getId()]); |
128 | 128 | } |
129 | 129 | |
130 | - $appendix = '/' . $item->getName() . $appendix; |
|
130 | + $appendix = '/'.$item->getName().$appendix; |
|
131 | 131 | } catch (NotFoundException $e) { |
132 | 132 | return $results; |
133 | 133 | } catch (InvalidPathException $e) { |
@@ -212,6 +212,6 @@ discard block |
||
212 | 212 | protected function getMountedPath(Node $node) { |
213 | 213 | $path = $node->getPath(); |
214 | 214 | $sections = explode('/', $path, 4); |
215 | - return '/' . $sections[3]; |
|
215 | + return '/'.$sections[3]; |
|
216 | 216 | } |
217 | 217 | } |
@@ -31,187 +31,187 @@ |
||
31 | 31 | use OCP\Share\IShareHelper; |
32 | 32 | |
33 | 33 | class ShareHelper implements IShareHelper { |
34 | - /** @var IManager */ |
|
35 | - private $shareManager; |
|
36 | - |
|
37 | - public function __construct(IManager $shareManager) { |
|
38 | - $this->shareManager = $shareManager; |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * @param Node $node |
|
43 | - * @return array [ users => [Mapping $uid => $pathForUser], remotes => [Mapping $cloudId => $pathToMountRoot]] |
|
44 | - */ |
|
45 | - public function getPathsForAccessList(Node $node) { |
|
46 | - $result = [ |
|
47 | - 'users' => [], |
|
48 | - 'remotes' => [], |
|
49 | - ]; |
|
50 | - |
|
51 | - $accessList = $this->shareManager->getAccessList($node, true, true); |
|
52 | - if (!empty($accessList['users'])) { |
|
53 | - $result['users'] = $this->getPathsForUsers($node, $accessList['users']); |
|
54 | - } |
|
55 | - if (!empty($accessList['remote'])) { |
|
56 | - $result['remotes'] = $this->getPathsForRemotes($node, $accessList['remote']); |
|
57 | - } |
|
58 | - |
|
59 | - return $result; |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Sample: |
|
64 | - * $users = [ |
|
65 | - * 'test1' => ['node_id' => 16, 'node_path' => '/foo'], |
|
66 | - * 'test2' => ['node_id' => 23, 'node_path' => '/bar'], |
|
67 | - * 'test3' => ['node_id' => 42, 'node_path' => '/cat'], |
|
68 | - * 'test4' => ['node_id' => 48, 'node_path' => '/dog'], |
|
69 | - * ]; |
|
70 | - * |
|
71 | - * Node tree: |
|
72 | - * - SixTeen is the parent of TwentyThree |
|
73 | - * - TwentyThree is the parent of FortyTwo |
|
74 | - * - FortyEight does not exist |
|
75 | - * |
|
76 | - * $return = [ |
|
77 | - * 'test1' => '/foo/TwentyThree/FortyTwo', |
|
78 | - * 'test2' => '/bar/FortyTwo', |
|
79 | - * 'test3' => '/cat', |
|
80 | - * ], |
|
81 | - * |
|
82 | - * @param Node $node |
|
83 | - * @param array[] $users |
|
84 | - * @return array |
|
85 | - */ |
|
86 | - protected function getPathsForUsers(Node $node, array $users) { |
|
87 | - /** @var array[] $byId */ |
|
88 | - $byId = []; |
|
89 | - /** @var array[] $results */ |
|
90 | - $results = []; |
|
91 | - |
|
92 | - foreach ($users as $uid => $info) { |
|
93 | - if (!isset($byId[$info['node_id']])) { |
|
94 | - $byId[$info['node_id']] = []; |
|
95 | - } |
|
96 | - $byId[$info['node_id']][$uid] = $info['node_path']; |
|
97 | - } |
|
98 | - |
|
99 | - try { |
|
100 | - if (isset($byId[$node->getId()])) { |
|
101 | - foreach ($byId[$node->getId()] as $uid => $path) { |
|
102 | - $results[$uid] = $path; |
|
103 | - } |
|
104 | - unset($byId[$node->getId()]); |
|
105 | - } |
|
106 | - } catch (NotFoundException $e) { |
|
107 | - return $results; |
|
108 | - } catch (InvalidPathException $e) { |
|
109 | - return $results; |
|
110 | - } |
|
111 | - |
|
112 | - if (empty($byId)) { |
|
113 | - return $results; |
|
114 | - } |
|
115 | - |
|
116 | - $item = $node; |
|
117 | - $appendix = '/' . $node->getName(); |
|
118 | - while (!empty($byId)) { |
|
119 | - try { |
|
120 | - /** @var Node $item */ |
|
121 | - $item = $item->getParent(); |
|
122 | - |
|
123 | - if (!empty($byId[$item->getId()])) { |
|
124 | - foreach ($byId[$item->getId()] as $uid => $path) { |
|
125 | - $results[$uid] = $path . $appendix; |
|
126 | - } |
|
127 | - unset($byId[$item->getId()]); |
|
128 | - } |
|
129 | - |
|
130 | - $appendix = '/' . $item->getName() . $appendix; |
|
131 | - } catch (NotFoundException $e) { |
|
132 | - return $results; |
|
133 | - } catch (InvalidPathException $e) { |
|
134 | - return $results; |
|
135 | - } catch (NotPermittedException $e) { |
|
136 | - return $results; |
|
137 | - } |
|
138 | - } |
|
139 | - |
|
140 | - return $results; |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Sample: |
|
145 | - * $remotes = [ |
|
146 | - * 'test1' => ['node_id' => 16, 'token' => 't1'], |
|
147 | - * 'test2' => ['node_id' => 23, 'token' => 't2'], |
|
148 | - * 'test3' => ['node_id' => 42, 'token' => 't3'], |
|
149 | - * 'test4' => ['node_id' => 48, 'token' => 't4'], |
|
150 | - * ]; |
|
151 | - * |
|
152 | - * Node tree: |
|
153 | - * - SixTeen is the parent of TwentyThree |
|
154 | - * - TwentyThree is the parent of FortyTwo |
|
155 | - * - FortyEight does not exist |
|
156 | - * |
|
157 | - * $return = [ |
|
158 | - * 'test1' => ['token' => 't1', 'node_path' => '/SixTeen'], |
|
159 | - * 'test2' => ['token' => 't2', 'node_path' => '/SixTeen/TwentyThree'], |
|
160 | - * 'test3' => ['token' => 't3', 'node_path' => '/SixTeen/TwentyThree/FortyTwo'], |
|
161 | - * ], |
|
162 | - * |
|
163 | - * @param Node $node |
|
164 | - * @param array[] $remotes |
|
165 | - * @return array |
|
166 | - */ |
|
167 | - protected function getPathsForRemotes(Node $node, array $remotes) { |
|
168 | - /** @var array[] $byId */ |
|
169 | - $byId = []; |
|
170 | - /** @var array[] $results */ |
|
171 | - $results = []; |
|
172 | - |
|
173 | - foreach ($remotes as $cloudId => $info) { |
|
174 | - if (!isset($byId[$info['node_id']])) { |
|
175 | - $byId[$info['node_id']] = []; |
|
176 | - } |
|
177 | - $byId[$info['node_id']][$cloudId] = $info['token']; |
|
178 | - } |
|
179 | - |
|
180 | - $item = $node; |
|
181 | - while (!empty($byId)) { |
|
182 | - try { |
|
183 | - if (!empty($byId[$item->getId()])) { |
|
184 | - $path = $this->getMountedPath($item); |
|
185 | - foreach ($byId[$item->getId()] as $uid => $token) { |
|
186 | - $results[$uid] = [ |
|
187 | - 'node_path' => $path, |
|
188 | - 'token' => $token, |
|
189 | - ]; |
|
190 | - } |
|
191 | - unset($byId[$item->getId()]); |
|
192 | - } |
|
193 | - |
|
194 | - /** @var Node $item */ |
|
195 | - $item = $item->getParent(); |
|
196 | - } catch (NotFoundException $e) { |
|
197 | - return $results; |
|
198 | - } catch (InvalidPathException $e) { |
|
199 | - return $results; |
|
200 | - } catch (NotPermittedException $e) { |
|
201 | - return $results; |
|
202 | - } |
|
203 | - } |
|
204 | - |
|
205 | - return $results; |
|
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * @param Node $node |
|
210 | - * @return string |
|
211 | - */ |
|
212 | - protected function getMountedPath(Node $node) { |
|
213 | - $path = $node->getPath(); |
|
214 | - $sections = explode('/', $path, 4); |
|
215 | - return '/' . $sections[3]; |
|
216 | - } |
|
34 | + /** @var IManager */ |
|
35 | + private $shareManager; |
|
36 | + |
|
37 | + public function __construct(IManager $shareManager) { |
|
38 | + $this->shareManager = $shareManager; |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * @param Node $node |
|
43 | + * @return array [ users => [Mapping $uid => $pathForUser], remotes => [Mapping $cloudId => $pathToMountRoot]] |
|
44 | + */ |
|
45 | + public function getPathsForAccessList(Node $node) { |
|
46 | + $result = [ |
|
47 | + 'users' => [], |
|
48 | + 'remotes' => [], |
|
49 | + ]; |
|
50 | + |
|
51 | + $accessList = $this->shareManager->getAccessList($node, true, true); |
|
52 | + if (!empty($accessList['users'])) { |
|
53 | + $result['users'] = $this->getPathsForUsers($node, $accessList['users']); |
|
54 | + } |
|
55 | + if (!empty($accessList['remote'])) { |
|
56 | + $result['remotes'] = $this->getPathsForRemotes($node, $accessList['remote']); |
|
57 | + } |
|
58 | + |
|
59 | + return $result; |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Sample: |
|
64 | + * $users = [ |
|
65 | + * 'test1' => ['node_id' => 16, 'node_path' => '/foo'], |
|
66 | + * 'test2' => ['node_id' => 23, 'node_path' => '/bar'], |
|
67 | + * 'test3' => ['node_id' => 42, 'node_path' => '/cat'], |
|
68 | + * 'test4' => ['node_id' => 48, 'node_path' => '/dog'], |
|
69 | + * ]; |
|
70 | + * |
|
71 | + * Node tree: |
|
72 | + * - SixTeen is the parent of TwentyThree |
|
73 | + * - TwentyThree is the parent of FortyTwo |
|
74 | + * - FortyEight does not exist |
|
75 | + * |
|
76 | + * $return = [ |
|
77 | + * 'test1' => '/foo/TwentyThree/FortyTwo', |
|
78 | + * 'test2' => '/bar/FortyTwo', |
|
79 | + * 'test3' => '/cat', |
|
80 | + * ], |
|
81 | + * |
|
82 | + * @param Node $node |
|
83 | + * @param array[] $users |
|
84 | + * @return array |
|
85 | + */ |
|
86 | + protected function getPathsForUsers(Node $node, array $users) { |
|
87 | + /** @var array[] $byId */ |
|
88 | + $byId = []; |
|
89 | + /** @var array[] $results */ |
|
90 | + $results = []; |
|
91 | + |
|
92 | + foreach ($users as $uid => $info) { |
|
93 | + if (!isset($byId[$info['node_id']])) { |
|
94 | + $byId[$info['node_id']] = []; |
|
95 | + } |
|
96 | + $byId[$info['node_id']][$uid] = $info['node_path']; |
|
97 | + } |
|
98 | + |
|
99 | + try { |
|
100 | + if (isset($byId[$node->getId()])) { |
|
101 | + foreach ($byId[$node->getId()] as $uid => $path) { |
|
102 | + $results[$uid] = $path; |
|
103 | + } |
|
104 | + unset($byId[$node->getId()]); |
|
105 | + } |
|
106 | + } catch (NotFoundException $e) { |
|
107 | + return $results; |
|
108 | + } catch (InvalidPathException $e) { |
|
109 | + return $results; |
|
110 | + } |
|
111 | + |
|
112 | + if (empty($byId)) { |
|
113 | + return $results; |
|
114 | + } |
|
115 | + |
|
116 | + $item = $node; |
|
117 | + $appendix = '/' . $node->getName(); |
|
118 | + while (!empty($byId)) { |
|
119 | + try { |
|
120 | + /** @var Node $item */ |
|
121 | + $item = $item->getParent(); |
|
122 | + |
|
123 | + if (!empty($byId[$item->getId()])) { |
|
124 | + foreach ($byId[$item->getId()] as $uid => $path) { |
|
125 | + $results[$uid] = $path . $appendix; |
|
126 | + } |
|
127 | + unset($byId[$item->getId()]); |
|
128 | + } |
|
129 | + |
|
130 | + $appendix = '/' . $item->getName() . $appendix; |
|
131 | + } catch (NotFoundException $e) { |
|
132 | + return $results; |
|
133 | + } catch (InvalidPathException $e) { |
|
134 | + return $results; |
|
135 | + } catch (NotPermittedException $e) { |
|
136 | + return $results; |
|
137 | + } |
|
138 | + } |
|
139 | + |
|
140 | + return $results; |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Sample: |
|
145 | + * $remotes = [ |
|
146 | + * 'test1' => ['node_id' => 16, 'token' => 't1'], |
|
147 | + * 'test2' => ['node_id' => 23, 'token' => 't2'], |
|
148 | + * 'test3' => ['node_id' => 42, 'token' => 't3'], |
|
149 | + * 'test4' => ['node_id' => 48, 'token' => 't4'], |
|
150 | + * ]; |
|
151 | + * |
|
152 | + * Node tree: |
|
153 | + * - SixTeen is the parent of TwentyThree |
|
154 | + * - TwentyThree is the parent of FortyTwo |
|
155 | + * - FortyEight does not exist |
|
156 | + * |
|
157 | + * $return = [ |
|
158 | + * 'test1' => ['token' => 't1', 'node_path' => '/SixTeen'], |
|
159 | + * 'test2' => ['token' => 't2', 'node_path' => '/SixTeen/TwentyThree'], |
|
160 | + * 'test3' => ['token' => 't3', 'node_path' => '/SixTeen/TwentyThree/FortyTwo'], |
|
161 | + * ], |
|
162 | + * |
|
163 | + * @param Node $node |
|
164 | + * @param array[] $remotes |
|
165 | + * @return array |
|
166 | + */ |
|
167 | + protected function getPathsForRemotes(Node $node, array $remotes) { |
|
168 | + /** @var array[] $byId */ |
|
169 | + $byId = []; |
|
170 | + /** @var array[] $results */ |
|
171 | + $results = []; |
|
172 | + |
|
173 | + foreach ($remotes as $cloudId => $info) { |
|
174 | + if (!isset($byId[$info['node_id']])) { |
|
175 | + $byId[$info['node_id']] = []; |
|
176 | + } |
|
177 | + $byId[$info['node_id']][$cloudId] = $info['token']; |
|
178 | + } |
|
179 | + |
|
180 | + $item = $node; |
|
181 | + while (!empty($byId)) { |
|
182 | + try { |
|
183 | + if (!empty($byId[$item->getId()])) { |
|
184 | + $path = $this->getMountedPath($item); |
|
185 | + foreach ($byId[$item->getId()] as $uid => $token) { |
|
186 | + $results[$uid] = [ |
|
187 | + 'node_path' => $path, |
|
188 | + 'token' => $token, |
|
189 | + ]; |
|
190 | + } |
|
191 | + unset($byId[$item->getId()]); |
|
192 | + } |
|
193 | + |
|
194 | + /** @var Node $item */ |
|
195 | + $item = $item->getParent(); |
|
196 | + } catch (NotFoundException $e) { |
|
197 | + return $results; |
|
198 | + } catch (InvalidPathException $e) { |
|
199 | + return $results; |
|
200 | + } catch (NotPermittedException $e) { |
|
201 | + return $results; |
|
202 | + } |
|
203 | + } |
|
204 | + |
|
205 | + return $results; |
|
206 | + } |
|
207 | + |
|
208 | + /** |
|
209 | + * @param Node $node |
|
210 | + * @return string |
|
211 | + */ |
|
212 | + protected function getMountedPath(Node $node) { |
|
213 | + $path = $node->getPath(); |
|
214 | + $sections = explode('/', $path, 4); |
|
215 | + return '/' . $sections[3]; |
|
216 | + } |
|
217 | 217 | } |
@@ -29,19 +29,19 @@ |
||
29 | 29 | */ |
30 | 30 | class FilesystemHelper { |
31 | 31 | |
32 | - /** |
|
33 | - * @brief states whether the filesystem was loaded |
|
34 | - * @return bool |
|
35 | - */ |
|
36 | - public function isLoaded() { |
|
37 | - return \OC\Files\Filesystem::$loaded; |
|
38 | - } |
|
32 | + /** |
|
33 | + * @brief states whether the filesystem was loaded |
|
34 | + * @return bool |
|
35 | + */ |
|
36 | + public function isLoaded() { |
|
37 | + return \OC\Files\Filesystem::$loaded; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @brief initializes the filesystem for the given user |
|
42 | - * @param string $uid the Nextcloud username of the user |
|
43 | - */ |
|
44 | - public function setup($uid) { |
|
45 | - \OC_Util::setupFS($uid); |
|
46 | - } |
|
40 | + /** |
|
41 | + * @brief initializes the filesystem for the given user |
|
42 | + * @param string $uid the Nextcloud username of the user |
|
43 | + */ |
|
44 | + public function setup($uid) { |
|
45 | + \OC_Util::setupFS($uid); |
|
46 | + } |
|
47 | 47 | } |
@@ -25,28 +25,28 @@ |
||
25 | 25 | use OCP\AppFramework\Http\JSONResponse; |
26 | 26 | |
27 | 27 | class RateLimitTestController extends Controller { |
28 | - /** |
|
29 | - * @PublicPage |
|
30 | - * @NoCSRFRequired |
|
31 | - * |
|
32 | - * @UserRateThrottle(limit=5, period=100) |
|
33 | - * @AnonRateThrottle(limit=1, period=100) |
|
34 | - * |
|
35 | - * @return JSONResponse |
|
36 | - */ |
|
37 | - public function userAndAnonProtected() { |
|
38 | - return new JSONResponse(); |
|
39 | - } |
|
28 | + /** |
|
29 | + * @PublicPage |
|
30 | + * @NoCSRFRequired |
|
31 | + * |
|
32 | + * @UserRateThrottle(limit=5, period=100) |
|
33 | + * @AnonRateThrottle(limit=1, period=100) |
|
34 | + * |
|
35 | + * @return JSONResponse |
|
36 | + */ |
|
37 | + public function userAndAnonProtected() { |
|
38 | + return new JSONResponse(); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * @PublicPage |
|
43 | - * @NoCSRFRequired |
|
44 | - * |
|
45 | - * @AnonRateThrottle(limit=1, period=10) |
|
46 | - * |
|
47 | - * @return JSONResponse |
|
48 | - */ |
|
49 | - public function onlyAnonProtected() { |
|
50 | - return new JSONResponse(); |
|
51 | - } |
|
41 | + /** |
|
42 | + * @PublicPage |
|
43 | + * @NoCSRFRequired |
|
44 | + * |
|
45 | + * @AnonRateThrottle(limit=1, period=10) |
|
46 | + * |
|
47 | + * @return JSONResponse |
|
48 | + */ |
|
49 | + public function onlyAnonProtected() { |
|
50 | + return new JSONResponse(); |
|
51 | + } |
|
52 | 52 | } |
@@ -25,7 +25,7 @@ |
||
25 | 25 | use OCP\AppFramework\Http; |
26 | 26 | |
27 | 27 | class RateLimitExceededException extends SecurityException { |
28 | - public function __construct() { |
|
29 | - parent::__construct('Rate limit exceeded', Http::STATUS_TOO_MANY_REQUESTS); |
|
30 | - } |
|
28 | + public function __construct() { |
|
29 | + parent::__construct('Rate limit exceeded', Http::STATUS_TOO_MANY_REQUESTS); |
|
30 | + } |
|
31 | 31 | } |
@@ -107,32 +107,32 @@ discard block |
||
107 | 107 | case '{DAV:}prop': |
108 | 108 | $newProps['properties'] = array_keys($elem['value']); |
109 | 109 | break; |
110 | - case '{' . SearchPlugin::NS_Nextcloud . '}filter': |
|
110 | + case '{'.SearchPlugin::NS_Nextcloud.'}filter': |
|
111 | 111 | foreach ($elem['value'] as $subElem) { |
112 | - if ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}comp-filter') { |
|
112 | + if ($subElem['name'] === '{'.SearchPlugin::NS_Nextcloud.'}comp-filter') { |
|
113 | 113 | if (!isset($newProps['filters']['comps']) || !is_array($newProps['filters']['comps'])) { |
114 | 114 | $newProps['filters']['comps'] = []; |
115 | 115 | } |
116 | 116 | $newProps['filters']['comps'][] = $subElem['value']; |
117 | - } elseif ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}prop-filter') { |
|
117 | + } elseif ($subElem['name'] === '{'.SearchPlugin::NS_Nextcloud.'}prop-filter') { |
|
118 | 118 | if (!isset($newProps['filters']['props']) || !is_array($newProps['filters']['props'])) { |
119 | 119 | $newProps['filters']['props'] = []; |
120 | 120 | } |
121 | 121 | $newProps['filters']['props'][] = $subElem['value']; |
122 | - } elseif ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}param-filter') { |
|
122 | + } elseif ($subElem['name'] === '{'.SearchPlugin::NS_Nextcloud.'}param-filter') { |
|
123 | 123 | if (!isset($newProps['filters']['params']) || !is_array($newProps['filters']['params'])) { |
124 | 124 | $newProps['filters']['params'] = []; |
125 | 125 | } |
126 | 126 | $newProps['filters']['params'][] = $subElem['value']; |
127 | - } elseif ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}search-term') { |
|
127 | + } elseif ($subElem['name'] === '{'.SearchPlugin::NS_Nextcloud.'}search-term') { |
|
128 | 128 | $newProps['filters']['search-term'] = $subElem['value']; |
129 | 129 | } |
130 | 130 | } |
131 | 131 | break; |
132 | - case '{' . SearchPlugin::NS_Nextcloud . '}limit': |
|
132 | + case '{'.SearchPlugin::NS_Nextcloud.'}limit': |
|
133 | 133 | $newProps['limit'] = $elem['value']; |
134 | 134 | break; |
135 | - case '{' . SearchPlugin::NS_Nextcloud . '}offset': |
|
135 | + case '{'.SearchPlugin::NS_Nextcloud.'}offset': |
|
136 | 136 | $newProps['offset'] = $elem['value']; |
137 | 137 | break; |
138 | 138 | |
@@ -140,21 +140,21 @@ discard block |
||
140 | 140 | } |
141 | 141 | |
142 | 142 | if (empty($newProps['filters'])) { |
143 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}filter element is required for this request'); |
|
143 | + throw new BadRequest('The {'.SearchPlugin::NS_Nextcloud.'}filter element is required for this request'); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | $propsOrParamsDefined = (!empty($newProps['filters']['props']) || !empty($newProps['filters']['params'])); |
147 | 147 | $noCompsDefined = empty($newProps['filters']['comps']); |
148 | 148 | if ($propsOrParamsDefined && $noCompsDefined) { |
149 | - throw new BadRequest('{' . SearchPlugin::NS_Nextcloud . '}prop-filter or {' . SearchPlugin::NS_Nextcloud . '}param-filter given without any {' . SearchPlugin::NS_Nextcloud . '}comp-filter'); |
|
149 | + throw new BadRequest('{'.SearchPlugin::NS_Nextcloud.'}prop-filter or {'.SearchPlugin::NS_Nextcloud.'}param-filter given without any {'.SearchPlugin::NS_Nextcloud.'}comp-filter'); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | if (!isset($newProps['filters']['search-term'])) { |
153 | - throw new BadRequest('{' . SearchPlugin::NS_Nextcloud . '}search-term is required for this request'); |
|
153 | + throw new BadRequest('{'.SearchPlugin::NS_Nextcloud.'}search-term is required for this request'); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | if (empty($newProps['filters']['props']) && empty($newProps['filters']['params'])) { |
157 | - throw new BadRequest('At least one{' . SearchPlugin::NS_Nextcloud . '}prop-filter or {' . SearchPlugin::NS_Nextcloud . '}param-filter is required for this request'); |
|
157 | + throw new BadRequest('At least one{'.SearchPlugin::NS_Nextcloud.'}prop-filter or {'.SearchPlugin::NS_Nextcloud.'}param-filter is required for this request'); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 |
@@ -35,133 +35,133 @@ |
||
35 | 35 | */ |
36 | 36 | class CalendarSearchReport implements XmlDeserializable { |
37 | 37 | |
38 | - /** |
|
39 | - * An array with requested properties. |
|
40 | - * |
|
41 | - * @var array |
|
42 | - */ |
|
43 | - public $properties; |
|
44 | - |
|
45 | - /** |
|
46 | - * List of property/component filters. |
|
47 | - * |
|
48 | - * @var array |
|
49 | - */ |
|
50 | - public $filters; |
|
51 | - |
|
52 | - /** |
|
53 | - * @var int |
|
54 | - */ |
|
55 | - public $limit; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var int |
|
59 | - */ |
|
60 | - public $offset; |
|
61 | - |
|
62 | - /** |
|
63 | - * The deserialize method is called during xml parsing. |
|
64 | - * |
|
65 | - * This method is called statically, this is because in theory this method |
|
66 | - * may be used as a type of constructor, or factory method. |
|
67 | - * |
|
68 | - * Often you want to return an instance of the current class, but you are |
|
69 | - * free to return other data as well. |
|
70 | - * |
|
71 | - * You are responsible for advancing the reader to the next element. Not |
|
72 | - * doing anything will result in a never-ending loop. |
|
73 | - * |
|
74 | - * If you just want to skip parsing for this element altogether, you can |
|
75 | - * just call $reader->next(); |
|
76 | - * |
|
77 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
78 | - * the next element. |
|
79 | - * |
|
80 | - * @param Reader $reader |
|
81 | - * @return mixed |
|
82 | - */ |
|
83 | - public static function xmlDeserialize(Reader $reader) { |
|
84 | - $elems = $reader->parseInnerTree([ |
|
85 | - '{http://nextcloud.com/ns}comp-filter' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\CompFilter', |
|
86 | - '{http://nextcloud.com/ns}prop-filter' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\PropFilter', |
|
87 | - '{http://nextcloud.com/ns}param-filter' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\ParamFilter', |
|
88 | - '{http://nextcloud.com/ns}search-term' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\SearchTermFilter', |
|
89 | - '{http://nextcloud.com/ns}limit' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\LimitFilter', |
|
90 | - '{http://nextcloud.com/ns}offset' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\OffsetFilter', |
|
91 | - '{DAV:}prop' => 'Sabre\\Xml\\Element\\KeyValue', |
|
92 | - ]); |
|
93 | - |
|
94 | - $newProps = [ |
|
95 | - 'filters' => [], |
|
96 | - 'properties' => [], |
|
97 | - 'limit' => null, |
|
98 | - 'offset' => null |
|
99 | - ]; |
|
100 | - |
|
101 | - if (!is_array($elems)) { |
|
102 | - $elems = []; |
|
103 | - } |
|
104 | - |
|
105 | - foreach ($elems as $elem) { |
|
106 | - switch ($elem['name']) { |
|
107 | - case '{DAV:}prop': |
|
108 | - $newProps['properties'] = array_keys($elem['value']); |
|
109 | - break; |
|
110 | - case '{' . SearchPlugin::NS_Nextcloud . '}filter': |
|
111 | - foreach ($elem['value'] as $subElem) { |
|
112 | - if ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}comp-filter') { |
|
113 | - if (!isset($newProps['filters']['comps']) || !is_array($newProps['filters']['comps'])) { |
|
114 | - $newProps['filters']['comps'] = []; |
|
115 | - } |
|
116 | - $newProps['filters']['comps'][] = $subElem['value']; |
|
117 | - } elseif ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}prop-filter') { |
|
118 | - if (!isset($newProps['filters']['props']) || !is_array($newProps['filters']['props'])) { |
|
119 | - $newProps['filters']['props'] = []; |
|
120 | - } |
|
121 | - $newProps['filters']['props'][] = $subElem['value']; |
|
122 | - } elseif ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}param-filter') { |
|
123 | - if (!isset($newProps['filters']['params']) || !is_array($newProps['filters']['params'])) { |
|
124 | - $newProps['filters']['params'] = []; |
|
125 | - } |
|
126 | - $newProps['filters']['params'][] = $subElem['value']; |
|
127 | - } elseif ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}search-term') { |
|
128 | - $newProps['filters']['search-term'] = $subElem['value']; |
|
129 | - } |
|
130 | - } |
|
131 | - break; |
|
132 | - case '{' . SearchPlugin::NS_Nextcloud . '}limit': |
|
133 | - $newProps['limit'] = $elem['value']; |
|
134 | - break; |
|
135 | - case '{' . SearchPlugin::NS_Nextcloud . '}offset': |
|
136 | - $newProps['offset'] = $elem['value']; |
|
137 | - break; |
|
138 | - |
|
139 | - } |
|
140 | - } |
|
141 | - |
|
142 | - if (empty($newProps['filters'])) { |
|
143 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}filter element is required for this request'); |
|
144 | - } |
|
145 | - |
|
146 | - $propsOrParamsDefined = (!empty($newProps['filters']['props']) || !empty($newProps['filters']['params'])); |
|
147 | - $noCompsDefined = empty($newProps['filters']['comps']); |
|
148 | - if ($propsOrParamsDefined && $noCompsDefined) { |
|
149 | - throw new BadRequest('{' . SearchPlugin::NS_Nextcloud . '}prop-filter or {' . SearchPlugin::NS_Nextcloud . '}param-filter given without any {' . SearchPlugin::NS_Nextcloud . '}comp-filter'); |
|
150 | - } |
|
151 | - |
|
152 | - if (!isset($newProps['filters']['search-term'])) { |
|
153 | - throw new BadRequest('{' . SearchPlugin::NS_Nextcloud . '}search-term is required for this request'); |
|
154 | - } |
|
155 | - |
|
156 | - if (empty($newProps['filters']['props']) && empty($newProps['filters']['params'])) { |
|
157 | - throw new BadRequest('At least one{' . SearchPlugin::NS_Nextcloud . '}prop-filter or {' . SearchPlugin::NS_Nextcloud . '}param-filter is required for this request'); |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - $obj = new self(); |
|
162 | - foreach ($newProps as $key => $value) { |
|
163 | - $obj->$key = $value; |
|
164 | - } |
|
165 | - return $obj; |
|
166 | - } |
|
38 | + /** |
|
39 | + * An array with requested properties. |
|
40 | + * |
|
41 | + * @var array |
|
42 | + */ |
|
43 | + public $properties; |
|
44 | + |
|
45 | + /** |
|
46 | + * List of property/component filters. |
|
47 | + * |
|
48 | + * @var array |
|
49 | + */ |
|
50 | + public $filters; |
|
51 | + |
|
52 | + /** |
|
53 | + * @var int |
|
54 | + */ |
|
55 | + public $limit; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var int |
|
59 | + */ |
|
60 | + public $offset; |
|
61 | + |
|
62 | + /** |
|
63 | + * The deserialize method is called during xml parsing. |
|
64 | + * |
|
65 | + * This method is called statically, this is because in theory this method |
|
66 | + * may be used as a type of constructor, or factory method. |
|
67 | + * |
|
68 | + * Often you want to return an instance of the current class, but you are |
|
69 | + * free to return other data as well. |
|
70 | + * |
|
71 | + * You are responsible for advancing the reader to the next element. Not |
|
72 | + * doing anything will result in a never-ending loop. |
|
73 | + * |
|
74 | + * If you just want to skip parsing for this element altogether, you can |
|
75 | + * just call $reader->next(); |
|
76 | + * |
|
77 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
78 | + * the next element. |
|
79 | + * |
|
80 | + * @param Reader $reader |
|
81 | + * @return mixed |
|
82 | + */ |
|
83 | + public static function xmlDeserialize(Reader $reader) { |
|
84 | + $elems = $reader->parseInnerTree([ |
|
85 | + '{http://nextcloud.com/ns}comp-filter' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\CompFilter', |
|
86 | + '{http://nextcloud.com/ns}prop-filter' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\PropFilter', |
|
87 | + '{http://nextcloud.com/ns}param-filter' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\ParamFilter', |
|
88 | + '{http://nextcloud.com/ns}search-term' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\SearchTermFilter', |
|
89 | + '{http://nextcloud.com/ns}limit' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\LimitFilter', |
|
90 | + '{http://nextcloud.com/ns}offset' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\OffsetFilter', |
|
91 | + '{DAV:}prop' => 'Sabre\\Xml\\Element\\KeyValue', |
|
92 | + ]); |
|
93 | + |
|
94 | + $newProps = [ |
|
95 | + 'filters' => [], |
|
96 | + 'properties' => [], |
|
97 | + 'limit' => null, |
|
98 | + 'offset' => null |
|
99 | + ]; |
|
100 | + |
|
101 | + if (!is_array($elems)) { |
|
102 | + $elems = []; |
|
103 | + } |
|
104 | + |
|
105 | + foreach ($elems as $elem) { |
|
106 | + switch ($elem['name']) { |
|
107 | + case '{DAV:}prop': |
|
108 | + $newProps['properties'] = array_keys($elem['value']); |
|
109 | + break; |
|
110 | + case '{' . SearchPlugin::NS_Nextcloud . '}filter': |
|
111 | + foreach ($elem['value'] as $subElem) { |
|
112 | + if ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}comp-filter') { |
|
113 | + if (!isset($newProps['filters']['comps']) || !is_array($newProps['filters']['comps'])) { |
|
114 | + $newProps['filters']['comps'] = []; |
|
115 | + } |
|
116 | + $newProps['filters']['comps'][] = $subElem['value']; |
|
117 | + } elseif ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}prop-filter') { |
|
118 | + if (!isset($newProps['filters']['props']) || !is_array($newProps['filters']['props'])) { |
|
119 | + $newProps['filters']['props'] = []; |
|
120 | + } |
|
121 | + $newProps['filters']['props'][] = $subElem['value']; |
|
122 | + } elseif ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}param-filter') { |
|
123 | + if (!isset($newProps['filters']['params']) || !is_array($newProps['filters']['params'])) { |
|
124 | + $newProps['filters']['params'] = []; |
|
125 | + } |
|
126 | + $newProps['filters']['params'][] = $subElem['value']; |
|
127 | + } elseif ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}search-term') { |
|
128 | + $newProps['filters']['search-term'] = $subElem['value']; |
|
129 | + } |
|
130 | + } |
|
131 | + break; |
|
132 | + case '{' . SearchPlugin::NS_Nextcloud . '}limit': |
|
133 | + $newProps['limit'] = $elem['value']; |
|
134 | + break; |
|
135 | + case '{' . SearchPlugin::NS_Nextcloud . '}offset': |
|
136 | + $newProps['offset'] = $elem['value']; |
|
137 | + break; |
|
138 | + |
|
139 | + } |
|
140 | + } |
|
141 | + |
|
142 | + if (empty($newProps['filters'])) { |
|
143 | + throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}filter element is required for this request'); |
|
144 | + } |
|
145 | + |
|
146 | + $propsOrParamsDefined = (!empty($newProps['filters']['props']) || !empty($newProps['filters']['params'])); |
|
147 | + $noCompsDefined = empty($newProps['filters']['comps']); |
|
148 | + if ($propsOrParamsDefined && $noCompsDefined) { |
|
149 | + throw new BadRequest('{' . SearchPlugin::NS_Nextcloud . '}prop-filter or {' . SearchPlugin::NS_Nextcloud . '}param-filter given without any {' . SearchPlugin::NS_Nextcloud . '}comp-filter'); |
|
150 | + } |
|
151 | + |
|
152 | + if (!isset($newProps['filters']['search-term'])) { |
|
153 | + throw new BadRequest('{' . SearchPlugin::NS_Nextcloud . '}search-term is required for this request'); |
|
154 | + } |
|
155 | + |
|
156 | + if (empty($newProps['filters']['props']) && empty($newProps['filters']['params'])) { |
|
157 | + throw new BadRequest('At least one{' . SearchPlugin::NS_Nextcloud . '}prop-filter or {' . SearchPlugin::NS_Nextcloud . '}param-filter is required for this request'); |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + $obj = new self(); |
|
162 | + foreach ($newProps as $key => $value) { |
|
163 | + $obj->$key = $value; |
|
164 | + } |
|
165 | + return $obj; |
|
166 | + } |
|
167 | 167 | } |
@@ -35,55 +35,55 @@ |
||
35 | 35 | * @since 8.0.0 |
36 | 36 | */ |
37 | 37 | interface IEventLogger { |
38 | - /** |
|
39 | - * Mark the start of an event setting its ID $id and providing event description $description. |
|
40 | - * |
|
41 | - * @param string $id |
|
42 | - * @param string $description |
|
43 | - * @since 8.0.0 |
|
44 | - */ |
|
45 | - public function start($id, $description); |
|
38 | + /** |
|
39 | + * Mark the start of an event setting its ID $id and providing event description $description. |
|
40 | + * |
|
41 | + * @param string $id |
|
42 | + * @param string $description |
|
43 | + * @since 8.0.0 |
|
44 | + */ |
|
45 | + public function start($id, $description); |
|
46 | 46 | |
47 | - /** |
|
48 | - * Mark the end of an event with specific ID $id, marked by start() method. |
|
49 | - * Ending event should store \OCP\Diagnostics\IEvent to |
|
50 | - * be returned with getEvents() method. |
|
51 | - * |
|
52 | - * @param string $id |
|
53 | - * @since 8.0.0 |
|
54 | - */ |
|
55 | - public function end($id); |
|
47 | + /** |
|
48 | + * Mark the end of an event with specific ID $id, marked by start() method. |
|
49 | + * Ending event should store \OCP\Diagnostics\IEvent to |
|
50 | + * be returned with getEvents() method. |
|
51 | + * |
|
52 | + * @param string $id |
|
53 | + * @since 8.0.0 |
|
54 | + */ |
|
55 | + public function end($id); |
|
56 | 56 | |
57 | - /** |
|
58 | - * Mark the start and the end of an event with specific ID $id and description $description, |
|
59 | - * explicitly marking start and end of the event, represented by $start and $end timestamps. |
|
60 | - * Logging event should store \OCP\Diagnostics\IEvent to |
|
61 | - * be returned with getEvents() method. |
|
62 | - * |
|
63 | - * @param string $id |
|
64 | - * @param string $description |
|
65 | - * @param float $start |
|
66 | - * @param float $end |
|
67 | - * @since 8.0.0 |
|
68 | - */ |
|
69 | - public function log($id, $description, $start, $end); |
|
57 | + /** |
|
58 | + * Mark the start and the end of an event with specific ID $id and description $description, |
|
59 | + * explicitly marking start and end of the event, represented by $start and $end timestamps. |
|
60 | + * Logging event should store \OCP\Diagnostics\IEvent to |
|
61 | + * be returned with getEvents() method. |
|
62 | + * |
|
63 | + * @param string $id |
|
64 | + * @param string $description |
|
65 | + * @param float $start |
|
66 | + * @param float $end |
|
67 | + * @since 8.0.0 |
|
68 | + */ |
|
69 | + public function log($id, $description, $start, $end); |
|
70 | 70 | |
71 | - /** |
|
72 | - * This method should return all \OCP\Diagnostics\IEvent objects stored using |
|
73 | - * start()/end() or log() methods |
|
74 | - * |
|
75 | - * @return \OCP\Diagnostics\IEvent[] |
|
76 | - * @since 8.0.0 |
|
77 | - */ |
|
78 | - public function getEvents(); |
|
71 | + /** |
|
72 | + * This method should return all \OCP\Diagnostics\IEvent objects stored using |
|
73 | + * start()/end() or log() methods |
|
74 | + * |
|
75 | + * @return \OCP\Diagnostics\IEvent[] |
|
76 | + * @since 8.0.0 |
|
77 | + */ |
|
78 | + public function getEvents(); |
|
79 | 79 | |
80 | - /** |
|
81 | - * Activate the module for the duration of the request. Deactivated module |
|
82 | - * does not create and store \OCP\Diagnostics\IEvent objects. |
|
83 | - * Only activated module should create and store objects to be |
|
84 | - * returned with getEvents() call. |
|
85 | - * |
|
86 | - * @since 12.0.0 |
|
87 | - */ |
|
88 | - public function activate(); |
|
80 | + /** |
|
81 | + * Activate the module for the duration of the request. Deactivated module |
|
82 | + * does not create and store \OCP\Diagnostics\IEvent objects. |
|
83 | + * Only activated module should create and store objects to be |
|
84 | + * returned with getEvents() call. |
|
85 | + * |
|
86 | + * @since 12.0.0 |
|
87 | + */ |
|
88 | + public function activate(); |
|
89 | 89 | } |
@@ -30,38 +30,38 @@ |
||
30 | 30 | * @since 8.0.0 |
31 | 31 | */ |
32 | 32 | interface IQuery { |
33 | - /** |
|
34 | - * @return string |
|
35 | - * @since 8.0.0 |
|
36 | - */ |
|
37 | - public function getSql(); |
|
33 | + /** |
|
34 | + * @return string |
|
35 | + * @since 8.0.0 |
|
36 | + */ |
|
37 | + public function getSql(); |
|
38 | 38 | |
39 | - /** |
|
40 | - * @return array |
|
41 | - * @since 8.0.0 |
|
42 | - */ |
|
43 | - public function getParams(); |
|
39 | + /** |
|
40 | + * @return array |
|
41 | + * @since 8.0.0 |
|
42 | + */ |
|
43 | + public function getParams(); |
|
44 | 44 | |
45 | - /** |
|
46 | - * @return float |
|
47 | - * @since 8.0.0 |
|
48 | - */ |
|
49 | - public function getDuration(); |
|
45 | + /** |
|
46 | + * @return float |
|
47 | + * @since 8.0.0 |
|
48 | + */ |
|
49 | + public function getDuration(); |
|
50 | 50 | |
51 | - /** |
|
52 | - * @return float |
|
53 | - * @since 11.0.0 |
|
54 | - */ |
|
55 | - public function getStartTime(); |
|
51 | + /** |
|
52 | + * @return float |
|
53 | + * @since 11.0.0 |
|
54 | + */ |
|
55 | + public function getStartTime(); |
|
56 | 56 | |
57 | - /** |
|
58 | - * @return array |
|
59 | - * @since 11.0.0 |
|
60 | - */ |
|
61 | - public function getStacktrace(); |
|
62 | - /** |
|
63 | - * @return array |
|
64 | - * @since 12.0.0 |
|
65 | - */ |
|
66 | - public function getStart(); |
|
57 | + /** |
|
58 | + * @return array |
|
59 | + * @since 11.0.0 |
|
60 | + */ |
|
61 | + public function getStacktrace(); |
|
62 | + /** |
|
63 | + * @return array |
|
64 | + * @since 12.0.0 |
|
65 | + */ |
|
66 | + public function getStart(); |
|
67 | 67 | } |