Passed
Push — master ( 1ad063...0f7fb7 )
by Morris
22:31 queued 11:17
created
lib/private/DB/Migrator.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
 	 * @return string
136 136
 	 */
137 137
 	protected function generateTemporaryTableName($name) {
138
-		return $this->config->getSystemValue('dbtableprefix', 'oc_') . $name . '_' . $this->random->generate(13, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS);
138
+		return $this->config->getSystemValue('dbtableprefix', 'oc_').$name.'_'.$this->random->generate(13, ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS);
139 139
 	}
140 140
 
141 141
 	/**
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
 				$indexName = $index->getName();
187 187
 			} else {
188 188
 				// avoid conflicts in index names
189
-				$indexName = $this->config->getSystemValue('dbtableprefix', 'oc_') . $this->random->generate(13, ISecureRandom::CHAR_LOWER);
189
+				$indexName = $this->config->getSystemValue('dbtableprefix', 'oc_').$this->random->generate(13, ISecureRandom::CHAR_LOWER);
190 190
 			}
191 191
 			$newIndexes[] = new Index($indexName, $index->getColumns(), $index->isUnique(), $index->isPrimary());
192 192
 		}
@@ -271,15 +271,15 @@  discard block
 block discarded – undo
271 271
 		$quotedSource = $this->connection->quoteIdentifier($sourceName);
272 272
 		$quotedTarget = $this->connection->quoteIdentifier($targetName);
273 273
 
274
-		$this->connection->exec('CREATE TABLE ' . $quotedTarget . ' (LIKE ' . $quotedSource . ')');
275
-		$this->connection->exec('INSERT INTO ' . $quotedTarget . ' SELECT * FROM ' . $quotedSource);
274
+		$this->connection->exec('CREATE TABLE '.$quotedTarget.' (LIKE '.$quotedSource.')');
275
+		$this->connection->exec('INSERT INTO '.$quotedTarget.' SELECT * FROM '.$quotedSource);
276 276
 	}
277 277
 
278 278
 	/**
279 279
 	 * @param string $name
280 280
 	 */
281 281
 	protected function dropTable($name) {
282
-		$this->connection->exec('DROP TABLE ' . $this->connection->quoteIdentifier($name));
282
+		$this->connection->exec('DROP TABLE '.$this->connection->quoteIdentifier($name));
283 283
 	}
284 284
 
285 285
 	/**
@@ -287,14 +287,14 @@  discard block
 block discarded – undo
287 287
 	 * @return string
288 288
 	 */
289 289
 	protected function convertStatementToScript($statement) {
290
-		$script = $statement . ';';
290
+		$script = $statement.';';
291 291
 		$script .= PHP_EOL;
292 292
 		$script .= PHP_EOL;
293 293
 		return $script;
294 294
 	}
295 295
 
296 296
 	protected function getFilterExpression() {
297
-		return '/^' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/';
297
+		return '/^'.preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')).'/';
298 298
 	}
299 299
 
