Passed
Push — master ( 6156a4...5d03b5 )
by Blizzz
14:08 queued 10s
created
lib/public/Group/Backend/IAddToGroupBackend.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -29,8 +29,8 @@
 block discarded – undo
29 29
  */
30 30
 interface IAddToGroupBackend {
31 31
 
32
-	/**
33
-	 * @since 14.0.0
34
-	 */
35
-	public function addToGroup(string $uid, string $gid): bool;
32
+    /**
33
+     * @since 14.0.0
34
+     */
35
+    public function addToGroup(string $uid, string $gid): bool;
36 36
 }
Please login to merge, or discard this patch.
lib/public/Group/Backend/IRemoveFromGroupBackend.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -29,8 +29,8 @@
 block discarded – undo
29 29
  */
30 30
 interface IRemoveFromGroupBackend {
31 31
 
32
-	/**
33
-	 * @since 14.0.0
34
-	 */
35
-	public function removeFromGroup(string $uid, string $gid);
32
+    /**
33
+     * @since 14.0.0
34
+     */
35
+    public function removeFromGroup(string $uid, string $gid);
36 36
 }
Please login to merge, or discard this patch.
lib/public/Group/Backend/ABackend.php 2 patches
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -31,37 +31,37 @@
 block discarded – undo
31 31
  */
32 32
 abstract class ABackend implements GroupInterface {
33 33
 
34
-	/**
35
-	 * @deprecated 14.0.0
36
-	 *
37
-	 * @param int $actions The action to check for
38
-	 * @return bool
39
-	 */
40
-	public function implementsActions($actions): bool {
41
-		$implements = 0;
34
+    /**
35
+     * @deprecated 14.0.0
36
+     *
37
+     * @param int $actions The action to check for
38
+     * @return bool
39
+     */
40
+    public function implementsActions($actions): bool {
41
+        $implements = 0;
42 42
 
43
-		if ($this instanceof IAddToGroupBackend) {
44
-			$implements |= GroupInterface::ADD_TO_GROUP;
45
-		}
46
-		if ($this instanceof ICountUsersBackend) {
47
-			$implements |= GroupInterface::COUNT_USERS;
48
-		}
49
-		if ($this instanceof ICreateGroupBackend) {
50
-			$implements |= GroupInterface::CREATE_GROUP;
51
-		}
52
-		if ($this instanceof IDeleteGroupBackend) {
53
-			$implements |= GroupInterface::DELETE_GROUP;
54
-		}
55
-		if ($this instanceof IGroupDetailsBackend) {
56
-			$implements |= GroupInterface::GROUP_DETAILS;
57
-		}
58
-		if ($this instanceof IIsAdminBackend) {
59
-			$implements |= GroupInterface::IS_ADMIN;
60
-		}
61
-		if ($this instanceof IRemoveFromGroupBackend) {
62
-			$implements |= GroupInterface::REMOVE_FROM_GOUP;
63
-		}
43
+        if ($this instanceof IAddToGroupBackend) {
44
+            $implements |= GroupInterface::ADD_TO_GROUP;
45
+        }
46
+        if ($this instanceof ICountUsersBackend) {
47
+            $implements |= GroupInterface::COUNT_USERS;
48
+        }
49
+        if ($this instanceof ICreateGroupBackend) {
50
+            $implements |= GroupInterface::CREATE_GROUP;
51
+        }
52
+        if ($this instanceof IDeleteGroupBackend) {
53
+            $implements |= GroupInterface::DELETE_GROUP;
54
+        }
55
+        if ($this instanceof IGroupDetailsBackend) {
56
+            $implements |= GroupInterface::GROUP_DETAILS;
57
+        }
58
+        if ($this instanceof IIsAdminBackend) {
59
+            $implements |= GroupInterface::IS_ADMIN;
60
+        }
61
+        if ($this instanceof IRemoveFromGroupBackend) {
62
+            $implements |= GroupInterface::REMOVE_FROM_GOUP;
63
+        }
64 64
 
65
-		return (bool)($actions & $implements);
66
-	}
65
+        return (bool)($actions & $implements);
66
+    }
67 67
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -62,6 +62,6 @@
 block discarded – undo
62 62
 			$implements |= GroupInterface::REMOVE_FROM_GOUP;
63 63
 		}
64 64
 
65
-		return (bool)($actions & $implements);
65
+		return (bool) ($actions & $implements);
66 66
 	}
67 67
 }
Please login to merge, or discard this patch.
lib/public/Group/Backend/IDeleteGroupBackend.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -29,8 +29,8 @@
 block discarded – undo
29 29
  */
