@@ -214,28 +214,28 @@ discard block |
||
214 | 214 | $alias = strtolower($alias); |
215 | 215 | |
216 | 216 | foreach ($this->blackListedClassNames as $blackListedAlias => $blackListedClassName) { |
217 | - if (strpos($blackListedClassName, $name . '\\') === 0) { |
|
217 | + if (strpos($blackListedClassName, $name.'\\') === 0) { |
|
218 | 218 | $aliasedClassName = str_replace($name, $alias, $blackListedClassName); |
219 | 219 | $this->blackListedClassNames[$aliasedClassName] = $blackListedClassName; |
220 | 220 | } |
221 | 221 | } |
222 | 222 | |
223 | 223 | foreach ($this->blackListedConstants as $blackListedAlias => $blackListedConstant) { |
224 | - if (strpos($blackListedConstant, $name . '\\') === 0 || strpos($blackListedConstant, $name . '::') === 0) { |
|
224 | + if (strpos($blackListedConstant, $name.'\\') === 0 || strpos($blackListedConstant, $name.'::') === 0) { |
|
225 | 225 | $aliasedConstantName = str_replace($name, $alias, $blackListedConstant); |
226 | 226 | $this->blackListedConstants[$aliasedConstantName] = $blackListedConstant; |
227 | 227 | } |
228 | 228 | } |
229 | 229 | |
230 | 230 | foreach ($this->blackListedFunctions as $blackListedAlias => $blackListedFunction) { |
231 | - if (strpos($blackListedFunction, $name . '\\') === 0 || strpos($blackListedFunction, $name . '::') === 0) { |
|
231 | + if (strpos($blackListedFunction, $name.'\\') === 0 || strpos($blackListedFunction, $name.'::') === 0) { |
|
232 | 232 | $aliasedFunctionName = str_replace($name, $alias, $blackListedFunction); |
233 | 233 | $this->blackListedFunctions[$aliasedFunctionName] = $blackListedFunction; |
234 | 234 | } |
235 | 235 | } |
236 | 236 | |
237 | 237 | foreach ($this->blackListedMethods as $blackListedAlias => $blackListedMethod) { |
238 | - if (strpos($blackListedMethod, $name . '\\') === 0 || strpos($blackListedMethod, $name . '::') === 0) { |
|
238 | + if (strpos($blackListedMethod, $name.'\\') === 0 || strpos($blackListedMethod, $name.'::') === 0) { |
|
239 | 239 | $aliasedMethodName = str_replace($name, $alias, $blackListedMethod); |
240 | 240 | $this->blackListedMethods[$aliasedMethodName] = $blackListedMethod; |
241 | 241 | } |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | } |
257 | 257 | |
258 | 258 | private function checkBlackListConstant($class, $constantName, Node $node) { |
259 | - $name = $class . '::' . $constantName; |
|
259 | + $name = $class.'::'.$constantName; |
|
260 | 260 | $lowerName = strtolower($name); |
261 | 261 | |
262 | 262 | if (isset($this->blackListedConstants[$lowerName])) { |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | } |
271 | 271 | |
272 | 272 | private function checkBlackListFunction($class, $functionName, Node $node) { |
273 | - $name = $class . '::' . $functionName; |
|
273 | + $name = $class.'::'.$functionName; |
|
274 | 274 | $lowerName = strtolower($name); |
275 | 275 | |
276 | 276 | if (isset($this->blackListedFunctions[$lowerName])) { |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | } |
285 | 285 | |
286 | 286 | private function checkBlackListMethod($class, $functionName, Node $node) { |
287 | - $name = $class . '::' . $functionName; |
|
287 | + $name = $class.'::'.$functionName; |
|
288 | 288 | $lowerName = strtolower($name); |
289 | 289 | |
290 | 290 | if (isset($this->blackListedMethods[$lowerName])) { |
@@ -30,280 +30,280 @@ |
||
30 | 30 | use PhpParser\NodeVisitorAbstract; |
31 | 31 | |
32 | 32 | class NodeVisitor extends NodeVisitorAbstract { |
33 | - /** @var ICheck */ |
|
34 | - protected $list; |
|
35 | - |
|
36 | - /** @var string */ |
|
37 | - protected $blackListDescription; |
|
38 | - /** @var string[] */ |
|
39 | - protected $blackListedClassNames; |
|
40 | - /** @var string[] */ |
|
41 | - protected $blackListedConstants; |
|
42 | - /** @var string[] */ |
|
43 | - protected $blackListedFunctions; |
|
44 | - /** @var string[] */ |
|
45 | - protected $blackListedMethods; |
|
46 | - /** @var bool */ |
|
47 | - protected $checkEqualOperatorUsage; |
|
48 | - /** @var string[] */ |
|
49 | - protected $errorMessages; |
|
50 | - |
|
51 | - /** |
|
52 | - * @param ICheck $list |
|
53 | - */ |
|
54 | - public function __construct(ICheck $list) { |
|
55 | - $this->list = $list; |
|
56 | - |
|
57 | - $this->blackListedClassNames = []; |
|
58 | - foreach ($list->getClasses() as $class => $blackListInfo) { |
|
59 | - if (is_numeric($class) && is_string($blackListInfo)) { |
|
60 | - $class = $blackListInfo; |
|
61 | - $blackListInfo = null; |
|
62 | - } |
|
63 | - |
|
64 | - $class = strtolower($class); |
|
65 | - $this->blackListedClassNames[$class] = $class; |
|
66 | - } |
|
67 | - |
|
68 | - $this->blackListedConstants = []; |
|
69 | - foreach ($list->getConstants() as $constantName => $blackListInfo) { |
|
70 | - $constantName = strtolower($constantName); |
|
71 | - $this->blackListedConstants[$constantName] = $constantName; |
|
72 | - } |
|
73 | - |
|
74 | - $this->blackListedFunctions = []; |
|
75 | - foreach ($list->getFunctions() as $functionName => $blackListInfo) { |
|
76 | - $functionName = strtolower($functionName); |
|
77 | - $this->blackListedFunctions[$functionName] = $functionName; |
|
78 | - } |
|
79 | - |
|
80 | - $this->blackListedMethods = []; |
|
81 | - foreach ($list->getMethods() as $functionName => $blackListInfo) { |
|
82 | - $functionName = strtolower($functionName); |
|
83 | - $this->blackListedMethods[$functionName] = $functionName; |
|
84 | - } |
|
85 | - |
|
86 | - $this->checkEqualOperatorUsage = $list->checkStrongComparisons(); |
|
87 | - |
|
88 | - $this->errorMessages = [ |
|
89 | - CodeChecker::CLASS_EXTENDS_NOT_ALLOWED => "%s class must not be extended", |
|
90 | - CodeChecker::CLASS_IMPLEMENTS_NOT_ALLOWED => "%s interface must not be implemented", |
|
91 | - CodeChecker::STATIC_CALL_NOT_ALLOWED => "Static method of %s class must not be called", |
|
92 | - CodeChecker::CLASS_CONST_FETCH_NOT_ALLOWED => "Constant of %s class must not not be fetched", |
|
93 | - CodeChecker::CLASS_NEW_NOT_ALLOWED => "%s class must not be instantiated", |
|
94 | - CodeChecker::CLASS_USE_NOT_ALLOWED => "%s class must not be imported with a use statement", |
|
95 | - CodeChecker::CLASS_METHOD_CALL_NOT_ALLOWED => "Method of %s class must not be called", |
|
96 | - |
|
97 | - CodeChecker::OP_OPERATOR_USAGE_DISCOURAGED => "is discouraged", |
|
98 | - ]; |
|
99 | - } |
|
100 | - |
|
101 | - /** @var array */ |
|
102 | - public $errors = []; |
|
103 | - |
|
104 | - public function enterNode(Node $node) { |
|
105 | - if ($this->checkEqualOperatorUsage && $node instanceof Node\Expr\BinaryOp\Equal) { |
|
106 | - $this->errors[] = [ |
|
107 | - 'disallowedToken' => '==', |
|
108 | - 'errorCode' => CodeChecker::OP_OPERATOR_USAGE_DISCOURAGED, |
|
109 | - 'line' => $node->getLine(), |
|
110 | - 'reason' => $this->buildReason('==', CodeChecker::OP_OPERATOR_USAGE_DISCOURAGED) |
|
111 | - ]; |
|
112 | - } |
|
113 | - if ($this->checkEqualOperatorUsage && $node instanceof Node\Expr\BinaryOp\NotEqual) { |
|
114 | - $this->errors[] = [ |
|
115 | - 'disallowedToken' => '!=', |
|
116 | - 'errorCode' => CodeChecker::OP_OPERATOR_USAGE_DISCOURAGED, |
|
117 | - 'line' => $node->getLine(), |
|
118 | - 'reason' => $this->buildReason('!=', CodeChecker::OP_OPERATOR_USAGE_DISCOURAGED) |
|
119 | - ]; |
|
120 | - } |
|
121 | - if ($node instanceof Node\Stmt\Class_) { |
|
122 | - if (!is_null($node->extends)) { |
|
123 | - $this->checkBlackList($node->extends->toString(), CodeChecker::CLASS_EXTENDS_NOT_ALLOWED, $node); |
|
124 | - } |
|
125 | - foreach ($node->implements as $implements) { |
|
126 | - $this->checkBlackList($implements->toString(), CodeChecker::CLASS_IMPLEMENTS_NOT_ALLOWED, $node); |
|
127 | - } |
|
128 | - } |
|
129 | - if ($node instanceof Node\Expr\StaticCall) { |
|
130 | - if (!is_null($node->class)) { |
|
131 | - if ($node->class instanceof Name) { |
|
132 | - $this->checkBlackList($node->class->toString(), CodeChecker::STATIC_CALL_NOT_ALLOWED, $node); |
|
133 | - |
|
134 | - $this->checkBlackListFunction($node->class->toString(), $node->name, $node); |
|
135 | - $this->checkBlackListMethod($node->class->toString(), $node->name, $node); |
|
136 | - } |
|
137 | - |
|
138 | - if ($node->class instanceof Node\Expr\Variable) { |
|
139 | - /** |
|
140 | - * TODO: find a way to detect something like this: |
|
141 | - * $c = "OC_API"; |
|
142 | - * $n = $c::call(); |
|
143 | - */ |
|
144 | - // $this->checkBlackListMethod($node->class->..., $node->name, $node); |
|
145 | - } |
|
146 | - } |
|
147 | - } |
|
148 | - if ($node instanceof Node\Expr\MethodCall) { |
|
149 | - if (!is_null($node->var)) { |
|
150 | - if ($node->var instanceof Node\Expr\Variable) { |
|
151 | - /** |
|
152 | - * TODO: find a way to detect something like this: |
|
153 | - * $c = new OC_API(); |
|
154 | - * $n = $c::call(); |
|
155 | - * $n = $c->call(); |
|
156 | - */ |
|
157 | - // $this->checkBlackListMethod($node->var->..., $node->name, $node); |
|
158 | - } |
|
159 | - } |
|
160 | - } |
|
161 | - if ($node instanceof Node\Expr\ClassConstFetch) { |
|
162 | - if (!is_null($node->class)) { |
|
163 | - if ($node->class instanceof Name) { |
|
164 | - $this->checkBlackList($node->class->toString(), CodeChecker::CLASS_CONST_FETCH_NOT_ALLOWED, $node); |
|
165 | - } |
|
166 | - if ($node->class instanceof Node\Expr\Variable || $node->class instanceof Node\Expr\PropertyFetch) { |
|
167 | - /** |
|
168 | - * TODO: find a way to detect something like this: |
|
169 | - * $c = "OC_API"; |
|
170 | - * $n = $i::ADMIN_AUTH; |
|
171 | - */ |
|
172 | - } else { |
|
173 | - $this->checkBlackListConstant($node->class->toString(), $node->name, $node); |
|
174 | - } |
|
175 | - } |
|
176 | - } |
|
177 | - if ($node instanceof Node\Expr\New_) { |
|
178 | - if (!is_null($node->class)) { |
|
179 | - if ($node->class instanceof Name) { |
|
180 | - $this->checkBlackList($node->class->toString(), CodeChecker::CLASS_NEW_NOT_ALLOWED, $node); |
|
181 | - } |
|
182 | - if ($node->class instanceof Node\Expr\Variable) { |
|
183 | - /** |
|
184 | - * TODO: find a way to detect something like this: |
|
185 | - * $c = "OC_API"; |
|
186 | - * $n = new $i; |
|
187 | - */ |
|
188 | - } |
|
189 | - } |
|
190 | - } |
|
191 | - if ($node instanceof Node\Stmt\UseUse) { |
|
192 | - $this->checkBlackList($node->name->toString(), CodeChecker::CLASS_USE_NOT_ALLOWED, $node); |
|
193 | - if ($node->alias) { |
|
194 | - $this->addUseNameToBlackList($node->name->toString(), $node->alias); |
|
195 | - } else { |
|
196 | - $this->addUseNameToBlackList($node->name->toString(), $node->name->getLast()); |
|
197 | - } |
|
198 | - } |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * Check whether an alias was introduced for a namespace of a blacklisted class |
|
203 | - * |
|
204 | - * Example: |
|
205 | - * - Blacklist entry: OCP\AppFramework\IApi |
|
206 | - * - Name: OCP\AppFramework |
|
207 | - * - Alias: OAF |
|
208 | - * => new blacklist entry: OAF\IApi |
|
209 | - * |
|
210 | - * @param string $name |
|
211 | - * @param string $alias |
|
212 | - */ |
|
213 | - private function addUseNameToBlackList($name, $alias) { |
|
214 | - $name = strtolower($name); |
|
215 | - $alias = strtolower($alias); |
|
216 | - |
|
217 | - foreach ($this->blackListedClassNames as $blackListedAlias => $blackListedClassName) { |
|
218 | - if (strpos($blackListedClassName, $name . '\\') === 0) { |
|
219 | - $aliasedClassName = str_replace($name, $alias, $blackListedClassName); |
|
220 | - $this->blackListedClassNames[$aliasedClassName] = $blackListedClassName; |
|
221 | - } |
|
222 | - } |
|
223 | - |
|
224 | - foreach ($this->blackListedConstants as $blackListedAlias => $blackListedConstant) { |
|
225 | - if (strpos($blackListedConstant, $name . '\\') === 0 || strpos($blackListedConstant, $name . '::') === 0) { |
|
226 | - $aliasedConstantName = str_replace($name, $alias, $blackListedConstant); |
|
227 | - $this->blackListedConstants[$aliasedConstantName] = $blackListedConstant; |
|
228 | - } |
|
229 | - } |
|
230 | - |
|
231 | - foreach ($this->blackListedFunctions as $blackListedAlias => $blackListedFunction) { |
|
232 | - if (strpos($blackListedFunction, $name . '\\') === 0 || strpos($blackListedFunction, $name . '::') === 0) { |
|
233 | - $aliasedFunctionName = str_replace($name, $alias, $blackListedFunction); |
|
234 | - $this->blackListedFunctions[$aliasedFunctionName] = $blackListedFunction; |
|
235 | - } |
|
236 | - } |
|
237 | - |
|
238 | - foreach ($this->blackListedMethods as $blackListedAlias => $blackListedMethod) { |
|
239 | - if (strpos($blackListedMethod, $name . '\\') === 0 || strpos($blackListedMethod, $name . '::') === 0) { |
|
240 | - $aliasedMethodName = str_replace($name, $alias, $blackListedMethod); |
|
241 | - $this->blackListedMethods[$aliasedMethodName] = $blackListedMethod; |
|
242 | - } |
|
243 | - } |
|
244 | - } |
|
245 | - |
|
246 | - private function checkBlackList($name, $errorCode, Node $node) { |
|
247 | - $lowerName = strtolower($name); |
|
248 | - |
|
249 | - if (isset($this->blackListedClassNames[$lowerName])) { |
|
250 | - $this->errors[] = [ |
|
251 | - 'disallowedToken' => $name, |
|
252 | - 'errorCode' => $errorCode, |
|
253 | - 'line' => $node->getLine(), |
|
254 | - 'reason' => $this->buildReason($this->blackListedClassNames[$lowerName], $errorCode) |
|
255 | - ]; |
|
256 | - } |
|
257 | - } |
|
258 | - |
|
259 | - private function checkBlackListConstant($class, $constantName, Node $node) { |
|
260 | - $name = $class . '::' . $constantName; |
|
261 | - $lowerName = strtolower($name); |
|
262 | - |
|
263 | - if (isset($this->blackListedConstants[$lowerName])) { |
|
264 | - $this->errors[] = [ |
|
265 | - 'disallowedToken' => $name, |
|
266 | - 'errorCode' => CodeChecker::CLASS_CONST_FETCH_NOT_ALLOWED, |
|
267 | - 'line' => $node->getLine(), |
|
268 | - 'reason' => $this->buildReason($this->blackListedConstants[$lowerName], CodeChecker::CLASS_CONST_FETCH_NOT_ALLOWED) |
|
269 | - ]; |
|
270 | - } |
|
271 | - } |
|
272 | - |
|
273 | - private function checkBlackListFunction($class, $functionName, Node $node) { |
|
274 | - $name = $class . '::' . $functionName; |
|
275 | - $lowerName = strtolower($name); |
|
276 | - |
|
277 | - if (isset($this->blackListedFunctions[$lowerName])) { |
|
278 | - $this->errors[] = [ |
|
279 | - 'disallowedToken' => $name, |
|
280 | - 'errorCode' => CodeChecker::STATIC_CALL_NOT_ALLOWED, |
|
281 | - 'line' => $node->getLine(), |
|
282 | - 'reason' => $this->buildReason($this->blackListedFunctions[$lowerName], CodeChecker::STATIC_CALL_NOT_ALLOWED) |
|
283 | - ]; |
|
284 | - } |
|
285 | - } |
|
286 | - |
|
287 | - private function checkBlackListMethod($class, $functionName, Node $node) { |
|
288 | - $name = $class . '::' . $functionName; |
|
289 | - $lowerName = strtolower($name); |
|
290 | - |
|
291 | - if (isset($this->blackListedMethods[$lowerName])) { |
|
292 | - $this->errors[] = [ |
|
293 | - 'disallowedToken' => $name, |
|
294 | - 'errorCode' => CodeChecker::CLASS_METHOD_CALL_NOT_ALLOWED, |
|
295 | - 'line' => $node->getLine(), |
|
296 | - 'reason' => $this->buildReason($this->blackListedMethods[$lowerName], CodeChecker::CLASS_METHOD_CALL_NOT_ALLOWED) |
|
297 | - ]; |
|
298 | - } |
|
299 | - } |
|
300 | - |
|
301 | - private function buildReason($name, $errorCode) { |
|
302 | - if (isset($this->errorMessages[$errorCode])) { |
|
303 | - $desc = $this->list->getDescription($errorCode, $name); |
|
304 | - return sprintf($this->errorMessages[$errorCode], $desc); |
|
305 | - } |
|
306 | - |
|
307 | - return "$name usage not allowed - error: $errorCode"; |
|
308 | - } |
|
33 | + /** @var ICheck */ |
|
34 | + protected $list; |
|
35 | + |
|
36 | + /** @var string */ |
|
37 | + protected $blackListDescription; |
|
38 | + /** @var string[] */ |
|
39 | + protected $blackListedClassNames; |
|
40 | + /** @var string[] */ |
|
41 | + protected $blackListedConstants; |
|
42 | + /** @var string[] */ |
|
43 | + protected $blackListedFunctions; |
|
44 | + /** @var string[] */ |
|
45 | + protected $blackListedMethods; |
|
46 | + /** @var bool */ |
|
47 | + protected $checkEqualOperatorUsage; |
|
48 | + /** @var string[] */ |
|
49 | + protected $errorMessages; |
|
50 | + |
|
51 | + /** |
|
52 | + * @param ICheck $list |
|
53 | + */ |
|
54 | + public function __construct(ICheck $list) { |
|
55 | + $this->list = $list; |
|
56 | + |
|
57 | + $this->blackListedClassNames = []; |
|
58 | + foreach ($list->getClasses() as $class => $blackListInfo) { |
|
59 | + if (is_numeric($class) && is_string($blackListInfo)) { |
|
60 | + $class = $blackListInfo; |
|
61 | + $blackListInfo = null; |
|
62 | + } |
|
63 | + |
|
64 | + $class = strtolower($class); |
|
65 | + $this->blackListedClassNames[$class] = $class; |
|
66 | + } |
|
67 | + |
|
68 | + $this->blackListedConstants = []; |
|
69 | + foreach ($list->getConstants() as $constantName => $blackListInfo) { |
|
70 | + $constantName = strtolower($constantName); |
|
71 | + $this->blackListedConstants[$constantName] = $constantName; |
|
72 | + } |
|
73 | + |
|
74 | + $this->blackListedFunctions = []; |
|
75 | + foreach ($list->getFunctions() as $functionName => $blackListInfo) { |
|
76 | + $functionName = strtolower($functionName); |
|
77 | + $this->blackListedFunctions[$functionName] = $functionName; |
|
78 | + } |
|
79 | + |
|
80 | + $this->blackListedMethods = []; |
|
81 | + foreach ($list->getMethods() as $functionName => $blackListInfo) { |
|
82 | + $functionName = strtolower($functionName); |
|
83 | + $this->blackListedMethods[$functionName] = $functionName; |
|
84 | + } |
|
85 | + |
|
86 | + $this->checkEqualOperatorUsage = $list->checkStrongComparisons(); |
|
87 | + |
|
88 | + $this->errorMessages = [ |
|
89 | + CodeChecker::CLASS_EXTENDS_NOT_ALLOWED => "%s class must not be extended", |
|
90 | + CodeChecker::CLASS_IMPLEMENTS_NOT_ALLOWED => "%s interface must not be implemented", |
|
91 | + CodeChecker::STATIC_CALL_NOT_ALLOWED => "Static method of %s class must not be called", |
|
92 | + CodeChecker::CLASS_CONST_FETCH_NOT_ALLOWED => "Constant of %s class must not not be fetched", |
|
93 | + CodeChecker::CLASS_NEW_NOT_ALLOWED => "%s class must not be instantiated", |
|
94 | + CodeChecker::CLASS_USE_NOT_ALLOWED => "%s class must not be imported with a use statement", |
|
95 | + CodeChecker::CLASS_METHOD_CALL_NOT_ALLOWED => "Method of %s class must not be called", |
|
96 | + |
|
97 | + CodeChecker::OP_OPERATOR_USAGE_DISCOURAGED => "is discouraged", |
|
98 | + ]; |
|
99 | + } |
|
100 | + |
|
101 | + /** @var array */ |
|
102 | + public $errors = []; |
|
103 | + |
|
104 | + public function enterNode(Node $node) { |
|
105 | + if ($this->checkEqualOperatorUsage && $node instanceof Node\Expr\BinaryOp\Equal) { |
|
106 | + $this->errors[] = [ |
|
107 | + 'disallowedToken' => '==', |
|
108 | + 'errorCode' => CodeChecker::OP_OPERATOR_USAGE_DISCOURAGED, |
|
109 | + 'line' => $node->getLine(), |
|
110 | + 'reason' => $this->buildReason('==', CodeChecker::OP_OPERATOR_USAGE_DISCOURAGED) |
|
111 | + ]; |
|
112 | + } |
|
113 | + if ($this->checkEqualOperatorUsage && $node instanceof Node\Expr\BinaryOp\NotEqual) { |
|
114 | + $this->errors[] = [ |
|
115 | + 'disallowedToken' => '!=', |
|
116 | + 'errorCode' => CodeChecker::OP_OPERATOR_USAGE_DISCOURAGED, |
|
117 | + 'line' => $node->getLine(), |
|
118 | + 'reason' => $this->buildReason('!=', CodeChecker::OP_OPERATOR_USAGE_DISCOURAGED) |
|
119 | + ]; |
|
120 | + } |
|
121 | + if ($node instanceof Node\Stmt\Class_) { |
|
122 | + if (!is_null($node->extends)) { |
|
123 | + $this->checkBlackList($node->extends->toString(), CodeChecker::CLASS_EXTENDS_NOT_ALLOWED, $node); |
|
124 | + } |
|
125 | + foreach ($node->implements as $implements) { |
|
126 | + $this->checkBlackList($implements->toString(), CodeChecker::CLASS_IMPLEMENTS_NOT_ALLOWED, $node); |
|
127 | + } |
|
128 | + } |
|
129 | + if ($node instanceof Node\Expr\StaticCall) { |
|
130 | + if (!is_null($node->class)) { |
|
131 | + if ($node->class instanceof Name) { |
|
132 | + $this->checkBlackList($node->class->toString(), CodeChecker::STATIC_CALL_NOT_ALLOWED, $node); |
|
133 | + |
|
134 | + $this->checkBlackListFunction($node->class->toString(), $node->name, $node); |
|
135 | + $this->checkBlackListMethod($node->class->toString(), $node->name, $node); |
|
136 | + } |
|
137 | + |
|
138 | + if ($node->class instanceof Node\Expr\Variable) { |
|
139 | + /** |
|
140 | + * TODO: find a way to detect something like this: |
|
141 | + * $c = "OC_API"; |
|
142 | + * $n = $c::call(); |
|
143 | + */ |
|
144 | + // $this->checkBlackListMethod($node->class->..., $node->name, $node); |
|
145 | + } |
|
146 | + } |
|
147 | + } |
|
148 | + if ($node instanceof Node\Expr\MethodCall) { |
|
149 | + if (!is_null($node->var)) { |
|
150 | + if ($node->var instanceof Node\Expr\Variable) { |
|
151 | + /** |
|
152 | + * TODO: find a way to detect something like this: |
|
153 | + * $c = new OC_API(); |
|
154 | + * $n = $c::call(); |
|
155 | + * $n = $c->call(); |
|
156 | + */ |
|
157 | + // $this->checkBlackListMethod($node->var->..., $node->name, $node); |
|
158 | + } |
|
159 | + } |
|
160 | + } |
|
161 | + if ($node instanceof Node\Expr\ClassConstFetch) { |
|
162 | + if (!is_null($node->class)) { |
|
163 | + if ($node->class instanceof Name) { |
|
164 | + $this->checkBlackList($node->class->toString(), CodeChecker::CLASS_CONST_FETCH_NOT_ALLOWED, $node); |
|
165 | + } |
|
166 | + if ($node->class instanceof Node\Expr\Variable || $node->class instanceof Node\Expr\PropertyFetch) { |
|
167 | + /** |
|
168 | + * TODO: find a way to detect something like this: |
|
169 | + * $c = "OC_API"; |
|
170 | + * $n = $i::ADMIN_AUTH; |
|
171 | + */ |
|
172 | + } else { |
|
173 | + $this->checkBlackListConstant($node->class->toString(), $node->name, $node); |
|
174 | + } |
|
175 | + } |
|
176 | + } |
|
177 | + if ($node instanceof Node\Expr\New_) { |
|
178 | + if (!is_null($node->class)) { |
|
179 | + if ($node->class instanceof Name) { |
|
180 | + $this->checkBlackList($node->class->toString(), CodeChecker::CLASS_NEW_NOT_ALLOWED, $node); |
|
181 | + } |
|
182 | + if ($node->class instanceof Node\Expr\Variable) { |
|
183 | + /** |
|
184 | + * TODO: find a way to detect something like this: |
|
185 | + * $c = "OC_API"; |
|
186 | + * $n = new $i; |
|
187 | + */ |
|
188 | + } |
|
189 | + } |
|
190 | + } |
|
191 | + if ($node instanceof Node\Stmt\UseUse) { |
|
192 | + $this->checkBlackList($node->name->toString(), CodeChecker::CLASS_USE_NOT_ALLOWED, $node); |
|
193 | + if ($node->alias) { |
|
194 | + $this->addUseNameToBlackList($node->name->toString(), $node->alias); |
|
195 | + } else { |
|
196 | + $this->addUseNameToBlackList($node->name->toString(), $node->name->getLast()); |
|
197 | + } |
|
198 | + } |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * Check whether an alias was introduced for a namespace of a blacklisted class |
|
203 | + * |
|
204 | + * Example: |
|
205 | + * - Blacklist entry: OCP\AppFramework\IApi |
|
206 | + * - Name: OCP\AppFramework |
|
207 | + * - Alias: OAF |
|
208 | + * => new blacklist entry: OAF\IApi |
|
209 | + * |
|
210 | + * @param string $name |
|
211 | + * @param string $alias |
|
212 | + */ |
|
213 | + private function addUseNameToBlackList($name, $alias) { |
|
214 | + $name = strtolower($name); |
|
215 | + $alias = strtolower($alias); |
|
216 | + |
|
217 | + foreach ($this->blackListedClassNames as $blackListedAlias => $blackListedClassName) { |
|
218 | + if (strpos($blackListedClassName, $name . '\\') === 0) { |
|
219 | + $aliasedClassName = str_replace($name, $alias, $blackListedClassName); |
|
220 | + $this->blackListedClassNames[$aliasedClassName] = $blackListedClassName; |
|
221 | + } |
|
222 | + } |
|
223 | + |
|
224 | + foreach ($this->blackListedConstants as $blackListedAlias => $blackListedConstant) { |
|
225 | + if (strpos($blackListedConstant, $name . '\\') === 0 || strpos($blackListedConstant, $name . '::') === 0) { |
|
226 | + $aliasedConstantName = str_replace($name, $alias, $blackListedConstant); |
|
227 | + $this->blackListedConstants[$aliasedConstantName] = $blackListedConstant; |
|
228 | + } |
|
229 | + } |
|
230 | + |
|
231 | + foreach ($this->blackListedFunctions as $blackListedAlias => $blackListedFunction) { |
|
232 | + if (strpos($blackListedFunction, $name . '\\') === 0 || strpos($blackListedFunction, $name . '::') === 0) { |
|
233 | + $aliasedFunctionName = str_replace($name, $alias, $blackListedFunction); |
|
234 | + $this->blackListedFunctions[$aliasedFunctionName] = $blackListedFunction; |
|
235 | + } |
|
236 | + } |
|
237 | + |
|
238 | + foreach ($this->blackListedMethods as $blackListedAlias => $blackListedMethod) { |
|
239 | + if (strpos($blackListedMethod, $name . '\\') === 0 || strpos($blackListedMethod, $name . '::') === 0) { |
|
240 | + $aliasedMethodName = str_replace($name, $alias, $blackListedMethod); |
|
241 | + $this->blackListedMethods[$aliasedMethodName] = $blackListedMethod; |
|
242 | + } |
|
243 | + } |
|
244 | + } |
|
245 | + |
|
246 | + private function checkBlackList($name, $errorCode, Node $node) { |
|
247 | + $lowerName = strtolower($name); |
|
248 | + |
|
249 | + if (isset($this->blackListedClassNames[$lowerName])) { |
|
250 | + $this->errors[] = [ |
|
251 | + 'disallowedToken' => $name, |
|
252 | + 'errorCode' => $errorCode, |
|
253 | + 'line' => $node->getLine(), |
|
254 | + 'reason' => $this->buildReason($this->blackListedClassNames[$lowerName], $errorCode) |
|
255 | + ]; |
|
256 | + } |
|
257 | + } |
|
258 | + |
|
259 | + private function checkBlackListConstant($class, $constantName, Node $node) { |
|
260 | + $name = $class . '::' . $constantName; |
|
261 | + $lowerName = strtolower($name); |
|
262 | + |
|
263 | + if (isset($this->blackListedConstants[$lowerName])) { |
|
264 | + $this->errors[] = [ |
|
265 | + 'disallowedToken' => $name, |
|
266 | + 'errorCode' => CodeChecker::CLASS_CONST_FETCH_NOT_ALLOWED, |
|
267 | + 'line' => $node->getLine(), |
|
268 | + 'reason' => $this->buildReason($this->blackListedConstants[$lowerName], CodeChecker::CLASS_CONST_FETCH_NOT_ALLOWED) |
|
269 | + ]; |
|
270 | + } |
|
271 | + } |
|
272 | + |
|
273 | + private function checkBlackListFunction($class, $functionName, Node $node) { |
|
274 | + $name = $class . '::' . $functionName; |
|
275 | + $lowerName = strtolower($name); |
|
276 | + |
|
277 | + if (isset($this->blackListedFunctions[$lowerName])) { |
|
278 | + $this->errors[] = [ |
|
279 | + 'disallowedToken' => $name, |
|
280 | + 'errorCode' => CodeChecker::STATIC_CALL_NOT_ALLOWED, |
|
281 | + 'line' => $node->getLine(), |
|
282 | + 'reason' => $this->buildReason($this->blackListedFunctions[$lowerName], CodeChecker::STATIC_CALL_NOT_ALLOWED) |
|
283 | + ]; |
|
284 | + } |
|
285 | + } |
|
286 | + |
|
287 | + private function checkBlackListMethod($class, $functionName, Node $node) { |
|
288 | + $name = $class . '::' . $functionName; |
|
289 | + $lowerName = strtolower($name); |
|
290 | + |
|
291 | + if (isset($this->blackListedMethods[$lowerName])) { |
|
292 | + $this->errors[] = [ |
|
293 | + 'disallowedToken' => $name, |
|
294 | + 'errorCode' => CodeChecker::CLASS_METHOD_CALL_NOT_ALLOWED, |
|
295 | + 'line' => $node->getLine(), |
|
296 | + 'reason' => $this->buildReason($this->blackListedMethods[$lowerName], CodeChecker::CLASS_METHOD_CALL_NOT_ALLOWED) |
|
297 | + ]; |
|
298 | + } |
|
299 | + } |
|
300 | + |
|
301 | + private function buildReason($name, $errorCode) { |
|
302 | + if (isset($this->errorMessages[$errorCode])) { |
|
303 | + $desc = $this->list->getDescription($errorCode, $name); |
|
304 | + return sprintf($this->errorMessages[$errorCode], $desc); |
|
305 | + } |
|
306 | + |
|
307 | + return "$name usage not allowed - error: $errorCode"; |
|
308 | + } |
|
309 | 309 | } |
@@ -32,7 +32,7 @@ |
||
32 | 32 | * @return bool |
33 | 33 | */ |
34 | 34 | private function isValidVersionString($versionString) { |
35 | - return (bool)preg_match('/^[0-9.]+$/', $versionString); |
|
35 | + return (bool) preg_match('/^[0-9.]+$/', $versionString); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |
@@ -30,56 +30,56 @@ |
||
30 | 30 | * @package OC\App\AppStore |
31 | 31 | */ |
32 | 32 | class VersionParser { |
33 | - /** |
|
34 | - * @param string $versionString |
|
35 | - * @return bool |
|
36 | - */ |
|
37 | - private function isValidVersionString($versionString) { |
|
38 | - return (bool)preg_match('/^[0-9.]+$/', $versionString); |
|
39 | - } |
|
33 | + /** |
|
34 | + * @param string $versionString |
|
35 | + * @return bool |
|
36 | + */ |
|
37 | + private function isValidVersionString($versionString) { |
|
38 | + return (bool)preg_match('/^[0-9.]+$/', $versionString); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * Returns the version for a version string |
|
43 | - * |
|
44 | - * @param string $versionSpec |
|
45 | - * @return Version |
|
46 | - * @throws \Exception If the version cannot be parsed |
|
47 | - */ |
|
48 | - public function getVersion($versionSpec) { |
|
49 | - // * indicates that the version is compatible with all versions |
|
50 | - if ($versionSpec === '*') { |
|
51 | - return new Version('', ''); |
|
52 | - } |
|
41 | + /** |
|
42 | + * Returns the version for a version string |
|
43 | + * |
|
44 | + * @param string $versionSpec |
|
45 | + * @return Version |
|
46 | + * @throws \Exception If the version cannot be parsed |
|
47 | + */ |
|
48 | + public function getVersion($versionSpec) { |
|
49 | + // * indicates that the version is compatible with all versions |
|
50 | + if ($versionSpec === '*') { |
|
51 | + return new Version('', ''); |
|
52 | + } |
|
53 | 53 | |
54 | - // Count the amount of =, if it is one then it's either maximum or minimum |
|
55 | - // version. If it is two then it is maximum and minimum. |
|
56 | - $versionElements = explode(' ', $versionSpec); |
|
57 | - $firstVersion = isset($versionElements[0]) ? $versionElements[0] : ''; |
|
58 | - $firstVersionNumber = substr($firstVersion, 2); |
|
59 | - $secondVersion = isset($versionElements[1]) ? $versionElements[1] : ''; |
|
60 | - $secondVersionNumber = substr($secondVersion, 2); |
|
54 | + // Count the amount of =, if it is one then it's either maximum or minimum |
|
55 | + // version. If it is two then it is maximum and minimum. |
|
56 | + $versionElements = explode(' ', $versionSpec); |
|
57 | + $firstVersion = isset($versionElements[0]) ? $versionElements[0] : ''; |
|
58 | + $firstVersionNumber = substr($firstVersion, 2); |
|
59 | + $secondVersion = isset($versionElements[1]) ? $versionElements[1] : ''; |
|
60 | + $secondVersionNumber = substr($secondVersion, 2); |
|
61 | 61 | |
62 | - switch (count($versionElements)) { |
|
63 | - case 1: |
|
64 | - if (!$this->isValidVersionString($firstVersionNumber)) { |
|
65 | - break; |
|
66 | - } |
|
67 | - if (strpos($firstVersion, '>') === 0) { |
|
68 | - return new Version($firstVersionNumber, ''); |
|
69 | - } |
|
70 | - return new Version('', $firstVersionNumber); |
|
71 | - case 2: |
|
72 | - if (!$this->isValidVersionString($firstVersionNumber) || !$this->isValidVersionString($secondVersionNumber)) { |
|
73 | - break; |
|
74 | - } |
|
75 | - return new Version($firstVersionNumber, $secondVersionNumber); |
|
76 | - } |
|
62 | + switch (count($versionElements)) { |
|
63 | + case 1: |
|
64 | + if (!$this->isValidVersionString($firstVersionNumber)) { |
|
65 | + break; |
|
66 | + } |
|
67 | + if (strpos($firstVersion, '>') === 0) { |
|
68 | + return new Version($firstVersionNumber, ''); |
|
69 | + } |
|
70 | + return new Version('', $firstVersionNumber); |
|
71 | + case 2: |
|
72 | + if (!$this->isValidVersionString($firstVersionNumber) || !$this->isValidVersionString($secondVersionNumber)) { |
|
73 | + break; |
|
74 | + } |
|
75 | + return new Version($firstVersionNumber, $secondVersionNumber); |
|
76 | + } |
|
77 | 77 | |
78 | - throw new \Exception( |
|
79 | - sprintf( |
|
80 | - 'Version cannot be parsed: %s', |
|
81 | - $versionSpec |
|
82 | - ) |
|
83 | - ); |
|
84 | - } |
|
78 | + throw new \Exception( |
|
79 | + sprintf( |
|
80 | + 'Version cannot be parsed: %s', |
|
81 | + $versionSpec |
|
82 | + ) |
|
83 | + ); |
|
84 | + } |
|
85 | 85 | } |
@@ -24,36 +24,36 @@ |
||
24 | 24 | use OCP\IL10N; |
25 | 25 | |
26 | 26 | abstract class Bundle { |
27 | - /** @var IL10N */ |
|
28 | - protected $l10n; |
|
27 | + /** @var IL10N */ |
|
28 | + protected $l10n; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @param IL10N $l10n |
|
32 | - */ |
|
33 | - public function __construct(IL10N $l10n) { |
|
34 | - $this->l10n = $l10n; |
|
35 | - } |
|
30 | + /** |
|
31 | + * @param IL10N $l10n |
|
32 | + */ |
|
33 | + public function __construct(IL10N $l10n) { |
|
34 | + $this->l10n = $l10n; |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * Get the identifier of the bundle |
|
39 | - * |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - final public function getIdentifier() { |
|
43 | - return substr(strrchr(get_class($this), '\\'), 1); |
|
44 | - } |
|
37 | + /** |
|
38 | + * Get the identifier of the bundle |
|
39 | + * |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + final public function getIdentifier() { |
|
43 | + return substr(strrchr(get_class($this), '\\'), 1); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Get the name of the bundle |
|
48 | - * |
|
49 | - * @return string |
|
50 | - */ |
|
51 | - abstract public function getName(); |
|
46 | + /** |
|
47 | + * Get the name of the bundle |
|
48 | + * |
|
49 | + * @return string |
|
50 | + */ |
|
51 | + abstract public function getName(); |
|
52 | 52 | |
53 | - /** |
|
54 | - * Get the list of app identifiers in the bundle |
|
55 | - * |
|
56 | - * @return array |
|
57 | - */ |
|
58 | - abstract public function getAppIdentifiers(); |
|
53 | + /** |
|
54 | + * Get the list of app identifiers in the bundle |
|
55 | + * |
|
56 | + * @return array |
|
57 | + */ |
|
58 | + abstract public function getAppIdentifiers(); |
|
59 | 59 | } |
@@ -66,7 +66,7 @@ |
||
66 | 66 | /** @var IShare[] $deletedShares */ |
67 | 67 | $deletedShares = $e->getArgument('deletedShares'); |
68 | 68 | |
69 | - $formattedDeletedShares = array_map(function ($share) { |
|
69 | + $formattedDeletedShares = array_map(function($share) { |
|
70 | 70 | return $this->formatHookParams($share); |
71 | 71 | }, $deletedShares); |
72 | 72 |
@@ -34,144 +34,144 @@ |
||
34 | 34 | |
35 | 35 | class LegacyHooks { |
36 | 36 | |
37 | - /** @var EventDispatcherInterface */ |
|
38 | - private $eventDispatcher; |
|
39 | - |
|
40 | - /** |
|
41 | - * LegacyHooks constructor. |
|
42 | - * |
|
43 | - * @param EventDispatcherInterface $eventDispatcher |
|
44 | - */ |
|
45 | - public function __construct(EventDispatcherInterface $eventDispatcher) { |
|
46 | - $this->eventDispatcher = $eventDispatcher; |
|
47 | - |
|
48 | - $this->eventDispatcher->addListener('OCP\Share::preUnshare', [$this, 'preUnshare']); |
|
49 | - $this->eventDispatcher->addListener('OCP\Share::postUnshare', [$this, 'postUnshare']); |
|
50 | - $this->eventDispatcher->addListener('OCP\Share::postUnshareFromSelf', [$this, 'postUnshareFromSelf']); |
|
51 | - $this->eventDispatcher->addListener('OCP\Share::preShare', [$this, 'preShare']); |
|
52 | - $this->eventDispatcher->addListener('OCP\Share::postShare', [$this, 'postShare']); |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * @param GenericEvent $e |
|
57 | - */ |
|
58 | - public function preUnshare(GenericEvent $e) { |
|
59 | - /** @var IShare $share */ |
|
60 | - $share = $e->getSubject(); |
|
61 | - |
|
62 | - $formatted = $this->formatHookParams($share); |
|
63 | - \OC_Hook::emit(Share::class, 'pre_unshare', $formatted); |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * @param GenericEvent $e |
|
68 | - */ |
|
69 | - public function postUnshare(GenericEvent $e) { |
|
70 | - /** @var IShare $share */ |
|
71 | - $share = $e->getSubject(); |
|
72 | - |
|
73 | - $formatted = $this->formatHookParams($share); |
|
74 | - |
|
75 | - /** @var IShare[] $deletedShares */ |
|
76 | - $deletedShares = $e->getArgument('deletedShares'); |
|
77 | - |
|
78 | - $formattedDeletedShares = array_map(function ($share) { |
|
79 | - return $this->formatHookParams($share); |
|
80 | - }, $deletedShares); |
|
81 | - |
|
82 | - $formatted['deletedShares'] = $formattedDeletedShares; |
|
83 | - |
|
84 | - \OC_Hook::emit(Share::class, 'post_unshare', $formatted); |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * @param GenericEvent $e |
|
89 | - */ |
|
90 | - public function postUnshareFromSelf(GenericEvent $e) { |
|
91 | - /** @var IShare $share */ |
|
92 | - $share = $e->getSubject(); |
|
93 | - |
|
94 | - $formatted = $this->formatHookParams($share); |
|
95 | - $formatted['itemTarget'] = $formatted['fileTarget']; |
|
96 | - $formatted['unsharedItems'] = [$formatted]; |
|
97 | - |
|
98 | - \OC_Hook::emit(Share::class, 'post_unshareFromSelf', $formatted); |
|
99 | - } |
|
100 | - |
|
101 | - private function formatHookParams(IShare $share) { |
|
102 | - // Prepare hook |
|
103 | - $shareType = $share->getShareType(); |
|
104 | - $sharedWith = ''; |
|
105 | - if ($shareType === IShare::TYPE_USER || |
|
106 | - $shareType === IShare::TYPE_GROUP || |
|
107 | - $shareType === IShare::TYPE_REMOTE) { |
|
108 | - $sharedWith = $share->getSharedWith(); |
|
109 | - } |
|
110 | - |
|
111 | - $hookParams = [ |
|
112 | - 'id' => $share->getId(), |
|
113 | - 'itemType' => $share->getNodeType(), |
|
114 | - 'itemSource' => $share->getNodeId(), |
|
115 | - 'shareType' => $shareType, |
|
116 | - 'shareWith' => $sharedWith, |
|
117 | - 'itemparent' => method_exists($share, 'getParent') ? $share->getParent() : '', |
|
118 | - 'uidOwner' => $share->getSharedBy(), |
|
119 | - 'fileSource' => $share->getNodeId(), |
|
120 | - 'fileTarget' => $share->getTarget() |
|
121 | - ]; |
|
122 | - return $hookParams; |
|
123 | - } |
|
124 | - |
|
125 | - public function preShare(GenericEvent $e) { |
|
126 | - /** @var IShare $share */ |
|
127 | - $share = $e->getSubject(); |
|
128 | - |
|
129 | - // Pre share hook |
|
130 | - $run = true; |
|
131 | - $error = ''; |
|
132 | - $preHookData = [ |
|
133 | - 'itemType' => $share->getNode() instanceof File ? 'file' : 'folder', |
|
134 | - 'itemSource' => $share->getNode()->getId(), |
|
135 | - 'shareType' => $share->getShareType(), |
|
136 | - 'uidOwner' => $share->getSharedBy(), |
|
137 | - 'permissions' => $share->getPermissions(), |
|
138 | - 'fileSource' => $share->getNode()->getId(), |
|
139 | - 'expiration' => $share->getExpirationDate(), |
|
140 | - 'token' => $share->getToken(), |
|
141 | - 'itemTarget' => $share->getTarget(), |
|
142 | - 'shareWith' => $share->getSharedWith(), |
|
143 | - 'run' => &$run, |
|
144 | - 'error' => &$error, |
|
145 | - ]; |
|
146 | - \OC_Hook::emit(Share::class, 'pre_shared', $preHookData); |
|
147 | - |
|
148 | - if ($run === false) { |
|
149 | - $e->setArgument('error', $error); |
|
150 | - $e->stopPropagation(); |
|
151 | - } |
|
152 | - |
|
153 | - return $e; |
|
154 | - } |
|
155 | - |
|
156 | - public function postShare(GenericEvent $e) { |
|
157 | - /** @var IShare $share */ |
|
158 | - $share = $e->getSubject(); |
|
159 | - |
|
160 | - $postHookData = [ |
|
161 | - 'itemType' => $share->getNode() instanceof File ? 'file' : 'folder', |
|
162 | - 'itemSource' => $share->getNode()->getId(), |
|
163 | - 'shareType' => $share->getShareType(), |
|
164 | - 'uidOwner' => $share->getSharedBy(), |
|
165 | - 'permissions' => $share->getPermissions(), |
|
166 | - 'fileSource' => $share->getNode()->getId(), |
|
167 | - 'expiration' => $share->getExpirationDate(), |
|
168 | - 'token' => $share->getToken(), |
|
169 | - 'id' => $share->getId(), |
|
170 | - 'shareWith' => $share->getSharedWith(), |
|
171 | - 'itemTarget' => $share->getTarget(), |
|
172 | - 'fileTarget' => $share->getTarget(), |
|
173 | - ]; |
|
174 | - |
|
175 | - \OC_Hook::emit(Share::class, 'post_shared', $postHookData); |
|
176 | - } |
|
37 | + /** @var EventDispatcherInterface */ |
|
38 | + private $eventDispatcher; |
|
39 | + |
|
40 | + /** |
|
41 | + * LegacyHooks constructor. |
|
42 | + * |
|
43 | + * @param EventDispatcherInterface $eventDispatcher |
|
44 | + */ |
|
45 | + public function __construct(EventDispatcherInterface $eventDispatcher) { |
|
46 | + $this->eventDispatcher = $eventDispatcher; |
|
47 | + |
|
48 | + $this->eventDispatcher->addListener('OCP\Share::preUnshare', [$this, 'preUnshare']); |
|
49 | + $this->eventDispatcher->addListener('OCP\Share::postUnshare', [$this, 'postUnshare']); |
|
50 | + $this->eventDispatcher->addListener('OCP\Share::postUnshareFromSelf', [$this, 'postUnshareFromSelf']); |
|
51 | + $this->eventDispatcher->addListener('OCP\Share::preShare', [$this, 'preShare']); |
|
52 | + $this->eventDispatcher->addListener('OCP\Share::postShare', [$this, 'postShare']); |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * @param GenericEvent $e |
|
57 | + */ |
|
58 | + public function preUnshare(GenericEvent $e) { |
|
59 | + /** @var IShare $share */ |
|
60 | + $share = $e->getSubject(); |
|
61 | + |
|
62 | + $formatted = $this->formatHookParams($share); |
|
63 | + \OC_Hook::emit(Share::class, 'pre_unshare', $formatted); |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * @param GenericEvent $e |
|
68 | + */ |
|
69 | + public function postUnshare(GenericEvent $e) { |
|
70 | + /** @var IShare $share */ |
|
71 | + $share = $e->getSubject(); |
|
72 | + |
|
73 | + $formatted = $this->formatHookParams($share); |
|
74 | + |
|
75 | + /** @var IShare[] $deletedShares */ |
|
76 | + $deletedShares = $e->getArgument('deletedShares'); |
|
77 | + |
|
78 | + $formattedDeletedShares = array_map(function ($share) { |
|
79 | + return $this->formatHookParams($share); |
|
80 | + }, $deletedShares); |
|
81 | + |
|
82 | + $formatted['deletedShares'] = $formattedDeletedShares; |
|
83 | + |
|
84 | + \OC_Hook::emit(Share::class, 'post_unshare', $formatted); |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * @param GenericEvent $e |
|
89 | + */ |
|
90 | + public function postUnshareFromSelf(GenericEvent $e) { |
|
91 | + /** @var IShare $share */ |
|
92 | + $share = $e->getSubject(); |
|
93 | + |
|
94 | + $formatted = $this->formatHookParams($share); |
|
95 | + $formatted['itemTarget'] = $formatted['fileTarget']; |
|
96 | + $formatted['unsharedItems'] = [$formatted]; |
|
97 | + |
|
98 | + \OC_Hook::emit(Share::class, 'post_unshareFromSelf', $formatted); |
|
99 | + } |
|
100 | + |
|
101 | + private function formatHookParams(IShare $share) { |
|
102 | + // Prepare hook |
|
103 | + $shareType = $share->getShareType(); |
|
104 | + $sharedWith = ''; |
|
105 | + if ($shareType === IShare::TYPE_USER || |
|
106 | + $shareType === IShare::TYPE_GROUP || |
|
107 | + $shareType === IShare::TYPE_REMOTE) { |
|
108 | + $sharedWith = $share->getSharedWith(); |
|
109 | + } |
|
110 | + |
|
111 | + $hookParams = [ |
|
112 | + 'id' => $share->getId(), |
|
113 | + 'itemType' => $share->getNodeType(), |
|
114 | + 'itemSource' => $share->getNodeId(), |
|
115 | + 'shareType' => $shareType, |
|
116 | + 'shareWith' => $sharedWith, |
|
117 | + 'itemparent' => method_exists($share, 'getParent') ? $share->getParent() : '', |
|
118 | + 'uidOwner' => $share->getSharedBy(), |
|
119 | + 'fileSource' => $share->getNodeId(), |
|
120 | + 'fileTarget' => $share->getTarget() |
|
121 | + ]; |
|
122 | + return $hookParams; |
|
123 | + } |
|
124 | + |
|
125 | + public function preShare(GenericEvent $e) { |
|
126 | + /** @var IShare $share */ |
|
127 | + $share = $e->getSubject(); |
|
128 | + |
|
129 | + // Pre share hook |
|
130 | + $run = true; |
|
131 | + $error = ''; |
|
132 | + $preHookData = [ |
|
133 | + 'itemType' => $share->getNode() instanceof File ? 'file' : 'folder', |
|
134 | + 'itemSource' => $share->getNode()->getId(), |
|
135 | + 'shareType' => $share->getShareType(), |
|
136 | + 'uidOwner' => $share->getSharedBy(), |
|
137 | + 'permissions' => $share->getPermissions(), |
|
138 | + 'fileSource' => $share->getNode()->getId(), |
|
139 | + 'expiration' => $share->getExpirationDate(), |
|
140 | + 'token' => $share->getToken(), |
|
141 | + 'itemTarget' => $share->getTarget(), |
|
142 | + 'shareWith' => $share->getSharedWith(), |
|
143 | + 'run' => &$run, |
|
144 | + 'error' => &$error, |
|
145 | + ]; |
|
146 | + \OC_Hook::emit(Share::class, 'pre_shared', $preHookData); |
|
147 | + |
|
148 | + if ($run === false) { |
|
149 | + $e->setArgument('error', $error); |
|
150 | + $e->stopPropagation(); |
|
151 | + } |
|
152 | + |
|
153 | + return $e; |
|
154 | + } |
|
155 | + |
|
156 | + public function postShare(GenericEvent $e) { |
|
157 | + /** @var IShare $share */ |
|
158 | + $share = $e->getSubject(); |
|
159 | + |
|
160 | + $postHookData = [ |
|
161 | + 'itemType' => $share->getNode() instanceof File ? 'file' : 'folder', |
|
162 | + 'itemSource' => $share->getNode()->getId(), |
|
163 | + 'shareType' => $share->getShareType(), |
|
164 | + 'uidOwner' => $share->getSharedBy(), |
|
165 | + 'permissions' => $share->getPermissions(), |
|
166 | + 'fileSource' => $share->getNode()->getId(), |
|
167 | + 'expiration' => $share->getExpirationDate(), |
|
168 | + 'token' => $share->getToken(), |
|
169 | + 'id' => $share->getId(), |
|
170 | + 'shareWith' => $share->getSharedWith(), |
|
171 | + 'itemTarget' => $share->getTarget(), |
|
172 | + 'fileTarget' => $share->getTarget(), |
|
173 | + ]; |
|
174 | + |
|
175 | + \OC_Hook::emit(Share::class, 'post_shared', $postHookData); |
|
176 | + } |
|
177 | 177 | } |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | */ |
87 | 87 | public function setId($id) { |
88 | 88 | if (is_int($id)) { |
89 | - $id = (string)$id; |
|
89 | + $id = (string) $id; |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | if (!is_string($id)) { |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | if ($this->providerId === null || $this->id === null) { |
116 | 116 | throw new \UnexpectedValueException; |
117 | 117 | } |
118 | - return $this->providerId . ':' . $this->id; |
|
118 | + return $this->providerId.':'.$this->id; |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | |
164 | 164 | $nodes = $userFolder->getById($this->fileId); |
165 | 165 | if (empty($nodes)) { |
166 | - throw new NotFoundException('Node for share not found, fileid: ' . $this->fileId); |
|
166 | + throw new NotFoundException('Node for share not found, fileid: '.$this->fileId); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | $this->node = $nodes[0]; |
@@ -40,538 +40,538 @@ |
||
40 | 40 | |
41 | 41 | class Share implements \OCP\Share\IShare { |
42 | 42 | |
43 | - /** @var string */ |
|
44 | - private $id; |
|
45 | - /** @var string */ |
|
46 | - private $providerId; |
|
47 | - /** @var Node */ |
|
48 | - private $node; |
|
49 | - /** @var int */ |
|
50 | - private $fileId; |
|
51 | - /** @var string */ |
|
52 | - private $nodeType; |
|
53 | - /** @var int */ |
|
54 | - private $shareType; |
|
55 | - /** @var string */ |
|
56 | - private $sharedWith; |
|
57 | - /** @var string */ |
|
58 | - private $sharedWithDisplayName; |
|
59 | - /** @var string */ |
|
60 | - private $sharedWithAvatar; |
|
61 | - /** @var string */ |
|
62 | - private $sharedBy; |
|
63 | - /** @var string */ |
|
64 | - private $shareOwner; |
|
65 | - /** @var int */ |
|
66 | - private $permissions; |
|
67 | - /** @var int */ |
|
68 | - private $status; |
|
69 | - /** @var string */ |
|
70 | - private $note = ''; |
|
71 | - /** @var \DateTime */ |
|
72 | - private $expireDate; |
|
73 | - /** @var string */ |
|
74 | - private $password; |
|
75 | - /** @var bool */ |
|
76 | - private $sendPasswordByTalk = false; |
|
77 | - /** @var string */ |
|
78 | - private $token; |
|
79 | - /** @var int */ |
|
80 | - private $parent; |
|
81 | - /** @var string */ |
|
82 | - private $target; |
|
83 | - /** @var \DateTime */ |
|
84 | - private $shareTime; |
|
85 | - /** @var bool */ |
|
86 | - private $mailSend; |
|
87 | - /** @var string */ |
|
88 | - private $label = ''; |
|
89 | - |
|
90 | - /** @var IRootFolder */ |
|
91 | - private $rootFolder; |
|
92 | - |
|
93 | - /** @var IUserManager */ |
|
94 | - private $userManager; |
|
95 | - |
|
96 | - /** @var ICacheEntry|null */ |
|
97 | - private $nodeCacheEntry; |
|
98 | - |
|
99 | - /** @var bool */ |
|
100 | - private $hideDownload = false; |
|
101 | - |
|
102 | - public function __construct(IRootFolder $rootFolder, IUserManager $userManager) { |
|
103 | - $this->rootFolder = $rootFolder; |
|
104 | - $this->userManager = $userManager; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @inheritdoc |
|
109 | - */ |
|
110 | - public function setId($id) { |
|
111 | - if (is_int($id)) { |
|
112 | - $id = (string)$id; |
|
113 | - } |
|
114 | - |
|
115 | - if (!is_string($id)) { |
|
116 | - throw new \InvalidArgumentException('String expected.'); |
|
117 | - } |
|
118 | - |
|
119 | - if ($this->id !== null) { |
|
120 | - throw new IllegalIDChangeException('Not allowed to assign a new internal id to a share'); |
|
121 | - } |
|
122 | - |
|
123 | - $this->id = trim($id); |
|
124 | - return $this; |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * @inheritdoc |
|
129 | - */ |
|
130 | - public function getId() { |
|
131 | - return $this->id; |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * @inheritdoc |
|
136 | - */ |
|
137 | - public function getFullId() { |
|
138 | - if ($this->providerId === null || $this->id === null) { |
|
139 | - throw new \UnexpectedValueException; |
|
140 | - } |
|
141 | - return $this->providerId . ':' . $this->id; |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * @inheritdoc |
|
146 | - */ |
|
147 | - public function setProviderId($id) { |
|
148 | - if (!is_string($id)) { |
|
149 | - throw new \InvalidArgumentException('String expected.'); |
|
150 | - } |
|
151 | - |
|
152 | - if ($this->providerId !== null) { |
|
153 | - throw new IllegalIDChangeException('Not allowed to assign a new provider id to a share'); |
|
154 | - } |
|
155 | - |
|
156 | - $this->providerId = trim($id); |
|
157 | - return $this; |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * @inheritdoc |
|
162 | - */ |
|
163 | - public function setNode(Node $node) { |
|
164 | - $this->fileId = null; |
|
165 | - $this->nodeType = null; |
|
166 | - $this->node = $node; |
|
167 | - return $this; |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * @inheritdoc |
|
172 | - */ |
|
173 | - public function getNode() { |
|
174 | - if ($this->node === null) { |
|
175 | - if ($this->shareOwner === null || $this->fileId === null) { |
|
176 | - throw new NotFoundException(); |
|
177 | - } |
|
178 | - |
|
179 | - // for federated shares the owner can be a remote user, in this |
|
180 | - // case we use the initiator |
|
181 | - if ($this->userManager->userExists($this->shareOwner)) { |
|
182 | - $userFolder = $this->rootFolder->getUserFolder($this->shareOwner); |
|
183 | - } else { |
|
184 | - $userFolder = $this->rootFolder->getUserFolder($this->sharedBy); |
|
185 | - } |
|
186 | - |
|
187 | - $nodes = $userFolder->getById($this->fileId); |
|
188 | - if (empty($nodes)) { |
|
189 | - throw new NotFoundException('Node for share not found, fileid: ' . $this->fileId); |
|
190 | - } |
|
191 | - |
|
192 | - $this->node = $nodes[0]; |
|
193 | - } |
|
194 | - |
|
195 | - return $this->node; |
|
196 | - } |
|
197 | - |
|
198 | - /** |
|
199 | - * @inheritdoc |
|
200 | - */ |
|
201 | - public function setNodeId($fileId) { |
|
202 | - $this->node = null; |
|
203 | - $this->fileId = $fileId; |
|
204 | - return $this; |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * @inheritdoc |
|
209 | - */ |
|
210 | - public function getNodeId() { |
|
211 | - if ($this->fileId === null) { |
|
212 | - $this->fileId = $this->getNode()->getId(); |
|
213 | - } |
|
214 | - |
|
215 | - return $this->fileId; |
|
216 | - } |
|
217 | - |
|
218 | - /** |
|
219 | - * @inheritdoc |
|
220 | - */ |
|
221 | - public function setNodeType($type) { |
|
222 | - if ($type !== 'file' && $type !== 'folder') { |
|
223 | - throw new \InvalidArgumentException(); |
|
224 | - } |
|
225 | - |
|
226 | - $this->nodeType = $type; |
|
227 | - return $this; |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * @inheritdoc |
|
232 | - */ |
|
233 | - public function getNodeType() { |
|
234 | - if ($this->nodeType === null) { |
|
235 | - $node = $this->getNode(); |
|
236 | - $this->nodeType = $node instanceof File ? 'file' : 'folder'; |
|
237 | - } |
|
238 | - |
|
239 | - return $this->nodeType; |
|
240 | - } |
|
241 | - |
|
242 | - /** |
|
243 | - * @inheritdoc |
|
244 | - */ |
|
245 | - public function setShareType($shareType) { |
|
246 | - $this->shareType = $shareType; |
|
247 | - return $this; |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * @inheritdoc |
|
252 | - */ |
|
253 | - public function getShareType() { |
|
254 | - return $this->shareType; |
|
255 | - } |
|
256 | - |
|
257 | - /** |
|
258 | - * @inheritdoc |
|
259 | - */ |
|
260 | - public function setSharedWith($sharedWith) { |
|
261 | - if (!is_string($sharedWith)) { |
|
262 | - throw new \InvalidArgumentException(); |
|
263 | - } |
|
264 | - $this->sharedWith = $sharedWith; |
|
265 | - return $this; |
|
266 | - } |
|
267 | - |
|
268 | - /** |
|
269 | - * @inheritdoc |
|
270 | - */ |
|
271 | - public function getSharedWith() { |
|
272 | - return $this->sharedWith; |
|
273 | - } |
|
274 | - |
|
275 | - /** |
|
276 | - * @inheritdoc |
|
277 | - */ |
|
278 | - public function setSharedWithDisplayName($displayName) { |
|
279 | - if (!is_string($displayName)) { |
|
280 | - throw new \InvalidArgumentException(); |
|
281 | - } |
|
282 | - $this->sharedWithDisplayName = $displayName; |
|
283 | - return $this; |
|
284 | - } |
|
285 | - |
|
286 | - /** |
|
287 | - * @inheritdoc |
|
288 | - */ |
|
289 | - public function getSharedWithDisplayName() { |
|
290 | - return $this->sharedWithDisplayName; |
|
291 | - } |
|
292 | - |
|
293 | - /** |
|
294 | - * @inheritdoc |
|
295 | - */ |
|
296 | - public function setSharedWithAvatar($src) { |
|
297 | - if (!is_string($src)) { |
|
298 | - throw new \InvalidArgumentException(); |
|
299 | - } |
|
300 | - $this->sharedWithAvatar = $src; |
|
301 | - return $this; |
|
302 | - } |
|
303 | - |
|
304 | - /** |
|
305 | - * @inheritdoc |
|
306 | - */ |
|
307 | - public function getSharedWithAvatar() { |
|
308 | - return $this->sharedWithAvatar; |
|
309 | - } |
|
310 | - |
|
311 | - /** |
|
312 | - * @inheritdoc |
|
313 | - */ |
|
314 | - public function setPermissions($permissions) { |
|
315 | - //TODO checkes |
|
316 | - |
|
317 | - $this->permissions = $permissions; |
|
318 | - return $this; |
|
319 | - } |
|
320 | - |
|
321 | - /** |
|
322 | - * @inheritdoc |
|
323 | - */ |
|
324 | - public function getPermissions() { |
|
325 | - return $this->permissions; |
|
326 | - } |
|
327 | - |
|
328 | - /** |
|
329 | - * @inheritdoc |
|
330 | - */ |
|
331 | - public function setStatus(int $status): IShare { |
|
332 | - $this->status = $status; |
|
333 | - return $this; |
|
334 | - } |
|
335 | - |
|
336 | - /** |
|
337 | - * @inheritdoc |
|
338 | - */ |
|
339 | - public function getStatus(): int { |
|
340 | - return $this->status; |
|
341 | - } |
|
342 | - |
|
343 | - /** |
|
344 | - * @inheritdoc |
|
345 | - */ |
|
346 | - public function setNote($note) { |
|
347 | - $this->note = $note; |
|
348 | - return $this; |
|
349 | - } |
|
350 | - |
|
351 | - /** |
|
352 | - * @inheritdoc |
|
353 | - */ |
|
354 | - public function getNote() { |
|
355 | - if (is_string($this->note)) { |
|
356 | - return $this->note; |
|
357 | - } |
|
358 | - return ''; |
|
359 | - } |
|
360 | - |
|
361 | - /** |
|
362 | - * @inheritdoc |
|
363 | - */ |
|
364 | - public function setLabel($label) { |
|
365 | - $this->label = $label; |
|
366 | - return $this; |
|
367 | - } |
|
368 | - |
|
369 | - /** |
|
370 | - * @inheritdoc |
|
371 | - */ |
|
372 | - public function getLabel() { |
|
373 | - return $this->label; |
|
374 | - } |
|
375 | - |
|
376 | - /** |
|
377 | - * @inheritdoc |
|
378 | - */ |
|
379 | - public function setExpirationDate($expireDate) { |
|
380 | - //TODO checks |
|
381 | - |
|
382 | - $this->expireDate = $expireDate; |
|
383 | - return $this; |
|
384 | - } |
|
385 | - |
|
386 | - /** |
|
387 | - * @inheritdoc |
|
388 | - */ |
|
389 | - public function getExpirationDate() { |
|
390 | - return $this->expireDate; |
|
391 | - } |
|
392 | - |
|
393 | - /** |
|
394 | - * @inheritdoc |
|
395 | - */ |
|
396 | - public function isExpired() { |
|
397 | - return $this->getExpirationDate() !== null && |
|
398 | - $this->getExpirationDate() <= new \DateTime(); |
|
399 | - } |
|
400 | - |
|
401 | - /** |
|
402 | - * @inheritdoc |
|
403 | - */ |
|
404 | - public function setSharedBy($sharedBy) { |
|
405 | - if (!is_string($sharedBy)) { |
|
406 | - throw new \InvalidArgumentException(); |
|
407 | - } |
|
408 | - //TODO checks |
|
409 | - $this->sharedBy = $sharedBy; |
|
410 | - |
|
411 | - return $this; |
|
412 | - } |
|
413 | - |
|
414 | - /** |
|
415 | - * @inheritdoc |
|
416 | - */ |
|
417 | - public function getSharedBy() { |
|
418 | - //TODO check if set |
|
419 | - return $this->sharedBy; |
|
420 | - } |
|
421 | - |
|
422 | - /** |
|
423 | - * @inheritdoc |
|
424 | - */ |
|
425 | - public function setShareOwner($shareOwner) { |
|
426 | - if (!is_string($shareOwner)) { |
|
427 | - throw new \InvalidArgumentException(); |
|
428 | - } |
|
429 | - //TODO checks |
|
430 | - |
|
431 | - $this->shareOwner = $shareOwner; |
|
432 | - return $this; |
|
433 | - } |
|
434 | - |
|
435 | - /** |
|
436 | - * @inheritdoc |
|
437 | - */ |
|
438 | - public function getShareOwner() { |
|
439 | - //TODO check if set |
|
440 | - return $this->shareOwner; |
|
441 | - } |
|
442 | - |
|
443 | - /** |
|
444 | - * @inheritdoc |
|
445 | - */ |
|
446 | - public function setPassword($password) { |
|
447 | - $this->password = $password; |
|
448 | - return $this; |
|
449 | - } |
|
450 | - |
|
451 | - /** |
|
452 | - * @inheritdoc |
|
453 | - */ |
|
454 | - public function getPassword() { |
|
455 | - return $this->password; |
|
456 | - } |
|
457 | - |
|
458 | - /** |
|
459 | - * @inheritdoc |
|
460 | - */ |
|
461 | - public function setSendPasswordByTalk(bool $sendPasswordByTalk) { |
|
462 | - $this->sendPasswordByTalk = $sendPasswordByTalk; |
|
463 | - return $this; |
|
464 | - } |
|
465 | - |
|
466 | - /** |
|
467 | - * @inheritdoc |
|
468 | - */ |
|
469 | - public function getSendPasswordByTalk(): bool { |
|
470 | - return $this->sendPasswordByTalk; |
|
471 | - } |
|
472 | - |
|
473 | - /** |
|
474 | - * @inheritdoc |
|
475 | - */ |
|
476 | - public function setToken($token) { |
|
477 | - $this->token = $token; |
|
478 | - return $this; |
|
479 | - } |
|
480 | - |
|
481 | - /** |
|
482 | - * @inheritdoc |
|
483 | - */ |
|
484 | - public function getToken() { |
|
485 | - return $this->token; |
|
486 | - } |
|
487 | - |
|
488 | - /** |
|
489 | - * Set the parent of this share |
|
490 | - * |
|
491 | - * @param int parent |
|
492 | - * @return \OCP\Share\IShare |
|
493 | - * @deprecated The new shares do not have parents. This is just here for legacy reasons. |
|
494 | - */ |
|
495 | - public function setParent($parent) { |
|
496 | - $this->parent = $parent; |
|
497 | - return $this; |
|
498 | - } |
|
499 | - |
|
500 | - /** |
|
501 | - * Get the parent of this share. |
|
502 | - * |
|
503 | - * @return int |
|
504 | - * @deprecated The new shares do not have parents. This is just here for legacy reasons. |
|
505 | - */ |
|
506 | - public function getParent() { |
|
507 | - return $this->parent; |
|
508 | - } |
|
509 | - |
|
510 | - /** |
|
511 | - * @inheritdoc |
|
512 | - */ |
|
513 | - public function setTarget($target) { |
|
514 | - $this->target = $target; |
|
515 | - return $this; |
|
516 | - } |
|
517 | - |
|
518 | - /** |
|
519 | - * @inheritdoc |
|
520 | - */ |
|
521 | - public function getTarget() { |
|
522 | - return $this->target; |
|
523 | - } |
|
524 | - |
|
525 | - /** |
|
526 | - * @inheritdoc |
|
527 | - */ |
|
528 | - public function setShareTime(\DateTime $shareTime) { |
|
529 | - $this->shareTime = $shareTime; |
|
530 | - return $this; |
|
531 | - } |
|
532 | - |
|
533 | - /** |
|
534 | - * @inheritdoc |
|
535 | - */ |
|
536 | - public function getShareTime() { |
|
537 | - return $this->shareTime; |
|
538 | - } |
|
539 | - |
|
540 | - /** |
|
541 | - * @inheritdoc |
|
542 | - */ |
|
543 | - public function setMailSend($mailSend) { |
|
544 | - $this->mailSend = $mailSend; |
|
545 | - return $this; |
|
546 | - } |
|
547 | - |
|
548 | - /** |
|
549 | - * @inheritdoc |
|
550 | - */ |
|
551 | - public function getMailSend() { |
|
552 | - return $this->mailSend; |
|
553 | - } |
|
554 | - |
|
555 | - /** |
|
556 | - * @inheritdoc |
|
557 | - */ |
|
558 | - public function setNodeCacheEntry(ICacheEntry $entry) { |
|
559 | - $this->nodeCacheEntry = $entry; |
|
560 | - } |
|
561 | - |
|
562 | - /** |
|
563 | - * @inheritdoc |
|
564 | - */ |
|
565 | - public function getNodeCacheEntry() { |
|
566 | - return $this->nodeCacheEntry; |
|
567 | - } |
|
568 | - |
|
569 | - public function setHideDownload(bool $hide): IShare { |
|
570 | - $this->hideDownload = $hide; |
|
571 | - return $this; |
|
572 | - } |
|
573 | - |
|
574 | - public function getHideDownload(): bool { |
|
575 | - return $this->hideDownload; |
|
576 | - } |
|
43 | + /** @var string */ |
|
44 | + private $id; |
|
45 | + /** @var string */ |
|
46 | + private $providerId; |
|
47 | + /** @var Node */ |
|
48 | + private $node; |
|
49 | + /** @var int */ |
|
50 | + private $fileId; |
|
51 | + /** @var string */ |
|
52 | + private $nodeType; |
|
53 | + /** @var int */ |
|
54 | + private $shareType; |
|
55 | + /** @var string */ |
|
56 | + private $sharedWith; |
|
57 | + /** @var string */ |
|
58 | + private $sharedWithDisplayName; |
|
59 | + /** @var string */ |
|
60 | + private $sharedWithAvatar; |
|
61 | + /** @var string */ |
|
62 | + private $sharedBy; |
|
63 | + /** @var string */ |
|
64 | + private $shareOwner; |
|
65 | + /** @var int */ |
|
66 | + private $permissions; |
|
67 | + /** @var int */ |
|
68 | + private $status; |
|
69 | + /** @var string */ |
|
70 | + private $note = ''; |
|
71 | + /** @var \DateTime */ |
|
72 | + private $expireDate; |
|
73 | + /** @var string */ |
|
74 | + private $password; |
|
75 | + /** @var bool */ |
|
76 | + private $sendPasswordByTalk = false; |
|
77 | + /** @var string */ |
|
78 | + private $token; |
|
79 | + /** @var int */ |
|
80 | + private $parent; |
|
81 | + /** @var string */ |
|
82 | + private $target; |
|
83 | + /** @var \DateTime */ |
|
84 | + private $shareTime; |
|
85 | + /** @var bool */ |
|
86 | + private $mailSend; |
|
87 | + /** @var string */ |
|
88 | + private $label = ''; |
|
89 | + |
|
90 | + /** @var IRootFolder */ |
|
91 | + private $rootFolder; |
|
92 | + |
|
93 | + /** @var IUserManager */ |
|
94 | + private $userManager; |
|
95 | + |
|
96 | + /** @var ICacheEntry|null */ |
|
97 | + private $nodeCacheEntry; |
|
98 | + |
|
99 | + /** @var bool */ |
|
100 | + private $hideDownload = false; |
|
101 | + |
|
102 | + public function __construct(IRootFolder $rootFolder, IUserManager $userManager) { |
|
103 | + $this->rootFolder = $rootFolder; |
|
104 | + $this->userManager = $userManager; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @inheritdoc |
|
109 | + */ |
|
110 | + public function setId($id) { |
|
111 | + if (is_int($id)) { |
|
112 | + $id = (string)$id; |
|
113 | + } |
|
114 | + |
|
115 | + if (!is_string($id)) { |
|
116 | + throw new \InvalidArgumentException('String expected.'); |
|
117 | + } |
|
118 | + |
|
119 | + if ($this->id !== null) { |
|
120 | + throw new IllegalIDChangeException('Not allowed to assign a new internal id to a share'); |
|
121 | + } |
|
122 | + |
|
123 | + $this->id = trim($id); |
|
124 | + return $this; |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * @inheritdoc |
|
129 | + */ |
|
130 | + public function getId() { |
|
131 | + return $this->id; |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * @inheritdoc |
|
136 | + */ |
|
137 | + public function getFullId() { |
|
138 | + if ($this->providerId === null || $this->id === null) { |
|
139 | + throw new \UnexpectedValueException; |
|
140 | + } |
|
141 | + return $this->providerId . ':' . $this->id; |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * @inheritdoc |
|
146 | + */ |
|
147 | + public function setProviderId($id) { |
|
148 | + if (!is_string($id)) { |
|
149 | + throw new \InvalidArgumentException('String expected.'); |
|
150 | + } |
|
151 | + |
|
152 | + if ($this->providerId !== null) { |
|
153 | + throw new IllegalIDChangeException('Not allowed to assign a new provider id to a share'); |
|
154 | + } |
|
155 | + |
|
156 | + $this->providerId = trim($id); |
|
157 | + return $this; |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * @inheritdoc |
|
162 | + */ |
|
163 | + public function setNode(Node $node) { |
|
164 | + $this->fileId = null; |
|
165 | + $this->nodeType = null; |
|
166 | + $this->node = $node; |
|
167 | + return $this; |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * @inheritdoc |
|
172 | + */ |
|
173 | + public function getNode() { |
|
174 | + if ($this->node === null) { |
|
175 | + if ($this->shareOwner === null || $this->fileId === null) { |
|
176 | + throw new NotFoundException(); |
|
177 | + } |
|
178 | + |
|
179 | + // for federated shares the owner can be a remote user, in this |
|
180 | + // case we use the initiator |
|
181 | + if ($this->userManager->userExists($this->shareOwner)) { |
|
182 | + $userFolder = $this->rootFolder->getUserFolder($this->shareOwner); |
|
183 | + } else { |
|
184 | + $userFolder = $this->rootFolder->getUserFolder($this->sharedBy); |
|
185 | + } |
|
186 | + |
|
187 | + $nodes = $userFolder->getById($this->fileId); |
|
188 | + if (empty($nodes)) { |
|
189 | + throw new NotFoundException('Node for share not found, fileid: ' . $this->fileId); |
|
190 | + } |
|
191 | + |
|
192 | + $this->node = $nodes[0]; |
|
193 | + } |
|
194 | + |
|
195 | + return $this->node; |
|
196 | + } |
|
197 | + |
|
198 | + /** |
|
199 | + * @inheritdoc |
|
200 | + */ |
|
201 | + public function setNodeId($fileId) { |
|
202 | + $this->node = null; |
|
203 | + $this->fileId = $fileId; |
|
204 | + return $this; |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * @inheritdoc |
|
209 | + */ |
|
210 | + public function getNodeId() { |
|
211 | + if ($this->fileId === null) { |
|
212 | + $this->fileId = $this->getNode()->getId(); |
|
213 | + } |
|
214 | + |
|
215 | + return $this->fileId; |
|
216 | + } |
|
217 | + |
|
218 | + /** |
|
219 | + * @inheritdoc |
|
220 | + */ |
|
221 | + public function setNodeType($type) { |
|
222 | + if ($type !== 'file' && $type !== 'folder') { |
|
223 | + throw new \InvalidArgumentException(); |
|
224 | + } |
|
225 | + |
|
226 | + $this->nodeType = $type; |
|
227 | + return $this; |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * @inheritdoc |
|
232 | + */ |
|
233 | + public function getNodeType() { |
|
234 | + if ($this->nodeType === null) { |
|
235 | + $node = $this->getNode(); |
|
236 | + $this->nodeType = $node instanceof File ? 'file' : 'folder'; |
|
237 | + } |
|
238 | + |
|
239 | + return $this->nodeType; |
|
240 | + } |
|
241 | + |
|
242 | + /** |
|
243 | + * @inheritdoc |
|
244 | + */ |
|
245 | + public function setShareType($shareType) { |
|
246 | + $this->shareType = $shareType; |
|
247 | + return $this; |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * @inheritdoc |
|
252 | + */ |
|
253 | + public function getShareType() { |
|
254 | + return $this->shareType; |
|
255 | + } |
|
256 | + |
|
257 | + /** |
|
258 | + * @inheritdoc |
|
259 | + */ |
|
260 | + public function setSharedWith($sharedWith) { |
|
261 | + if (!is_string($sharedWith)) { |
|
262 | + throw new \InvalidArgumentException(); |
|
263 | + } |
|
264 | + $this->sharedWith = $sharedWith; |
|
265 | + return $this; |
|
266 | + } |
|
267 | + |
|
268 | + /** |
|
269 | + * @inheritdoc |
|
270 | + */ |
|
271 | + public function getSharedWith() { |
|
272 | + return $this->sharedWith; |
|
273 | + } |
|
274 | + |
|
275 | + /** |
|
276 | + * @inheritdoc |
|
277 | + */ |
|
278 | + public function setSharedWithDisplayName($displayName) { |
|
279 | + if (!is_string($displayName)) { |
|
280 | + throw new \InvalidArgumentException(); |
|
281 | + } |
|
282 | + $this->sharedWithDisplayName = $displayName; |
|
283 | + return $this; |
|
284 | + } |
|
285 | + |
|
286 | + /** |
|
287 | + * @inheritdoc |
|
288 | + */ |
|
289 | + public function getSharedWithDisplayName() { |
|
290 | + return $this->sharedWithDisplayName; |
|
291 | + } |
|
292 | + |
|
293 | + /** |
|
294 | + * @inheritdoc |
|
295 | + */ |
|
296 | + public function setSharedWithAvatar($src) { |
|
297 | + if (!is_string($src)) { |
|
298 | + throw new \InvalidArgumentException(); |
|
299 | + } |
|
300 | + $this->sharedWithAvatar = $src; |
|
301 | + return $this; |
|
302 | + } |
|
303 | + |
|
304 | + /** |
|
305 | + * @inheritdoc |
|
306 | + */ |
|
307 | + public function getSharedWithAvatar() { |
|
308 | + return $this->sharedWithAvatar; |
|
309 | + } |
|
310 | + |
|
311 | + /** |
|
312 | + * @inheritdoc |
|
313 | + */ |
|
314 | + public function setPermissions($permissions) { |
|
315 | + //TODO checkes |
|
316 | + |
|
317 | + $this->permissions = $permissions; |
|
318 | + return $this; |
|
319 | + } |
|
320 | + |
|
321 | + /** |
|
322 | + * @inheritdoc |
|
323 | + */ |
|
324 | + public function getPermissions() { |
|
325 | + return $this->permissions; |
|
326 | + } |
|
327 | + |
|
328 | + /** |
|
329 | + * @inheritdoc |
|
330 | + */ |
|
331 | + public function setStatus(int $status): IShare { |
|
332 | + $this->status = $status; |
|
333 | + return $this; |
|
334 | + } |
|
335 | + |
|
336 | + /** |
|
337 | + * @inheritdoc |
|
338 | + */ |
|
339 | + public function getStatus(): int { |
|
340 | + return $this->status; |
|
341 | + } |
|
342 | + |
|
343 | + /** |
|
344 | + * @inheritdoc |
|
345 | + */ |
|
346 | + public function setNote($note) { |
|
347 | + $this->note = $note; |
|
348 | + return $this; |
|
349 | + } |
|
350 | + |
|
351 | + /** |
|
352 | + * @inheritdoc |
|
353 | + */ |
|
354 | + public function getNote() { |
|
355 | + if (is_string($this->note)) { |
|
356 | + return $this->note; |
|
357 | + } |
|
358 | + return ''; |
|
359 | + } |
|
360 | + |
|
361 | + /** |
|
362 | + * @inheritdoc |
|
363 | + */ |
|
364 | + public function setLabel($label) { |
|
365 | + $this->label = $label; |
|
366 | + return $this; |
|
367 | + } |
|
368 | + |
|
369 | + /** |
|
370 | + * @inheritdoc |
|
371 | + */ |
|
372 | + public function getLabel() { |
|
373 | + return $this->label; |
|
374 | + } |
|
375 | + |
|
376 | + /** |
|
377 | + * @inheritdoc |
|
378 | + */ |
|
379 | + public function setExpirationDate($expireDate) { |
|
380 | + //TODO checks |
|
381 | + |
|
382 | + $this->expireDate = $expireDate; |
|
383 | + return $this; |
|
384 | + } |
|
385 | + |
|
386 | + /** |
|
387 | + * @inheritdoc |
|
388 | + */ |
|
389 | + public function getExpirationDate() { |
|
390 | + return $this->expireDate; |
|
391 | + } |
|
392 | + |
|
393 | + /** |
|
394 | + * @inheritdoc |
|
395 | + */ |
|
396 | + public function isExpired() { |
|
397 | + return $this->getExpirationDate() !== null && |
|
398 | + $this->getExpirationDate() <= new \DateTime(); |
|
399 | + } |
|
400 | + |
|
401 | + /** |
|
402 | + * @inheritdoc |
|
403 | + */ |
|
404 | + public function setSharedBy($sharedBy) { |
|
405 | + if (!is_string($sharedBy)) { |
|
406 | + throw new \InvalidArgumentException(); |
|
407 | + } |
|
408 | + //TODO checks |
|
409 | + $this->sharedBy = $sharedBy; |
|
410 | + |
|
411 | + return $this; |
|
412 | + } |
|
413 | + |
|
414 | + /** |
|
415 | + * @inheritdoc |
|
416 | + */ |
|
417 | + public function getSharedBy() { |
|
418 | + //TODO check if set |
|
419 | + return $this->sharedBy; |
|
420 | + } |
|
421 | + |
|
422 | + /** |
|
423 | + * @inheritdoc |
|
424 | + */ |
|
425 | + public function setShareOwner($shareOwner) { |
|
426 | + if (!is_string($shareOwner)) { |
|
427 | + throw new \InvalidArgumentException(); |
|
428 | + } |
|
429 | + //TODO checks |
|
430 | + |
|
431 | + $this->shareOwner = $shareOwner; |
|
432 | + return $this; |
|
433 | + } |
|
434 | + |
|
435 | + /** |
|
436 | + * @inheritdoc |
|
437 | + */ |
|
438 | + public function getShareOwner() { |
|
439 | + //TODO check if set |
|
440 | + return $this->shareOwner; |
|
441 | + } |
|
442 | + |
|
443 | + /** |
|
444 | + * @inheritdoc |
|
445 | + */ |
|
446 | + public function setPassword($password) { |
|
447 | + $this->password = $password; |
|
448 | + return $this; |
|
449 | + } |
|
450 | + |
|
451 | + /** |
|
452 | + * @inheritdoc |
|
453 | + */ |
|
454 | + public function getPassword() { |
|
455 | + return $this->password; |
|
456 | + } |
|
457 | + |
|
458 | + /** |
|
459 | + * @inheritdoc |
|
460 | + */ |
|
461 | + public function setSendPasswordByTalk(bool $sendPasswordByTalk) { |
|
462 | + $this->sendPasswordByTalk = $sendPasswordByTalk; |
|
463 | + return $this; |
|
464 | + } |
|
465 | + |
|
466 | + /** |
|
467 | + * @inheritdoc |
|
468 | + */ |
|
469 | + public function getSendPasswordByTalk(): bool { |
|
470 | + return $this->sendPasswordByTalk; |
|
471 | + } |
|
472 | + |
|
473 | + /** |
|
474 | + * @inheritdoc |
|
475 | + */ |
|
476 | + public function setToken($token) { |
|
477 | + $this->token = $token; |
|
478 | + return $this; |
|
479 | + } |
|
480 | + |
|
481 | + /** |
|
482 | + * @inheritdoc |
|
483 | + */ |
|
484 | + public function getToken() { |
|
485 | + return $this->token; |
|
486 | + } |
|
487 | + |
|
488 | + /** |
|
489 | + * Set the parent of this share |
|
490 | + * |
|
491 | + * @param int parent |
|
492 | + * @return \OCP\Share\IShare |
|
493 | + * @deprecated The new shares do not have parents. This is just here for legacy reasons. |
|
494 | + */ |
|
495 | + public function setParent($parent) { |
|
496 | + $this->parent = $parent; |
|
497 | + return $this; |
|
498 | + } |
|
499 | + |
|
500 | + /** |
|
501 | + * Get the parent of this share. |
|
502 | + * |
|
503 | + * @return int |
|
504 | + * @deprecated The new shares do not have parents. This is just here for legacy reasons. |
|
505 | + */ |
|
506 | + public function getParent() { |
|
507 | + return $this->parent; |
|
508 | + } |
|
509 | + |
|
510 | + /** |
|
511 | + * @inheritdoc |
|
512 | + */ |
|
513 | + public function setTarget($target) { |
|
514 | + $this->target = $target; |
|
515 | + return $this; |
|
516 | + } |
|
517 | + |
|
518 | + /** |
|
519 | + * @inheritdoc |
|
520 | + */ |
|
521 | + public function getTarget() { |
|
522 | + return $this->target; |
|
523 | + } |
|
524 | + |
|
525 | + /** |
|
526 | + * @inheritdoc |
|
527 | + */ |
|
528 | + public function setShareTime(\DateTime $shareTime) { |
|
529 | + $this->shareTime = $shareTime; |
|
530 | + return $this; |
|
531 | + } |
|
532 | + |
|
533 | + /** |
|
534 | + * @inheritdoc |
|
535 | + */ |
|
536 | + public function getShareTime() { |
|
537 | + return $this->shareTime; |
|
538 | + } |
|
539 | + |
|
540 | + /** |
|
541 | + * @inheritdoc |
|
542 | + */ |
|
543 | + public function setMailSend($mailSend) { |
|
544 | + $this->mailSend = $mailSend; |
|
545 | + return $this; |
|
546 | + } |
|
547 | + |
|
548 | + /** |
|
549 | + * @inheritdoc |
|
550 | + */ |
|
551 | + public function getMailSend() { |
|
552 | + return $this->mailSend; |
|
553 | + } |
|
554 | + |
|
555 | + /** |
|
556 | + * @inheritdoc |
|
557 | + */ |
|
558 | + public function setNodeCacheEntry(ICacheEntry $entry) { |
|
559 | + $this->nodeCacheEntry = $entry; |
|
560 | + } |
|
561 | + |
|
562 | + /** |
|
563 | + * @inheritdoc |
|
564 | + */ |
|
565 | + public function getNodeCacheEntry() { |
|
566 | + return $this->nodeCacheEntry; |
|
567 | + } |
|
568 | + |
|
569 | + public function setHideDownload(bool $hide): IShare { |
|
570 | + $this->hideDownload = $hide; |
|
571 | + return $this; |
|
572 | + } |
|
573 | + |
|
574 | + public function getHideDownload(): bool { |
|
575 | + return $this->hideDownload; |
|
576 | + } |
|
577 | 577 | } |
@@ -275,7 +275,7 @@ |
||
275 | 275 | return $this->getAppValues($app); |
276 | 276 | } else { |
277 | 277 | $appIds = $this->getApps(); |
278 | - $values = array_map(function ($appId) use ($key) { |
|
278 | + $values = array_map(function($appId) use ($key) { |
|
279 | 279 | return isset($this->cache[$appId][$key]) ? $this->cache[$appId][$key] : null; |
280 | 280 | }, $appIds); |
281 | 281 | $result = array_combine($appIds, $values); |
@@ -43,328 +43,328 @@ |
||
43 | 43 | */ |
44 | 44 | class AppConfig implements IAppConfig { |
45 | 45 | |
46 | - /** @var array[] */ |
|
47 | - protected $sensitiveValues = [ |
|
48 | - 'external' => [ |
|
49 | - '/^sites$/', |
|
50 | - ], |
|
51 | - 'spreed' => [ |
|
52 | - '/^bridge_bot_password/', |
|
53 | - '/^signaling_servers$/', |
|
54 | - '/^signaling_ticket_secret$/', |
|
55 | - '/^stun_servers$/', |
|
56 | - '/^turn_servers$/', |
|
57 | - '/^turn_server_secret$/', |
|
58 | - ], |
|
59 | - 'theming' => [ |
|
60 | - '/^imprintUrl$/', |
|
61 | - '/^privacyUrl$/', |
|
62 | - '/^slogan$/', |
|
63 | - '/^url$/', |
|
64 | - ], |
|
65 | - 'user_ldap' => [ |
|
66 | - '/^(s..)?ldap_agent_password$/', |
|
67 | - ], |
|
68 | - ]; |
|
69 | - |
|
70 | - /** @var \OCP\IDBConnection */ |
|
71 | - protected $conn; |
|
72 | - |
|
73 | - /** @var array[] */ |
|
74 | - private $cache = []; |
|
75 | - |
|
76 | - /** @var bool */ |
|
77 | - private $configLoaded = false; |
|
78 | - |
|
79 | - /** |
|
80 | - * @param IDBConnection $conn |
|
81 | - */ |
|
82 | - public function __construct(IDBConnection $conn) { |
|
83 | - $this->conn = $conn; |
|
84 | - $this->configLoaded = false; |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * @param string $app |
|
89 | - * @return array |
|
90 | - */ |
|
91 | - private function getAppValues($app) { |
|
92 | - $this->loadConfigValues(); |
|
93 | - |
|
94 | - if (isset($this->cache[$app])) { |
|
95 | - return $this->cache[$app]; |
|
96 | - } |
|
97 | - |
|
98 | - return []; |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * Get all apps using the config |
|
103 | - * |
|
104 | - * @return array an array of app ids |
|
105 | - * |
|
106 | - * This function returns a list of all apps that have at least one |
|
107 | - * entry in the appconfig table. |
|
108 | - */ |
|
109 | - public function getApps() { |
|
110 | - $this->loadConfigValues(); |
|
111 | - |
|
112 | - return $this->getSortedKeys($this->cache); |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * Get the available keys for an app |
|
117 | - * |
|
118 | - * @param string $app the app we are looking for |
|
119 | - * @return array an array of key names |
|
120 | - * |
|
121 | - * This function gets all keys of an app. Please note that the values are |
|
122 | - * not returned. |
|
123 | - */ |
|
124 | - public function getKeys($app) { |
|
125 | - $this->loadConfigValues(); |
|
126 | - |
|
127 | - if (isset($this->cache[$app])) { |
|
128 | - return $this->getSortedKeys($this->cache[$app]); |
|
129 | - } |
|
130 | - |
|
131 | - return []; |
|
132 | - } |
|
133 | - |
|
134 | - public function getSortedKeys($data) { |
|
135 | - $keys = array_keys($data); |
|
136 | - sort($keys); |
|
137 | - return $keys; |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * Gets the config value |
|
142 | - * |
|
143 | - * @param string $app app |
|
144 | - * @param string $key key |
|
145 | - * @param string $default = null, default value if the key does not exist |
|
146 | - * @return string the value or $default |
|
147 | - * |
|
148 | - * This function gets a value from the appconfig table. If the key does |
|
149 | - * not exist the default value will be returned |
|
150 | - */ |
|
151 | - public function getValue($app, $key, $default = null) { |
|
152 | - $this->loadConfigValues(); |
|
153 | - |
|
154 | - if ($this->hasKey($app, $key)) { |
|
155 | - return $this->cache[$app][$key]; |
|
156 | - } |
|
157 | - |
|
158 | - return $default; |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * check if a key is set in the appconfig |
|
163 | - * |
|
164 | - * @param string $app |
|
165 | - * @param string $key |
|
166 | - * @return bool |
|
167 | - */ |
|
168 | - public function hasKey($app, $key) { |
|
169 | - $this->loadConfigValues(); |
|
170 | - |
|
171 | - return isset($this->cache[$app][$key]); |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * Sets a value. If the key did not exist before it will be created. |
|
176 | - * |
|
177 | - * @param string $app app |
|
178 | - * @param string $key key |
|
179 | - * @param string|float|int $value value |
|
180 | - * @return bool True if the value was inserted or updated, false if the value was the same |
|
181 | - */ |
|
182 | - public function setValue($app, $key, $value) { |
|
183 | - if (!$this->hasKey($app, $key)) { |
|
184 | - $inserted = (bool) $this->conn->insertIfNotExist('*PREFIX*appconfig', [ |
|
185 | - 'appid' => $app, |
|
186 | - 'configkey' => $key, |
|
187 | - 'configvalue' => $value, |
|
188 | - ], [ |
|
189 | - 'appid', |
|
190 | - 'configkey', |
|
191 | - ]); |
|
192 | - |
|
193 | - if ($inserted) { |
|
194 | - if (!isset($this->cache[$app])) { |
|
195 | - $this->cache[$app] = []; |
|
196 | - } |
|
197 | - |
|
198 | - $this->cache[$app][$key] = $value; |
|
199 | - return true; |
|
200 | - } |
|
201 | - } |
|
202 | - |
|
203 | - $sql = $this->conn->getQueryBuilder(); |
|
204 | - $sql->update('appconfig') |
|
205 | - ->set('configvalue', $sql->createNamedParameter($value)) |
|
206 | - ->where($sql->expr()->eq('appid', $sql->createNamedParameter($app))) |
|
207 | - ->andWhere($sql->expr()->eq('configkey', $sql->createNamedParameter($key))); |
|
208 | - |
|
209 | - /* |
|
46 | + /** @var array[] */ |
|
47 | + protected $sensitiveValues = [ |
|
48 | + 'external' => [ |
|
49 | + '/^sites$/', |
|
50 | + ], |
|
51 | + 'spreed' => [ |
|
52 | + '/^bridge_bot_password/', |
|
53 | + '/^signaling_servers$/', |
|
54 | + '/^signaling_ticket_secret$/', |
|
55 | + '/^stun_servers$/', |
|
56 | + '/^turn_servers$/', |
|
57 | + '/^turn_server_secret$/', |
|
58 | + ], |
|
59 | + 'theming' => [ |
|
60 | + '/^imprintUrl$/', |
|
61 | + '/^privacyUrl$/', |
|
62 | + '/^slogan$/', |
|
63 | + '/^url$/', |
|
64 | + ], |
|
65 | + 'user_ldap' => [ |
|
66 | + '/^(s..)?ldap_agent_password$/', |
|
67 | + ], |
|
68 | + ]; |
|
69 | + |
|
70 | + /** @var \OCP\IDBConnection */ |
|
71 | + protected $conn; |
|
72 | + |
|
73 | + /** @var array[] */ |
|
74 | + private $cache = []; |
|
75 | + |
|
76 | + /** @var bool */ |
|
77 | + private $configLoaded = false; |
|
78 | + |
|
79 | + /** |
|
80 | + * @param IDBConnection $conn |
|
81 | + */ |
|
82 | + public function __construct(IDBConnection $conn) { |
|
83 | + $this->conn = $conn; |
|
84 | + $this->configLoaded = false; |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * @param string $app |
|
89 | + * @return array |
|
90 | + */ |
|
91 | + private function getAppValues($app) { |
|
92 | + $this->loadConfigValues(); |
|
93 | + |
|
94 | + if (isset($this->cache[$app])) { |
|
95 | + return $this->cache[$app]; |
|
96 | + } |
|
97 | + |
|
98 | + return []; |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * Get all apps using the config |
|
103 | + * |
|
104 | + * @return array an array of app ids |
|
105 | + * |
|
106 | + * This function returns a list of all apps that have at least one |
|
107 | + * entry in the appconfig table. |
|
108 | + */ |
|
109 | + public function getApps() { |
|
110 | + $this->loadConfigValues(); |
|
111 | + |
|
112 | + return $this->getSortedKeys($this->cache); |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * Get the available keys for an app |
|
117 | + * |
|
118 | + * @param string $app the app we are looking for |
|
119 | + * @return array an array of key names |
|
120 | + * |
|
121 | + * This function gets all keys of an app. Please note that the values are |
|
122 | + * not returned. |
|
123 | + */ |
|
124 | + public function getKeys($app) { |
|
125 | + $this->loadConfigValues(); |
|
126 | + |
|
127 | + if (isset($this->cache[$app])) { |
|
128 | + return $this->getSortedKeys($this->cache[$app]); |
|
129 | + } |
|
130 | + |
|
131 | + return []; |
|
132 | + } |
|
133 | + |
|
134 | + public function getSortedKeys($data) { |
|
135 | + $keys = array_keys($data); |
|
136 | + sort($keys); |
|
137 | + return $keys; |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * Gets the config value |
|
142 | + * |
|
143 | + * @param string $app app |
|
144 | + * @param string $key key |
|
145 | + * @param string $default = null, default value if the key does not exist |
|
146 | + * @return string the value or $default |
|
147 | + * |
|
148 | + * This function gets a value from the appconfig table. If the key does |
|
149 | + * not exist the default value will be returned |
|
150 | + */ |
|
151 | + public function getValue($app, $key, $default = null) { |
|
152 | + $this->loadConfigValues(); |
|
153 | + |
|
154 | + if ($this->hasKey($app, $key)) { |
|
155 | + return $this->cache[$app][$key]; |
|
156 | + } |
|
157 | + |
|
158 | + return $default; |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * check if a key is set in the appconfig |
|
163 | + * |
|
164 | + * @param string $app |
|
165 | + * @param string $key |
|
166 | + * @return bool |
|
167 | + */ |
|
168 | + public function hasKey($app, $key) { |
|
169 | + $this->loadConfigValues(); |
|
170 | + |
|
171 | + return isset($this->cache[$app][$key]); |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * Sets a value. If the key did not exist before it will be created. |
|
176 | + * |
|
177 | + * @param string $app app |
|
178 | + * @param string $key key |
|
179 | + * @param string|float|int $value value |
|
180 | + * @return bool True if the value was inserted or updated, false if the value was the same |
|
181 | + */ |
|
182 | + public function setValue($app, $key, $value) { |
|
183 | + if (!$this->hasKey($app, $key)) { |
|
184 | + $inserted = (bool) $this->conn->insertIfNotExist('*PREFIX*appconfig', [ |
|
185 | + 'appid' => $app, |
|
186 | + 'configkey' => $key, |
|
187 | + 'configvalue' => $value, |
|
188 | + ], [ |
|
189 | + 'appid', |
|
190 | + 'configkey', |
|
191 | + ]); |
|
192 | + |
|
193 | + if ($inserted) { |
|
194 | + if (!isset($this->cache[$app])) { |
|
195 | + $this->cache[$app] = []; |
|
196 | + } |
|
197 | + |
|
198 | + $this->cache[$app][$key] = $value; |
|
199 | + return true; |
|
200 | + } |
|
201 | + } |
|
202 | + |
|
203 | + $sql = $this->conn->getQueryBuilder(); |
|
204 | + $sql->update('appconfig') |
|
205 | + ->set('configvalue', $sql->createNamedParameter($value)) |
|
206 | + ->where($sql->expr()->eq('appid', $sql->createNamedParameter($app))) |
|
207 | + ->andWhere($sql->expr()->eq('configkey', $sql->createNamedParameter($key))); |
|
208 | + |
|
209 | + /* |
|
210 | 210 | * Only limit to the existing value for non-Oracle DBs: |
211 | 211 | * http://docs.oracle.com/cd/E11882_01/server.112/e26088/conditions002.htm#i1033286 |
212 | 212 | * > Large objects (LOBs) are not supported in comparison conditions. |
213 | 213 | */ |
214 | - if (!($this->conn instanceof OracleConnection)) { |
|
214 | + if (!($this->conn instanceof OracleConnection)) { |
|
215 | 215 | |
216 | - /* |
|
216 | + /* |
|
217 | 217 | * Only update the value when it is not the same |
218 | 218 | * Note that NULL requires some special handling. Since comparing |
219 | 219 | * against null can have special results. |
220 | 220 | */ |
221 | 221 | |
222 | - if ($value === null) { |
|
223 | - $sql->andWhere( |
|
224 | - $sql->expr()->isNotNull('configvalue') |
|
225 | - ); |
|
226 | - } else { |
|
227 | - $sql->andWhere( |
|
228 | - $sql->expr()->orX( |
|
229 | - $sql->expr()->isNull('configvalue'), |
|
230 | - $sql->expr()->neq('configvalue', $sql->createNamedParameter($value)) |
|
231 | - ) |
|
232 | - ); |
|
233 | - } |
|
234 | - } |
|
235 | - |
|
236 | - $changedRow = (bool) $sql->execute(); |
|
237 | - |
|
238 | - $this->cache[$app][$key] = $value; |
|
239 | - |
|
240 | - return $changedRow; |
|
241 | - } |
|
242 | - |
|
243 | - /** |
|
244 | - * Deletes a key |
|
245 | - * |
|
246 | - * @param string $app app |
|
247 | - * @param string $key key |
|
248 | - * @return boolean |
|
249 | - */ |
|
250 | - public function deleteKey($app, $key) { |
|
251 | - $this->loadConfigValues(); |
|
252 | - |
|
253 | - $sql = $this->conn->getQueryBuilder(); |
|
254 | - $sql->delete('appconfig') |
|
255 | - ->where($sql->expr()->eq('appid', $sql->createParameter('app'))) |
|
256 | - ->andWhere($sql->expr()->eq('configkey', $sql->createParameter('configkey'))) |
|
257 | - ->setParameter('app', $app) |
|
258 | - ->setParameter('configkey', $key); |
|
259 | - $sql->execute(); |
|
260 | - |
|
261 | - unset($this->cache[$app][$key]); |
|
262 | - return false; |
|
263 | - } |
|
264 | - |
|
265 | - /** |
|
266 | - * Remove app from appconfig |
|
267 | - * |
|
268 | - * @param string $app app |
|
269 | - * @return boolean |
|
270 | - * |
|
271 | - * Removes all keys in appconfig belonging to the app. |
|
272 | - */ |
|
273 | - public function deleteApp($app) { |
|
274 | - $this->loadConfigValues(); |
|
275 | - |
|
276 | - $sql = $this->conn->getQueryBuilder(); |
|
277 | - $sql->delete('appconfig') |
|
278 | - ->where($sql->expr()->eq('appid', $sql->createParameter('app'))) |
|
279 | - ->setParameter('app', $app); |
|
280 | - $sql->execute(); |
|
281 | - |
|
282 | - unset($this->cache[$app]); |
|
283 | - return false; |
|
284 | - } |
|
285 | - |
|
286 | - /** |
|
287 | - * get multiple values, either the app or key can be used as wildcard by setting it to false |
|
288 | - * |
|
289 | - * @param string|false $app |
|
290 | - * @param string|false $key |
|
291 | - * @return array|false |
|
292 | - */ |
|
293 | - public function getValues($app, $key) { |
|
294 | - if (($app !== false) === ($key !== false)) { |
|
295 | - return false; |
|
296 | - } |
|
297 | - |
|
298 | - if ($key === false) { |
|
299 | - return $this->getAppValues($app); |
|
300 | - } else { |
|
301 | - $appIds = $this->getApps(); |
|
302 | - $values = array_map(function ($appId) use ($key) { |
|
303 | - return isset($this->cache[$appId][$key]) ? $this->cache[$appId][$key] : null; |
|
304 | - }, $appIds); |
|
305 | - $result = array_combine($appIds, $values); |
|
306 | - |
|
307 | - return array_filter($result); |
|
308 | - } |
|
309 | - } |
|
310 | - |
|
311 | - /** |
|
312 | - * get all values of the app or and filters out sensitive data |
|
313 | - * |
|
314 | - * @param string $app |
|
315 | - * @return array |
|
316 | - */ |
|
317 | - public function getFilteredValues($app) { |
|
318 | - $values = $this->getValues($app, false); |
|
319 | - |
|
320 | - if (isset($this->sensitiveValues[$app])) { |
|
321 | - foreach ($this->sensitiveValues[$app] as $sensitiveKeyExp) { |
|
322 | - $sensitiveKeys = preg_grep($sensitiveKeyExp, array_keys($values)); |
|
323 | - foreach ($sensitiveKeys as $sensitiveKey) { |
|
324 | - $values[$sensitiveKey] = IConfig::SENSITIVE_VALUE; |
|
325 | - } |
|
326 | - } |
|
327 | - } |
|
328 | - |
|
329 | - return $values; |
|
330 | - } |
|
331 | - |
|
332 | - /** |
|
333 | - * Load all the app config values |
|
334 | - */ |
|
335 | - protected function loadConfigValues() { |
|
336 | - if ($this->configLoaded) { |
|
337 | - return; |
|
338 | - } |
|
339 | - |
|
340 | - $this->cache = []; |
|
341 | - |
|
342 | - $sql = $this->conn->getQueryBuilder(); |
|
343 | - $sql->select('*') |
|
344 | - ->from('appconfig'); |
|
345 | - $result = $sql->execute(); |
|
346 | - |
|
347 | - // we are going to store the result in memory anyway |
|
348 | - $rows = $result->fetchAll(); |
|
349 | - foreach ($rows as $row) { |
|
350 | - if (!isset($this->cache[$row['appid']])) { |
|
351 | - $this->cache[$row['appid']] = []; |
|
352 | - } |
|
353 | - |
|
354 | - $this->cache[$row['appid']][$row['configkey']] = $row['configvalue']; |
|
355 | - } |
|
356 | - $result->closeCursor(); |
|
357 | - |
|
358 | - $this->configLoaded = true; |
|
359 | - } |
|
360 | - |
|
361 | - /** |
|
362 | - * Clear all the cached app config values |
|
363 | - * |
|
364 | - * WARNING: do not use this - this is only for usage with the SCSSCacher to |
|
365 | - * clear the memory cache of the app config |
|
366 | - */ |
|
367 | - public function clearCachedConfig() { |
|
368 | - $this->configLoaded = false; |
|
369 | - } |
|
222 | + if ($value === null) { |
|
223 | + $sql->andWhere( |
|
224 | + $sql->expr()->isNotNull('configvalue') |
|
225 | + ); |
|
226 | + } else { |
|
227 | + $sql->andWhere( |
|
228 | + $sql->expr()->orX( |
|
229 | + $sql->expr()->isNull('configvalue'), |
|
230 | + $sql->expr()->neq('configvalue', $sql->createNamedParameter($value)) |
|
231 | + ) |
|
232 | + ); |
|
233 | + } |
|
234 | + } |
|
235 | + |
|
236 | + $changedRow = (bool) $sql->execute(); |
|
237 | + |
|
238 | + $this->cache[$app][$key] = $value; |
|
239 | + |
|
240 | + return $changedRow; |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * Deletes a key |
|
245 | + * |
|
246 | + * @param string $app app |
|
247 | + * @param string $key key |
|
248 | + * @return boolean |
|
249 | + */ |
|
250 | + public function deleteKey($app, $key) { |
|
251 | + $this->loadConfigValues(); |
|
252 | + |
|
253 | + $sql = $this->conn->getQueryBuilder(); |
|
254 | + $sql->delete('appconfig') |
|
255 | + ->where($sql->expr()->eq('appid', $sql->createParameter('app'))) |
|
256 | + ->andWhere($sql->expr()->eq('configkey', $sql->createParameter('configkey'))) |
|
257 | + ->setParameter('app', $app) |
|
258 | + ->setParameter('configkey', $key); |
|
259 | + $sql->execute(); |
|
260 | + |
|
261 | + unset($this->cache[$app][$key]); |
|
262 | + return false; |
|
263 | + } |
|
264 | + |
|
265 | + /** |
|
266 | + * Remove app from appconfig |
|
267 | + * |
|
268 | + * @param string $app app |
|
269 | + * @return boolean |
|
270 | + * |
|
271 | + * Removes all keys in appconfig belonging to the app. |
|
272 | + */ |
|
273 | + public function deleteApp($app) { |
|
274 | + $this->loadConfigValues(); |
|
275 | + |
|
276 | + $sql = $this->conn->getQueryBuilder(); |
|
277 | + $sql->delete('appconfig') |
|
278 | + ->where($sql->expr()->eq('appid', $sql->createParameter('app'))) |
|
279 | + ->setParameter('app', $app); |
|
280 | + $sql->execute(); |
|
281 | + |
|
282 | + unset($this->cache[$app]); |
|
283 | + return false; |
|
284 | + } |
|
285 | + |
|
286 | + /** |
|
287 | + * get multiple values, either the app or key can be used as wildcard by setting it to false |
|
288 | + * |
|
289 | + * @param string|false $app |
|
290 | + * @param string|false $key |
|
291 | + * @return array|false |
|
292 | + */ |
|
293 | + public function getValues($app, $key) { |
|
294 | + if (($app !== false) === ($key !== false)) { |
|
295 | + return false; |
|
296 | + } |
|
297 | + |
|
298 | + if ($key === false) { |
|
299 | + return $this->getAppValues($app); |
|
300 | + } else { |
|
301 | + $appIds = $this->getApps(); |
|
302 | + $values = array_map(function ($appId) use ($key) { |
|
303 | + return isset($this->cache[$appId][$key]) ? $this->cache[$appId][$key] : null; |
|
304 | + }, $appIds); |
|
305 | + $result = array_combine($appIds, $values); |
|
306 | + |
|
307 | + return array_filter($result); |
|
308 | + } |
|
309 | + } |
|
310 | + |
|
311 | + /** |
|
312 | + * get all values of the app or and filters out sensitive data |
|
313 | + * |
|
314 | + * @param string $app |
|
315 | + * @return array |
|
316 | + */ |
|
317 | + public function getFilteredValues($app) { |
|
318 | + $values = $this->getValues($app, false); |
|
319 | + |
|
320 | + if (isset($this->sensitiveValues[$app])) { |
|
321 | + foreach ($this->sensitiveValues[$app] as $sensitiveKeyExp) { |
|
322 | + $sensitiveKeys = preg_grep($sensitiveKeyExp, array_keys($values)); |
|
323 | + foreach ($sensitiveKeys as $sensitiveKey) { |
|
324 | + $values[$sensitiveKey] = IConfig::SENSITIVE_VALUE; |
|
325 | + } |
|
326 | + } |
|
327 | + } |
|
328 | + |
|
329 | + return $values; |
|
330 | + } |
|
331 | + |
|
332 | + /** |
|
333 | + * Load all the app config values |
|
334 | + */ |
|
335 | + protected function loadConfigValues() { |
|
336 | + if ($this->configLoaded) { |
|
337 | + return; |
|
338 | + } |
|
339 | + |
|
340 | + $this->cache = []; |
|
341 | + |
|
342 | + $sql = $this->conn->getQueryBuilder(); |
|
343 | + $sql->select('*') |
|
344 | + ->from('appconfig'); |
|
345 | + $result = $sql->execute(); |
|
346 | + |
|
347 | + // we are going to store the result in memory anyway |
|
348 | + $rows = $result->fetchAll(); |
|
349 | + foreach ($rows as $row) { |
|
350 | + if (!isset($this->cache[$row['appid']])) { |
|
351 | + $this->cache[$row['appid']] = []; |
|
352 | + } |
|
353 | + |
|
354 | + $this->cache[$row['appid']][$row['configkey']] = $row['configvalue']; |
|
355 | + } |
|
356 | + $result->closeCursor(); |
|
357 | + |
|
358 | + $this->configLoaded = true; |
|
359 | + } |
|
360 | + |
|
361 | + /** |
|
362 | + * Clear all the cached app config values |
|
363 | + * |
|
364 | + * WARNING: do not use this - this is only for usage with the SCSSCacher to |
|
365 | + * clear the memory cache of the app config |
|
366 | + */ |
|
367 | + public function clearCachedConfig() { |
|
368 | + $this->configLoaded = false; |
|
369 | + } |
|
370 | 370 | } |
@@ -28,51 +28,51 @@ |
||
28 | 28 | |
29 | 29 | class MoveUpdaterStepFile implements IRepairStep { |
30 | 30 | |
31 | - /** @var \OCP\IConfig */ |
|
32 | - protected $config; |
|
31 | + /** @var \OCP\IConfig */ |
|
32 | + protected $config; |
|
33 | 33 | |
34 | - /** |
|
35 | - * @param \OCP\IConfig $config |
|
36 | - */ |
|
37 | - public function __construct($config) { |
|
38 | - $this->config = $config; |
|
39 | - } |
|
34 | + /** |
|
35 | + * @param \OCP\IConfig $config |
|
36 | + */ |
|
37 | + public function __construct($config) { |
|
38 | + $this->config = $config; |
|
39 | + } |
|
40 | 40 | |
41 | - public function getName() { |
|
42 | - return 'Move .step file of updater to backup location'; |
|
43 | - } |
|
41 | + public function getName() { |
|
42 | + return 'Move .step file of updater to backup location'; |
|
43 | + } |
|
44 | 44 | |
45 | - public function run(IOutput $output) { |
|
46 | - $dataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data'); |
|
47 | - $instanceId = $this->config->getSystemValue('instanceid', null); |
|
45 | + public function run(IOutput $output) { |
|
46 | + $dataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data'); |
|
47 | + $instanceId = $this->config->getSystemValue('instanceid', null); |
|
48 | 48 | |
49 | - if (!is_string($instanceId) || empty($instanceId)) { |
|
50 | - return; |
|
51 | - } |
|
49 | + if (!is_string($instanceId) || empty($instanceId)) { |
|
50 | + return; |
|
51 | + } |
|
52 | 52 | |
53 | - $updaterFolderPath = $dataDir . '/updater-' . $instanceId; |
|
54 | - $stepFile = $updaterFolderPath . '/.step'; |
|
55 | - if (file_exists($stepFile)) { |
|
56 | - $output->info('.step file exists'); |
|
53 | + $updaterFolderPath = $dataDir . '/updater-' . $instanceId; |
|
54 | + $stepFile = $updaterFolderPath . '/.step'; |
|
55 | + if (file_exists($stepFile)) { |
|
56 | + $output->info('.step file exists'); |
|
57 | 57 | |
58 | - $previousStepFile = $updaterFolderPath . '/.step-previous-update'; |
|
58 | + $previousStepFile = $updaterFolderPath . '/.step-previous-update'; |
|
59 | 59 | |
60 | - // cleanup |
|
61 | - if (file_exists($previousStepFile)) { |
|
62 | - if (\OC_Helper::rmdirr($previousStepFile)) { |
|
63 | - $output->info('.step-previous-update removed'); |
|
64 | - } else { |
|
65 | - $output->info('.step-previous-update can\'t be removed - abort move of .step file'); |
|
66 | - return; |
|
67 | - } |
|
68 | - } |
|
60 | + // cleanup |
|
61 | + if (file_exists($previousStepFile)) { |
|
62 | + if (\OC_Helper::rmdirr($previousStepFile)) { |
|
63 | + $output->info('.step-previous-update removed'); |
|
64 | + } else { |
|
65 | + $output->info('.step-previous-update can\'t be removed - abort move of .step file'); |
|
66 | + return; |
|
67 | + } |
|
68 | + } |
|
69 | 69 | |
70 | - // move step file |
|
71 | - if (rename($stepFile, $previousStepFile)) { |
|
72 | - $output->info('.step file moved to .step-previous-update'); |
|
73 | - } else { |
|
74 | - $output->warning('.step file can\'t be moved'); |
|
75 | - } |
|
76 | - } |
|
77 | - } |
|
70 | + // move step file |
|
71 | + if (rename($stepFile, $previousStepFile)) { |
|
72 | + $output->info('.step file moved to .step-previous-update'); |
|
73 | + } else { |
|
74 | + $output->warning('.step file can\'t be moved'); |
|
75 | + } |
|
76 | + } |
|
77 | + } |
|
78 | 78 | } |
@@ -43,19 +43,19 @@ |
||
43 | 43 | } |
44 | 44 | |
45 | 45 | public function run(IOutput $output) { |
46 | - $dataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data'); |
|
46 | + $dataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data'); |
|
47 | 47 | $instanceId = $this->config->getSystemValue('instanceid', null); |
48 | 48 | |
49 | 49 | if (!is_string($instanceId) || empty($instanceId)) { |
50 | 50 | return; |
51 | 51 | } |
52 | 52 | |
53 | - $updaterFolderPath = $dataDir . '/updater-' . $instanceId; |
|
54 | - $stepFile = $updaterFolderPath . '/.step'; |
|
53 | + $updaterFolderPath = $dataDir.'/updater-'.$instanceId; |
|
54 | + $stepFile = $updaterFolderPath.'/.step'; |
|
55 | 55 | if (file_exists($stepFile)) { |
56 | 56 | $output->info('.step file exists'); |
57 | 57 | |
58 | - $previousStepFile = $updaterFolderPath . '/.step-previous-update'; |
|
58 | + $previousStepFile = $updaterFolderPath.'/.step-previous-update'; |
|
59 | 59 | |
60 | 60 | // cleanup |
61 | 61 | if (file_exists($previousStepFile)) { |
@@ -53,7 +53,7 @@ |
||
53 | 53 | public function sort($a, $b) { |
54 | 54 | if (!isset($a[$this->key]) || !isset($b[$this->key])) { |
55 | 55 | if (!is_null($this->log)) { |
56 | - $this->log->error('Sharing dialogue: cannot sort due to ' . |
|
56 | + $this->log->error('Sharing dialogue: cannot sort due to '. |
|
57 | 57 | 'missing array key', ['app' => 'core']); |
58 | 58 | } |
59 | 59 | return 0; |
@@ -29,50 +29,50 @@ |
||
29 | 29 | use OCP\ILogger; |
30 | 30 | |
31 | 31 | class SearchResultSorter { |
32 | - private $search; |
|
33 | - private $encoding; |
|
34 | - private $key; |
|
35 | - private $log; |
|
32 | + private $search; |
|
33 | + private $encoding; |
|
34 | + private $key; |
|
35 | + private $log; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @param string $search the search term as was given by the user |
|
39 | - * @param string $key the array key containing the value that should be compared |
|
40 | - * against |
|
41 | - * @param string $encoding optional, encoding to use, defaults to UTF-8 |
|
42 | - * @param ILogger $log optional |
|
43 | - */ |
|
44 | - public function __construct($search, $key, ILogger $log = null, $encoding = 'UTF-8') { |
|
45 | - $this->encoding = $encoding; |
|
46 | - $this->key = $key; |
|
47 | - $this->log = $log; |
|
48 | - $this->search = mb_strtolower($search, $this->encoding); |
|
49 | - } |
|
37 | + /** |
|
38 | + * @param string $search the search term as was given by the user |
|
39 | + * @param string $key the array key containing the value that should be compared |
|
40 | + * against |
|
41 | + * @param string $encoding optional, encoding to use, defaults to UTF-8 |
|
42 | + * @param ILogger $log optional |
|
43 | + */ |
|
44 | + public function __construct($search, $key, ILogger $log = null, $encoding = 'UTF-8') { |
|
45 | + $this->encoding = $encoding; |
|
46 | + $this->key = $key; |
|
47 | + $this->log = $log; |
|
48 | + $this->search = mb_strtolower($search, $this->encoding); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * User and Group names matching the search term at the beginning shall appear |
|
53 | - * on top of the share dialog. Following entries in alphabetical order. |
|
54 | - * Callback function for usort. http://php.net/usort |
|
55 | - */ |
|
56 | - public function sort($a, $b) { |
|
57 | - if (!isset($a[$this->key]) || !isset($b[$this->key])) { |
|
58 | - if (!is_null($this->log)) { |
|
59 | - $this->log->error('Sharing dialogue: cannot sort due to ' . |
|
60 | - 'missing array key', ['app' => 'core']); |
|
61 | - } |
|
62 | - return 0; |
|
63 | - } |
|
64 | - $nameA = mb_strtolower($a[$this->key], $this->encoding); |
|
65 | - $nameB = mb_strtolower($b[$this->key], $this->encoding); |
|
66 | - $i = mb_strpos($nameA, $this->search, 0, $this->encoding); |
|
67 | - $j = mb_strpos($nameB, $this->search, 0, $this->encoding); |
|
51 | + /** |
|
52 | + * User and Group names matching the search term at the beginning shall appear |
|
53 | + * on top of the share dialog. Following entries in alphabetical order. |
|
54 | + * Callback function for usort. http://php.net/usort |
|
55 | + */ |
|
56 | + public function sort($a, $b) { |
|
57 | + if (!isset($a[$this->key]) || !isset($b[$this->key])) { |
|
58 | + if (!is_null($this->log)) { |
|
59 | + $this->log->error('Sharing dialogue: cannot sort due to ' . |
|
60 | + 'missing array key', ['app' => 'core']); |
|
61 | + } |
|
62 | + return 0; |
|
63 | + } |
|
64 | + $nameA = mb_strtolower($a[$this->key], $this->encoding); |
|
65 | + $nameB = mb_strtolower($b[$this->key], $this->encoding); |
|
66 | + $i = mb_strpos($nameA, $this->search, 0, $this->encoding); |
|
67 | + $j = mb_strpos($nameB, $this->search, 0, $this->encoding); |
|
68 | 68 | |
69 | - if ($i === $j || $i > 0 && $j > 0) { |
|
70 | - return strcmp(mb_strtolower($nameA, $this->encoding), |
|
71 | - mb_strtolower($nameB, $this->encoding)); |
|
72 | - } elseif ($i === 0) { |
|
73 | - return -1; |
|
74 | - } else { |
|
75 | - return 1; |
|
76 | - } |
|
77 | - } |
|
69 | + if ($i === $j || $i > 0 && $j > 0) { |
|
70 | + return strcmp(mb_strtolower($nameA, $this->encoding), |
|
71 | + mb_strtolower($nameB, $this->encoding)); |
|
72 | + } elseif ($i === 0) { |
|
73 | + return -1; |
|
74 | + } else { |
|
75 | + return 1; |
|
76 | + } |
|
77 | + } |
|
78 | 78 | } |
@@ -60,7 +60,7 @@ |
||
60 | 60 | $capabilities = array_replace_recursive($capabilities, $c->getCapabilities()); |
61 | 61 | } |
62 | 62 | } else { |
63 | - throw new \InvalidArgumentException('The given Capability (' . get_class($c) . ') does not implement the ICapability interface'); |
|
63 | + throw new \InvalidArgumentException('The given Capability ('.get_class($c).') does not implement the ICapability interface'); |
|
64 | 64 | } |
65 | 65 | } |
66 | 66 |
@@ -36,58 +36,58 @@ |
||
36 | 36 | |
37 | 37 | class CapabilitiesManager { |
38 | 38 | |
39 | - /** @var \Closure[] */ |
|
40 | - private $capabilities = []; |
|
39 | + /** @var \Closure[] */ |
|
40 | + private $capabilities = []; |
|
41 | 41 | |
42 | - /** @var ILogger */ |
|
43 | - private $logger; |
|
42 | + /** @var ILogger */ |
|
43 | + private $logger; |
|
44 | 44 | |
45 | - public function __construct(ILogger $logger) { |
|
46 | - $this->logger = $logger; |
|
47 | - } |
|
45 | + public function __construct(ILogger $logger) { |
|
46 | + $this->logger = $logger; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Get an array of al the capabilities that are registered at this manager |
|
51 | - * |
|
52 | - * @param bool $public get public capabilities only |
|
53 | - * @throws \InvalidArgumentException |
|
54 | - * @return array |
|
55 | - */ |
|
56 | - public function getCapabilities(bool $public = false) : array { |
|
57 | - $capabilities = []; |
|
58 | - foreach ($this->capabilities as $capability) { |
|
59 | - try { |
|
60 | - $c = $capability(); |
|
61 | - } catch (QueryException $e) { |
|
62 | - $this->logger->logException($e, [ |
|
63 | - 'message' => 'CapabilitiesManager', |
|
64 | - 'level' => ILogger::ERROR, |
|
65 | - 'app' => 'core', |
|
66 | - ]); |
|
67 | - continue; |
|
68 | - } |
|
49 | + /** |
|
50 | + * Get an array of al the capabilities that are registered at this manager |
|
51 | + * |
|
52 | + * @param bool $public get public capabilities only |
|
53 | + * @throws \InvalidArgumentException |
|
54 | + * @return array |
|
55 | + */ |
|
56 | + public function getCapabilities(bool $public = false) : array { |
|
57 | + $capabilities = []; |
|
58 | + foreach ($this->capabilities as $capability) { |
|
59 | + try { |
|
60 | + $c = $capability(); |
|
61 | + } catch (QueryException $e) { |
|
62 | + $this->logger->logException($e, [ |
|
63 | + 'message' => 'CapabilitiesManager', |
|
64 | + 'level' => ILogger::ERROR, |
|
65 | + 'app' => 'core', |
|
66 | + ]); |
|
67 | + continue; |
|
68 | + } |
|
69 | 69 | |
70 | - if ($c instanceof ICapability) { |
|
71 | - if (!$public || $c instanceof IPublicCapability) { |
|
72 | - $capabilities = array_replace_recursive($capabilities, $c->getCapabilities()); |
|
73 | - } |
|
74 | - } else { |
|
75 | - throw new \InvalidArgumentException('The given Capability (' . get_class($c) . ') does not implement the ICapability interface'); |
|
76 | - } |
|
77 | - } |
|
70 | + if ($c instanceof ICapability) { |
|
71 | + if (!$public || $c instanceof IPublicCapability) { |
|
72 | + $capabilities = array_replace_recursive($capabilities, $c->getCapabilities()); |
|
73 | + } |
|
74 | + } else { |
|
75 | + throw new \InvalidArgumentException('The given Capability (' . get_class($c) . ') does not implement the ICapability interface'); |
|
76 | + } |
|
77 | + } |
|
78 | 78 | |
79 | - return $capabilities; |
|
80 | - } |
|
79 | + return $capabilities; |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * In order to improve lazy loading a closure can be registered which will be called in case |
|
84 | - * capabilities are actually requested |
|
85 | - * |
|
86 | - * $callable has to return an instance of OCP\Capabilities\ICapability |
|
87 | - * |
|
88 | - * @param \Closure $callable |
|
89 | - */ |
|
90 | - public function registerCapability(\Closure $callable) { |
|
91 | - $this->capabilities[] = $callable; |
|
92 | - } |
|
82 | + /** |
|
83 | + * In order to improve lazy loading a closure can be registered which will be called in case |
|
84 | + * capabilities are actually requested |
|
85 | + * |
|
86 | + * $callable has to return an instance of OCP\Capabilities\ICapability |
|
87 | + * |
|
88 | + * @param \Closure $callable |
|
89 | + */ |
|
90 | + public function registerCapability(\Closure $callable) { |
|
91 | + $this->capabilities[] = $callable; |
|
92 | + } |
|
93 | 93 | } |