300 300
 	protected function emit($sql, $step, $max) {
Please login to merge, or discard this patch.
Indentation   +267 added lines, -267 removed lines patch added patch discarded remove patch
@@ -46,271 +46,271 @@
 block discarded – undo
46 46
 
47 47
 class Migrator {
48 48
 
49
-	/** @var \Doctrine\DBAL\Connection */
50
-	protected $connection;
51
-
52
-	/** @var ISecureRandom */
53
-	private $random;
54
-
55
-	/** @var IConfig */
56
-	protected $config;
57
-
58
-	/** @var EventDispatcherInterface  */
59
-	private $dispatcher;
60
-
61
-	/** @var bool */
62
-	private $noEmit = false;
63
-
64
-	/**
65
-	 * @param \Doctrine\DBAL\Connection $connection
66
-	 * @param ISecureRandom $random
67
-	 * @param IConfig $config
68
-	 * @param EventDispatcherInterface $dispatcher
69
-	 */
70
-	public function __construct(\Doctrine\DBAL\Connection $connection,
71
-								ISecureRandom $random,
72
-								IConfig $config,
73
-								EventDispatcherInterface $dispatcher = null) {
74
-		$this->connection = $connection;
75
-		$this->random = $random;
76
-		$this->config = $config;
77
-		$this->dispatcher = $dispatcher;
78
-	}
79
-
80
-	/**
81
-	 * @param \Doctrine\DBAL\Schema\Schema $targetSchema
82
-	 */
83
-	public function migrate(Schema $targetSchema) {
84
-		$this->noEmit = true;
85
-		$this->applySchema($targetSchema);
86
-	}
87
-
88
-	/**
89
-	 * @param \Doctrine\DBAL\Schema\Schema $targetSchema
90
-	 * @return string
91
-	 */
92
-	public function generateChangeScript(Schema $targetSchema) {
93
-		$schemaDiff = $this->getDiff($targetSchema, $this->connection);
94
-
95
-		$script = '';
96
-		$sqls = $schemaDiff->toSql($this->connection->getDatabasePlatform());
97
-		foreach ($sqls as $sql) {
98
-			$script .= $this->convertStatementToScript($sql);
99
-		}
100
-
101
-		return $script;
102
-	}
103
-
104
-	/**
105
-	 * @param Schema $targetSchema
106
-	 * @throws \OC\DB\MigrationException
107
-	 */
108
-	public function checkMigrate(Schema $targetSchema) {
109
-		$this->noEmit = true;
110
-		/**@var \Doctrine\DBAL\Schema\Table[] $tables */
111
-		$tables = $targetSchema->getTables();
112
-		$filterExpression = $this->getFilterExpression();
113
-		$this->connection->getConfiguration()->
114
-			setFilterSchemaAssetsExpression($filterExpression);
115
-		$existingTables = $this->connection->getSchemaManager()->listTableNames();
116
-
117
-		$step = 0;
118
-		foreach ($tables as $table) {
119
-			if (strpos($table->getName(), '.')) {
120
-				list(, $tableName) = explode('.', $table->getName());
121
-			} else {
122
-				$tableName = $table->getName();
123
-			}
124
-			$this->emitCheckStep($tableName, $step++, count($tables));
125
-			// don't need to check for new tables
126
-			if (array_search($tableName, $existingTables) !== false) {
127
-				$this->checkTableMigrate($table);
128
-			}
129
-		}
130
-	}
131
-
132
-	/**
133
-	 * Create a unique name for the temporary table
134
-	 *
135
-	 * @param string $name
136
-	 * @return string
137
-	 */
138
-	protected function generateTemporaryTableName($name) {
139
-		return $this->config->getSystemValue('dbtableprefix', 'oc_') . $name . '_' . $this->random->generate(13, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS);
140
-	}
141
-
142
-	/**
143
-	 * Check the migration of a table on a copy so we can detect errors before messing with the real table
144
-	 *
145
-	 * @param \Doctrine\DBAL\Schema\Table $table
146
-	 * @throws \OC\DB\MigrationException
147
-	 */
148
-	protected function checkTableMigrate(Table $table) {
149
-		$name = $table->getName();
150
-		$tmpName = $this->generateTemporaryTableName($name);
151
-
152
-		$this->copyTable($name, $tmpName);
153
-
154
-		//create the migration schema for the temporary table
155
-		$tmpTable = $this->renameTableSchema($table, $tmpName);
156
-		$schemaConfig = new SchemaConfig();
157
-		$schemaConfig->setName($this->connection->getDatabase());
158
-		$schema = new Schema([$tmpTable], [], $schemaConfig);
159
-
160
-		try {
161
-			$this->applySchema($schema);
162
-			$this->dropTable($tmpName);
163
-		} catch (DBALException $e) {
164
-			// pgsql needs to commit it's failed transaction before doing anything else
165
-			if ($this->connection->isTransactionActive()) {
166
-				$this->connection->commit();
167
-			}
168
-			$this->dropTable($tmpName);
169
-			throw new MigrationException($table->getName(), $e->getMessage());
170
-		}
171
-	}
172
-
173
-	/**
174
-	 * @param \Doctrine\DBAL\Schema\Table $table
175
-	 * @param string $newName
176
-	 * @return \Doctrine\DBAL\Schema\Table
177
-	 */
178
-	protected function renameTableSchema(Table $table, $newName) {
179
-		/**
180
-		 * @var \Doctrine\DBAL\Schema\Index[] $indexes
181
-		 */
182
-		$indexes = $table->getIndexes();
183
-		$newIndexes = [];
184
-		foreach ($indexes as $index) {
185
-			if ($index->isPrimary()) {
186
-				// do not rename primary key
187
-				$indexName = $index->getName();
188
-			} else {
189
-				// avoid conflicts in index names
190
-				$indexName = $this->config->getSystemValue('dbtableprefix', 'oc_') . $this->random->generate(13, ISecureRandom::CHAR_LOWER);
191
-			}
192
-			$newIndexes[] = new Index($indexName, $index->getColumns(), $index->isUnique(), $index->isPrimary());
193
-		}
194
-
195
-		// foreign keys are not supported so we just set it to an empty array
196
-		return new Table($newName, $table->getColumns(), $newIndexes, [], 0, $table->getOptions());
197
-	}
198
-
199
-	public function createSchema() {
200
-		$filterExpression = $this->getFilterExpression();
201
-		$this->connection->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression);
202
-		return $this->connection->getSchemaManager()->createSchema();
203
-	}
204
-
205
-	/**
206
-	 * @param Schema $targetSchema
207
-	 * @param \Doctrine\DBAL\Connection $connection
208
-	 * @return \Doctrine\DBAL\Schema\SchemaDiff
209
-	 * @throws DBALException
210
-	 */
211
-	protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) {
212
-		// adjust varchar columns with a length higher then getVarcharMaxLength to clob
213
-		foreach ($targetSchema->getTables() as $table) {
214
-			foreach ($table->getColumns() as $column) {
215
-				if ($column->getType() instanceof StringType) {
216
-					if ($column->getLength() > $connection->getDatabasePlatform()->getVarcharMaxLength()) {
217
-						$column->setType(Type::getType('text'));
218
-						$column->setLength(null);
219
-					}
220
-				}
221
-			}
222
-		}
223
-
224
-		$filterExpression = $this->getFilterExpression();
225
-		$this->connection->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression);
226
-		$sourceSchema = $connection->getSchemaManager()->createSchema();
227
-
228
-		// remove tables we don't know about
229
-		foreach ($sourceSchema->getTables() as $table) {
230
-			if (!$targetSchema->hasTable($table->getName())) {
231
-				$sourceSchema->dropTable($table->getName());
232
-			}
233
-		}
234
-		// remove sequences we don't know about
235
-		foreach ($sourceSchema->getSequences() as $table) {
236
-			if (!$targetSchema->hasSequence($table->getName())) {
237
-				$sourceSchema->dropSequence($table->getName());
238
-			}
239
-		}
240
-
241
-		$comparator = new Comparator();
242
-		return $comparator->compare($sourceSchema, $targetSchema);
243
-	}
244
-
245
-	/**
246
-	 * @param \Doctrine\DBAL\Schema\Schema $targetSchema
247
-	 * @param \Doctrine\DBAL\Connection $connection
248
-	 */
249
-	protected function applySchema(Schema $targetSchema, \Doctrine\DBAL\Connection $connection = null) {
250
-		if (is_null($connection)) {
251
-			$connection = $this->connection;
252
-		}
253
-
254
-		$schemaDiff = $this->getDiff($targetSchema, $connection);
255
-
256
-		$connection->beginTransaction();
257
-		$sqls = $schemaDiff->toSql($connection->getDatabasePlatform());
258
-		$step = 0;
259
-		foreach ($sqls as $sql) {
260
-			$this->emit($sql, $step++, count($sqls));
261
-			$connection->query($sql);
262
-		}
263
-		$connection->commit();
264
-	}
265
-
266
-	/**
267
-	 * @param string $sourceName
268
-	 * @param string $targetName
269
-	 */
270
-	protected function copyTable($sourceName, $targetName) {
271
-		$quotedSource = $this->connection->quoteIdentifier($sourceName);
272
-		$quotedTarget = $this->connection->quoteIdentifier($targetName);
273
-
274
-		$this->connection->exec('CREATE TABLE ' . $quotedTarget . ' (LIKE ' . $quotedSource . ')');
275
-		$this->connection->exec('INSERT INTO ' . $quotedTarget . ' SELECT * FROM ' . $quotedSource);
276
-	}
277
-
278
-	/**
279
-	 * @param string $name
280
-	 */
281
-	protected function dropTable($name) {
282
-		$this->connection->exec('DROP TABLE ' . $this->connection->quoteIdentifier($name));
283
-	}
284
-
285
-	/**
286
-	 * @param $statement
287
-	 * @return string
288
-	 */
289
-	protected function convertStatementToScript($statement) {
290
-		$script = $statement . ';';
291
-		$script .= PHP_EOL;
292
-		$script .= PHP_EOL;
293
-		return $script;
294
-	}
295
-
296
-	protected function getFilterExpression() {
297
-		return '/^' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/';
298
-	}
299
-
300
-	protected function emit($sql, $step, $max) {
301
-		if ($this->noEmit) {
302
-			return;
303
-		}
304
-		if (is_null($this->dispatcher)) {
305
-			return;
306
-		}
307
-		$this->dispatcher->dispatch('\OC\DB\Migrator::executeSql', new GenericEvent($sql, [$step + 1, $max]));
308
-	}
309
-
310
-	private function emitCheckStep($tableName, $step, $max) {
311
-		if (is_null($this->dispatcher)) {
312
-			return;
313
-		}
314
-		$this->dispatcher->dispatch('\OC\DB\Migrator::checkTable', new GenericEvent($tableName, [$step + 1, $max]));
315
-	}
49
+    /** @var \Doctrine\DBAL\Connection */
50
+    protected $connection;
51
+
52
+    /** @var ISecureRandom */
53
+    private $random;
54
+
55
+    /** @var IConfig */
56
+    protected $config;
57
+
58
+    /** @var EventDispatcherInterface  */
59
+    private $dispatcher;
60
+
61
+    /** @var bool */
62
+    private $noEmit = false;
63
+
64
+    /**
65
+     * @param \Doctrine\DBAL\Connection $connection
66
+     * @param ISecureRandom $random
67
+     * @param IConfig $config
68
+     * @param EventDispatcherInterface $dispatcher
69
+     */
70
+    public function __construct(\Doctrine\DBAL\Connection $connection,
71
+                                ISecureRandom $random,
72
+                                IConfig $config,
73
+                                EventDispatcherInterface $dispatcher = null) {
74
+        $this->connection = $connection;
75
+        $this->random = $random;
76
+        $this->config = $config;
77
+        $this->dispatcher = $dispatcher;
78
+    }
79
+
80
+    /**
81
+     * @param \Doctrine\DBAL\Schema\Schema $targetSchema
82
+     */
83
+    public function migrate(Schema $targetSchema) {
84
+        $this->noEmit = true;
85
+        $this->applySchema($targetSchema);
86
+    }
87
+
88
+    /**
89
+     * @param \Doctrine\DBAL\Schema\Schema $targetSchema
90
+     * @return string
91
+     */
92
+    public function generateChangeScript(Schema $targetSchema) {
93
+        $schemaDiff = $this->getDiff($targetSchema, $this->connection);
94
+
95
+        $script = '';
96
+        $sqls = $schemaDiff->toSql($this->connection->getDatabasePlatform());
97
+        foreach ($sqls as $sql) {
98
+            $script .= $this->convertStatementToScript($sql);
99
+        }
100
+
101
+        return $script;
102
+    }
103
+
104
+    /**
105
+     * @param Schema $targetSchema
106
+     * @throws \OC\DB\MigrationException
107
+     */
108
+    public function checkMigrate(Schema $targetSchema) {
109
+        $this->noEmit = true;
110
+        /**@var \Doctrine\DBAL\Schema\Table[] $tables */
111
+        $tables = $targetSchema->getTables();
112
+        $filterExpression = $this->getFilterExpression();
113
+        $this->connection->getConfiguration()->
114
+            setFilterSchemaAssetsExpression($filterExpression);
115
+        $existingTables = $this->connection->getSchemaManager()->listTableNames();
116
+
117
+        $step = 0;
118
+        foreach ($tables as $table) {
119
+            if (strpos($table->getName(), '.')) {
120
+                list(, $tableName) = explode('.', $table->getName());
121
+            } else {
122
+                $tableName = $table->getName();
123
+            }
124
+            $this->emitCheckStep($tableName, $step++, count($tables));
125
+            // don't need to check for new tables
126
+            if (array_search($tableName, $existingTables) !== false) {
127
+                $this->checkTableMigrate($table);
128
+            }
129
+        }
130
+    }
131
+
132
+    /**
133
+     * Create a unique name for the temporary table
134
+     *
135
+     * @param string $name
136
+     * @return string
137
+     */
138
+    protected function generateTemporaryTableName($name) {
139
+        return $this->config->getSystemValue('dbtableprefix', 'oc_') . $name . '_' . $this->random->generate(13, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS);
140
+    }
141
+
142
+    /**
143
+     * Check the migration of a table on a copy so we can detect errors before messing with the real table
144
+     *
145
+     * @param \Doctrine\DBAL\Schema\Table $table
146
+     * @throws \OC\DB\MigrationException
147
+     */
148
+    protected function checkTableMigrate(Table $table) {
149
+        $name = $table->getName();
150
+        $tmpName = $this->generateTemporaryTableName($name);
151
+
152
+        $this->copyTable($name, $tmpName);
153
+
154
+        //create the migration schema for the temporary table
155
+        $tmpTable = $this->renameTableSchema($table, $tmpName);
156
+        $schemaConfig = new SchemaConfig();
157
+        $schemaConfig->setName($this->connection->getDatabase());
158
+        $schema = new Schema([$tmpTable], [], $schemaConfig);
159
+
160
+        try {
161
+            $this->applySchema($schema);
162
+            $this->dropTable($tmpName);
163
+        } catch (DBALException $e) {
164
+            // pgsql needs to commit it's failed transaction before doing anything else
165
+            if ($this->connection->isTransactionActive()) {
166
+                $this->connection->commit();
167
+            }
168
+            $this->dropTable($tmpName);
169
+            throw new MigrationException($table->getName(), $e->getMessage());
170
+        }
171
+    }
172
+
173
+    /**
174
+     * @param \Doctrine\DBAL\Schema\Table $table
175
+     * @param string $newName
176
+     * @return \Doctrine\DBAL\Schema\Table
177
+     */
178
+    protected function renameTableSchema(Table $table, $newName) {
179
+        /**
180
+         * @var \Doctrine\DBAL\Schema\Index[] $indexes
181
+         */
182
+        $indexes = $table->getIndexes();
183
+        $newIndexes = [];
184
+        foreach ($indexes as $index) {
185
+            if ($index->isPrimary()) {
186
+                // do not rename primary key
187
+                $indexName = $index->getName();
188
+            } else {
189
+                // avoid conflicts in index names
190
+                $indexName = $this->config->getSystemValue('dbtableprefix', 'oc_') . $this->random->generate(13, ISecureRandom::CHAR_LOWER);
191
+            }
192
+            $newIndexes[] = new Index($indexName, $index->getColumns(), $index->isUnique(), $index->isPrimary());
193
+        }
194
+
195
+        // foreign keys are not supported so we just set it to an empty array
196
+        return new Table($newName, $table->getColumns(), $newIndexes, [], 0, $table->getOptions());
197
+    }
198
+
199
+    public function createSchema() {
200
+        $filterExpression = $this->getFilterExpression();
201
+        $this->connection->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression);
202
+        return $this->connection->getSchemaManager()->createSchema();
203
+    }
204
+
205
+    /**
206
+     * @param Schema $targetSchema
207
+     * @param \Doctrine\DBAL\Connection $connection
208
+     * @return \Doctrine\DBAL\Schema\SchemaDiff
209
+     * @throws DBALException
210
+     */
211
+    protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) {
212
+        // adjust varchar columns with a length higher then getVarcharMaxLength to clob
213
+        foreach ($targetSchema->getTables() as $table) {
214
+            foreach ($table->getColumns() as $column) {
215
+                if ($column->getType() instanceof StringType) {
216
+                    if ($column->getLength() > $connection->getDatabasePlatform()->getVarcharMaxLength()) {
217
+                        $column->setType(Type::getType('text'));
218
+                        $column->setLength(null);
219
+                    }
220
+                }
221
+            }
222
+        }
223
+
224
+        $filterExpression = $this->getFilterExpression();
225
+        $this->connection->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression);
226
+        $sourceSchema = $connection->getSchemaManager()->createSchema();
227
+
228
+        // remove tables we don't know about
229
+        foreach ($sourceSchema->getTables() as $table) {
230
+            if (!$targetSchema->hasTable($table->getName())) {
231
+                $sourceSchema->dropTable($table->getName());
232
+            }
233
+        }
234
+        // remove sequences we don't know about
235
+        foreach ($sourceSchema->getSequences() as $table) {
236
+            if (!$targetSchema->hasSequence($table->getName())) {
237
+                $sourceSchema->dropSequence($table->getName());
238
+            }
239
+        }
240
+
241
+        $comparator = new Comparator();
242
+        return $comparator->compare($sourceSchema, $targetSchema);
243
+    }
244
+
245
+    /**
246
+     * @param \Doctrine\DBAL\Schema\Schema $targetSchema
247
+     * @param \Doctrine\DBAL\Connection $connection
248
+     */
249
+    protected function applySchema(Schema $targetSchema, \Doctrine\DBAL\Connection $connection = null) {
250
+        if (is_null($connection)) {
251
+            $connection = $this->connection;
252
+        }
253
+
254
+        $schemaDiff = $this->getDiff($targetSchema, $connection);
255
+
256
+        $connection->beginTransaction();
257
+        $sqls = $schemaDiff->toSql($connection->getDatabasePlatform());
258
+        $step = 0;
259
+        foreach ($sqls as $sql) {
260
+            $this->emit($sql, $step++, count($sqls));
261
+            $connection->query($sql);
262
+        }
263
+        $connection->commit();
264
+    }
265
+
266
+    /**
267
+     * @param string $sourceName
268
+     * @param string $targetName
269
+     */
270
+    protected function copyTable($sourceName, $targetName) {
271
+        $quotedSource = $this->connection->quoteIdentifier($sourceName);
272
+        $quotedTarget = $this->connection->quoteIdentifier($targetName);
273
+
274
+        $this->connection->exec('CREATE TABLE ' . $quotedTarget . ' (LIKE ' . $quotedSource . ')');
275
+        $this->connection->exec('INSERT INTO ' . $quotedTarget . ' SELECT * FROM ' . $quotedSource);
276
+    }
277
+
278
+    /**
279
+     * @param string $name
280
+     */
281
+    protected function dropTable($name) {
282
+        $this->connection->exec('DROP TABLE ' . $this->connection->quoteIdentifier($name));
283
+    }
284
+
285
+    /**
286
+     * @param $statement
287
+     * @return string
288
+     */
289
+    protected function convertStatementToScript($statement) {
290
+        $script = $statement . ';';
291
+        $script .= PHP_EOL;
292
+        $script .= PHP_EOL;
293
+        return $script;
294
+    }
295
+
296
+    protected function getFilterExpression() {
297
+        return '/^' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/';
298
+    }
299
+
300
+    protected function emit($sql, $step, $max) {
301
+        if ($this->noEmit) {
302
+            return;
303
+        }
304
+        if (is_null($this->dispatcher)) {
305
+            return;
306
+        }
307
+        $this->dispatcher->dispatch('\OC\DB\Migrator::executeSql', new GenericEvent($sql, [$step + 1, $max]));
308
+    }
309
+
310
+    private function emitCheckStep($tableName, $step, $max) {
311
+        if (is_null($this->dispatcher)) {
312
+            return;
313
+        }
314
+        $this->dispatcher->dispatch('\OC\DB\Migrator::checkTable', new GenericEvent($tableName, [$step + 1, $max]));
315
+    }
316 316
 }
Please login to merge, or discard this patch.
lib/private/Memcache/Memcached.php 2 patches
Indentation   +189 added lines, -189 removed lines patch added patch discarded remove patch
@@ -33,193 +33,193 @@
 block discarded – undo
33 33
 use OCP\IMemcache;
34 34
 