30 30
 interface IDeleteGroupBackend {
31 31
 
32
-	/**
33
-	 * @since 14.0.0
34
-	 */
35
-	public function deleteGroup(string $gid): bool;
32
+    /**
33
+     * @since 14.0.0
34
+     */
35
+    public function deleteGroup(string $gid): bool;
36 36
 }
Please login to merge, or discard this patch.
apps/dav/lib/Direct/DirectFile.php 1 patch
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -32,79 +32,79 @@
 block discarded – undo
32 32
 use Sabre\DAV\IFile;
33 33
 
34 34
 class DirectFile implements IFile {
35
-	/** @var Direct */
36
-	private $direct;
35
+    /** @var Direct */
36
+    private $direct;
37 37
 
38
-	/** @var IRootFolder */
39
-	private $rootFolder;
38
+    /** @var IRootFolder */
39
+    private $rootFolder;
40 40
 
41
-	/** @var File */
42
-	private $file;
41
+    /** @var File */
42
+    private $file;
43 43
 
44
-	public function __construct(Direct $direct, IRootFolder $rootFolder) {
45
-		$this->direct = $direct;
46
-		$this->rootFolder = $rootFolder;
47
-	}
44
+    public function __construct(Direct $direct, IRootFolder $rootFolder) {
45
+        $this->direct = $direct;
46
+        $this->rootFolder = $rootFolder;
47
+    }
48 48
 
49
-	public function put($data) {
50
-		throw new Forbidden();
51
-	}
49
+    public function put($data) {
50
+        throw new Forbidden();
51
+    }
52 52
 
53
-	public function get() {
54
-		$this->getFile();
53
+    public function get() {
54
+        $this->getFile();
55 55
 
56
-		return $this->file->fopen('rb');
57
-	}
56
+        return $this->file->fopen('rb');
57
+    }
58 58
 
59
-	public function getContentType() {
60
-		$this->getFile();
59
+    public function getContentType() {
60
+        $this->getFile();
61 61
 
62
-		return $this->file->getMimeType();
63
-	}
62
+        return $this->file->getMimeType();
63
+    }
64 64
 
65
-	public function getETag() {
66
-		$this->getFile();
65
+    public function getETag() {
66
+        $this->getFile();
67 67
 
68
-		return $this->file->getEtag();
69
-	}
68
+        return $this->file->getEtag();
69
+    }
70 70
 
71
-	public function getSize() {
72
-		$this->getFile();
71
+    public function getSize() {
72
+        $this->getFile();
73 73
 
74
-		return $this->file->getSize();
75
-	}
74
+        return $this->file->getSize();
75
+    }
76 76
 
77
-	public function delete() {
78
-		throw new Forbidden();
79
-	}
77
+    public function delete() {
78
+        throw new Forbidden();
79
+    }
80 80
 
81
-	public function getName() {
82
-		return $this->direct->getToken();
83
-	}
81
+    public function getName() {
82
+        return $this->direct->getToken();
83
+    }
84 84
 
85
-	public function setName($name) {
86
-		throw new Forbidden();
87
-	}
85
+    public function setName($name) {
86
+        throw new Forbidden();
87
+    }
88 88
 
89
-	public function getLastModified() {
90
-		$this->getFile();
89
+    public function getLastModified() {
90
+        $this->getFile();
91 91
 
92
-		return $this->file->getMTime();
93
-	}
92
+        return $this->file->getMTime();
93
+    }
94 94
 
95
-	private function getFile() {
96
-		if ($this->file === null) {
97
-			$userFolder = $this->rootFolder->getUserFolder($this->direct->getUserId());
98
-			$files = $userFolder->getById($this->direct->getFileId());
95
+    private function getFile() {
96
+        if ($this->file === null) {
97
+            $userFolder = $this->rootFolder->getUserFolder($this->direct->getUserId());
98
+            $files = $userFolder->getById($this->direct->getFileId());
99 99
 
100
-			if ($files === []) {
101
-				throw new NotFound();
102
-			}
100
+            if ($files === []) {
101
+                throw new NotFound();
102
+            }
103 103
 
104
-			$this->file = array_shift($files);
105
-		}
104
+            $this->file = array_shift($files);
105
+        }
106 106
 
107
-		return $this->file;
108
-	}
107
+        return $this->file;
108
+    }
109 109
 
110 110
 }
Please login to merge, or discard this patch.
lib/private/Log.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -217,7 +217,7 @@
 block discarded – undo
217 217
 		// interpolate $message as defined in PSR-3
218 218
 		$replace = [];
219 219
 		foreach ($context as $key => $val) {
220
-			$replace['{' . $key . '}'] = $val;
220
+			$replace['{'.$key.'}'] = $val;
221 221
 		}
