Passed
Push — master ( 323fe4...fd76ec )
by Roeland
21:10 queued 09:16
created
lib/public/Diagnostics/IEventLogger.php 1 patch
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -35,55 +35,55 @@
 block discarded – undo
35 35
  * @since 8.0.0
36 36
  */
37 37
 interface IEventLogger {
38
-	/**
39
-	 * Mark the start of an event setting its ID $id and providing event description $description.
40
-	 *
41
-	 * @param string $id
42
-	 * @param string $description
43
-	 * @since 8.0.0
44
-	 */
45
-	public function start($id, $description);
38
+    /**
39
+     * Mark the start of an event setting its ID $id and providing event description $description.
40
+     *
41
+     * @param string $id
42
+     * @param string $description
43
+     * @since 8.0.0
44
+     */
45
+    public function start($id, $description);
46 46
 
47
-	/**
48
-	 * Mark the end of an event with specific ID $id, marked by start() method.
49
-	 * Ending event should store \OCP\Diagnostics\IEvent to
50
-	 * be returned with getEvents() method.
51
-	 *
52
-	 * @param string $id
53
-	 * @since 8.0.0
54
-	 */
55
-	public function end($id);
47
+    /**
48
+     * Mark the end of an event with specific ID $id, marked by start() method.
49
+     * Ending event should store \OCP\Diagnostics\IEvent to
50
+     * be returned with getEvents() method.
51
+     *
52
+     * @param string $id
53
+     * @since 8.0.0
54
+     */
55
+    public function end($id);
56 56
 
57
-	/**
58
-	 * Mark the start and the end of an event with specific ID $id and description $description,
59
-	 * explicitly marking start and end of the event, represented by $start and $end timestamps.
60
-	 * Logging event should store \OCP\Diagnostics\IEvent to
61
-	 * be returned with getEvents() method.
62
-	 *
63
-	 * @param string $id
64
-	 * @param string $description
65
-	 * @param float $start
66
-	 * @param float $end
67
-	 * @since 8.0.0
68
-	 */
69
-	public function log($id, $description, $start, $end);
57
+    /**
58
+     * Mark the start and the end of an event with specific ID $id and description $description,
59
+     * explicitly marking start and end of the event, represented by $start and $end timestamps.
60
+     * Logging event should store \OCP\Diagnostics\IEvent to
61
+     * be returned with getEvents() method.
62
+     *
63
+     * @param string $id
64
+     * @param string $description
65
+     * @param float $start
66
+     * @param float $end
67
+     * @since 8.0.0
68
+     */
69
+    public function log($id, $description, $start, $end);
70 70
 
71
-	/**
72
-	 * This method should return all \OCP\Diagnostics\IEvent objects stored using
73
-	 * start()/end() or log() methods
74
-	 *
75
-	 * @return \OCP\Diagnostics\IEvent[]
76
-	 * @since 8.0.0
77
-	 */
78
-	public function getEvents();
71
+    /**
72
+     * This method should return all \OCP\Diagnostics\IEvent objects stored using
73
+     * start()/end() or log() methods
74
+     *
75
+     * @return \OCP\Diagnostics\IEvent[]
76
+     * @since 8.0.0
77
+     */
78
+    public function getEvents();
79 79
 
80
-	/**
81
-	 * Activate the module for the duration of the request. Deactivated module
82
-	 * does not create and store \OCP\Diagnostics\IEvent objects.
83
-	 * Only activated module should create and store objects to be
84
-	 * returned with getEvents() call.
85
-	 *
86
-	 * @since 12.0.0
87
-	 */
88
-	public function activate();
80
+    /**
81
+     * Activate the module for the duration of the request. Deactivated module
82
+     * does not create and store \OCP\Diagnostics\IEvent objects.
83
+     * Only activated module should create and store objects to be
84
+     * returned with getEvents() call.
85
+     *
86
+     * @since 12.0.0
87
+     */
88
+    public function activate();
89 89
 }
Please login to merge, or discard this patch.
lib/public/Diagnostics/IQuery.php 1 patch
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -30,38 +30,38 @@
 block discarded – undo
30 30
  * @since 8.0.0
31 31
  */
32 32
 interface IQuery {
33
-	/**
34
-	 * @return string
35
-	 * @since 8.0.0
36
-	 */
37
-	public function getSql();
33
+    /**
34
+     * @return string
35
+     * @since 8.0.0
36
+     */
37
+    public function getSql();
38 38
 
39
-	/**
40
-	 * @return array
41
-	 * @since 8.0.0
42
-	 */
43
-	public function getParams();
39
+    /**
40
+     * @return array
41
+     * @since 8.0.0
42
+     */
43
+    public function getParams();
44 44
 
45
-	/**
46
-	 * @return float
47
-	 * @since 8.0.0
48
-	 */
49
-	public function getDuration();
45
+    /**
46
+     * @return float
47
+     * @since 8.0.0
48
+     */
49
+    public function getDuration();
50 50
 
51
-	/**
52
-	 * @return float
53
-	 * @since 11.0.0
54
-	 */
55
-	public function getStartTime();
51
+    /**
52
+     * @return float
53
+     * @since 11.0.0
54
+     */
55
+    public function getStartTime();
56 56
 
57
-	/**
58
-	 * @return array
59
-	 * @since 11.0.0
60
-	 */
61
-	public function getStacktrace();
62
-	/**
63
-	 * @return array
64
-	 * @since 12.0.0
65
-	 */
66
-	public function getStart();
57
+    /**
58
+     * @return array
59
+     * @since 11.0.0
60
+     */
61
+    public function getStacktrace();
62
+    /**
63
+     * @return array
64
+     * @since 12.0.0
65
+     */
66
+    public function getStart();
67 67
 }
Please login to merge, or discard this patch.
lib/private/DB/Connection.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 			return parent::connect();
59 59
 		} catch (DBALException $e) {
60 60
 			// throw a new exception to prevent leaking info from the stacktrace
61
-			throw new DBALException('Failed to connect to the database: ' . $e->getMessage(), $e->getCode());
61
+			throw new DBALException('Failed to connect to the database: '.$e->getMessage(), $e->getCode());
62 62
 		}
63 63
 	}
64 64
 
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 		// 0 is the method where we use `getCallerBacktrace`
111 111
 		// 1 is the target method which uses the method we want to log
112 112
 		if (isset($traces[1])) {
113
-			return $traces[1]['file'] . ':' . $traces[1]['line'];
113
+			return $traces[1]['file'].':'.$traces[1]['line'];
114 114
 		}
115 115
 
116 116
 		return '';
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 	 * @param int $offset
157 157
 	 * @return \Doctrine\DBAL\Driver\Statement The prepared statement.
158 158
 	 */
159
-	public function prepare( $statement, $limit=null, $offset=null ) {
159
+	public function prepare($statement, $limit = null, $offset = null) {
160 160
 		if ($limit === -1) {
161 161
 			$limit = null;
162 162
 		}
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
 			throw new \BadMethodCallException('Can not lock a new table until the previous lock is released.');
322 322
 		}
323 323
 
324
-		$tableName = $this->tablePrefix . $tableName;
324
+		$tableName = $this->tablePrefix.$tableName;
325 325
 		$this->lockedTable = $tableName;
326 326
 		$this->adapter->lockTable($tableName);
327 327
 	}
@@ -342,11 +342,11 @@  discard block
 block discarded – undo
342 342
 	 * @return string
343 343
 	 */