35 35
 class Memcached extends Cache implements IMemcache {
36
-	use CASTrait;
37
-
38
-	/**
39
-	 * @var \Memcached $cache
40
-	 */
41
-	private static $cache = null;
42
-
43
-	use CADTrait;
44
-
45
-	public function __construct($prefix = '') {
46
-		parent::__construct($prefix);
47
-		if (is_null(self::$cache)) {
48
-			self::$cache = new \Memcached();
49
-
50
-			$defaultOptions = [
51
-				\Memcached::OPT_CONNECT_TIMEOUT => 50,
52
-				\Memcached::OPT_RETRY_TIMEOUT => 50,
53
-				\Memcached::OPT_SEND_TIMEOUT => 50,
54
-				\Memcached::OPT_RECV_TIMEOUT => 50,
55
-				\Memcached::OPT_POLL_TIMEOUT => 50,
56
-
57
-				// Enable compression
58
-				\Memcached::OPT_COMPRESSION => true,
59
-
60
-				// Turn on consistent hashing
61
-				\Memcached::OPT_LIBKETAMA_COMPATIBLE => true,
62
-
63
-				// Enable Binary Protocol
64
-				//\Memcached::OPT_BINARY_PROTOCOL =>      true,
65
-			];
66
-			// by default enable igbinary serializer if available
67
-			if (\Memcached::HAVE_IGBINARY) {
68
-				$defaultOptions[\Memcached::OPT_SERIALIZER] =
69
-					\Memcached::SERIALIZER_IGBINARY;
70
-			}
71
-			$options = \OC::$server->getConfig()->getSystemValue('memcached_options', []);
72
-			if (is_array($options)) {
73
-				$options = $options + $defaultOptions;
74
-				self::$cache->setOptions($options);
75
-			} else {
76
-				throw new HintException("Expected 'memcached_options' config to be an array, got $options");
77
-			}
78
-
79
-			$servers = \OC::$server->getSystemConfig()->getValue('memcached_servers');
80
-			if (!$servers) {
81
-				$server = \OC::$server->getSystemConfig()->getValue('memcached_server');
82
-				if ($server) {
83
-					$servers = [$server];
84
-				} else {
85
-					$servers = [['localhost', 11211]];
86
-				}
87
-			}
88
-			self::$cache->addServers($servers);
89
-		}
90
-	}
91
-
92
-	/**
93
-	 * entries in XCache gets namespaced to prevent collisions between owncloud instances and users
94
-	 */
95
-	protected function getNameSpace() {
96
-		return $this->prefix;
97
-	}
98
-
99
-	public function get($key) {
100
-		$result = self::$cache->get($this->getNameSpace() . $key);
101
-		if ($result === false and self::$cache->getResultCode() == \Memcached::RES_NOTFOUND) {
102
-			return null;
103
-		} else {
104
-			return $result;
105
-		}
106
-	}
107
-
108
-	public function set($key, $value, $ttl = 0) {
109
-		if ($ttl > 0) {
110
-			$result = self::$cache->set($this->getNameSpace() . $key, $value, $ttl);
111
-		} else {
112
-			$result = self::$cache->set($this->getNameSpace() . $key, $value);
113
-		}
114
-		if ($result !== true) {
115
-			$this->verifyReturnCode();
116
-		}
117
-		return $result;
118
-	}
119
-
120
-	public function hasKey($key) {
121
-		self::$cache->get($this->getNameSpace() . $key);
122
-		return self::$cache->getResultCode() === \Memcached::RES_SUCCESS;
123
-	}
124
-
125
-	public function remove($key) {
126
-		$result = self::$cache->delete($this->getNameSpace() . $key);
127
-		if (self::$cache->getResultCode() !== \Memcached::RES_NOTFOUND) {
128
-			$this->verifyReturnCode();
129
-		}
130
-		return $result;
131
-	}
132
-
133
-	public function clear($prefix = '') {
134
-		$prefix = $this->getNameSpace() . $prefix;
135
-		$allKeys = self::$cache->getAllKeys();
136
-		if ($allKeys === false) {
137
-			// newer Memcached doesn't like getAllKeys(), flush everything
138
-			self::$cache->flush();
139
-			return true;
140
-		}
141
-		$keys = [];
142
-		$prefixLength = strlen($prefix);
143
-		foreach ($allKeys as $key) {
144
-			if (substr($key, 0, $prefixLength) === $prefix) {
145
-				$keys[] = $key;
146
-			}
147
-		}
148
-		if (method_exists(self::$cache, 'deleteMulti')) {
149
-			self::$cache->deleteMulti($keys);
150
-		} else {
151
-			foreach ($keys as $key) {
152
-				self::$cache->delete($key);
153
-			}
154
-		}
155
-		return true;
156
-	}
157
-
158
-	/**
159
-	 * Set a value in the cache if it's not already stored
160
-	 *
161
-	 * @param string $key
162
-	 * @param mixed $value
163
-	 * @param int $ttl Time To Live in seconds. Defaults to 60*60*24
164
-	 * @return bool
165
-	 * @throws \Exception
166
-	 */
167
-	public function add($key, $value, $ttl = 0) {
168
-		$result = self::$cache->add($this->getPrefix() . $key, $value, $ttl);
169
-		if (self::$cache->getResultCode() !== \Memcached::RES_NOTSTORED) {
170
-			$this->verifyReturnCode();
171
-		}
172
-		return $result;
173
-	}
174
-
175
-	/**
176
-	 * Increase a stored number
177
-	 *
178
-	 * @param string $key
179
-	 * @param int $step
180
-	 * @return int | bool
181
-	 */
182
-	public function inc($key, $step = 1) {
183
-		$this->add($key, 0);
184
-		$result = self::$cache->increment($this->getPrefix() . $key, $step);
185
-
186
-		if (self::$cache->getResultCode() !== \Memcached::RES_SUCCESS) {
187
-			return false;
188
-		}
189
-
190
-		return $result;
191
-	}
192
-
193
-	/**
194
-	 * Decrease a stored number
195
-	 *
196
-	 * @param string $key
197
-	 * @param int $step
198
-	 * @return int | bool
199
-	 */
200
-	public function dec($key, $step = 1) {
201
-		$result = self::$cache->decrement($this->getPrefix() . $key, $step);
202
-
203
-		if (self::$cache->getResultCode() !== \Memcached::RES_SUCCESS) {
204
-			return false;
205
-		}
206
-
207
-		return $result;
208
-	}
209
-
210
-	public static function isAvailable() {
211
-		return extension_loaded('memcached');
212
-	}
213
-
214
-	/**
215
-	 * @throws \Exception
216
-	 */
217
-	private function verifyReturnCode() {
218
-		$code = self::$cache->getResultCode();
219
-		if ($code === \Memcached::RES_SUCCESS) {
220
-			return;
221
-		}
222
-		$message = self::$cache->getResultMessage();
223
-		throw new \Exception("Error $code interacting with memcached : $message");
224
-	}
36
+    use CASTrait;
37
+
38
+    /**
39
+     * @var \Memcached $cache
40
+     */
41
+    private static $cache = null;
42
+
43
+    use CADTrait;
44
+
45
+    public function __construct($prefix = '') {
46
+        parent::__construct($prefix);
47
+        if (is_null(self::$cache)) {
48
+            self::$cache = new \Memcached();
49
+
50
+            $defaultOptions = [
51
+                \Memcached::OPT_CONNECT_TIMEOUT => 50,
52
+                \Memcached::OPT_RETRY_TIMEOUT => 50,
53
+                \Memcached::OPT_SEND_TIMEOUT => 50,
54
+                \Memcached::OPT_RECV_TIMEOUT => 50,
55
+                \Memcached::OPT_POLL_TIMEOUT => 50,
56
+
57
+                // Enable compression
58
+                \Memcached::OPT_COMPRESSION => true,
59
+
60
+                // Turn on consistent hashing
61
+                \Memcached::OPT_LIBKETAMA_COMPATIBLE => true,
62
+
63
+                // Enable Binary Protocol
64
+                //\Memcached::OPT_BINARY_PROTOCOL =>      true,
65
+            ];
66
+            // by default enable igbinary serializer if available
67
+            if (\Memcached::HAVE_IGBINARY) {
68
+                $defaultOptions[\Memcached::OPT_SERIALIZER] =
69
+                    \Memcached::SERIALIZER_IGBINARY;
70
+            }
71
+            $options = \OC::$server->getConfig()->getSystemValue('memcached_options', []);
72
+            if (is_array($options)) {
73
+                $options = $options + $defaultOptions;
74
+                self::$cache->setOptions($options);
75
+            } else {
76
+                throw new HintException("Expected 'memcached_options' config to be an array, got $options");
77
+            }
78
+
79
+            $servers = \OC::$server->getSystemConfig()->getValue('memcached_servers');
80
+            if (!$servers) {
81
+                $server = \OC::$server->getSystemConfig()->getValue('memcached_server');
82
+                if ($server) {
83
+                    $servers = [$server];
84
+                } else {
85
+                    $servers = [['localhost', 11211]];
86
+                }
87
+            }
88
+            self::$cache->addServers($servers);
89
+        }
90
+    }
91
+
92
+    /**
93
+     * entries in XCache gets namespaced to prevent collisions between owncloud instances and users
94
+     */
95
+    protected function getNameSpace() {
96
+        return $this->prefix;
97
+    }
98
+
99
+    public function get($key) {
100
+        $result = self::$cache->get($this->getNameSpace() . $key);
101
+        if ($result === false and self::$cache->getResultCode() == \Memcached::RES_NOTFOUND) {
102
+            return null;
103
+        } else {
104
+            return $result;
105
+        }
106
+    }
107
+
108
+    public function set($key, $value, $ttl = 0) {
109
+        if ($ttl > 0) {
110
+            $result = self::$cache->set($this->getNameSpace() . $key, $value, $ttl);
111
+        } else {
112
+            $result = self::$cache->set($this->getNameSpace() . $key, $value);
113
+        }
114
+        if ($result !== true) {
115
+            $this->verifyReturnCode();
116
+        }
117
+        return $result;
118
+    }
119
+
120
+    public function hasKey($key) {
121
+        self::$cache->get($this->getNameSpace() . $key);
122
+        return self::$cache->getResultCode() === \Memcached::RES_SUCCESS;
123
+    }
124
+
125
+    public function remove($key) {
126
+        $result = self::$cache->delete($this->getNameSpace() . $key);
127
+        if (self::$cache->getResultCode() !== \Memcached::RES_NOTFOUND) {
128
+            $this->verifyReturnCode();
129
+        }
130
+        return $result;
131
+    }
132
+
133
+    public function clear($prefix = '') {
134
+        $prefix = $this->getNameSpace() . $prefix;
135
+        $allKeys = self::$cache->getAllKeys();
136
+        if ($allKeys === false) {
137
+            // newer Memcached doesn't like getAllKeys(), flush everything
138
+            self::$cache->flush();
139
+            return true;
140
+        }
141
+        $keys = [];
142
+        $prefixLength = strlen($prefix);
143
+        foreach ($allKeys as $key) {
144
+            if (substr($key, 0, $prefixLength) === $prefix) {
145
+                $keys[] = $key;
146
+            }
147
+        }
148
+        if (method_exists(self::$cache, 'deleteMulti')) {
149
+            self::$cache->deleteMulti($keys);
150
+        } else {
151
+            foreach ($keys as $key) {
152
+                self::$cache->delete($key);
153
+            }
154
+        }
155
+        return true;
156
+    }
157
+
158
+    /**
159
+     * Set a value in the cache if it's not already stored
160
+     *
161
+     * @param string $key
162
+     * @param mixed $value
163
+     * @param int $ttl Time To Live in seconds. Defaults to 60*60*24
164
+     * @return bool
165
+     * @throws \Exception
166
+     */
167
+    public function add($key, $value, $ttl = 0) {
168
+        $result = self::$cache->add($this->getPrefix() . $key, $value, $ttl);
169
+        if (self::$cache->getResultCode() !== \Memcached::RES_NOTSTORED) {
170
+            $this->verifyReturnCode();
171
+        }
172
+        return $result;
173
+    }
174
+
175
+    /**
176
+     * Increase a stored number
177
+     *
178
+     * @param string $key
179
+     * @param int $step
180
+     * @return int | bool
181
+     */
182
+    public function inc($key, $step = 1) {
183
+        $this->add($key, 0);
184
+        $result = self::$cache->increment($this->getPrefix() . $key, $step);
185
+
186
+        if (self::$cache->getResultCode() !== \Memcached::RES_SUCCESS) {
187
+            return false;
188
+        }
189
+
190
+        return $result;
191
+    }
192
+
193
+    /**
194
+     * Decrease a stored number
195
+     *
196
+     * @param string $key
197
+     * @param int $step
198
+     * @return int | bool
199
+     */
200
+    public function dec($key, $step = 1) {
201
+        $result = self::$cache->decrement($this->getPrefix() . $key, $step);
202
+
203
+        if (self::$cache->getResultCode() !== \Memcached::RES_SUCCESS) {
204
+            return false;
205
+        }
206
+
207
+        return $result;
208
+    }
209
+
210
+    public static function isAvailable() {
211
+        return extension_loaded('memcached');
212
+    }
213
+
214
+    /**
215
+     * @throws \Exception
216
+     */
217
+    private function verifyReturnCode() {
218
+        $code = self::$cache->getResultCode();
219
+        if ($code === \Memcached::RES_SUCCESS) {
220
+            return;
221
+        }
222
+        $message = self::$cache->getResultMessage();
223
+        throw new \Exception("Error $code interacting with memcached : $message");
224
+    }
225 225
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 	}
98 98
 