222 222
 		$message = strtr($message, $replace);
223 223
 
Please login to merge, or discard this patch.
Indentation   +321 added lines, -321 removed lines patch added patch discarded remove patch
@@ -57,325 +57,325 @@
 block discarded – undo
57 57
  */
58 58
 class Log implements ILogger, IDataLogger {
59 59
 
60
-	/** @var IWriter */
61
-	private $logger;
62
-
63
-	/** @var SystemConfig */
64
-	private $config;
65
-
66
-	/** @var boolean|null cache the result of the log condition check for the request */
67
-	private $logConditionSatisfied = null;
68
-
69
-	/** @var Normalizer */
70
-	private $normalizer;
71
-
72
-	/** @var IRegistry */
73
-	private $crashReporters;
74
-
75
-	/**
76
-	 * @param IWriter $logger The logger that should be used
77
-	 * @param SystemConfig $config the system config object
78
-	 * @param Normalizer|null $normalizer
79
-	 * @param IRegistry|null $registry
80
-	 */
81
-	public function __construct(IWriter $logger, SystemConfig $config = null, $normalizer = null, IRegistry $registry = null) {
82
-		// FIXME: Add this for backwards compatibility, should be fixed at some point probably
83
-		if ($config === null) {
84
-			$config = \OC::$server->getSystemConfig();
85
-		}
86
-
87
-		$this->config = $config;
88
-		$this->logger = $logger;
89
-		if ($normalizer === null) {
90
-			$this->normalizer = new Normalizer();
91
-		} else {
92
-			$this->normalizer = $normalizer;
93
-		}
94
-		$this->crashReporters = $registry;
95
-	}
96
-
97
-	/**
98
-	 * System is unusable.
99
-	 *
100
-	 * @param string $message
101
-	 * @param array $context
102
-	 * @return void
103
-	 */
104
-	public function emergency(string $message, array $context = []) {
105
-		$this->log(ILogger::FATAL, $message, $context);
106
-	}
107
-
108
-	/**
109
-	 * Action must be taken immediately.
110
-	 *
111
-	 * Example: Entire website down, database unavailable, etc. This should
112
-	 * trigger the SMS alerts and wake you up.
113
-	 *
114
-	 * @param string $message
115
-	 * @param array $context
116
-	 * @return void
117
-	 */
118
-	public function alert(string $message, array $context = []) {
119
-		$this->log(ILogger::ERROR, $message, $context);
120
-	}
121
-
122
-	/**
123
-	 * Critical conditions.
124
-	 *
125
-	 * Example: Application component unavailable, unexpected exception.
126
-	 *
127
-	 * @param string $message
128
-	 * @param array $context
129
-	 * @return void
130
-	 */
131
-	public function critical(string $message, array $context = []) {
132
-		$this->log(ILogger::ERROR, $message, $context);
133
-	}
134
-
135
-	/**
136
-	 * Runtime errors that do not require immediate action but should typically
137
-	 * be logged and monitored.
138
-	 *
139
-	 * @param string $message
140
-	 * @param array $context
141
-	 * @return void
142
-	 */
143
-	public function error(string $message, array $context = []) {
144
-		$this->log(ILogger::ERROR, $message, $context);
145
-	}
146
-
147
-	/**
148
-	 * Exceptional occurrences that are not errors.
149
-	 *
150
-	 * Example: Use of deprecated APIs, poor use of an API, undesirable things
151
-	 * that are not necessarily wrong.
152
-	 *
153
-	 * @param string $message
154
-	 * @param array $context
155
-	 * @return void
156
-	 */
157
-	public function warning(string $message, array $context = []) {
158
-		$this->log(ILogger::WARN, $message, $context);
159
-	}
160
-
161
-	/**
162
-	 * Normal but significant events.
163
-	 *
164
-	 * @param string $message
165
-	 * @param array $context
166
-	 * @return void
167
-	 */
168
-	public function notice(string $message, array $context = []) {
169
-		$this->log(ILogger::INFO, $message, $context);
170
-	}
171
-
172
-	/**
173
-	 * Interesting events.
174
-	 *
175
-	 * Example: User logs in, SQL logs.
176
-	 *
177
-	 * @param string $message
178
-	 * @param array $context
179
-	 * @return void
180
-	 */
181
-	public function info(string $message, array $context = []) {
182
-		$this->log(ILogger::INFO, $message, $context);
183
-	}
184
-
185
-	/**
186
-	 * Detailed debug information.
187
-	 *
188
-	 * @param string $message
189
-	 * @param array $context
190
-	 * @return void
191
-	 */
192
-	public function debug(string $message, array $context = []) {
193
-		$this->log(ILogger::DEBUG, $message, $context);
194
-	}
195
-
196
-
197
-	/**
198
-	 * Logs with an arbitrary level.
199
-	 *
200
-	 * @param int $level
201
-	 * @param string $message
202
-	 * @param array $context
203
-	 * @return void
204
-	 */
205
-	public function log(int $level, string $message, array $context = []) {
206
-		$minLevel = $this->getLogLevel($context);
207
-
208
-		array_walk($context, [$this->normalizer, 'format']);
209
-
210
-		$app = $context['app'] ?? 'no app in context';
211
-
212
-		// interpolate $message as defined in PSR-3
213
-		$replace = [];
214
-		foreach ($context as $key => $val) {
215
-			$replace['{' . $key . '}'] = $val;
216
-		}
217
-		$message = strtr($message, $replace);
218
-
219
-		try {
220
-			if ($level >= $minLevel) {
221
-				$this->writeLog($app, $message, $level);
222
-
223
-				if ($this->crashReporters !== null) {
224
-					$messageContext = array_merge(
225
-						$context,
226
-						[
227
-							'level' => $level
228
-						]
229
-					);
230
-					$this->crashReporters->delegateMessage($message, $messageContext);
231
-				}
232
-			} else {
233
-				if ($this->crashReporters !== null) {
234
-					$this->crashReporters->delegateBreadcrumb($message, 'log', $context);
235
-				}
236
-			}
237
-		} catch (\Throwable $e) {
238
-			// make sure we dont hard crash if logging fails
239
-		}
240
-	}
241
-
242
-	private function getLogLevel($context) {
243
-		$logCondition = $this->config->getValue('log.condition', []);
244
-
245
-		/**
246
-		 * check for a special log condition - this enables an increased log on
247
-		 * a per request/user base
248
-		 */
249
-		if ($this->logConditionSatisfied === null) {
250
-			// default to false to just process this once per request
251
-			$this->logConditionSatisfied = false;
252
-			if (!empty($logCondition)) {
253
-
254
-				// check for secret token in the request
255
-				if (isset($logCondition['shared_secret'])) {
256
-					$request = \OC::$server->getRequest();
257
-
258
-					if ($request->getMethod() === 'PUT' &&
259
-						strpos($request->getHeader('Content-Type'), 'application/x-www-form-urlencoded') === false &&
260
-						strpos($request->getHeader('Content-Type'), 'application/json') === false) {
261
-						$logSecretRequest = '';
262
-					} else {
263
-						$logSecretRequest = $request->getParam('log_secret', '');
264
-					}
265
-
266
-					// if token is found in the request change set the log condition to satisfied
267
-					if ($request && hash_equals($logCondition['shared_secret'], $logSecretRequest)) {
268
-						$this->logConditionSatisfied = true;
269
-					}
270
-				}
271
-
272
-				// check for user
273
-				if (isset($logCondition['users'])) {
274
-					$user = \OC::$server->getUserSession()->getUser();
275
-
276
-					// if the user matches set the log condition to satisfied
277
-					if ($user !== null && in_array($user->getUID(), $logCondition['users'], true)) {
278
-						$this->logConditionSatisfied = true;
279
-					}
280
-				}
281
-			}
282
-		}
283
-
284
-		// if log condition is satisfied change the required log level to DEBUG
285
-		if ($this->logConditionSatisfied) {
286
-			return ILogger::DEBUG;
287
-		}
288
-
289
-		if (isset($context['app'])) {
290
-			$app = $context['app'];
291
-
292
-			/**
293
-			 * check log condition based on the context of each log message
294
-			 * once this is met -> change the required log level to debug
295
-			 */
296
-			if (!empty($logCondition)
297
-				&& isset($logCondition['apps'])
298
-				&& in_array($app, $logCondition['apps'], true)) {
299
-				return ILogger::DEBUG;
300
-			}
301
-		}
302
-
303
-		return min($this->config->getValue('loglevel', ILogger::WARN), ILogger::FATAL);
304
-	}
305
-
306
-	/**
307
-	 * Logs an exception very detailed
308
-	 *
309
-	 * @param \Exception|\Throwable $exception
310
-	 * @param array $context
311
-	 * @return void
312
-	 * @since 8.2.0
313
-	 */
314
-	public function logException(\Throwable $exception, array $context = []) {
315
-		$app = $context['app'] ?? 'no app in context';
316
-		$level = $context['level'] ?? ILogger::ERROR;
317
-
318
-		$serializer = new ExceptionSerializer();
319
-		$data = $serializer->serializeException($exception);
320
-		$data['CustomMessage'] = $context['message'] ?? '--';
321
-
322
-		$minLevel = $this->getLogLevel($context);
323
-
324
-		array_walk($context, [$this->normalizer, 'format']);
325
-
326
-		try {
327
-			if ($level >= $minLevel) {
328
-				if (!$this->logger instanceof IFileBased) {
329
-					$data = json_encode($data, JSON_PARTIAL_OUTPUT_ON_ERROR | JSON_UNESCAPED_SLASHES);
330
-				}
331
-				$this->writeLog($app, $data, $level);
332
-			}
333
-
334
-			$context['level'] = $level;
335
-			if (!is_null($this->crashReporters)) {
336
-				$this->crashReporters->delegateReport($exception, $context);
337
-			}
338
-		} catch (\Throwable $e) {
339
-			// make sure we dont hard crash if logging fails
340
-		}
341
-	}
342
-
343
-	public function logData(string $message, array $data, array $context = []): void {
344
-		$app = $context['app'] ?? 'no app in context';
345
-		$level = $context['level'] ?? ILogger::ERROR;
346
-
347
-		$minLevel = $this->getLogLevel($context);
348
-
349
-		array_walk($context, [$this->normalizer, 'format']);
350
-
351
-		try {
352
-			if ($level >= $minLevel) {
353
-				$data['message'] = $message;
354
-				if (!$this->logger instanceof IFileBased) {
355
-					$data = json_encode($data, JSON_PARTIAL_OUTPUT_ON_ERROR | JSON_UNESCAPED_SLASHES);
356
-				}
357
-				$this->writeLog($app, $data, $level);
358
-			}
359
-
360
-			$context['level'] = $level;
361
-		} catch (\Throwable $e) {
362
-			// make sure we dont hard crash if logging fails
363
-		}
364
-	}
365
-
366
-	/**
367
-	 * @param string $app
368
-	 * @param string|array $entry
369
-	 * @param int $level
370
-	 */
371
-	protected function writeLog(string $app, $entry, int $level) {
372
-		$this->logger->write($app, $entry, $level);
373
-	}
374
-
375
-	public function getLogPath():string {
376
-		if ($this->logger instanceof IFileBased) {
377
-			return $this->logger->getLogFilePath();
378
-		}
379
-		throw new \RuntimeException('Log implementation has no path');
380
-	}
60
+    /** @var IWriter */
61
+    private $logger;
62
+
63
+    /** @var SystemConfig */
64
+    private $config;
65
+
66
+    /** @var boolean|null cache the result of the log condition check for the request */
67
+    private $logConditionSatisfied = null;
68
+
69
+    /** @var Normalizer */
70
+    private $normalizer;
71
+
72
+    /** @var IRegistry */
73
+    private $crashReporters;
74
+
75
+    /**
76
+     * @param IWriter $logger The logger that should be used
77
+     * @param SystemConfig $config the system config object
78
+     * @param Normalizer|null $normalizer
79
+     * @param IRegistry|null $registry
80
+     */
81
+    public function __construct(IWriter $logger, SystemConfig $config = null, $normalizer = null, IRegistry $registry = null) {
82
+        // FIXME: Add this for backwards compatibility, should be fixed at some point probably
83
+        if ($config === null) {
84
+            $config = \OC::$server->getSystemConfig();
85
+        }
86
+
87
+        $this->config = $config;
88
+        $this->logger = $logger;
89
+        if ($normalizer === null) {
90
+            $this->normalizer = new Normalizer();
91
+        } else {
92
+            $this->normalizer = $normalizer;
93
+        }
94
+        $this->crashReporters = $registry;
95
+    }
96
+
97
+    /**
98
+     * System is unusable.
99
+     *
100
+     * @param string $message
101
+     * @param array $context
102
+     * @return void
103
+     */
104
+    public function emergency(string $message, array $context = []) {
105
+        $this->log(ILogger::FATAL, $message, $context);
106
+    }
107
+
108
+    /**
109
+     * Action must be taken immediately.
110
+     *
111
+     * Example: Entire website down, database unavailable, etc. This should
112
+     * trigger the SMS alerts and wake you up.
113
+     *
114
+     * @param string $message
115
+     * @param array $context
116
+     * @return void
117
+     */
118
+    public function alert(string $message, array $context = []) {
119
+        $this->log(ILogger::ERROR, $message, $context);
120
+    }
121
+
122
+    /**
123
+     * Critical conditions.
124
+     *
125
+     * Example: Application component unavailable, unexpected exception.
126
+     *
127
+     * @param string $message
128
+     * @param array $context
129
+     * @return void
130
+     */
131
+    public function critical(string $message, array $context = []) {
132
+        $this->log(ILogger::ERROR, $message, $context);
133
+    }
134
+
135
+    /**
136
+     * Runtime errors that do not require immediate action but should typically
137
+     * be logged and monitored.
138
+     *
139
+     * @param string $message
140
+     * @param array $context
141
+     * @return void
142
+     */
143
+    public function error(string $message, array $context = []) {
144
+        $this->log(ILogger::ERROR, $message, $context);
145
+    }
146
+
147
+    /**
148
+     * Exceptional occurrences that are not errors.
149
+     *
150
+     * Example: Use of deprecated APIs, poor use of an API, undesirable things
151
+     * that are not necessarily wrong.
152
+     *
153
+     * @param string $message
154
+     * @param array $context
155
+     * @return void
156
+     */
157
+    public function warning(string $message, array $context = []) {
158
+        $this->log(ILogger::WARN, $message, $context);
159
+    }
160
+
161
+    /**
162
+     * Normal but significant events.
163
+     *
164
+     * @param string $message
165
+     * @param array $context
166
+     * @return void
167
+     */
168
+    public function notice(string $message, array $context = []) {
169
+        $this->log(ILogger::INFO, $message, $context);
170
+    }
171
+
172
+    /**
173
+     * Interesting events.
174
+     *
175
+     * Example: User logs in, SQL logs.
176
+     *
177
+     * @param string $message
178
+     * @param array $context
179
+     * @return void
180
+     */
181
+    public function info(string $message, array $context = []) {
182
+        $this->log(ILogger::INFO, $message, $context);
183
+    }
184
+
185
+    /**
186
+     * Detailed debug information.
187
+     *
188
+     * @param string $message
189
+     * @param array $context
190
+     * @return void
191
+     */
192
+    public function debug(string $message, array $context = []) {
193
+        $this->log(ILogger::DEBUG, $message, $context);
194
+    }
195
+
196
+
197
+    /**
198
+     * Logs with an arbitrary level.
199
+     *
200
+     * @param int $level
201
+     * @param string $message
202
+     * @param array $context
203
+     * @return void
204
+     */
205
+    public function log(int $level, string $message, array $context = []) {
206
+        $minLevel = $this->getLogLevel($context);
207
+
208
+        array_walk($context, [$this->normalizer, 'format']);
209
+
210
+        $app = $context['app'] ?? 'no app in context';
211
+
212
+        // interpolate $message as defined in PSR-3
213
+        $replace = [];
214
+        foreach ($context as $key => $val) {
215
+            $replace['{' . $key . '}'] = $val;
216
+        }
217
+        $message = strtr($message, $replace);
218
+
219
+        try {
220
+            if ($level >= $minLevel) {
221
+                $this->writeLog($app, $message, $level);
222
+
223
+                if ($this->crashReporters !== null) {
224
+                    $messageContext = array_merge(
225
+                        $context,
226
+                        [
227
+                            'level' => $level
228
+                        ]
229
+                    );
230
+                    $this->crashReporters->delegateMessage($message, $messageContext);
231
+                }
232
+            } else {
233
+                if ($this->crashReporters !== null) {
234
+                    $this->crashReporters->delegateBreadcrumb($message, 'log', $context);
235
+                }
236
+            }
237
+        } catch (\Throwable $e) {
238
+            // make sure we dont hard crash if logging fails
239
+        }
240
+    }
241
+
242
+    private function getLogLevel($context) {
243
+        $logCondition = $this->config->getValue('log.condition', []);
244
+
245
+        /**
246
+         * check for a special log condition - this enables an increased log on
247
+         * a per request/user base
248
+         */
249
+        if ($this->logConditionSatisfied === null) {
250
+            // default to false to just process this once per request
251
+            $this->logConditionSatisfied = false;
252
+            if (!empty($logCondition)) {
253
+
254
+                // check for secret token in the request
255
+                if (isset($logCondition['shared_secret'])) {
256
+                    $request = \OC::$server->getRequest();
257
+
258
+                    if ($request->getMethod() === 'PUT' &&
259
+                        strpos($request->getHeader('Content-Type'), 'application/x-www-form-urlencoded') === false &&
260
+                        strpos($request->getHeader('Content-Type'), 'application/json') === false) {
261
+                        $logSecretRequest = '';
262
+                    } else {
263
+                        $logSecretRequest = $request->getParam('log_secret', '');
264
+                    }
265
+
266
+                    // if token is found in the request change set the log condition to satisfied
267
+                    if ($request && hash_equals($logCondition['shared_secret'], $logSecretRequest)) {
268
+                        $this->logConditionSatisfied = true;
269
+                    }
270
+                }
271
+
272
+                // check for user
273
+                if (isset($logCondition['users'])) {
274
+                    $user = \OC::$server->getUserSession()->getUser();
275
+
276
+                    // if the user matches set the log condition to satisfied
277
+                    if ($user !== null && in_array($user->getUID(), $logCondition['users'], true)) {
278
+                        $this->logConditionSatisfied = true;
279
+                    }
280
+                }
281
+            }
282
+        }
283
+
284
+        // if log condition is satisfied change the required log level to DEBUG
285
+        if ($this->logConditionSatisfied) {
286
+            return ILogger::DEBUG;
287
+        }
288
+
289
+        if (isset($context['app'])) {
290
+            $app = $context['app'];
291
+
292
+            /**
293
+             * check log condition based on the context of each log message
294
+             * once this is met -> change the required log level to debug
295
+             */
296
+            if (!empty($logCondition)
297
+                && isset($logCondition['apps'])
298
+                && in_array($app, $logCondition['apps'], true)) {
299
+                return ILogger::DEBUG;
300
+            }
301
+        }
302
+
303
+        return min($this->config->getValue('loglevel', ILogger::WARN), ILogger::FATAL);
304
+    }
305
+
306
+    /**
307
+     * Logs an exception very detailed
308
+     *
309
+     * @param \Exception|\Throwable $exception
310
+     * @param array $context
311
+     * @return void
312
+     * @since 8.2.0
313
+     */
314
+    public function logException(\Throwable $exception, array $context = []) {
315
+        $app = $context['app'] ?? 'no app in context';
316
+        $level = $context['level'] ?? ILogger::ERROR;
317
+
318
+        $serializer = new ExceptionSerializer();
319
+        $data = $serializer->serializeException($exception);
320
+        $data['CustomMessage'] = $context['message'] ?? '--';
321
+
322
+        $minLevel = $this->getLogLevel($context);
323
+
324
+        array_walk($context, [$this->normalizer, 'format']);
325
+
326
+        try {
327
+            if ($level >= $minLevel) {
328
+                if (!$this->logger instanceof IFileBased) {
329
+                    $data = json_encode($data, JSON_PARTIAL_OUTPUT_ON_ERROR | JSON_UNESCAPED_SLASHES);
330
+                }
331
+                $this->writeLog($app, $data, $level);
332
+            }
333
+
334
+            $context['level'] = $level;
335
+            if (!is_null($this->crashReporters)) {
336
+                $this->crashReporters->delegateReport($exception, $context);
337
+            }
338
+        } catch (\Throwable $e) {
339
+            // make sure we dont hard crash if logging fails
340
+        }
341
+    }
342
+
343
+    public function logData(string $message, array $data, array $context = []): void {
344
+        $app = $context['app'] ?? 'no app in context';
345
+        $level = $context['level'] ?? ILogger::ERROR;
346
+
347
+        $minLevel = $this->getLogLevel($context);
348
+
349
+        array_walk($context, [$this->normalizer, 'format']);
350
+
351
+        try {
352
+            if ($level >= $minLevel) {
353
+                $data['message'] = $message;
354
+                if (!$this->logger instanceof IFileBased) {
355
+                    $data = json_encode($data, JSON_PARTIAL_OUTPUT_ON_ERROR | JSON_UNESCAPED_SLASHES);
356
+                }
357
+                $this->writeLog($app, $data, $level);
358
+            }
359
+
360
+            $context['level'] = $level;
361
+        } catch (\Throwable $e) {
362
+            // make sure we dont hard crash if logging fails
363
+        }
364
+    }
365
+
366
+    /**
367
+     * @param string $app
368
+     * @param string|array $entry
369
+     * @param int $level
370
+     */
371
+    protected function writeLog(string $app, $entry, int $level) {
372
+        $this->logger->write($app, $entry, $level);
373
+    }
374
+
375
+    public function getLogPath():string {
376
+        if ($this->logger instanceof IFileBased) {
377
+            return $this->logger->getLogFilePath();
378
+        }
379
+        throw new \RuntimeException('Log implementation has no path');
380
+    }
381 381
 }