344 344
 	public function getError() {
345
-		$msg = $this->errorCode() . ': ';
345
+		$msg = $this->errorCode().': ';
346 346
 		$errorInfo = $this->errorInfo();
347 347
 		if (is_array($errorInfo)) {
348
-			$msg .= 'SQLSTATE = '.$errorInfo[0] . ', ';
349
-			$msg .= 'Driver Code = '.$errorInfo[1] . ', ';
348
+			$msg .= 'SQLSTATE = '.$errorInfo[0].', ';
349
+			$msg .= 'Driver Code = '.$errorInfo[1].', ';
350 350
 			$msg .= 'Driver Message = '.$errorInfo[2];
351 351
 		}
352 352
 		return $msg;
@@ -358,9 +358,9 @@  discard block
 block discarded – undo
358 358
 	 * @param string $table table name without the prefix
359 359
 	 */
360 360
 	public function dropTable($table) {
361
-		$table = $this->tablePrefix . trim($table);
361
+		$table = $this->tablePrefix.trim($table);
362 362
 		$schema = $this->getSchemaManager();
363
-		if($schema->tablesExist(array($table))) {
363
+		if ($schema->tablesExist(array($table))) {
364 364
 			$schema->dropTable($table);
365 365
 		}
366 366
 	}
@@ -371,8 +371,8 @@  discard block
 block discarded – undo
371 371
 	 * @param string $table table name without the prefix
372 372
 	 * @return bool
373 373
 	 */
374
-	public function tableExists($table){
375
-		$table = $this->tablePrefix . trim($table);
374
+	public function tableExists($table) {
375
+		$table = $this->tablePrefix.trim($table);
376 376
 		$schema = $this->getSchemaManager();
377 377
 		return $schema->tablesExist(array($table));
378 378
 	}
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
 	 * @return string
384 384
 	 */
385 385
 	protected function replaceTablePrefix($statement) {
386
-		return str_replace( '*PREFIX*', $this->tablePrefix, $statement );
386
+		return str_replace('*PREFIX*', $this->tablePrefix, $statement);
387 387
 	}
388 388
 
389 389
 	/**
Please login to merge, or discard this patch.
Indentation   +408 added lines, -408 removed lines patch added patch discarded remove patch
@@ -45,412 +45,412 @@
 block discarded – undo
45 45
 use OCP\PreConditionNotMetException;
46 46
 
47 47
 class Connection extends ReconnectWrapper implements IDBConnection {
48
-	/**
49
-	 * @var string $tablePrefix
50
-	 */
51
-	protected $tablePrefix;
52
-
53
-	/**
54
-	 * @var \OC\DB\Adapter $adapter
55
-	 */
56
-	protected $adapter;
57
-
58
-	protected $lockedTable = null;
59
-
60
-	public function connect() {
61
-		try {
62
-			return parent::connect();
63
-		} catch (DBALException $e) {
64
-			// throw a new exception to prevent leaking info from the stacktrace
65
-			throw new DBALException('Failed to connect to the database: ' . $e->getMessage(), $e->getCode());
66
-		}
67
-	}
68
-
69
-	/**
70
-	 * Returns a QueryBuilder for the connection.
71
-	 *
72
-	 * @return \OCP\DB\QueryBuilder\IQueryBuilder
73
-	 */
74
-	public function getQueryBuilder() {
75
-		return new QueryBuilder(
76
-			$this,
77
-			\OC::$server->getSystemConfig(),
78
-			\OC::$server->getLogger()
79
-		);
80
-	}
81
-
82
-	/**
83
-	 * Gets the QueryBuilder for the connection.
84
-	 *
85
-	 * @return \Doctrine\DBAL\Query\QueryBuilder
86
-	 * @deprecated please use $this->getQueryBuilder() instead
87
-	 */
88
-	public function createQueryBuilder() {
89
-		$backtrace = $this->getCallerBacktrace();
90
-		\OC::$server->getLogger()->debug('Doctrine QueryBuilder retrieved in {backtrace}', ['app' => 'core', 'backtrace' => $backtrace]);
91
-		return parent::createQueryBuilder();
92
-	}
93
-
94
-	/**
95
-	 * Gets the ExpressionBuilder for the connection.
96
-	 *
97
-	 * @return \Doctrine\DBAL\Query\Expression\ExpressionBuilder
98
-	 * @deprecated please use $this->getQueryBuilder()->expr() instead
99
-	 */
100
-	public function getExpressionBuilder() {
101
-		$backtrace = $this->getCallerBacktrace();
102
-		\OC::$server->getLogger()->debug('Doctrine ExpressionBuilder retrieved in {backtrace}', ['app' => 'core', 'backtrace' => $backtrace]);
103
-		return parent::getExpressionBuilder();
104
-	}
105
-
106
-	/**
107
-	 * Get the file and line that called the method where `getCallerBacktrace()` was used
108
-	 *
109
-	 * @return string
110
-	 */
111
-	protected function getCallerBacktrace() {
112
-		$traces = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
113
-
114
-		// 0 is the method where we use `getCallerBacktrace`
115
-		// 1 is the target method which uses the method we want to log
116
-		if (isset($traces[1])) {
117
-			return $traces[1]['file'] . ':' . $traces[1]['line'];
118
-		}
119
-
120
-		return '';
121
-	}
122
-
123
-	/**
124
-	 * @return string
125
-	 */
126
-	public function getPrefix() {
127
-		return $this->tablePrefix;
128
-	}
129
-
130
-	/**
131
-	 * Initializes a new instance of the Connection class.
132
-	 *
133
-	 * @param array $params  The connection parameters.
134
-	 * @param \Doctrine\DBAL\Driver $driver
135
-	 * @param \Doctrine\DBAL\Configuration $config
136
-	 * @param \Doctrine\Common\EventManager $eventManager
137
-	 * @throws \Exception
138
-	 */
139
-	public function __construct(array $params, Driver $driver, Configuration $config = null,
140
-		EventManager $eventManager = null)
141
-	{
142
-		if (!isset($params['adapter'])) {
143
-			throw new \Exception('adapter not set');
144
-		}
145
-		if (!isset($params['tablePrefix'])) {
146
-			throw new \Exception('tablePrefix not set');
147
-		}
148
-		parent::__construct($params, $driver, $config, $eventManager);
149
-		$this->adapter = new $params['adapter']($this);
150
-		$this->tablePrefix = $params['tablePrefix'];
151
-
152
-		$this->setTransactionIsolation(TransactionIsolationLevel::READ_COMMITTED);
153
-	}
154
-
155
-	/**
156
-	 * Prepares an SQL statement.
157
-	 *
158
-	 * @param string $statement The SQL statement to prepare.
159
-	 * @param int $limit
160
-	 * @param int $offset
161
-	 * @return \Doctrine\DBAL\Driver\Statement The prepared statement.
162
-	 */
163
-	public function prepare( $statement, $limit=null, $offset=null ) {
164
-		if ($limit === -1) {
165
-			$limit = null;
166
-		}
167
-		if (!is_null($limit)) {
168
-			$platform = $this->getDatabasePlatform();
169
-			$statement = $platform->modifyLimitQuery($statement, $limit, $offset);
170
-		}
171
-		$statement = $this->replaceTablePrefix($statement);
172
-		$statement = $this->adapter->fixupStatement($statement);
173
-
174
-		return parent::prepare($statement);
175
-	}
176
-
177
-	/**
178
-	 * Executes an, optionally parametrized, SQL query.
179
-	 *
180
-	 * If the query is parametrized, a prepared statement is used.
181
-	 * If an SQLLogger is configured, the execution is logged.
182
-	 *
183
-	 * @param string                                      $query  The SQL query to execute.
184
-	 * @param array                                       $params The parameters to bind to the query, if any.
185
-	 * @param array                                       $types  The types the previous parameters are in.
186
-	 * @param \Doctrine\DBAL\Cache\QueryCacheProfile|null $qcp    The query cache profile, optional.
187
-	 *
188
-	 * @return \Doctrine\DBAL\Driver\Statement The executed statement.
189
-	 *
190
-	 * @throws \Doctrine\DBAL\DBALException
191
-	 */
192
-	public function executeQuery($query, array $params = array(), $types = array(), QueryCacheProfile $qcp = null)
193
-	{
194
-		$query = $this->replaceTablePrefix($query);
195
-		$query = $this->adapter->fixupStatement($query);
196
-		return parent::executeQuery($query, $params, $types, $qcp);
197
-	}
198
-
199
-	/**
200
-	 * Executes an SQL INSERT/UPDATE/DELETE query with the given parameters
201
-	 * and returns the number of affected rows.
202
-	 *
203
-	 * This method supports PDO binding types as well as DBAL mapping types.
204
-	 *
205
-	 * @param string $query  The SQL query.
206
-	 * @param array  $params The query parameters.
207
-	 * @param array  $types  The parameter types.
208
-	 *
209
-	 * @return integer The number of affected rows.
210
-	 *
211
-	 * @throws \Doctrine\DBAL\DBALException
212
-	 */
213
-	public function executeUpdate($query, array $params = array(), array $types = array())
214
-	{
215
-		$query = $this->replaceTablePrefix($query);
216
-		$query = $this->adapter->fixupStatement($query);
217
-		return parent::executeUpdate($query, $params, $types);
218
-	}
219
-
220
-	/**
221
-	 * Returns the ID of the last inserted row, or the last value from a sequence object,
222
-	 * depending on the underlying driver.
223
-	 *
224
-	 * Note: This method may not return a meaningful or consistent result across different drivers,
225
-	 * because the underlying database may not even support the notion of AUTO_INCREMENT/IDENTITY
226
-	 * columns or sequences.
227
-	 *
228
-	 * @param string $seqName Name of the sequence object from which the ID should be returned.
229
-	 * @return string A string representation of the last inserted ID.
230
-	 */
231
-	public function lastInsertId($seqName = null) {
232
-		if ($seqName) {
233
-			$seqName = $this->replaceTablePrefix($seqName);
234
-		}
235
-		return $this->adapter->lastInsertId($seqName);
236
-	}
237
-
238
-	// internal use
239
-	public function realLastInsertId($seqName = null) {
240
-		return parent::lastInsertId($seqName);
241
-	}
242
-
243
-	/**
244
-	 * Insert a row if the matching row does not exists. To accomplish proper race condition avoidance
245
-	 * it is needed that there is also a unique constraint on the values. Then this method will
246
-	 * catch the exception and return 0.
247
-	 *
248
-	 * @param string $table The table name (will replace *PREFIX* with the actual prefix)
249
-	 * @param array $input data that should be inserted into the table  (column name => value)
250
-	 * @param array|null $compare List of values that should be checked for "if not exists"
251
-	 *				If this is null or an empty array, all keys of $input will be compared
252
-	 *				Please note: text fields (clob) must not be used in the compare array
253
-	 * @return int number of inserted rows
254
-	 * @throws \Doctrine\DBAL\DBALException
255
-	 * @deprecated 15.0.0 - use unique index and "try { $db->insert() } catch (UniqueConstraintViolationException $e) {}" instead, because it is more reliable and does not have the risk for deadlocks - see https://github.com/nextcloud/server/pull/12371
256
-	 */
257
-	public function insertIfNotExist($table, $input, array $compare = null) {
258
-		return $this->adapter->insertIfNotExist($table, $input, $compare);
259
-	}
260
-
261
-	public function insertIgnoreConflict(string $table, array $values) : int {
262
-		return $this->adapter->insertIgnoreConflict($table, $values);
263
-	}
264
-
265
-	private function getType($value) {
266
-		if (is_bool($value)) {
267
-			return IQueryBuilder::PARAM_BOOL;
268
-		} else if (is_int($value)) {
269
-			return IQueryBuilder::PARAM_INT;
270
-		} else {
271
-			return IQueryBuilder::PARAM_STR;
272
-		}
273
-	}
274
-
275
-	/**
276
-	 * Insert or update a row value
277
-	 *
278
-	 * @param string $table
279
-	 * @param array $keys (column name => value)
280
-	 * @param array $values (column name => value)
281
-	 * @param array $updatePreconditionValues ensure values match preconditions (column name => value)
282
-	 * @return int number of new rows
283
-	 * @throws \Doctrine\DBAL\DBALException
284
-	 * @throws PreConditionNotMetException
285
-	 * @suppress SqlInjectionChecker
286
-	 */
287
-	public function setValues($table, array $keys, array $values, array $updatePreconditionValues = []) {
288
-		try {
289
-			$insertQb = $this->getQueryBuilder();
290
-			$insertQb->insert($table)
291
-				->values(
292
-					array_map(function($value) use ($insertQb) {
293
-						return $insertQb->createNamedParameter($value, $this->getType($value));
294
-					}, array_merge($keys, $values))
295
-				);
296
-			return $insertQb->execute();
297
-		} catch (ConstraintViolationException $e) {
298
-			// value already exists, try update
299
-			$updateQb = $this->getQueryBuilder();
300
-			$updateQb->update($table);
301
-			foreach ($values as $name => $value) {
302
-				$updateQb->set($name, $updateQb->createNamedParameter($value, $this->getType($value)));
303
-			}
304
-			$where = $updateQb->expr()->andX();
305
-			$whereValues = array_merge($keys, $updatePreconditionValues);
306
-			foreach ($whereValues as $name => $value) {
307
-				$where->add($updateQb->expr()->eq(
308
-					$name,
309
-					$updateQb->createNamedParameter($value, $this->getType($value)),
310
-					$this->getType($value)
311
-				));
312
-			}
313
-			$updateQb->where($where);
314
-			$affected = $updateQb->execute();
315
-
316
-			if ($affected === 0 && !empty($updatePreconditionValues)) {
317
-				throw new PreConditionNotMetException();
318
-			}
319
-
320
-			return 0;
321
-		}
322
-	}
323
-
324
-	/**
325
-	 * Create an exclusive read+write lock on a table
326
-	 *
327
-	 * @param string $tableName
328
-	 * @throws \BadMethodCallException When trying to acquire a second lock
329
-	 * @since 9.1.0
330
-	 */
331
-	public function lockTable($tableName) {
332
-		if ($this->lockedTable !== null) {
333
-			throw new \BadMethodCallException('Can not lock a new table until the previous lock is released.');
334
-		}
335
-
336
-		$tableName = $this->tablePrefix . $tableName;
337
-		$this->lockedTable = $tableName;
338
-		$this->adapter->lockTable($tableName);
339
-	}
340
-
341
-	/**
342
-	 * Release a previous acquired lock again
343
-	 *
344
-	 * @since 9.1.0
345
-	 */
346
-	public function unlockTable() {
347
-		$this->adapter->unlockTable();
348
-		$this->lockedTable = null;
349
-	}
350
-
351
-	/**
352
-	 * returns the error code and message as a string for logging
353
-	 * works with DoctrineException
354
-	 * @return string
355
-	 */
356
-	public function getError() {
357
-		$msg = $this->errorCode() . ': ';
358
-		$errorInfo = $this->errorInfo();
359
-		if (is_array($errorInfo)) {
360
-			$msg .= 'SQLSTATE = '.$errorInfo[0] . ', ';
361
-			$msg .= 'Driver Code = '.$errorInfo[1] . ', ';
362
-			$msg .= 'Driver Message = '.$errorInfo[2];
363
-		}
364
-		return $msg;
365
-	}
366
-
367
-	/**
368
-	 * Drop a table from the database if it exists
369
-	 *
370
-	 * @param string $table table name without the prefix
371
-	 */
372
-	public function dropTable($table) {
373
-		$table = $this->tablePrefix . trim($table);
374
-		$schema = $this->getSchemaManager();
375
-		if($schema->tablesExist(array($table))) {
376
-			$schema->dropTable($table);
377
-		}
378
-	}
379
-
380
-	/**
381
-	 * Check if a table exists
382
-	 *
383
-	 * @param string $table table name without the prefix
384
-	 * @return bool
385
-	 */
386
-	public function tableExists($table){
387
-		$table = $this->tablePrefix . trim($table);
388
-		$schema = $this->getSchemaManager();
389
-		return $schema->tablesExist(array($table));
390
-	}
391
-
392
-	// internal use
393
-	/**
394
-	 * @param string $statement
395
-	 * @return string
396
-	 */
397
-	protected function replaceTablePrefix($statement) {
398
-		return str_replace( '*PREFIX*', $this->tablePrefix, $statement );
399
-	}
400
-
401
-	/**
402
-	 * Check if a transaction is active
403
-	 *
404
-	 * @return bool
405
-	 * @since 8.2.0
406
-	 */
407
-	public function inTransaction() {
408
-		return $this->getTransactionNestingLevel() > 0;
409
-	}
410
-
411
-	/**
412
-	 * Escape a parameter to be used in a LIKE query
413
-	 *
414
-	 * @param string $param
415
-	 * @return string
416
-	 */
417
-	public function escapeLikeParameter($param) {
418
-		return addcslashes($param, '\\_%');
419
-	}
420
-
421
-	/**
422
-	 * Check whether or not the current database support 4byte wide unicode
423
-	 *
424
-	 * @return bool
425
-	 * @since 11.0.0
426
-	 */
427
-	public function supports4ByteText() {
428
-		if (!$this->getDatabasePlatform() instanceof MySqlPlatform) {
429
-			return true;
430
-		}
431
-		return $this->getParams()['charset'] === 'utf8mb4';
432
-	}
433
-
434
-
435
-	/**
436
-	 * Create the schema of the connected database
437
-	 *
438
-	 * @return Schema
439
-	 */
440
-	public function createSchema() {
441
-		$schemaManager = new MDB2SchemaManager($this);
442
-		$migrator = $schemaManager->getMigrator();
443
-		return $migrator->createSchema();
444
-	}
445
-
446
-	/**
447
-	 * Migrate the database to the given schema
448
-	 *
449
-	 * @param Schema $toSchema
450
-	 */
451
-	public function migrateToSchema(Schema $toSchema) {
452
-		$schemaManager = new MDB2SchemaManager($this);
453
-		$migrator = $schemaManager->getMigrator();
454
-		$migrator->migrate($toSchema);
455
-	}
48
+    /**
49
+     * @var string $tablePrefix
50
+     */
51
+    protected $tablePrefix;
52
+
53
+    /**
54
+     * @var \OC\DB\Adapter $adapter
55
+     */
56
+    protected $adapter;
57
+
58
+    protected $lockedTable = null;
59
+
60
+    public function connect() {
61
+        try {
62
+            return parent::connect();
63
+        } catch (DBALException $e) {
64
+            // throw a new exception to prevent leaking info from the stacktrace
65
+            throw new DBALException('Failed to connect to the database: ' . $e->getMessage(), $e->getCode());
66
+        }
67
+    }
68
+
69
+    /**
70
+     * Returns a QueryBuilder for the connection.
71
+     *
72
+     * @return \OCP\DB\QueryBuilder\IQueryBuilder
73
+     */
74
+    public function getQueryBuilder() {
75
+        return new QueryBuilder(
76
+            $this,
77
+            \OC::$server->getSystemConfig(),
78
+            \OC::$server->getLogger()
79
+        );
80
+    }
81
+
82
+    /**
83
+     * Gets the QueryBuilder for the connection.
84
+     *
85
+     * @return \Doctrine\DBAL\Query\QueryBuilder
86
+     * @deprecated please use $this->getQueryBuilder() instead
87
+     */
88
+    public function createQueryBuilder() {
89
+        $backtrace = $this->getCallerBacktrace();
90
+        \OC::$server->getLogger()->debug('Doctrine QueryBuilder retrieved in {backtrace}', ['app' => 'core', 'backtrace' => $backtrace]);
91
+        return parent::createQueryBuilder();
92
+    }
93
+
94
+    /**
95
+     * Gets the ExpressionBuilder for the connection.
96
+     *
97
+     * @return \Doctrine\DBAL\Query\Expression\ExpressionBuilder
98
+     * @deprecated please use $this->getQueryBuilder()->expr() instead
99
+     */
100
+    public function getExpressionBuilder() {
101
+        $backtrace = $this->getCallerBacktrace();
102
+        \OC::$server->getLogger()->debug('Doctrine ExpressionBuilder retrieved in {backtrace}', ['app' => 'core', 'backtrace' => $backtrace]);
103
+        return parent::getExpressionBuilder();
104
+    }
105
+
106
+    /**
107
+     * Get the file and line that called the method where `getCallerBacktrace()` was used
108
+     *
109
+     * @return string
110
+     */
111
+    protected function getCallerBacktrace() {
112
+        $traces = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
113
+
114
+        // 0 is the method where we use `getCallerBacktrace`
115
+        // 1 is the target method which uses the method we want to log
116
+        if (isset($traces[1])) {
117
+            return $traces[1]['file'] . ':' . $traces[1]['line'];
118
+        }
119
+
120
+        return '';
121
+    }
122
+
123
+    /**
124
+     * @return string
125
+     */
126
+    public function getPrefix() {
127
+        return $this->tablePrefix;
128
+    }
129
+
130
+    /**
131
+     * Initializes a new instance of the Connection class.
132
+     *
133
+     * @param array $params  The connection parameters.
134
+     * @param \Doctrine\DBAL\Driver $driver
135
+     * @param \Doctrine\DBAL\Configuration $config
136
+     * @param \Doctrine\Common\EventManager $eventManager
137
+     * @throws \Exception
138
+     */
139
+    public function __construct(array $params, Driver $driver, Configuration $config = null,
140
+        EventManager $eventManager = null)
141
+    {
142
+        if (!isset($params['adapter'])) {
143
+            throw new \Exception('adapter not set');
144
+        }
145
+        if (!isset($params['tablePrefix'])) {
146
+            throw new \Exception('tablePrefix not set');
147
+        }
148
+        parent::__construct($params, $driver, $config, $eventManager);
149
+        $this->adapter = new $params['adapter']($this);
150
+        $this->tablePrefix = $params['tablePrefix'];
151
+
152
+        $this->setTransactionIsolation(TransactionIsolationLevel::READ_COMMITTED);
153
+    }
154
+
155
+    /**
156
+     * Prepares an SQL statement.
157
+     *
158
+     * @param string $statement The SQL statement to prepare.
159
+     * @param int $limit
160
+     * @param int $offset
161
+     * @return \Doctrine\DBAL\Driver\Statement The prepared statement.
162
+     */
163
+    public function prepare( $statement, $limit=null, $offset=null ) {
164
+        if ($limit === -1) {
165
+            $limit = null;
166
+        }
167
+        if (!is_null($limit)) {
168
+            $platform = $this->getDatabasePlatform();
169
+            $statement = $platform->modifyLimitQuery($statement, $limit, $offset);
170
+        }
171
+        $statement = $this->replaceTablePrefix($statement);
172
+        $statement = $this->adapter->fixupStatement($statement);
173
+
174
+        return parent::prepare($statement);
175
+    }
176
+
177
+    /**
178
+     * Executes an, optionally parametrized, SQL query.
179
+     *
180
+     * If the query is parametrized, a prepared statement is used.
181
+     * If an SQLLogger is configured, the execution is logged.
182
+     *
183
+     * @param string                                      $query  The SQL query to execute.
184
+     * @param array                                       $params The parameters to bind to the query, if any.
185
+     * @param array                                       $types  The types the previous parameters are in.
186
+     * @param \Doctrine\DBAL\Cache\QueryCacheProfile|null $qcp    The query cache profile, optional.
187
+     *
188
+     * @return \Doctrine\DBAL\Driver\Statement The executed statement.
189
+     *
190
+     * @throws \Doctrine\DBAL\DBALException
191
+     */
192
+    public function executeQuery($query, array $params = array(), $types = array(), QueryCacheProfile $qcp = null)
193
+    {
194
+        $query = $this->replaceTablePrefix($query);
195
+        $query = $this->adapter->fixupStatement($query);
196
+        return parent::executeQuery($query, $params, $types, $qcp);
197
+    }
198
+
199
+    /**
200
+     * Executes an SQL INSERT/UPDATE/DELETE query with the given parameters
201
+     * and returns the number of affected rows.
202
+     *
203
+     * This method supports PDO binding types as well as DBAL mapping types.
204
+     *
205
+     * @param string $query  The SQL query.
206
+     * @param array  $params The query parameters.
207
+     * @param array  $types  The parameter types.
208
+     *
209
+     * @return integer The number of affected rows.
210
+     *
211
+     * @throws \Doctrine\DBAL\DBALException
212
+     */
213
+    public function executeUpdate($query, array $params = array(), array $types = array())
214
+    {
215
+        $query = $this->replaceTablePrefix($query);
216
+        $query = $this->adapter->fixupStatement($query);
217
+        return parent::executeUpdate($query, $params, $types);
218
+    }
219
+
220
+    /**
221
+     * Returns the ID of the last inserted row, or the last value from a sequence object,
222
+     * depending on the underlying driver.
223
+     *
224
+     * Note: This method may not return a meaningful or consistent result across different drivers,
225
+     * because the underlying database may not even support the notion of AUTO_INCREMENT/IDENTITY
226
+     * columns or sequences.
227
+     *
228
+     * @param string $seqName Name of the sequence object from which the ID should be returned.
229
+     * @return string A string representation of the last inserted ID.
230
+     */
231
+    public function lastInsertId($seqName = null) {
232
+        if ($seqName) {
233
+            $seqName = $this->replaceTablePrefix($seqName);
234
+        }
235
+        return $this->adapter->lastInsertId($seqName);
236
+    }
237
+
238
+    // internal use
239
+    public function realLastInsertId($seqName = null) {
240
+        return parent::lastInsertId($seqName);
241
+    }
242
+
243
+    /**
244
+     * Insert a row if the matching row does not exists. To accomplish proper race condition avoidance
245
+     * it is needed that there is also a unique constraint on the values. Then this method will
246
+     * catch the exception and return 0.
247
+     *
248
+     * @param string $table The table name (will replace *PREFIX* with the actual prefix)
249
+     * @param array $input data that should be inserted into the table  (column name => value)
250
+     * @param array|null $compare List of values that should be checked for "if not exists"
251
+     *				If this is null or an empty array, all keys of $input will be compared
252
+     *				Please note: text fields (clob) must not be used in the compare array
253
+     * @return int number of inserted rows
254
+     * @throws \Doctrine\DBAL\DBALException
255
+     * @deprecated 15.0.0 - use unique index and "try { $db->insert() } catch (UniqueConstraintViolationException $e) {}" instead, because it is more reliable and does not have the risk for deadlocks - see https://github.com/nextcloud/server/pull/12371
256
+     */
257
+    public function insertIfNotExist($table, $input, array $compare = null) {
258
+        return $this->adapter->insertIfNotExist($table, $input, $compare);
259
+    }
260
+
261
+    public function insertIgnoreConflict(string $table, array $values) : int {
262
+        return $this->adapter->insertIgnoreConflict($table, $values);
263
+    }
264
+
265
+    private function getType($value) {
266
+        if (is_bool($value)) {
267
+            return IQueryBuilder::PARAM_BOOL;
268
+        } else if (is_int($value)) {
269
+            return IQueryBuilder::PARAM_INT;
270
+        } else {
271
+            return IQueryBuilder::PARAM_STR;
272
+        }
273
+    }
274
+
275
+    /**
276
+     * Insert or update a row value
277
+     *
278
+     * @param string $table
279
+     * @param array $keys (column name => value)
280
+     * @param array $values (column name => value)
281
+     * @param array $updatePreconditionValues ensure values match preconditions (column name => value)
282
+     * @return int number of new rows
283
+     * @throws \Doctrine\DBAL\DBALException
284
+     * @throws PreConditionNotMetException
285
+     * @suppress SqlInjectionChecker
286
+     */
287
+    public function setValues($table, array $keys, array $values, array $updatePreconditionValues = []) {
288
+        try {
289
+            $insertQb = $this->getQueryBuilder();
290
+            $insertQb->insert($table)
291
+                ->values(
292
+                    array_map(function($value) use ($insertQb) {
293
+                        return $insertQb->createNamedParameter($value, $this->getType($value));
294
+                    }, array_merge($keys, $values))
295
+                );
296
+            return $insertQb->execute();
297
+        } catch (ConstraintViolationException $e) {
298
+            // value already exists, try update
299
+            $updateQb = $this->getQueryBuilder();
300
+            $updateQb->update($table);
301
+            foreach ($values as $name => $value) {
302
+                $updateQb->set($name, $updateQb->createNamedParameter($value, $this->getType($value)));
303
+            }
304
+            $where = $updateQb->expr()->andX();
305
+            $whereValues = array_merge($keys, $updatePreconditionValues);
306
+            foreach ($whereValues as $name => $value) {
307
+                $where->add($updateQb->expr()->eq(
308
+                    $name,
309
+                    $updateQb->createNamedParameter($value, $this->getType($value)),
310
+                    $this->getType($value)
311
+                ));
312
+            }
313
+            $updateQb->where($where);
314
+            $affected = $updateQb->execute();
315
+
316
+            if ($affected === 0 && !empty($updatePreconditionValues)) {
317
+                throw new PreConditionNotMetException();
318
+            }
319
+
320
+            return 0;
321
+        }
322
+    }
323
+
324
+    /**
325
+     * Create an exclusive read+write lock on a table
326
+     *
327
+     * @param string $tableName
328
+     * @throws \BadMethodCallException When trying to acquire a second lock
329
+     * @since 9.1.0
330
+     */
331
+    public function lockTable($tableName) {
332
+        if ($this->lockedTable !== null) {
333
+            throw new \BadMethodCallException('Can not lock a new table until the previous lock is released.');
334
+        }
335
+
336
+        $tableName = $this->tablePrefix . $tableName;
337
+        $this->lockedTable = $tableName;
338
+        $this->adapter->lockTable($tableName);
339
+    }
340
+
341
+    /**
342
+     * Release a previous acquired lock again
343
+     *
344
+     * @since 9.1.0
345
+     */
346
+    public function unlockTable() {
347
+        $this->adapter->unlockTable();
348
+        $this->lockedTable = null;
349
+    }
350
+
351
+    /**
352
+     * returns the error code and message as a string for logging
353
+     * works with DoctrineException
354
+     * @return string
355
+     */
356
+    public function getError() {
357
+        $msg = $this->errorCode() . ': ';
358
+        $errorInfo = $this->errorInfo();
359
+        if (is_array($errorInfo)) {
360
+            $msg .= 'SQLSTATE = '.$errorInfo[0] . ', ';
361
+            $msg .= 'Driver Code = '.$errorInfo[1] . ', ';
362
+            $msg .= 'Driver Message = '.$errorInfo[2];
363
+        }
364
+        return $msg;
365
+    }
366
+
367
+    /**
368
+     * Drop a table from the database if it exists
369
+     *
370
+     * @param string $table table name without the prefix
371
+     */
372
+    public function dropTable($table) {
373
+        $table = $this->tablePrefix . trim($table);
374
+        $schema = $this->getSchemaManager();
375
+        if($schema->tablesExist(array($table))) {
376
+            $schema->dropTable($table);
377
+        }
378
+    }
379
+
380
+    /**
381
+     * Check if a table exists
382
+     *
383
+     * @param string $table table name without the prefix
384
+     * @return bool
385
+     */
386
+    public function tableExists($table){
387
+        $table = $this->tablePrefix . trim($table);
388
+        $schema = $this->getSchemaManager();
389
+        return $schema->tablesExist(array($table));
390
+    }
391
+
392
+    // internal use
393
+    /**
394
+     * @param string $statement
395
+     * @return string
396
+     */
397
+    protected function replaceTablePrefix($statement) {
398
+        return str_replace( '*PREFIX*', $this->tablePrefix, $statement );
399
+    }
400
+
401
+    /**
402
+     * Check if a transaction is active
403
+     *
404
+     * @return bool
405
+     * @since 8.2.0
406
+     */
407
+    public function inTransaction() {
408
+        return $this->getTransactionNestingLevel() > 0;
409
+    }
410
+
411
+    /**
412
+     * Escape a parameter to be used in a LIKE query
413
+     *
414
+     * @param string $param
415
+     * @return string
416
+     */
417
+    public function escapeLikeParameter($param) {
418
+        return addcslashes($param, '\\_%');
419
+    }
420
+
421
+    /**
422
+     * Check whether or not the current database support 4byte wide unicode
423
+     *
424
+     * @return bool
425
+     * @since 11.0.0
426
+     */
427
+    public function supports4ByteText() {
428
+        if (!$this->getDatabasePlatform() instanceof MySqlPlatform) {
429
+            return true;
430
+        }
431
+        return $this->getParams()['charset'] === 'utf8mb4';
432
+    }
433
+
434
+
435
+    /**
436
+     * Create the schema of the connected database
437
+     *
438
+     * @return Schema
439
+     */
440
+    public function createSchema() {
441
+        $schemaManager = new MDB2SchemaManager($this);
442
+        $migrator = $schemaManager->getMigrator();
443
+        return $migrator->createSchema();
444
+    }
445
+
446
+    /**
447
+     * Migrate the database to the given schema
448
+     *
449
+     * @param Schema $toSchema
450
+     */
451
+    public function migrateToSchema(Schema $toSchema) {
452
+        $schemaManager = new MDB2SchemaManager($this);
453
+        $migrator = $schemaManager->getMigrator();
454
+        $migrator->migrate($toSchema);
455
+    }
456 456
 }
Please login to merge, or discard this patch.
lib/private/Diagnostics/EventLogger.php 2 patches
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -28,56 +28,56 @@
 block discarded – undo
28 28
 use OCP\Diagnostics\IEventLogger;
29 29
 
30 30
 class EventLogger implements IEventLogger {
31
-	/**
32
-	 * @var \OC\Diagnostics\Event[]
33
-	 */
34
-	private $events = [];
31
+    /**
32
+     * @var \OC\Diagnostics\Event[]
33
+     */
34
+    private $events = [];
35 35
 	
36
-	/**
37
-	 * @var bool - Module needs to be activated by some app
38
-	 */
39
-	private $activated = false;
36
+    /**
37
+     * @var bool - Module needs to be activated by some app
38
+     */
39
+    private $activated = false;
40 40
 
41
-	/**
42
-	 * @inheritdoc
43
-	 */
44
-	public function start($id, $description) {
45
-		if ($this->activated){
46
-			$this->events[$id] = new Event($id, $description, microtime(true));
47
-		}
48
-	}
41
+    /**
42
+     * @inheritdoc
43
+     */
44
+    public function start($id, $description) {
45
+        if ($this->activated){
46
+            $this->events[$id] = new Event($id, $description, microtime(true));
47
+        }
48
+    }
49 49
 
50
-	/**
51
-	 * @inheritdoc
52
-	 */
53
-	public function end($id) {
54
-		if ($this->activated && isset($this->events[$id])) {
55
-			$timing = $this->events[$id];
56
-			$timing->end(microtime(true));
57
-		}
58
-	}
50
+    /**
51
+     * @inheritdoc
52
+     */
53
+    public function end($id) {
54
+        if ($this->activated && isset($this->events[$id])) {
55
+            $timing = $this->events[$id];
56
+            $timing->end(microtime(true));
57
+        }
58
+    }
59 59
 
60
-	/**
61
-	 * @inheritdoc
62
-	 */
63
-	public function log($id, $description, $start, $end) {
64
-		if ($this->activated) {
65
-			$this->events[$id] = new Event($id, $description, $start);
66
-			$this->events[$id]->end($end);
67
-		}
68
-	}
60
+    /**
61
+     * @inheritdoc
62
+     */
63
+    public function log($id, $description, $start, $end) {
64
+        if ($this->activated) {
65
+            $this->events[$id] = new Event($id, $description, $start);
66
+            $this->events[$id]->end($end);
67
+        }
68
+    }
69 69
 
70
-	/**
71
-	 * @inheritdoc
72
-	 */
73
-	public function getEvents() {
74
-		return $this->events;
75
-	}
70
+    /**
71
+     * @inheritdoc
72
+     */
73
+    public function getEvents() {
74
+        return $this->events;
75
+    }
76 76
 	
77
-	/**
78
-	 * @inheritdoc
79
-	 */
80
-	public function activate() {
81
-		$this->activated = true;
82
-	}
77
+    /**
78
+     * @inheritdoc
79
+     */
80
+    public function activate() {
81
+        $this->activated = true;
82
+    }
83 83
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@
 block discarded – undo
42 42
 	 * @inheritdoc
43 43
 	 */
44 44
 	public function start($id, $description) {
45
-		if ($this->activated){
45
+		if ($this->activated) {
46 46
 			$this->events[$id] = new Event($id, $description, microtime(true));
47 47
 		}
48 48
 	}
Please login to merge, or discard this patch.
lib/private/Diagnostics/Query.php 1 patch
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -26,65 +26,65 @@
 block discarded – undo
26 26
 use OCP\Diagnostics\IQuery;
27 27
 
28 28
 class Query implements IQuery {
29
-	private $sql;
29
+    private $sql;
30 30
 
31
-	private $params;
31
+    private $params;
32 32
 
33
-	private $start;
33
+    private $start;
34 34
 
35
-	private $end;
35
+    private $end;
36 36
 
37
-	private $stack;
37
+    private $stack;
38 38
 
39
-	/**
40
-	 * @param string $sql
41
-	 * @param array $params
42
-	 * @param int $start
43
-	 */
44
-	public function __construct($sql, $params, $start, array $stack) {
45
-		$this->sql = $sql;
46
-		$this->params = $params;
47
-		$this->start = $start;
48
-		$this->stack = $stack;
49
-	}
39
+    /**
40
+     * @param string $sql
41
+     * @param array $params
42
+     * @param int $start
43
+     */
44
+    public function __construct($sql, $params, $start, array $stack) {
45
+        $this->sql = $sql;
46
+        $this->params = $params;
47
+        $this->start = $start;
48
+        $this->stack = $stack;
49
+    }
50 50
 
51
-	public function end($time) {
52
-		$this->end = $time;
53
-	}
51
+    public function end($time) {
52
+        $this->end = $time;
53
+    }
54 54
 
55
-	/**
56
-	 * @return array
57
-	 */
58
-	public function getParams() {
59
-		return $this->params;
60
-	}
55
+    /**
56
+     * @return array
57
+     */
58
+    public function getParams() {
59
+        return $this->params;
60
+    }
61 61
 
62
-	/**
63
-	 * @return string
64
-	 */
65
-	public function getSql() {
66
-		return $this->sql;
67
-	}
62
+    /**
63
+     * @return string
64
+     */
65
+    public function getSql() {
66
+        return $this->sql;
67
+    }
68 68
 
69
-	/**
70
-	 * @return float
71
-	 */
72
-	public function getStart() {
73
-		return $this->start;
74
-	}
69
+    /**
70
+     * @return float
71
+     */
72
+    public function getStart() {
73
+        return $this->start;
74
+    }
75 75
 	
76
-	/**
77
-	 * @return float
78
-	 */
79
-	public function getDuration() {
80
-		return $this->end - $this->start;
81
-	}
76
+    /**
77
+     * @return float
78
+     */
79
+    public function getDuration() {
80
+        return $this->end - $this->start;
81
+    }
82 82
 
83
-	public function getStartTime() {
84
-		return $this->start;
85
-	}
83
+    public function getStartTime() {
84
+        return $this->start;
85
+    }
86 86
 
87
-	public function getStacktrace() {
88
-		return $this->stack;
89
-	}
87
+    public function getStacktrace() {
88
+        return $this->stack;
89
+    }
90 90
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Config/ExternalMountPoint.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@
 block discarded – undo
24 24
 use OC\Files\Mount\MountPoint;
25 25
 
26 26
 class ExternalMountPoint extends MountPoint {
27
-	public function getMountType() {
28
-		return 'external';
29
-	}
27
+    public function getMountType() {
28
+        return 'external';
29
+    }
30 30
 }
Please login to merge, or discard this patch.
lib/private/App/AppStore/Bundles/SocialSharingBundle.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@
 block discarded – undo
27 27
 	 * {@inheritDoc}
28 28
 	 */
29 29
 	public function getName() {
30
-		return (string)$this->l10n->t('Social sharing bundle');
30
+		return (string) $this->l10n->t('Social sharing bundle');
31 31
 	}
32 32
 
33 33
 	/**
Please login to merge, or discard this patch.
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -25,23 +25,23 @@
 block discarded – undo
25 25
 
26 26
 class SocialSharingBundle extends Bundle {
27 27
 
28
-	/**
29
-	 * {@inheritDoc}
30
-	 */
31
-	public function getName() {
32
-		return (string)$this->l10n->t('Social sharing bundle');
33
-	}
28
+    /**
29
+     * {@inheritDoc}
30
+     */
31
+    public function getName() {
32
+        return (string)$this->l10n->t('Social sharing bundle');
33
+    }
34 34
 
35
-	/**
36
-	 * {@inheritDoc}
37
-	 */
38
-	public function getAppIdentifiers() {
39
-		return [
40
-			'socialsharing_twitter',
41
-			'socialsharing_facebook',
42
-			'socialsharing_email',
43
-			'socialsharing_diaspora',
44
-		];
45
-	}
35
+    /**
36
+     * {@inheritDoc}
37
+     */
38
+    public function getAppIdentifiers() {
39
+        return [
40
+            'socialsharing_twitter',
41
+            'socialsharing_facebook',
42
+            'socialsharing_email',
43
+            'socialsharing_diaspora',
44
+        ];
45
+    }
46 46
 
47 47
 }
Please login to merge, or discard this patch.
lib/public/Files/Mount/IMountPoint.php 1 patch
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -29,103 +29,103 @@
 block discarded – undo
29 29
  */
30 30
 interface IMountPoint {
31 31
 
32
-	/**
33
-	 * get complete path to the mount point
34
-	 *
35
-	 * @return string
36
-	 * @since 8.0.0
37
-	 */
38
-	public function getMountPoint();
32
+    /**
33
+     * get complete path to the mount point
34
+     *
35
+     * @return string
36
+     * @since 8.0.0
37
+     */
38
+    public function getMountPoint();
39 39
 
40
-	/**
41
-	 * Set the mountpoint
42
-	 *
43
-	 * @param string $mountPoint new mount point
44
-	 * @since 8.0.0
45
-	 */
46
-	public function setMountPoint($mountPoint);
40
+    /**
41
+     * Set the mountpoint
42
+     *
43
+     * @param string $mountPoint new mount point
44
+     * @since 8.0.0
45
+     */
46
+    public function setMountPoint($mountPoint);
47 47
 
48
-	/**
49
-	 * Get the storage that is mounted
50
-	 *
51
-	 * @return \OC\Files\Storage\Storage
52
-	 * @since 8.0.0
53
-	 */
54
-	public function getStorage();
48
+    /**
49
+     * Get the storage that is mounted
50
+     *
51
+     * @return \OC\Files\Storage\Storage
52
+     * @since 8.0.0
53
+     */
54
+    public function getStorage();
55 55
 
56
-	/**
57
-	 * Get the id of the storages
58
-	 *
59
-	 * @return string
60
-	 * @since 8.0.0
61
-	 */
62
-	public function getStorageId();
56
+    /**
57
+     * Get the id of the storages
58
+     *
59
+     * @return string
60
+     * @since 8.0.0
61
+     */
62
+    public function getStorageId();
63 63
 
64
-	/**
65
-	 * Get the id of the storages
66
-	 *
67
-	 * @return int
68
-	 * @since 9.1.0
69
-	 */
70
-	public function getNumericStorageId();
64
+    /**
65
+     * Get the id of the storages
66
+     *
67
+     * @return int
68
+     * @since 9.1.0
69
+     */
70
+    public function getNumericStorageId();
71 71
 
72
-	/**
73
-	 * Get the path relative to the mountpoint
74
-	 *
75
-	 * @param string $path absolute path to a file or folder
76
-	 * @return string
77
-	 * @since 8.0.0
78
-	 */
79
-	public function getInternalPath($path);
72
+    /**
73
+     * Get the path relative to the mountpoint
74
+     *
75
+     * @param string $path absolute path to a file or folder
76
+     * @return string
77
+     * @since 8.0.0
78
+     */
79
+    public function getInternalPath($path);
80 80
 
81
-	/**
82
-	 * Apply a storage wrapper to the mounted storage
83
-	 *
84
-	 * @param callable $wrapper
85
-	 * @since 8.0.0
86
-	 */
87
-	public function wrapStorage($wrapper);
81
+    /**
82
+     * Apply a storage wrapper to the mounted storage
83
+     *
84
+     * @param callable $wrapper
85
+     * @since 8.0.0
86
+     */
87
+    public function wrapStorage($wrapper);
88 88
 
89
-	/**
90
-	 * Get a mount option
91
-	 *
92
-	 * @param string $name Name of the mount option to get
93
-	 * @param mixed $default Default value for the mount option
94
-	 * @return mixed
95
-	 * @since 8.0.0
96
-	 */
97
-	public function getOption($name, $default);
89
+    /**
90
+     * Get a mount option
91
+     *
92
+     * @param string $name Name of the mount option to get
93
+     * @param mixed $default Default value for the mount option
94
+     * @return mixed
95
+     * @since 8.0.0
96
+     */
97
+    public function getOption($name, $default);
98 98
 
99
-	/**
100
-	 * Get all options for the mount
101
-	 *
102
-	 * @return array
103
-	 * @since 8.1.0
104
-	 */
105
-	public function getOptions();
99
+    /**
100
+     * Get all options for the mount
101
+     *
102
+     * @return array
103
+     * @since 8.1.0
104
+     */
105
+    public function getOptions();
106 106
 
107
-	/**
108
-	 * Get the file id of the root of the storage
109
-	 *
110
-	 * @return int
111
-	 * @since 9.1.0
112
-	 */
113
-	public function getStorageRootId();
107
+    /**
108
+     * Get the file id of the root of the storage
109
+     *
110
+     * @return int
111
+     * @since 9.1.0
112
+     */
113
+    public function getStorageRootId();
114 114
 
115
-	/**
116
-	 * Get the id of the configured mount
117
-	 *
118
-	 * @return int|null mount id or null if not applicable
119
-	 * @since 9.1.0
120
-	 */
121
-	public function getMountId();
115
+    /**
116
+     * Get the id of the configured mount
117
+     *
118
+     * @return int|null mount id or null if not applicable
119
+     * @since 9.1.0
120
+     */
121
+    public function getMountId();
122 122
 
123
-	/**
124
-	 * Get the type of mount point, used to distinguish things like shares and external storages
125
-	 * in the web interface
126
-	 *
127
-	 * @return string
128
-	 * @since 12.0.0
129
-	 */
130
-	public function getMountType();
123
+    /**
124
+     * Get the type of mount point, used to distinguish things like shares and external storages
125
+     * in the web interface
126
+     *
127
+     * @return string
128
+     * @since 12.0.0
129
+     */
130
+    public function getMountType();
131 131
 }
Please login to merge, or discard this patch.
apps/dav/lib/CardDAV/ImageExportPlugin.php 2 patches
Indentation   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -32,85 +32,85 @@
 block discarded – undo
32 32
 
33 33
 class ImageExportPlugin extends ServerPlugin {
34 34
 
35
-	/** @var Server */
36
-	protected $server;
37
-	/** @var PhotoCache */
38
-	private $cache;
39
-
40
-	/**
41
-	 * ImageExportPlugin constructor.
42
-	 *
43
-	 * @param PhotoCache $cache
44
-	 */
45
-	public function __construct(PhotoCache $cache) {
46
-		$this->cache = $cache;
47
-	}
48
-
49
-	/**
50
-	 * Initializes the plugin and registers event handlers
51
-	 *
52
-	 * @param Server $server
53
-	 * @return void
54
-	 */
55
-	public function initialize(Server $server) {
56
-		$this->server = $server;
57
-		$this->server->on('method:GET', [$this, 'httpGet'], 90);
58
-	}
59
-
60
-	/**
61
-	 * Intercepts GET requests on addressbook urls ending with ?photo.
62
-	 *
63
-	 * @param RequestInterface $request
64
-	 * @param ResponseInterface $response
65
-	 * @return bool
66
-	 */
67
-	public function httpGet(RequestInterface $request, ResponseInterface $response) {
68
-
69
-		$queryParams = $request->getQueryParameters();
70
-		// TODO: in addition to photo we should also add logo some point in time
71
-		if (!array_key_exists('photo', $queryParams)) {
72
-			return true;
73
-		}
74
-
75
-		$size = isset($queryParams['size']) ? (int)$queryParams['size'] : -1;
76
-
77
-		$path = $request->getPath();
78
-		$node = $this->server->tree->getNodeForPath($path);
79
-
80
-		if (!($node instanceof Card)) {
81
-			return true;
82
-		}
83
-
84
-		$this->server->transactionType = 'carddav-image-export';
85
-
86
-		// Checking ACL, if available.
87
-		if ($aclPlugin = $this->server->getPlugin('acl')) {
88
-			/** @var \Sabre\DAVACL\Plugin $aclPlugin */
89
-			$aclPlugin->checkPrivileges($path, '{DAV:}read');
90
-		}
91
-
92
-		// Fetch addressbook
93
-		$addressbookpath = explode('/', $path);
94
-		array_pop($addressbookpath);
95
-		$addressbookpath = implode('/', $addressbookpath);
96
-		/** @var AddressBook $addressbook */
97
-		$addressbook = $this->server->tree->getNodeForPath($addressbookpath);
98
-
99
-		$response->setHeader('Cache-Control', 'private, max-age=3600, must-revalidate');
100
-		$response->setHeader('Etag', $node->getETag() );
101
-		$response->setHeader('Pragma', 'public');
102
-
103
-		try {
104
-			$file = $this->cache->get($addressbook->getResourceId(), $node->getName(), $size, $node);
105
-			$response->setHeader('Content-Type', $file->getMimeType());
106
-			$response->setHeader('Content-Disposition', 'attachment');
107
-			$response->setStatus(200);
108
-
109
-			$response->setBody($file->getContent());
110
-		} catch (NotFoundException $e) {
111
-			$response->setStatus(404);
112
-		}
113
-
114
-		return false;
115
-	}
35
+    /** @var Server */
36
+    protected $server;
37
+    /** @var PhotoCache */
38
+    private $cache;
39
+
40
+    /**
41
+     * ImageExportPlugin constructor.
42
+     *
43
+     * @param PhotoCache $cache
44
+     */
45
+    public function __construct(PhotoCache $cache) {
46
+        $this->cache = $cache;
47
+    }
48
+
49
+    /**
50
+     * Initializes the plugin and registers event handlers
51
+     *
52
+     * @param Server $server
53
+     * @return void
54
+     */
55
+    public function initialize(Server $server) {
56
+        $this->server = $server;
57
+        $this->server->on('method:GET', [$this, 'httpGet'], 90);
58
+    }
59
+
60
+    /**
61
+     * Intercepts GET requests on addressbook urls ending with ?photo.
62
+     *
63
+     * @param RequestInterface $request
64
+     * @param ResponseInterface $response
65
+     * @return bool
66
+     */
67
+    public function httpGet(RequestInterface $request, ResponseInterface $response) {
68
+
69
+        $queryParams = $request->getQueryParameters();
70
+        // TODO: in addition to photo we should also add logo some point in time
71
+        if (!array_key_exists('photo', $queryParams)) {
72
+            return true;
73
+        }
74
+
75
+        $size = isset($queryParams['size']) ? (int)$queryParams['size'] : -1;
76
+
77
+        $path = $request->getPath();
78
+        $node = $this->server->tree->getNodeForPath($path);
79
+
80
+        if (!($node instanceof Card)) {
81
+            return true;
82
+        }
83
+
84
+        $this->server->transactionType = 'carddav-image-export';
85
+
86
+        // Checking ACL, if available.
87
+        if ($aclPlugin = $this->server->getPlugin('acl')) {
88
+            /** @var \Sabre\DAVACL\Plugin $aclPlugin */
89
+            $aclPlugin->checkPrivileges($path, '{DAV:}read');
90
+        }
91
+
92
+        // Fetch addressbook
93
+        $addressbookpath = explode('/', $path);
94
+        array_pop($addressbookpath);
95
+        $addressbookpath = implode('/', $addressbookpath);
96
+        /** @var AddressBook $addressbook */
97
+        $addressbook = $this->server->tree->getNodeForPath($addressbookpath);
98
+
99
+        $response->setHeader('Cache-Control', 'private, max-age=3600, must-revalidate');
100
+        $response->setHeader('Etag', $node->getETag() );
101
+        $response->setHeader('Pragma', 'public');
102
+
103
+        try {
104
+            $file = $this->cache->get($addressbook->getResourceId(), $node->getName(), $size, $node);
105
+            $response->setHeader('Content-Type', $file->getMimeType());
106
+            $response->setHeader('Content-Disposition', 'attachment');
107
+            $response->setStatus(200);
108
+
109
+            $response->setBody($file->getContent());
110
+        } catch (NotFoundException $e) {
111
+            $response->setStatus(404);
112
+        }
113
+
114
+        return false;
115
+    }
116 116
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 			return true;
73 73
 		}
74 74
 
75
-		$size = isset($queryParams['size']) ? (int)$queryParams['size'] : -1;
75
+		$size = isset($queryParams['size']) ? (int) $queryParams['size'] : -1;
76 76
 
77 77
 		$path = $request->getPath();
78 78
 		$node = $this->server->tree->getNodeForPath($path);
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 		$addressbook = $this->server->tree->getNodeForPath($addressbookpath);
98 98
 
99 99
 		$response->setHeader('Cache-Control', 'private, max-age=3600, must-revalidate');
100
-		$response->setHeader('Etag', $node->getETag() );
100
+		$response->setHeader('Etag', $node->getETag());
101 101
 		$response->setHeader('Pragma', 'public');
102 102
 
103 103
 		try {
Please login to merge, or discard this patch.