99 99
 	public function get($key) {
100
-		$result = self::$cache->get($this->getNameSpace() . $key);
100
+		$result = self::$cache->get($this->getNameSpace().$key);
101 101
 		if ($result === false and self::$cache->getResultCode() == \Memcached::RES_NOTFOUND) {
102 102
 			return null;
103 103
 		} else {
@@ -107,9 +107,9 @@  discard block
 block discarded – undo
107 107
 
108 108
 	public function set($key, $value, $ttl = 0) {
109 109
 		if ($ttl > 0) {
110
-			$result = self::$cache->set($this->getNameSpace() . $key, $value, $ttl);
110
+			$result = self::$cache->set($this->getNameSpace().$key, $value, $ttl);
111 111
 		} else {
112
-			$result = self::$cache->set($this->getNameSpace() . $key, $value);
112
+			$result = self::$cache->set($this->getNameSpace().$key, $value);
113 113
 		}
114 114
 		if ($result !== true) {
115 115
 			$this->verifyReturnCode();
@@ -118,12 +118,12 @@  discard block
 block discarded – undo
118 118
 	}
119 119
 
120 120
 	public function hasKey($key) {
121
-		self::$cache->get($this->getNameSpace() . $key);
121
+		self::$cache->get($this->getNameSpace().$key);
122 122
 		return self::$cache->getResultCode() === \Memcached::RES_SUCCESS;
123 123
 	}
124 124
 
125 125
 	public function remove($key) {
126
-		$result = self::$cache->delete($this->getNameSpace() . $key);
126
+		$result = self::$cache->delete($this->getNameSpace().$key);
127 127
 		if (self::$cache->getResultCode() !== \Memcached::RES_NOTFOUND) {
128 128
 			$this->verifyReturnCode();
129 129
 		}
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
 	}
132 132
 
133 133
 	public function clear($prefix = '') {
134
-		$prefix = $this->getNameSpace() . $prefix;
134
+		$prefix = $this->getNameSpace().$prefix;
135 135
 		$allKeys = self::$cache->getAllKeys();
136 136
 		if ($allKeys === false) {
137 137
 			// newer Memcached doesn't like getAllKeys(), flush everything
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 	 * @throws \Exception
166 166
 	 */
167 167
 	public function add($key, $value, $ttl = 0) {
168
-		$result = self::$cache->add($this->getPrefix() . $key, $value, $ttl);
168
+		$result = self::$cache->add($this->getPrefix().$key, $value, $ttl);
169 169
 		if (self::$cache->getResultCode() !== \Memcached::RES_NOTSTORED) {
170 170
 			$this->verifyReturnCode();
171 171
 		}
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 	 */
182 182
 	public function inc($key, $step = 1) {
183 183
 		$this->add($key, 0);
184
-		$result = self::$cache->increment($this->getPrefix() . $key, $step);
184
+		$result = self::$cache->increment($this->getPrefix().$key, $step);
185 185
 
186 186
 		if (self::$cache->getResultCode() !== \Memcached::RES_SUCCESS) {
187 187
 			return false;
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
 	 * @return int | bool
199 199
 	 */
200 200
 	public function dec($key, $step = 1) {
201
-		$result = self::$cache->decrement($this->getPrefix() . $key, $step);
201
+		$result = self::$cache->decrement($this->getPrefix().$key, $step);
202 202
 
203 203
 		if (self::$cache->getResultCode() !== \Memcached::RES_SUCCESS) {
204 204
 			return false;
Please login to merge, or discard this patch.
lib/private/Template/JSResourceLocator.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -77,20 +77,20 @@
 block discarded – undo
77 77
 
78 78
 		// missing translations files fill be ignored
79 79
 		if (strpos($script, 'l10n/') === 0) {
80
-			$this->appendIfExist($app_path, $script . '.js', $app_url);
80
+			$this->appendIfExist($app_path, $script.'.js', $app_url);
81 81
 			return;
82 82
 		}
83 83
 
84 84
 		if ($app_path === false && $app_url === false) {
85 85
 			$this->logger->error('Could not find resource {resource} to load', [
86
-				'resource' => $app . '/' . $script . '.js',
86
+				'resource' => $app.'/'.$script.'.js',
87 87
 				'app' => 'jsresourceloader',
88 88
 			]);
89 89
 			return;
90 90
 		}
91 91
 
92 92
 		if (!$this->cacheAndAppendCombineJsonIfExist($app_path, $script.'.json', $app)) {
93
-			$this->append($app_path, $script . '.js', $app_url);
93
+			$this->append($app_path, $script.'.js', $app_url);
94 94
 		}
95 95
 	}
96 96
 
Please login to merge, or discard this patch.
Indentation   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -30,103 +30,103 @@
 block discarded – undo
30 30
 
31 31
 class JSResourceLocator extends ResourceLocator {
32 32
 
33
-	/** @var JSCombiner */
34
-	protected $jsCombiner;
35
-
36
-	public function __construct(\OCP\ILogger $logger, $theme, array $core_map, array $party_map, JSCombiner $JSCombiner) {
37
-		parent::__construct($logger, $theme, $core_map, $party_map);
38
-
39
-		$this->jsCombiner = $JSCombiner;
40
-	}
41
-
42
-	/**
43
-	 * @param string $script
44
-	 */
45
-	public function doFind($script) {
46
-		$theme_dir = 'themes/'.$this->theme.'/';
47
-		if (strpos($script, '3rdparty') === 0
48
-			&& $this->appendIfExist($this->thirdpartyroot, $script.'.js')) {
49
-			return;
50
-		}
51
-
52
-		if (strpos($script, '/l10n/') !== false) {
53
-			// For language files we try to load them all, so themes can overwrite
54
-			// single l10n strings without having to translate all of them.
55
-			$found = 0;
56
-			$found += $this->appendIfExist($this->serverroot, 'core/'.$script.'.js');
57
-			$found += $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$script.'.js');
58
-			$found += $this->appendIfExist($this->serverroot, $script.'.js');
59
-			$found += $this->appendIfExist($this->serverroot, $theme_dir.$script.'.js');
60
-			$found += $this->appendIfExist($this->serverroot, 'apps/'.$script.'.js');
61
-			$found += $this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$script.'.js');
62
-
63
-			if ($found) {
64
-				return;
65
-			}
66
-		} elseif ($this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$script.'.js')
67
-			|| $this->appendIfExist($this->serverroot, $theme_dir.$script.'.js')
68
-			|| $this->appendIfExist($this->serverroot, $script.'.js')
69
-			|| $this->cacheAndAppendCombineJsonIfExist($this->serverroot, $script.'.json')
70
-			|| $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$script.'.js')
71
-			|| $this->appendIfExist($this->serverroot, 'core/'.$script.'.js')
72
-			|| $this->cacheAndAppendCombineJsonIfExist($this->serverroot, 'core/'.$script.'.json')
73
-		) {
74
-			return;
75
-		}
76
-
77
-		$app = substr($script, 0, strpos($script, '/'));
78
-		$script = substr($script, strpos($script, '/') + 1);
79
-		$app_path = \OC_App::getAppPath($app);
80
-		$app_url = \OC_App::getAppWebPath($app);
81
-
82
-		if ($app_path !== false) {
83
-			// Account for the possibility of having symlinks in app path. Only
84
-			// do this if $app_path is set, because an empty argument to realpath
85
-			// gets turned into cwd.
86
-			$app_path = realpath($app_path);
87
-		}
88
-
89
-		// missing translations files fill be ignored
90
-		if (strpos($script, 'l10n/') === 0) {
91
-			$this->appendIfExist($app_path, $script . '.js', $app_url);
92
-			return;
93
-		}
94
-
95
-		if ($app_path === false && $app_url === false) {
96
-			$this->logger->error('Could not find resource {resource} to load', [
97
-				'resource' => $app . '/' . $script . '.js',
98
-				'app' => 'jsresourceloader',
99
-			]);
100
-			return;
101
-		}
102
-
103
-		if (!$this->cacheAndAppendCombineJsonIfExist($app_path, $script.'.json', $app)) {
104
-			$this->append($app_path, $script . '.js', $app_url);
105
-		}
106
-	}
107
-
108
-	/**
109
-	 * @param string $script
110
-	 */
111
-	public function doFindTheme($script) {
112
-	}
113
-
114
-	protected function cacheAndAppendCombineJsonIfExist($root, $file, $app = 'core') {
115
-		if (is_file($root.'/'.$file)) {
116
-			if ($this->jsCombiner->process($root, $file, $app)) {
117
-				$this->append($this->serverroot, $this->jsCombiner->getCachedJS($app, $file), false, false);
118
-			} else {
119
-				// Add all the files from the json
120
-				$files = $this->jsCombiner->getContent($root, $file);
121
-				$app_url = \OC_App::getAppWebPath($app);
122
-
123
-				foreach ($files as $jsFile) {
124
-					$this->append($root, $jsFile, $app_url);
125
-				}
126
-			}
127
-			return true;
128
-		}
129
-
130
-		return false;
131
-	}
33
+    /** @var JSCombiner */
34
+    protected $jsCombiner;
35
+
36
+    public function __construct(\OCP\ILogger $logger, $theme, array $core_map, array $party_map, JSCombiner $JSCombiner) {
37
+        parent::__construct($logger, $theme, $core_map, $party_map);
38
+
39
+        $this->jsCombiner = $JSCombiner;
40
+    }
41
+
42
+    /**
43
+     * @param string $script
44
+     */
45
+    public function doFind($script) {
46
+        $theme_dir = 'themes/'.$this->theme.'/';
47
+        if (strpos($script, '3rdparty') === 0
48
+            && $this->appendIfExist($this->thirdpartyroot, $script.'.js')) {
49
+            return;
50
+        }
51
+
52
+        if (strpos($script, '/l10n/') !== false) {
53
+            // For language files we try to load them all, so themes can overwrite
54
+            // single l10n strings without having to translate all of them.
55
+            $found = 0;
56
+            $found += $this->appendIfExist($this->serverroot, 'core/'.$script.'.js');
57
+            $found += $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$script.'.js');
58
+            $found += $this->appendIfExist($this->serverroot, $script.'.js');
59
+            $found += $this->appendIfExist($this->serverroot, $theme_dir.$script.'.js');
60
+            $found += $this->appendIfExist($this->serverroot, 'apps/'.$script.'.js');
61
+            $found += $this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$script.'.js');
62
+
63
+            if ($found) {
64
+                return;
65
+            }
66
+        } elseif ($this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$script.'.js')
67
+            || $this->appendIfExist($this->serverroot, $theme_dir.$script.'.js')
68
+            || $this->appendIfExist($this->serverroot, $script.'.js')
69
+            || $this->cacheAndAppendCombineJsonIfExist($this->serverroot, $script.'.json')
70
+            || $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$script.'.js')
71
+            || $this->appendIfExist($this->serverroot, 'core/'.$script.'.js')
72
+            || $this->cacheAndAppendCombineJsonIfExist($this->serverroot, 'core/'.$script.'.json')
73
+        ) {
74
+            return;
75
+        }
76
+
77
+        $app = substr($script, 0, strpos($script, '/'));
78
+        $script = substr($script, strpos($script, '/') + 1);
79
+        $app_path = \OC_App::getAppPath($app);
80
+        $app_url = \OC_App::getAppWebPath($app);
81
+
82
+        if ($app_path !== false) {
83
+            // Account for the possibility of having symlinks in app path. Only
84
+            // do this if $app_path is set, because an empty argument to realpath
85
+            // gets turned into cwd.
86
+            $app_path = realpath($app_path);
87
+        }
88
+
89
+        // missing translations files fill be ignored
90
+        if (strpos($script, 'l10n/') === 0) {
91
+            $this->appendIfExist($app_path, $script . '.js', $app_url);
92
+            return;
93
+        }
94
+
95
+        if ($app_path === false && $app_url === false) {
96
+            $this->logger->error('Could not find resource {resource} to load', [
97
+                'resource' => $app . '/' . $script . '.js',
98
+                'app' => 'jsresourceloader',
99
+            ]);
100
+            return;
101
+        }
102
+
103
+        if (!$this->cacheAndAppendCombineJsonIfExist($app_path, $script.'.json', $app)) {
104
+            $this->append($app_path, $script . '.js', $app_url);
105
+        }
106
+    }
107
+
108
+    /**
109
+     * @param string $script
110
+     */
111
+    public function doFindTheme($script) {
112
+    }
113
+
114
+    protected function cacheAndAppendCombineJsonIfExist($root, $file, $app = 'core') {
115
+        if (is_file($root.'/'.$file)) {
116
+            if ($this->jsCombiner->process($root, $file, $app)) {
117
+                $this->append($this->serverroot, $this->jsCombiner->getCachedJS($app, $file), false, false);
118
+            } else {
119
+                // Add all the files from the json
120
+                $files = $this->jsCombiner->getContent($root, $file);
121
+                $app_url = \OC_App::getAppWebPath($app);
122
+
123
+                foreach ($files as $jsFile) {
124
+                    $this->append($root, $jsFile, $app_url);
125
+                }
126
+            }
127
+            return true;
128
+        }
129
+
130
+        return false;
131
+    }
132 132
 }
Please login to merge, or discard this patch.
lib/private/Template/CSSResourceLocator.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@
 block discarded – undo
65 65
 
66 66
 		if ($app_path === false && $app_url === false) {
67 67
 			$this->logger->error('Could not find resource {resource} to load', [
68
-				'resource' => $app . '/' . $style . '.css',
68
+				'resource' => $app.'/'.$style.'.css',
69 69
 				'app' => 'cssresourceloader',
70 70
 			]);
71 71
 			return;
Please login to merge, or discard this patch.
Indentation   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -36,116 +36,116 @@
 block discarded – undo
36 36
 
37 37
 class CSSResourceLocator extends ResourceLocator {
38 38
 
39
-	/** @var SCSSCacher */
40
-	protected $scssCacher;
41
-
42
-	/**
43
-	 * @param ILogger $logger
44
-	 * @param string $theme
45
-	 * @param array $core_map
46
-	 * @param array $party_map
47
-	 * @param SCSSCacher $scssCacher
48
-	 */
49
-	public function __construct(ILogger $logger, $theme, $core_map, $party_map, $scssCacher) {
50
-		$this->scssCacher = $scssCacher;
51
-
52
-		parent::__construct($logger, $theme, $core_map, $party_map);
53
-	}
54
-
55
-	/**
56
-	 * @param string $style
57
-	 */
58
-	public function doFind($style) {
59
-		$app = substr($style, 0, strpos($style, '/'));
60
-		if (strpos($style, '3rdparty') === 0
61
-			&& $this->appendIfExist($this->thirdpartyroot, $style.'.css')
62
-			|| $this->cacheAndAppendScssIfExist($this->serverroot, $style.'.scss', $app)
63
-			|| $this->cacheAndAppendScssIfExist($this->serverroot, 'core/'.$style.'.scss')
64
-			|| $this->appendIfExist($this->serverroot, $style.'.css')
65
-			|| $this->appendIfExist($this->serverroot, 'core/'.$style.'.css')
66
-		) {
67
-			return;
68
-		}
69
-		$style = substr($style, strpos($style, '/') + 1);
70
-		$app_path = \OC_App::getAppPath($app);
71
-		$app_url = \OC_App::getAppWebPath($app);
72
-
73
-		if ($app_path === false && $app_url === false) {
74
-			$this->logger->error('Could not find resource {resource} to load', [
75
-				'resource' => $app . '/' . $style . '.css',
76
-				'app' => 'cssresourceloader',
77
-			]);
78
-			return;
79
-		}
80
-
81
-		// Account for the possibility of having symlinks in app path. Doing
82
-		// this here instead of above as an empty argument to realpath gets
83
-		// turned into cwd.
84
-		$app_path = realpath($app_path);
85
-
86
-		if (!$this->cacheAndAppendScssIfExist($app_path, $style.'.scss', $app)) {
87
-			$this->append($app_path, $style.'.css', $app_url);
88
-		}
89
-	}
90
-
91
-	/**
92
-	 * @param string $style
93
-	 */
94
-	public function doFindTheme($style) {
95
-		$theme_dir = 'themes/'.$this->theme.'/';
96
-		$this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$style.'.css')
97
-			|| $this->appendIfExist($this->serverroot, $theme_dir.$style.'.css')
98
-			|| $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$style.'.css');
99
-	}
100
-
101
-	/**
102
-	 * cache and append the scss $file if exist at $root
103
-	 *
104
-	 * @param string $root path to check
105
-	 * @param string $file the filename
106
-	 * @return bool True if the resource was found and cached, false otherwise
107
-	 */
108
-	protected function cacheAndAppendScssIfExist($root, $file, $app = 'core') {
109
-		if (is_file($root.'/'.$file)) {
110
-			if ($this->scssCacher !== null) {
111
-				if ($this->scssCacher->process($root, $file, $app)) {
112
-					$this->append($this->serverroot, $this->scssCacher->getCachedSCSS($app, $file), \OC::$WEBROOT, true, true);
113
-					return true;
114
-				} else {
115
-					$this->logger->warning('Failed to compile and/or save '.$root.'/'.$file, ['app' => 'core']);
116
-					return false;
117
-				}
118
-			} else {
119
-				return true;
120
-			}
121
-		}
122
-		return false;
123
-	}
124
-
125
-	public function append($root, $file, $webRoot = null, $throw = true, $scss = false) {
126
-		if (!$scss) {
127
-			parent::append($root, $file, $webRoot, $throw);
128
-		} else {
129
-			if (!$webRoot) {
130
-				$webRoot = $this->findWebRoot($root);
131
-
132
-				if ($webRoot === null) {
133
-					$webRoot = '';
134
-					$this->logger->error('ResourceLocator can not find a web root (root: {root}, file: {file}, webRoot: {webRoot}, throw: {throw})', [
135
-						'app' => 'lib',
136
-						'root' => $root,
137
-						'file' => $file,
138
-						'webRoot' => $webRoot,
139
-						'throw' => $throw ? 'true' : 'false'
140
-					]);
141
-
142
-					if ($throw && $root === '/') {
143
-						throw new ResourceNotFoundException($file, $webRoot);
144
-					}
145
-				}
146
-			}
147
-
148
-			$this->resources[] = [$webRoot ?: \OC::$WEBROOT, $webRoot, $file];
149
-		}
150
-	}
39
+    /** @var SCSSCacher */
40
+    protected $scssCacher;
41
+
42
+    /**
43
+     * @param ILogger $logger
44
+     * @param string $theme
45
+     * @param array $core_map
46
+     * @param array $party_map
47
+     * @param SCSSCacher $scssCacher
48
+     */
49
+    public function __construct(ILogger $logger, $theme, $core_map, $party_map, $scssCacher) {
50
+        $this->scssCacher = $scssCacher;
51
+
52
+        parent::__construct($logger, $theme, $core_map, $party_map);
53
+    }
54
+
55
+    /**
56
+     * @param string $style
57
+     */
58
+    public function doFind($style) {
59
+        $app = substr($style, 0, strpos($style, '/'));
60
+        if (strpos($style, '3rdparty') === 0
61
+            && $this->appendIfExist($this->thirdpartyroot, $style.'.css')
62
+            || $this->cacheAndAppendScssIfExist($this->serverroot, $style.'.scss', $app)
63
+            || $this->cacheAndAppendScssIfExist($this->serverroot, 'core/'.$style.'.scss')
64
+            || $this->appendIfExist($this->serverroot, $style.'.css')
65
+            || $this->appendIfExist($this->serverroot, 'core/'.$style.'.css')
66
+        ) {
67
+            return;
68
+        }
69
+        $style = substr($style, strpos($style, '/') + 1);
70
+        $app_path = \OC_App::getAppPath($app);
71
+        $app_url = \OC_App::getAppWebPath($app);
72
+
73
+        if ($app_path === false && $app_url === false) {
74
+            $this->logger->error('Could not find resource {resource} to load', [
75
+                'resource' => $app . '/' . $style . '.css',
76
+                'app' => 'cssresourceloader',
77
+            ]);
78
+            return;
79
+        }
80
+
81
+        // Account for the possibility of having symlinks in app path. Doing
82
+        // this here instead of above as an empty argument to realpath gets
83
+        // turned into cwd.
84
+        $app_path = realpath($app_path);
85
+
86
+        if (!$this->cacheAndAppendScssIfExist($app_path, $style.'.scss', $app)) {
87
+            $this->append($app_path, $style.'.css', $app_url);
88
+        }
89
+    }
90
+
91
+    /**
92
+     * @param string $style
93
+     */
94
+    public function doFindTheme($style) {
95
+        $theme_dir = 'themes/'.$this->theme.'/';
96
+        $this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$style.'.css')
97
+            || $this->appendIfExist($this->serverroot, $theme_dir.$style.'.css')
98
+            || $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$style.'.css');
99
+    }
100
+
101
+    /**
102
+     * cache and append the scss $file if exist at $root
103
+     *
104
+     * @param string $root path to check
105
+     * @param string $file the filename
106
+     * @return bool True if the resource was found and cached, false otherwise
107
+     */
108
+    protected function cacheAndAppendScssIfExist($root, $file, $app = 'core') {
109
+        if (is_file($root.'/'.$file)) {
110
+            if ($this->scssCacher !== null) {
111
+                if ($this->scssCacher->process($root, $file, $app)) {
112
+                    $this->append($this->serverroot, $this->scssCacher->getCachedSCSS($app, $file), \OC::$WEBROOT, true, true);
113
+                    return true;
114
+                } else {
115
+                    $this->logger->warning('Failed to compile and/or save '.$root.'/'.$file, ['app' => 'core']);
116
+                    return false;
117
+                }
118
+            } else {
119
+                return true;
120
+            }
121
+        }
122
+        return false;
123
+    }
124
+
125
+    public function append($root, $file, $webRoot = null, $throw = true, $scss = false) {
126
+        if (!$scss) {
127
+            parent::append($root, $file, $webRoot, $throw);
128
+        } else {
129
+            if (!$webRoot) {
130
+                $webRoot = $this->findWebRoot($root);
131
+
132
+                if ($webRoot === null) {
133
+                    $webRoot = '';
134
+                    $this->logger->error('ResourceLocator can not find a web root (root: {root}, file: {file}, webRoot: {webRoot}, throw: {throw})', [
135
+                        'app' => 'lib',
136
+                        'root' => $root,
137
+                        'file' => $file,
138
+                        'webRoot' => $webRoot,
139
+                        'throw' => $throw ? 'true' : 'false'
140
+                    ]);
141
+
142
+                    if ($throw && $root === '/') {
143
+                        throw new ResourceNotFoundException($file, $webRoot);
144
+                    }
145
+                }
146
+            }
147
+
148
+            $this->resources[] = [$webRoot ?: \OC::$WEBROOT, $webRoot, $file];
149
+        }
150
+    }
151 151
 }