Please login to merge, or discard this patch.
lib/public/SystemTag/SystemTagsEntityEvent.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@
 block discarded – undo
62 62
 	 */
63 63
 	public function addEntityCollection(string $name, \Closure $entityExistsFunction) {
64 64
 		if (isset($this->collections[$name])) {
65
-			throw new \OutOfBoundsException('Duplicate entity name "' . $name . '"');
65
+			throw new \OutOfBoundsException('Duplicate entity name "'.$name.'"');
66 66
 		}
67 67
 
68 68
 		$this->collections[$name] = $entityExistsFunction;
Please login to merge, or discard this patch.
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -36,46 +36,46 @@
 block discarded – undo
36 36
  * @since 9.1.0
37 37
  */
38 38
 class SystemTagsEntityEvent extends Event {
39
-	public const EVENT_ENTITY = 'OCP\SystemTag\ISystemTagManager::registerEntity';
39
+    public const EVENT_ENTITY = 'OCP\SystemTag\ISystemTagManager::registerEntity';
40 40
 
41
-	/** @var string */
42
-	protected $event;
43
-	/** @var \Closure[] */
44
-	protected $collections;
41
+    /** @var string */
42
+    protected $event;
43
+    /** @var \Closure[] */
44
+    protected $collections;
45 45
 
46
-	/**
47
-	 * SystemTagsEntityEvent constructor.
48
-	 *
49
-	 * @param string $event
50
-	 * @since 9.1.0
51
-	 */
52
-	public function __construct(string $event) {
53
-		$this->event = $event;
54
-		$this->collections = [];
55
-	}
46
+    /**
47
+     * SystemTagsEntityEvent constructor.
48
+     *
49
+     * @param string $event
50
+     * @since 9.1.0
51
+     */
52
+    public function __construct(string $event) {
53
+        $this->event = $event;
54
+        $this->collections = [];
55
+    }
56 56
 
57
-	/**
58
-	 * @param string $name
59
-	 * @param \Closure $entityExistsFunction The closure should take one
60
-	 *                 argument, which is the id of the entity, that tags
61
-	 *                 should be handled for. The return should then be bool,
62
-	 *                 depending on whether tags are allowed (true) or not.
63
-	 * @throws \OutOfBoundsException when the entity name is already taken
64
-	 * @since 9.1.0
65
-	 */
66
-	public function addEntityCollection(string $name, \Closure $entityExistsFunction) {
67
-		if (isset($this->collections[$name])) {
68
-			throw new \OutOfBoundsException('Duplicate entity name "' . $name . '"');
69
-		}
57
+    /**
58
+     * @param string $name
59
+     * @param \Closure $entityExistsFunction The closure should take one
60
+     *                 argument, which is the id of the entity, that tags
61
+     *                 should be handled for. The return should then be bool,
62
+     *                 depending on whether tags are allowed (true) or not.
63
+     * @throws \OutOfBoundsException when the entity name is already taken
64
+     * @since 9.1.0
65
+     */
66
+    public function addEntityCollection(string $name, \Closure $entityExistsFunction) {
67
+        if (isset($this->collections[$name])) {
68
+            throw new \OutOfBoundsException('Duplicate entity name "' . $name . '"');
69
+        }
70 70
 
71
-		$this->collections[$name] = $entityExistsFunction;
72
-	}
71
+        $this->collections[$name] = $entityExistsFunction;
72
+    }
73 73
 
74
-	/**
75
-	 * @return \Closure[]
76
-	 * @since 9.1.0
77
-	 */
78
-	public function getEntityCollections(): array {
79
-		return $this->collections;
80
-	}
74
+    /**
75
+     * @return \Closure[]
76
+     * @since 9.1.0
77
+     */
78
+    public function getEntityCollections(): array {
79
+        return $this->collections;
80
+    }
81 81
 }
Please login to merge, or discard this patch.
lib/private/Log/Errorlog.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -29,14 +29,14 @@
 block discarded – undo
29 29
 
30 30
 class Errorlog implements IWriter {
31 31
 
32
-	/**
33
-	 * write a message in the log
34
-	 * @param string $app
35
-	 * @param string $message
36
-	 * @param int $level
37
-	 */
38
-	public function write(string $app, $message, int $level) {
39
-		error_log('[owncloud]['.$app.']['.$level.'] '.$message);
40
-	}
32
+    /**
33
+     * write a message in the log
34
+     * @param string $app
35
+     * @param string $message
36
+     * @param int $level
37
+     */
38
+    public function write(string $app, $message, int $level) {
39
+        error_log('[owncloud]['.$app.']['.$level.'] '.$message);
40
+    }
41 41
 }
42 42
 
Please login to merge, or discard this patch.
lib/public/Log/IWriter.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -30,8 +30,8 @@
 block discarded – undo
30 30
  * @since 14.0.0
31 31
  */
32 32
 interface IWriter {
33
-	/**
34
-	 * @since 14.0.0
35
-	 */
36
-	public function write(string $app, $message, int $level);
33
+    /**
34
+     * @since 14.0.0
35
+     */
36
+    public function write(string $app, $message, int $level);
37 37
 }
Please login to merge, or discard this patch.