Please login to merge, or discard this patch.
lib/private/Setup/MySQL.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 			//we don't have a dbuser specified in config
125 125
 			if ($this->dbUser !== $oldUser) {
126 126
 				//add prefix to the admin username to prevent collisions
127
-				$adminUser = substr('oc_' . $username, 0, 16);
127
+				$adminUser = substr('oc_'.$username, 0, 16);
128 128
 
129 129
 				$i = 1;
130 130
 				while (true) {
@@ -148,8 +148,8 @@  discard block
 block discarded – undo
148 148
 							break;
149 149
 						} else {
150 150
 							//repeat with different username
151
-							$length = strlen((string)$i);
152
-							$adminUser = substr('oc_' . $username, 0, 16 - $length) . $i;
151
+							$length = strlen((string) $i);
152
+							$adminUser = substr('oc_'.$username, 0, 16 - $length).$i;
153 153
 							$i++;
154 154
 						}
155 155
 					} else {
Please login to merge, or discard this patch.
Indentation   +156 added lines, -156 removed lines patch added patch discarded remove patch
@@ -38,160 +38,160 @@
 block discarded – undo
38 38
 use Doctrine\DBAL\Platforms\MySQL80Platform;
39 39
 
40 40
 class MySQL extends AbstractDatabase {
41
-	public $dbprettyname = 'MySQL/MariaDB';
42
-
43
-	public function setupDatabase($username) {
44
-		//check if the database user has admin right
45
-		$connection = $this->connect(['dbname' => null]);
46
-
47
-		// detect mb4
48
-		$tools = new MySqlTools();
49
-		if ($tools->supports4ByteCharset($connection)) {
50
-			$this->config->setValue('mysql.utf8mb4', true);
51
-			$connection = $this->connect(['dbname' => null]);
52
-		}
53
-
54
-		$this->createSpecificUser($username, $connection);
55
-
56
-		//create the database
57
-		$this->createDatabase($connection);
58
-
59
-		//fill the database if needed
60
-		$query = 'select count(*) from information_schema.tables where table_schema=? AND table_name = ?';
61
-		$connection->executeQuery($query, [$this->dbName, $this->tablePrefix.'users']);
62
-
63
-		$connection->close();
64
-		$connection = $this->connect();
65
-		try {
66
-			$connection->connect();
67
-		} catch (\Exception $e) {
68
-			$this->logger->logException($e);
69
-			throw new \OC\DatabaseSetupException($this->trans->t('MySQL username and/or password not valid'),
70
-				$this->trans->t('You need to enter details of an existing account.'));
71
-		}
72
-	}
73
-
74
-	/**
75
-	 * @param \OC\DB\Connection $connection
76
-	 */
77
-	private function createDatabase($connection) {
78
-		try {
79
-			$name = $this->dbName;
80
-			$user = $this->dbUser;
81
-			//we can't use OC_DB functions here because we need to connect as the administrative user.
82
-			$characterSet = $this->config->getValue('mysql.utf8mb4', false) ? 'utf8mb4' : 'utf8';
83
-			$query = "CREATE DATABASE IF NOT EXISTS `$name` CHARACTER SET $characterSet COLLATE ${characterSet}_bin;";
84
-			$connection->executeUpdate($query);
85
-		} catch (\Exception $ex) {
86
-			$this->logger->logException($ex, [
87
-				'message' => 'Database creation failed.',
88
-				'level' => ILogger::ERROR,
89
-				'app' => 'mysql.setup',
90
-			]);
91
-			return;
92
-		}
93
-
94
-		try {
95
-			//this query will fail if there aren't the right permissions, ignore the error
96
-			$query = "GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EVENT, TRIGGER ON `$name` . * TO '$user'";
97
-			$connection->executeUpdate($query);
98
-		} catch (\Exception $ex) {
99
-			$this->logger->logException($ex, [
100
-				'message' => 'Could not automatically grant privileges, this can be ignored if database user already had privileges.',
101
-				'level' => ILogger::DEBUG,
102
-				'app' => 'mysql.setup',
103
-			]);
104
-		}
105
-	}
106
-
107
-	/**
108
-	 * @param IDBConnection $connection
109
-	 * @throws \OC\DatabaseSetupException
110
-	 */
111
-	private function createDBUser($connection) {
112
-		try {
113
-			$name = $this->dbUser;
114
-			$password = $this->dbPassword;
115
-			// we need to create 2 accounts, one for global use and one for local user. if we don't specify the local one,
116
-			// the anonymous user would take precedence when there is one.
117
-
118
-			if ($connection->getDatabasePlatform() instanceof Mysql80Platform) {
119
-				$query = "CREATE USER '$name'@'localhost' IDENTIFIED WITH mysql_native_password BY '$password'";
120
-				$connection->executeUpdate($query);
121
-				$query = "CREATE USER '$name'@'%' IDENTIFIED WITH mysql_native_password BY '$password'";
122
-				$connection->executeUpdate($query);
123
-			} else {
124
-				$query = "CREATE USER '$name'@'localhost' IDENTIFIED BY '$password'";
125
-				$connection->executeUpdate($query);
126
-				$query = "CREATE USER '$name'@'%' IDENTIFIED BY '$password'";
127
-				$connection->executeUpdate($query);
128
-			}
129
-		} catch (\Exception $ex) {
130
-			$this->logger->logException($ex, [
131
-				'message' => 'Database user creation failed.',
132
-				'level' => ILogger::ERROR,
133
-				'app' => 'mysql.setup',
134
-			]);
135
-		}
136
-	}
137
-
138
-	/**
139
-	 * @param $username
140
-	 * @param IDBConnection $connection
141
-	 * @return array
142
-	 */
143
-	private function createSpecificUser($username, $connection) {
144
-		try {
145
-			//user already specified in config
146
-			$oldUser = $this->config->getValue('dbuser', false);
147
-
148
-			//we don't have a dbuser specified in config
149
-			if ($this->dbUser !== $oldUser) {
150
-				//add prefix to the admin username to prevent collisions
151
-				$adminUser = substr('oc_' . $username, 0, 16);
152
-
153
-				$i = 1;
154
-				while (true) {
155
-					//this should be enough to check for admin rights in mysql
156
-					$query = 'SELECT user FROM mysql.user WHERE user=?';
157
-					$result = $connection->executeQuery($query, [$adminUser]);
158
-
159
-					//current dbuser has admin rights
160
-					if ($result) {
161
-						$data = $result->fetchAll();
162
-						//new dbuser does not exist
163
-						if (count($data) === 0) {
164
-							//use the admin login data for the new database user
165
-							$this->dbUser = $adminUser;
166
-
167
-							//create a random password so we don't need to store the admin password in the config file
168
-							$this->dbPassword = $this->random->generate(30);
169
-
170
-							$this->createDBUser($connection);
171
-
172
-							break;
173
-						} else {
174
-							//repeat with different username
175
-							$length = strlen((string)$i);
176
-							$adminUser = substr('oc_' . $username, 0, 16 - $length) . $i;
177
-							$i++;
178
-						}
179
-					} else {
180
-						break;
181
-					}
182
-				}
183
-			}
184
-		} catch (\Exception $ex) {
185
-			$this->logger->logException($ex, [
186
-				'message' => 'Can not create a new MySQL user, will continue with the provided user.',
187
-				'level' => ILogger::INFO,
188
-				'app' => 'mysql.setup',
189
-			]);
190
-		}
191
-
192
-		$this->config->setValues([
193
-			'dbuser' => $this->dbUser,
194
-			'dbpassword' => $this->dbPassword,
195
-		]);
196
-	}
41
+    public $dbprettyname = 'MySQL/MariaDB';
42
+
43
+    public function setupDatabase($username) {
44
+        //check if the database user has admin right
45
+        $connection = $this->connect(['dbname' => null]);
46
+
47
+        // detect mb4
48
+        $tools = new MySqlTools();
49
+        if ($tools->supports4ByteCharset($connection)) {
50
+            $this->config->setValue('mysql.utf8mb4', true);
51
+            $connection = $this->connect(['dbname' => null]);
52
+        }
53
+
54
+        $this->createSpecificUser($username, $connection);
55
+
56
+        //create the database
57
+        $this->createDatabase($connection);
58
+
59
+        //fill the database if needed
60
+        $query = 'select count(*) from information_schema.tables where table_schema=? AND table_name = ?';
61
+        $connection->executeQuery($query, [$this->dbName, $this->tablePrefix.'users']);
62
+
63
+        $connection->close();
64
+        $connection = $this->connect();
65
+        try {
66
+            $connection->connect();
67
+        } catch (\Exception $e) {
68
+            $this->logger->logException($e);
69
+            throw new \OC\DatabaseSetupException($this->trans->t('MySQL username and/or password not valid'),
70
+                $this->trans->t('You need to enter details of an existing account.'));
71
+        }
72
+    }
73
+
74
+    /**
75
+     * @param \OC\DB\Connection $connection
76
+     */
77
+    private function createDatabase($connection) {
78
+        try {
79
+            $name = $this->dbName;
80
+            $user = $this->dbUser;
81
+            //we can't use OC_DB functions here because we need to connect as the administrative user.
82
+            $characterSet = $this->config->getValue('mysql.utf8mb4', false) ? 'utf8mb4' : 'utf8';
83
+            $query = "CREATE DATABASE IF NOT EXISTS `$name` CHARACTER SET $characterSet COLLATE ${characterSet}_bin;";
84
+            $connection->executeUpdate($query);
85
+        } catch (\Exception $ex) {
86
+            $this->logger->logException($ex, [
87
+                'message' => 'Database creation failed.',
88
+                'level' => ILogger::ERROR,
89
+                'app' => 'mysql.setup',
90
+            ]);
91
+            return;
92
+        }
93
+
94
+        try {
95
+            //this query will fail if there aren't the right permissions, ignore the error
96
+            $query = "GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EVENT, TRIGGER ON `$name` . * TO '$user'";
97
+            $connection->executeUpdate($query);
98
+        } catch (\Exception $ex) {
99
+            $this->logger->logException($ex, [
100
+                'message' => 'Could not automatically grant privileges, this can be ignored if database user already had privileges.',
101
+                'level' => ILogger::DEBUG,
102
+                'app' => 'mysql.setup',
103
+            ]);
104
+        }
105
+    }
106
+
107
+    /**
108
+     * @param IDBConnection $connection
109
+     * @throws \OC\DatabaseSetupException
110
+     */
111
+    private function createDBUser($connection) {
112
+        try {
113
+            $name = $this->dbUser;
114
+            $password = $this->dbPassword;
115
+            // we need to create 2 accounts, one for global use and one for local user. if we don't specify the local one,
116
+            // the anonymous user would take precedence when there is one.
117
+
118
+            if ($connection->getDatabasePlatform() instanceof Mysql80Platform) {
119
+                $query = "CREATE USER '$name'@'localhost' IDENTIFIED WITH mysql_native_password BY '$password'";
120
+                $connection->executeUpdate($query);
121
+                $query = "CREATE USER '$name'@'%' IDENTIFIED WITH mysql_native_password BY '$password'";
122
+                $connection->executeUpdate($query);
123
+            } else {
124
+                $query = "CREATE USER '$name'@'localhost' IDENTIFIED BY '$password'";
125
+                $connection->executeUpdate($query);
126
+                $query = "CREATE USER '$name'@'%' IDENTIFIED BY '$password'";
127
+                $connection->executeUpdate($query);
128
+            }
129
+        } catch (\Exception $ex) {
130
+            $this->logger->logException($ex, [
131
+                'message' => 'Database user creation failed.',
132
+                'level' => ILogger::ERROR,
133
+                'app' => 'mysql.setup',
134
+            ]);
135
+        }
136
+    }
137
+
138
+    /**
139
+     * @param $username
140
+     * @param IDBConnection $connection
141
+     * @return array
142
+     */
143
+    private function createSpecificUser($username, $connection) {
144
+        try {
145
+            //user already specified in config
146
+            $oldUser = $this->config->getValue('dbuser', false);
147
+
148
+            //we don't have a dbuser specified in config
149
+            if ($this->dbUser !== $oldUser) {
150
+                //add prefix to the admin username to prevent collisions
151
+                $adminUser = substr('oc_' . $username, 0, 16);
152
+
153
+                $i = 1;
154
+                while (true) {
155
+                    //this should be enough to check for admin rights in mysql
156
+                    $query = 'SELECT user FROM mysql.user WHERE user=?';
157
+                    $result = $connection->executeQuery($query, [$adminUser]);
158
+
159
+                    //current dbuser has admin rights
160
+                    if ($result) {
161
+                        $data = $result->fetchAll();
162
+                        //new dbuser does not exist
163
+                        if (count($data) === 0) {
164
+                            //use the admin login data for the new database user
165
+                            $this->dbUser = $adminUser;
166
+
167
+                            //create a random password so we don't need to store the admin password in the config file
168
+                            $this->dbPassword = $this->random->generate(30);
169
+
170
+                            $this->createDBUser($connection);
171
+
172
+                            break;
173
+                        } else {
174
+                            //repeat with different username
175
+                            $length = strlen((string)$i);
176
+                            $adminUser = substr('oc_' . $username, 0, 16 - $length) . $i;
177
+                            $i++;
178
+                        }
179
+                    } else {
180
+                        break;
181
+                    }
182
+                }
183
+            }
184
+        } catch (\Exception $ex) {
185
+            $this->logger->logException($ex, [
186
+                'message' => 'Can not create a new MySQL user, will continue with the provided user.',
187
+                'level' => ILogger::INFO,
188
+                'app' => 'mysql.setup',
189
+            ]);
190
+        }
191
+
192
+        $this->config->setValues([
193
+            'dbuser' => $this->dbUser,
194
+            'dbpassword' => $this->dbPassword,
195
+        ]);
196
+    }
197 197
 }
Please login to merge, or discard this patch.
lib/private/Tagging/TagMapper.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -54,8 +54,8 @@  discard block
 block discarded – undo
54 54
 			$owners = [$owners];
55 55
 		}
56 56
 
57
-		$sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` '
58
-			. 'WHERE `uid` IN (' . str_repeat('?,', count($owners) - 1) . '?) AND `type` = ? ORDER BY `category`';
57
+		$sql = 'SELECT `id`, `uid`, `type`, `category` FROM `'.$this->getTableName().'` '
58
+			. 'WHERE `uid` IN ('.str_repeat('?,', count($owners) - 1).'?) AND `type` = ? ORDER BY `category`';
59 59
 		return $this->findEntities($sql, array_merge($owners, [$type]));
60 60
 	}
61 61
 
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 	 * @return bool
67 67
 	 */
68 68
 	public function tagExists($tag) {
69
-		$sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` '
69
+		$sql = 'SELECT `id`, `uid`, `type`, `category` FROM `'.$this->getTableName().'` '
70 70
 			. 'WHERE `uid` = ? AND `type` = ? AND `category` = ?';
71 71
 		try {
72 72
 			$this->findEntity($sql, [$tag->getOwner(), $tag->getType(), $tag->getName()]);
Please login to merge, or discard this patch.
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -35,46 +35,46 @@
 block discarded – undo
35 35
  */
36 36
 class TagMapper extends Mapper {
37 37
 
38
-	/**
39
-	 * Constructor.
40
-	 *
41
-	 * @param IDBConnection $db Instance of the Db abstraction layer.
42
-	 */
43
-	public function __construct(IDBConnection $db) {
44
-		parent::__construct($db, 'vcategory', Tag::class);
45
-	}
38
+    /**
39
+     * Constructor.
40
+     *
41
+     * @param IDBConnection $db Instance of the Db abstraction layer.
42
+     */
43
+    public function __construct(IDBConnection $db) {
44
+        parent::__construct($db, 'vcategory', Tag::class);
45
+    }
46 46
 
47
-	/**
48
-	 * Load tags from the database.
49
-	 *
50
-	 * @param array|string $owners The user(s) whose tags we are going to load.
51
-	 * @param string $type The type of item for which we are loading tags.
52
-	 * @return array An array of Tag objects.
53
-	 */
54
-	public function loadTags($owners, $type) {
55
-		if (!is_array($owners)) {
56
-			$owners = [$owners];
57
-		}
47
+    /**
48
+     * Load tags from the database.
49
+     *
50
+     * @param array|string $owners The user(s) whose tags we are going to load.
51
+     * @param string $type The type of item for which we are loading tags.
52
+     * @return array An array of Tag objects.
53
+     */
54
+    public function loadTags($owners, $type) {
55
+        if (!is_array($owners)) {
56
+            $owners = [$owners];
57
+        }
58 58
 
59
-		$sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` '
60
-			. 'WHERE `uid` IN (' . str_repeat('?,', count($owners) - 1) . '?) AND `type` = ? ORDER BY `category`';
61
-		return $this->findEntities($sql, array_merge($owners, [$type]));
62
-	}
59
+        $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` '
60
+            . 'WHERE `uid` IN (' . str_repeat('?,', count($owners) - 1) . '?) AND `type` = ? ORDER BY `category`';
61
+        return $this->findEntities($sql, array_merge($owners, [$type]));
62
+    }
63 63
 
64
-	/**
65
-	 * Check if a given Tag object already exists in the database.
66
-	 *
67
-	 * @param Tag $tag The tag to look for in the database.
68
-	 * @return bool
69
-	 */
70
-	public function tagExists($tag) {
71
-		$sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` '
72
-			. 'WHERE `uid` = ? AND `type` = ? AND `category` = ?';
73
-		try {
74
-			$this->findEntity($sql, [$tag->getOwner(), $tag->getType(), $tag->getName()]);
75
-		} catch (DoesNotExistException $e) {
76
-			return false;
77
-		}
78
-		return true;
79
-	}
64
+    /**
65
+     * Check if a given Tag object already exists in the database.
66
+     *
67
+     * @param Tag $tag The tag to look for in the database.
68
+     * @return bool
69
+     */
70
+    public function tagExists($tag) {
71
+        $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` '
72
+            . 'WHERE `uid` = ? AND `type` = ? AND `category` = ?';
73
+        try {
74
+            $this->findEntity($sql, [$tag->getOwner(), $tag->getType(), $tag->getName()]);
75
+        } catch (DoesNotExistException $e) {
76
+            return false;
77
+        }
78
+        return true;
79
+    }
80 80
 }
Please login to merge, or discard this patch.
lib/private/AppFramework/OCS/V1Response.php 2 patches
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -27,52 +27,52 @@
 block discarded – undo
27 27
 
28 28
 class V1Response extends BaseResponse {
29 29
 
30
-	/**
31
-	 * The V1 endpoint has very limited http status codes basically everything
32
-	 * is status 200 except 401
33
-	 *
34
-	 * @return int
35
-	 */
36
-	public function getStatus() {
37
-		$status = parent::getStatus();
38
-		if ($status === Http::STATUS_FORBIDDEN || $status === API::RESPOND_UNAUTHORISED) {
39
-			return Http::STATUS_UNAUTHORIZED;
40
-		}
30
+    /**
31
+     * The V1 endpoint has very limited http status codes basically everything
32
+     * is status 200 except 401
33
+     *
34
+     * @return int
35
+     */
36
+    public function getStatus() {
37
+        $status = parent::getStatus();
38
+        if ($status === Http::STATUS_FORBIDDEN || $status === API::RESPOND_UNAUTHORISED) {
39
+            return Http::STATUS_UNAUTHORIZED;
40
+        }
41 41
 
42
-		return Http::STATUS_OK;
43
-	}
42
+        return Http::STATUS_OK;
43
+    }
44 44
 
45
-	/**
46
-	 * In v1 all OK is 100
47
-	 *
48
-	 * @return int
49
-	 */
50
-	public function getOCSStatus() {
51
-		$status = parent::getOCSStatus();
45
+    /**
46
+     * In v1 all OK is 100
47
+     *
48
+     * @return int
49
+     */
50
+    public function getOCSStatus() {
51
+        $status = parent::getOCSStatus();
52 52
 
53
-		if ($status === Http::STATUS_OK) {
54
-			return 100;
55
-		}
53
+        if ($status === Http::STATUS_OK) {
54
+            return 100;
55
+        }
56 56
 
57
-		return $status;
58
-	}
57
+        return $status;
58
+    }
59 59
 
60
-	/**
61
-	 * Construct the meta part of the response
62
-	 * And then late the base class render
63
-	 *
64
-	 * @return string
65
-	 */
66
-	public function render() {
67
-		$meta = [
68
-			'status' => $this->getOCSStatus() === 100 ? 'ok' : 'failure',
69
-			'statuscode' => $this->getOCSStatus(),
70
-			'message' => $this->getOCSStatus() === 100 ? 'OK' : $this->statusMessage,
71
-		];
60
+    /**
61
+     * Construct the meta part of the response
62
+     * And then late the base class render
63
+     *
64
+     * @return string
65
+     */
66
+    public function render() {
67
+        $meta = [
68
+            'status' => $this->getOCSStatus() === 100 ? 'ok' : 'failure',
69
+            'statuscode' => $this->getOCSStatus(),
70
+            'message' => $this->getOCSStatus() === 100 ? 'OK' : $this->statusMessage,
71
+        ];
72 72
 
73
-		$meta['totalitems'] = $this->itemsCount !== null ? (string)$this->itemsCount : '';
74
-		$meta['itemsperpage'] = $this->itemsPerPage !== null ? (string)$this->itemsPerPage: '';
73
+        $meta['totalitems'] = $this->itemsCount !== null ? (string)$this->itemsCount : '';
74
+        $meta['itemsperpage'] = $this->itemsPerPage !== null ? (string)$this->itemsPerPage: '';
75 75
 
76
-		return $this->renderResult($meta);
77
-	}
76
+        return $this->renderResult($meta);
77
+    }
78 78
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -70,8 +70,8 @@
 block discarded – undo
70 70
 			'message' => $this->getOCSStatus() === 100 ? 'OK' : $this->statusMessage,
71 71
 		];
72 72
 
73
-		$meta['totalitems'] = $this->itemsCount !== null ? (string)$this->itemsCount : '';
74
-		$meta['itemsperpage'] = $this->itemsPerPage !== null ? (string)$this->itemsPerPage: '';
73
+		$meta['totalitems'] = $this->itemsCount !== null ? (string) $this->itemsCount : '';
74
+		$meta['itemsperpage'] = $this->itemsPerPage !== null ? (string) $this->itemsPerPage : '';
75 75
 
76 76
 		return $this->renderResult($meta);
77 77
 	}
Please login to merge, or discard this patch.
lib/private/AppFramework/OCS/V2Response.php 1 patch
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -27,49 +27,49 @@
 block discarded – undo
27 27
 
28 28
 class V2Response extends BaseResponse {
29 29
 
30
-	/**
31
-	 * The V2 endpoint just passes on status codes.
32
-	 * Of course we have to map the OCS specific codes to proper HTTP status codes
33
-	 *
34
-	 * @return int
35
-	 */
36
-	public function getStatus() {
37
-		$status = parent::getStatus();
38
-		if ($status === API::RESPOND_UNAUTHORISED) {
39
-			return Http::STATUS_UNAUTHORIZED;
40
-		} elseif ($status === API::RESPOND_NOT_FOUND) {
41
-			return Http::STATUS_NOT_FOUND;
42
-		} elseif ($status === API::RESPOND_SERVER_ERROR || $status === API::RESPOND_UNKNOWN_ERROR) {
43
-			return Http::STATUS_INTERNAL_SERVER_ERROR;
44
-		} elseif ($status < 200 || $status > 600) {
45
-			return Http::STATUS_BAD_REQUEST;
46
-		}
30
+    /**
31
+     * The V2 endpoint just passes on status codes.
32
+     * Of course we have to map the OCS specific codes to proper HTTP status codes
33
+     *
34
+     * @return int
35
+     */
36
+    public function getStatus() {
37
+        $status = parent::getStatus();
38
+        if ($status === API::RESPOND_UNAUTHORISED) {
39
+            return Http::STATUS_UNAUTHORIZED;
40
+        } elseif ($status === API::RESPOND_NOT_FOUND) {
41
+            return Http::STATUS_NOT_FOUND;
42
+        } elseif ($status === API::RESPOND_SERVER_ERROR || $status === API::RESPOND_UNKNOWN_ERROR) {
43
+            return Http::STATUS_INTERNAL_SERVER_ERROR;
44
+        } elseif ($status < 200 || $status > 600) {
45
+            return Http::STATUS_BAD_REQUEST;
46
+        }
47 47
 
48
-		return $status;
49
-	}
48
+        return $status;
49
+    }
50 50
 
51
-	/**
52
-	 * Construct the meta part of the response
53
-	 * And then late the base class render
54
-	 *
55
-	 * @return string
56
-	 */
57
-	public function render() {
58
-		$status = parent::getStatus();
51
+    /**
52
+     * Construct the meta part of the response
53
+     * And then late the base class render
54
+     *
55
+     * @return string
56
+     */
57
+    public function render() {
58
+        $status = parent::getStatus();
59 59
 
60
-		$meta = [
61
-			'status' => $status >= 200 && $status < 300 ? 'ok' : 'failure',
62
-			'statuscode' => $this->getOCSStatus(),
63
-			'message' => $status >= 200 && $status < 300 ? 'OK' : $this->statusMessage,
64
-		];
60
+        $meta = [
61
+            'status' => $status >= 200 && $status < 300 ? 'ok' : 'failure',
62
+            'statuscode' => $this->getOCSStatus(),
63
+            'message' => $status >= 200 && $status < 300 ? 'OK' : $this->statusMessage,
64
+        ];
65 65
 
66
-		if ($this->itemsCount !== null) {
67
-			$meta['totalitems'] = $this->itemsCount;
68
-		}
69
-		if ($this->itemsPerPage !== null) {
70
-			$meta['itemsperpage'] = $this->itemsPerPage;
71
-		}
66
+        if ($this->itemsCount !== null) {
67
+            $meta['totalitems'] = $this->itemsCount;
68
+        }
69
+        if ($this->itemsPerPage !== null) {
70
+            $meta['itemsperpage'] = $this->itemsPerPage;
71
+        }
72 72
 
73
-		return $this->renderResult($meta);
74
-	}
73
+        return $this->renderResult($meta);
74
+    }
75 75
 }
Please login to merge, or discard this patch.
apps/dav/lib/Comments/EntityCollection.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@
 block discarded – undo
68 68
 		foreach (['id', 'name'] as $property) {
69 69
 			$$property = trim($$property);
70 70
 			if (empty($$property) || !is_string($$property)) {
71
-				throw new \InvalidArgumentException('"' . $property . '" parameter must be non-empty string');
71
+				throw new \InvalidArgumentException('"'.$property.'" parameter must be non-empty string');
72 72
 			}
73 73
 		}
74 74
 		$this->id = $id;
Please login to merge, or discard this patch.
Indentation   +140 added lines, -140 removed lines patch added patch discarded remove patch
@@ -42,155 +42,155 @@
 block discarded – undo
42 42
  * @package OCA\DAV\Comments
43 43
  */
44 44
 class EntityCollection extends RootCollection implements IProperties {
45
-	public const PROPERTY_NAME_READ_MARKER = '{http://owncloud.org/ns}readMarker';
45
+    public const PROPERTY_NAME_READ_MARKER = '{http://owncloud.org/ns}readMarker';
46 46
 
47
-	/** @var  string */
48
-	protected $id;
47
+    /** @var  string */
48
+    protected $id;
49 49
 
50
-	/** @var  ILogger */
51
-	protected $logger;
50
+    /** @var  ILogger */
51
+    protected $logger;
52 52
 
53
-	/**
54
-	 * @param string $id
55
-	 * @param string $name
56
-	 * @param ICommentsManager $commentsManager
57
-	 * @param IUserManager $userManager
58
-	 * @param IUserSession $userSession
59
-	 * @param ILogger $logger
60
-	 */
61
-	public function __construct(
62
-		$id,
63
-		$name,
64
-		ICommentsManager $commentsManager,
65
-		IUserManager $userManager,
66
-		IUserSession $userSession,
67
-		ILogger $logger
68
-	) {
69
-		foreach (['id', 'name'] as $property) {
70
-			$$property = trim($$property);
71
-			if (empty($$property) || !is_string($$property)) {
72
-				throw new \InvalidArgumentException('"' . $property . '" parameter must be non-empty string');
73
-			}
74
-		}
75
-		$this->id = $id;
76
-		$this->name = $name;
77
-		$this->commentsManager = $commentsManager;
78
-		$this->logger = $logger;
79
-		$this->userManager = $userManager;
80
-		$this->userSession = $userSession;
81
-	}
53
+    /**
54
+     * @param string $id
55
+     * @param string $name
56
+     * @param ICommentsManager $commentsManager
57
+     * @param IUserManager $userManager
58
+     * @param IUserSession $userSession
59
+     * @param ILogger $logger
60
+     */
61
+    public function __construct(
62
+        $id,
63
+        $name,
64
+        ICommentsManager $commentsManager,
65
+        IUserManager $userManager,
66
+        IUserSession $userSession,
67
+        ILogger $logger
68
+    ) {
69
+        foreach (['id', 'name'] as $property) {
70
+            $$property = trim($$property);
71
+            if (empty($$property) || !is_string($$property)) {
72
+                throw new \InvalidArgumentException('"' . $property . '" parameter must be non-empty string');
73
+            }
74
+        }
75
+        $this->id = $id;
76
+        $this->name = $name;
77
+        $this->commentsManager = $commentsManager;
78
+        $this->logger = $logger;
79
+        $this->userManager = $userManager;
80
+        $this->userSession = $userSession;
81
+    }
82 82
 
83
-	/**
84
-	 * returns the ID of this entity
85
-	 *
86
-	 * @return string
87
-	 */
88
-	public function getId() {
89
-		return $this->id;
90
-	}
83
+    /**
84
+     * returns the ID of this entity
85
+     *
86
+     * @return string
87
+     */
88
+    public function getId() {
89
+        return $this->id;
90
+    }
91 91
 
92
-	/**
93
-	 * Returns a specific child node, referenced by its name
94
-	 *
95
-	 * This method must throw Sabre\DAV\Exception\NotFound if the node does not
96
-	 * exist.
97
-	 *
98
-	 * @param string $name
99
-	 * @return \Sabre\DAV\INode
100
-	 * @throws NotFound
101
-	 */
102
-	public function getChild($name) {
103
-		try {
104
-			$comment = $this->commentsManager->get($name);
105
-			return new CommentNode(
106
-				$this->commentsManager,
107
-				$comment,
108
-				$this->userManager,
109
-				$this->userSession,
110
-				$this->logger
111
-			);
112
-		} catch (NotFoundException $e) {
113
-			throw new NotFound();
114
-		}
115
-	}
92
+    /**
93
+     * Returns a specific child node, referenced by its name
94
+     *
95
+     * This method must throw Sabre\DAV\Exception\NotFound if the node does not
96
+     * exist.
97
+     *
98
+     * @param string $name
99
+     * @return \Sabre\DAV\INode
100
+     * @throws NotFound
101
+     */
102
+    public function getChild($name) {
103
+        try {
104
+            $comment = $this->commentsManager->get($name);
105
+            return new CommentNode(
106
+                $this->commentsManager,
107
+                $comment,
108
+                $this->userManager,
109
+                $this->userSession,
110
+                $this->logger
111
+            );
112
+        } catch (NotFoundException $e) {
113
+            throw new NotFound();
114
+        }
115
+    }
116 116
 
117
-	/**
118
-	 * Returns an array with all the child nodes
119
-	 *
120
-	 * @return \Sabre\DAV\INode[]
121
-	 */
122
-	public function getChildren() {
123
-		return $this->findChildren();
124
-	}
117
+    /**
118
+     * Returns an array with all the child nodes
119
+     *
120
+     * @return \Sabre\DAV\INode[]
121
+     */
122
+    public function getChildren() {
123
+        return $this->findChildren();
124
+    }
125 125
 
126
-	/**
127
-	 * Returns an array of comment nodes. Result can be influenced by offset,
128
-	 * limit and date time parameters.
129
-	 *
130
-	 * @param int $limit
131
-	 * @param int $offset
132
-	 * @param \DateTime|null $datetime
133
-	 * @return CommentNode[]
134
-	 */
135
-	public function findChildren($limit = 0, $offset = 0, \DateTime $datetime = null) {
136
-		$comments = $this->commentsManager->getForObject($this->name, $this->id, $limit, $offset, $datetime);
137
-		$result = [];
138
-		foreach ($comments as $comment) {
139
-			$result[] = new CommentNode(
140
-				$this->commentsManager,
141
-				$comment,
142
-				$this->userManager,
143
-				$this->userSession,
144
-				$this->logger
145
-			);
146
-		}
147
-		return $result;
148
-	}
126
+    /**
127
+     * Returns an array of comment nodes. Result can be influenced by offset,
128
+     * limit and date time parameters.
129
+     *
130
+     * @param int $limit
131
+     * @param int $offset
132
+     * @param \DateTime|null $datetime
133
+     * @return CommentNode[]
134
+     */
135
+    public function findChildren($limit = 0, $offset = 0, \DateTime $datetime = null) {
136
+        $comments = $this->commentsManager->getForObject($this->name, $this->id, $limit, $offset, $datetime);
137
+        $result = [];
138
+        foreach ($comments as $comment) {
139
+            $result[] = new CommentNode(
140
+                $this->commentsManager,
141
+                $comment,
142
+                $this->userManager,
143
+                $this->userSession,
144
+                $this->logger
145
+            );
146
+        }
147
+        return $result;
148
+    }
149 149
 
150
-	/**
151
-	 * Checks if a child-node with the specified name exists
152
-	 *
153
-	 * @param string $name
154
-	 * @return bool
155
-	 */
156
-	public function childExists($name) {
157
-		try {
158
-			$this->commentsManager->get($name);
159
-			return true;
160
-		} catch (NotFoundException $e) {
161
-			return false;
162
-		}
163
-	}
150
+    /**
151
+     * Checks if a child-node with the specified name exists
152
+     *
153
+     * @param string $name
154
+     * @return bool
155
+     */
156
+    public function childExists($name) {
157
+        try {
158
+            $this->commentsManager->get($name);
159
+            return true;
160
+        } catch (NotFoundException $e) {
161
+            return false;
162
+        }
163
+    }
164 164
 
165
-	/**
166
-	 * Sets the read marker to the specified date for the logged in user
167
-	 *
168
-	 * @param \DateTime $value
169
-	 * @return bool
170
-	 */
171
-	public function setReadMarker($value) {
172
-		$dateTime = new \DateTime($value);
173
-		$user = $this->userSession->getUser();
174
-		$this->commentsManager->setReadMark($this->name, $this->id, $dateTime, $user);
175
-		return true;
176
-	}
165
+    /**
166
+     * Sets the read marker to the specified date for the logged in user
167
+     *
168
+     * @param \DateTime $value
169
+     * @return bool
170
+     */
171
+    public function setReadMarker($value) {
172
+        $dateTime = new \DateTime($value);
173
+        $user = $this->userSession->getUser();
174
+        $this->commentsManager->setReadMark($this->name, $this->id, $dateTime, $user);
175
+        return true;
176
+    }
177 177
 
178
-	/**
179
-	 * @inheritdoc
180
-	 */
181
-	public function propPatch(PropPatch $propPatch) {
182
-		$propPatch->handle(self::PROPERTY_NAME_READ_MARKER, [$this, 'setReadMarker']);
183
-	}
178
+    /**
179
+     * @inheritdoc
180
+     */
181
+    public function propPatch(PropPatch $propPatch) {
182
+        $propPatch->handle(self::PROPERTY_NAME_READ_MARKER, [$this, 'setReadMarker']);
183
+    }
184 184
 
185
-	/**
186
-	 * @inheritdoc
187
-	 */
188
-	public function getProperties($properties) {
189
-		$marker = null;
190
-		$user = $this->userSession->getUser();
191
-		if (!is_null($user)) {
192
-			$marker = $this->commentsManager->getReadMark($this->name, $this->id, $user);
193
-		}
194
-		return [self::PROPERTY_NAME_READ_MARKER => $marker];
195
-	}
185
+    /**
186
+     * @inheritdoc
187
+     */
188
+    public function getProperties($properties) {
189
+        $marker = null;
190
+        $user = $this->userSession->getUser();
191
+        if (!is_null($user)) {
192
+            $marker = $this->commentsManager->getReadMark($this->name, $this->id, $user);
193
+        }
194
+        return [self::PROPERTY_NAME_READ_MARKER => $marker];
195
+    }
196 196
 }
Please login to merge, or discard this patch.