Passed
Push — master ( 963d96...2d5047 )
by Morris
13:06
created
lib/private/DB/Migrator.php 1 patch
Indentation   +268 added lines, -268 removed lines patch added patch discarded remove patch
@@ -43,272 +43,272 @@
 block discarded – undo
43 43
 
44 44
 class Migrator {
45 45
 
46
-	/** @var \Doctrine\DBAL\Connection */
47
-	protected $connection;
48
-
49
-	/** @var ISecureRandom */
50
-	private $random;
51
-
52
-	/** @var IConfig */
53
-	protected $config;
54
-
55
-	/** @var EventDispatcher  */
56
-	private $dispatcher;
57
-
58
-	/** @var bool */
59
-	private $noEmit = false;
60
-
61
-	/**
62
-	 * @param \Doctrine\DBAL\Connection|Connection $connection
63
-	 * @param ISecureRandom $random
64
-	 * @param IConfig $config
65
-	 * @param EventDispatcher $dispatcher
66
-	 */
67
-	public function __construct(\Doctrine\DBAL\Connection $connection,
68
-								ISecureRandom $random,
69
-								IConfig $config,
70
-								EventDispatcher $dispatcher = null) {
71
-		$this->connection = $connection;
72
-		$this->random = $random;
73
-		$this->config = $config;
74
-		$this->dispatcher = $dispatcher;
75
-	}
76
-
77
-	/**
78
-	 * @param \Doctrine\DBAL\Schema\Schema $targetSchema
79
-	 */
80
-	public function migrate(Schema $targetSchema) {
81
-		$this->noEmit = true;
82
-		$this->applySchema($targetSchema);
83
-	}
84
-
85
-	/**
86
-	 * @param \Doctrine\DBAL\Schema\Schema $targetSchema
87
-	 * @return string
88
-	 */
89
-	public function generateChangeScript(Schema $targetSchema) {
90
-		$schemaDiff = $this->getDiff($targetSchema, $this->connection);
91
-
92
-		$script = '';
93
-		$sqls = $schemaDiff->toSql($this->connection->getDatabasePlatform());
94
-		foreach ($sqls as $sql) {
95
-			$script .= $this->convertStatementToScript($sql);
96
-		}
97
-
98
-		return $script;
99
-	}
100
-
101
-	/**
102
-	 * @param Schema $targetSchema
103
-	 * @throws \OC\DB\MigrationException
104
-	 */
105
-	public function checkMigrate(Schema $targetSchema) {
106
-		$this->noEmit = true;
107
-		/**@var \Doctrine\DBAL\Schema\Table[] $tables */
108
-		$tables = $targetSchema->getTables();
109
-		$filterExpression = $this->getFilterExpression();
110
-		$this->connection->getConfiguration()->
111
-			setFilterSchemaAssetsExpression($filterExpression);
112
-		$existingTables = $this->connection->getSchemaManager()->listTableNames();
113
-
114
-		$step = 0;
115
-		foreach ($tables as $table) {
116
-			if (strpos($table->getName(), '.')) {
117
-				list(, $tableName) = explode('.', $table->getName());
118
-			} else {
119
-				$tableName = $table->getName();
120
-			}
121
-			$this->emitCheckStep($tableName, $step++, count($tables));
122
-			// don't need to check for new tables
123
-			if (array_search($tableName, $existingTables) !== false) {
124
-				$this->checkTableMigrate($table);
125
-			}
126
-		}
127
-	}
128
-
129
-	/**
130
-	 * Create a unique name for the temporary table
131
-	 *
132
-	 * @param string $name
133
-	 * @return string
134
-	 */
135
-	protected function generateTemporaryTableName($name) {
136
-		return $this->config->getSystemValue('dbtableprefix', 'oc_') . $name . '_' . $this->random->generate(13, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS);
137
-	}
138
-
139
-	/**
140
-	 * Check the migration of a table on a copy so we can detect errors before messing with the real table
141
-	 *
142
-	 * @param \Doctrine\DBAL\Schema\Table $table
143
-	 * @throws \OC\DB\MigrationException
144
-	 */
145
-	protected function checkTableMigrate(Table $table) {
146
-		$name = $table->getName();
147
-		$tmpName = $this->generateTemporaryTableName($name);
148
-
149
-		$this->copyTable($name, $tmpName);
150
-
151
-		//create the migration schema for the temporary table
152
-		$tmpTable = $this->renameTableSchema($table, $tmpName);
153
-		$schemaConfig = new SchemaConfig();
154
-		$schemaConfig->setName($this->connection->getDatabase());
155
-		$schema = new Schema(array($tmpTable), array(), $schemaConfig);
156
-
157
-		try {
158
-			$this->applySchema($schema);
159
-			$this->dropTable($tmpName);
160
-		} catch (DBALException $e) {
161
-			// pgsql needs to commit it's failed transaction before doing anything else
162
-			if ($this->connection->isTransactionActive()) {
163
-				$this->connection->commit();
164
-			}
165
-			$this->dropTable($tmpName);
166
-			throw new MigrationException($table->getName(), $e->getMessage());
167
-		}
168
-	}
169
-
170
-	/**
171
-	 * @param \Doctrine\DBAL\Schema\Table $table
172
-	 * @param string $newName
173
-	 * @return \Doctrine\DBAL\Schema\Table
174
-	 */
175
-	protected function renameTableSchema(Table $table, $newName) {
176
-		/**
177
-		 * @var \Doctrine\DBAL\Schema\Index[] $indexes
178
-		 */
179
-		$indexes = $table->getIndexes();
180
-		$newIndexes = array();
181
-		foreach ($indexes as $index) {
182
-			if ($index->isPrimary()) {
183
-				// do not rename primary key
184
-				$indexName = $index->getName();
185
-			} else {
186
-				// avoid conflicts in index names
187
-				$indexName = $this->config->getSystemValue('dbtableprefix', 'oc_') . $this->random->generate(13, ISecureRandom::CHAR_LOWER);
188
-			}
189
-			$newIndexes[] = new Index($indexName, $index->getColumns(), $index->isUnique(), $index->isPrimary());
190
-		}
191
-
192
-		// foreign keys are not supported so we just set it to an empty array
193
-		return new Table($newName, $table->getColumns(), $newIndexes, array(), 0, $table->getOptions());
194
-	}
195
-
196
-	public function createSchema() {
197
-		$filterExpression = $this->getFilterExpression();
198
-		$this->connection->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression);
199
-		return $this->connection->getSchemaManager()->createSchema();
200
-	}
201
-
202
-	/**
203
-	 * @param Schema $targetSchema
204
-	 * @param \Doctrine\DBAL\Connection $connection
205
-	 * @return \Doctrine\DBAL\Schema\SchemaDiff
206
-	 * @throws DBALException
207
-	 */
208
-	protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) {
209
-		// adjust varchar columns with a length higher then getVarcharMaxLength to clob
210
-		foreach ($targetSchema->getTables() as $table) {
211
-			foreach ($table->getColumns() as $column) {
212
-				if ($column->getType() instanceof StringType) {
213
-					if ($column->getLength() > $connection->getDatabasePlatform()->getVarcharMaxLength()) {
214
-						$column->setType(Type::getType('text'));
215
-						$column->setLength(null);
216
-					}
217
-				}
218
-			}
219
-		}
220
-
221
-		$filterExpression = $this->getFilterExpression();
222
-		$this->connection->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression);
223
-		$sourceSchema = $connection->getSchemaManager()->createSchema();
224
-
225
-		// remove tables we don't know about
226
-		/** @var $table \Doctrine\DBAL\Schema\Table */
227
-		foreach ($sourceSchema->getTables() as $table) {
228
-			if (!$targetSchema->hasTable($table->getName())) {
229
-				$sourceSchema->dropTable($table->getName());
230
-			}
231
-		}
232
-		// remove sequences we don't know about
233
-		foreach ($sourceSchema->getSequences() as $table) {
234
-			if (!$targetSchema->hasSequence($table->getName())) {
235
-				$sourceSchema->dropSequence($table->getName());
236
-			}
237
-		}
238
-
239
-		$comparator = new Comparator();
240
-		return $comparator->compare($sourceSchema, $targetSchema);
241
-	}
242
-
243
-	/**
244
-	 * @param \Doctrine\DBAL\Schema\Schema $targetSchema
245
-	 * @param \Doctrine\DBAL\Connection $connection
246
-	 */
247
-	protected function applySchema(Schema $targetSchema, \Doctrine\DBAL\Connection $connection = null) {
248
-		if (is_null($connection)) {
249
-			$connection = $this->connection;
250
-		}
251
-
252
-		$schemaDiff = $this->getDiff($targetSchema, $connection);
253
-
254
-		$connection->beginTransaction();
255
-		$sqls = $schemaDiff->toSql($connection->getDatabasePlatform());
256
-		$step = 0;
257
-		foreach ($sqls as $sql) {
258
-			$this->emit($sql, $step++, count($sqls));
259
-			$connection->query($sql);
260
-		}
261
-		$connection->commit();
262
-	}
263
-
264
-	/**
265
-	 * @param string $sourceName
266
-	 * @param string $targetName
267
-	 */
268
-	protected function copyTable($sourceName, $targetName) {
269
-		$quotedSource = $this->connection->quoteIdentifier($sourceName);
270
-		$quotedTarget = $this->connection->quoteIdentifier($targetName);
271
-
272
-		$this->connection->exec('CREATE TABLE ' . $quotedTarget . ' (LIKE ' . $quotedSource . ')');
273
-		$this->connection->exec('INSERT INTO ' . $quotedTarget . ' SELECT * FROM ' . $quotedSource);
274
-	}
275
-
276
-	/**
277
-	 * @param string $name
278
-	 */
279
-	protected function dropTable($name) {
280
-		$this->connection->exec('DROP TABLE ' . $this->connection->quoteIdentifier($name));
281
-	}
282
-
283
-	/**
284
-	 * @param $statement
285
-	 * @return string
286
-	 */
287
-	protected function convertStatementToScript($statement) {
288
-		$script = $statement . ';';
289
-		$script .= PHP_EOL;
290
-		$script .= PHP_EOL;
291
-		return $script;
292
-	}
293
-
294
-	protected function getFilterExpression() {
295
-		return '/^' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/';
296
-	}
297
-
298
-	protected function emit($sql, $step, $max) {
299
-		if ($this->noEmit) {
300
-			return;
301
-		}
302
-		if(is_null($this->dispatcher)) {
303
-			return;
304
-		}
305
-		$this->dispatcher->dispatch('\OC\DB\Migrator::executeSql', new GenericEvent($sql, [$step+1, $max]));
306
-	}
307
-
308
-	private function emitCheckStep($tableName, $step, $max) {
309
-		if(is_null($this->dispatcher)) {
310
-			return;
311
-		}
312
-		$this->dispatcher->dispatch('\OC\DB\Migrator::checkTable', new GenericEvent($tableName, [$step+1, $max]));
313
-	}
46
+    /** @var \Doctrine\DBAL\Connection */
47
+    protected $connection;
48
+
49
+    /** @var ISecureRandom */
50
+    private $random;
51
+
52
+    /** @var IConfig */
53
+    protected $config;
54
+
55
+    /** @var EventDispatcher  */
56
+    private $dispatcher;
57
+
58
+    /** @var bool */
59
+    private $noEmit = false;
60
+
61
+    /**
62
+     * @param \Doctrine\DBAL\Connection|Connection $connection
63
+     * @param ISecureRandom $random
64
+     * @param IConfig $config
65
+     * @param EventDispatcher $dispatcher
66
+     */
67
+    public function __construct(\Doctrine\DBAL\Connection $connection,
68
+                                ISecureRandom $random,
69
+                                IConfig $config,
70
+                                EventDispatcher $dispatcher = null) {
71
+        $this->connection = $connection;
72
+        $this->random = $random;
73
+        $this->config = $config;
74
+        $this->dispatcher = $dispatcher;
75
+    }
76
+
77
+    /**
78
+     * @param \Doctrine\DBAL\Schema\Schema $targetSchema
79
+     */
80
+    public function migrate(Schema $targetSchema) {
81
+        $this->noEmit = true;
82
+        $this->applySchema($targetSchema);
83
+    }
84
+
85
+    /**
86
+     * @param \Doctrine\DBAL\Schema\Schema $targetSchema
87
+     * @return string
88
+     */
89
+    public function generateChangeScript(Schema $targetSchema) {
90
+        $schemaDiff = $this->getDiff($targetSchema, $this->connection);
91
+
92
+        $script = '';
93
+        $sqls = $schemaDiff->toSql($this->connection->getDatabasePlatform());
94
+        foreach ($sqls as $sql) {
95
+            $script .= $this->convertStatementToScript($sql);
96
+        }
97
+
98
+        return $script;
99
+    }
100
+
101
+    /**
102
+     * @param Schema $targetSchema
103
+     * @throws \OC\DB\MigrationException
104
+     */
105
+    public function checkMigrate(Schema $targetSchema) {
106
+        $this->noEmit = true;
107
+        /**@var \Doctrine\DBAL\Schema\Table[] $tables */
108
+        $tables = $targetSchema->getTables();
109
+        $filterExpression = $this->getFilterExpression();
110
+        $this->connection->getConfiguration()->
111
+            setFilterSchemaAssetsExpression($filterExpression);
112
+        $existingTables = $this->connection->getSchemaManager()->listTableNames();
113
+
114
+        $step = 0;
115
+        foreach ($tables as $table) {
116
+            if (strpos($table->getName(), '.')) {
117
+                list(, $tableName) = explode('.', $table->getName());
118
+            } else {
119
+                $tableName = $table->getName();
120
+            }
121
+            $this->emitCheckStep($tableName, $step++, count($tables));
122
+            // don't need to check for new tables
123
+            if (array_search($tableName, $existingTables) !== false) {
124
+                $this->checkTableMigrate($table);
125
+            }
126
+        }
127
+    }
128
+
129
+    /**
130
+     * Create a unique name for the temporary table
131
+     *
132
+     * @param string $name
133
+     * @return string
134
+     */
135
+    protected function generateTemporaryTableName($name) {
136
+        return $this->config->getSystemValue('dbtableprefix', 'oc_') . $name . '_' . $this->random->generate(13, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS);
137
+    }
138
+
139
+    /**
140
+     * Check the migration of a table on a copy so we can detect errors before messing with the real table
141
+     *
142
+     * @param \Doctrine\DBAL\Schema\Table $table
143
+     * @throws \OC\DB\MigrationException
144
+     */
145
+    protected function checkTableMigrate(Table $table) {
146
+        $name = $table->getName();
147
+        $tmpName = $this->generateTemporaryTableName($name);
148
+
149
+        $this->copyTable($name, $tmpName);
150
+
151
+        //create the migration schema for the temporary table
152
+        $tmpTable = $this->renameTableSchema($table, $tmpName);
153
+        $schemaConfig = new SchemaConfig();
154
+        $schemaConfig->setName($this->connection->getDatabase());
155
+        $schema = new Schema(array($tmpTable), array(), $schemaConfig);
156
+
157
+        try {
158
+            $this->applySchema($schema);
159
+            $this->dropTable($tmpName);
160
+        } catch (DBALException $e) {
161
+            // pgsql needs to commit it's failed transaction before doing anything else
162
+            if ($this->connection->isTransactionActive()) {
163
+                $this->connection->commit();
164
+            }
165
+            $this->dropTable($tmpName);
166
+            throw new MigrationException($table->getName(), $e->getMessage());
167
+        }
168
+    }
169
+
170
+    /**
171
+     * @param \Doctrine\DBAL\Schema\Table $table
172
+     * @param string $newName
173
+     * @return \Doctrine\DBAL\Schema\Table
174
+     */
175
+    protected function renameTableSchema(Table $table, $newName) {
176
+        /**
177
+         * @var \Doctrine\DBAL\Schema\Index[] $indexes
178
+         */
179
+        $indexes = $table->getIndexes();
180
+        $newIndexes = array();
181
+        foreach ($indexes as $index) {
182
+            if ($index->isPrimary()) {
183
+                // do not rename primary key
184
+                $indexName = $index->getName();
185
+            } else {
186
+                // avoid conflicts in index names
187
+                $indexName = $this->config->getSystemValue('dbtableprefix', 'oc_') . $this->random->generate(13, ISecureRandom::CHAR_LOWER);
188
+            }
189
+            $newIndexes[] = new Index($indexName, $index->getColumns(), $index->isUnique(), $index->isPrimary());
190
+        }
191
+
192
+        // foreign keys are not supported so we just set it to an empty array
193
+        return new Table($newName, $table->getColumns(), $newIndexes, array(), 0, $table->getOptions());
194
+    }
195
+
196
+    public function createSchema() {
197
+        $filterExpression = $this->getFilterExpression();
198
+        $this->connection->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression);
199
+        return $this->connection->getSchemaManager()->createSchema();
200
+    }
201
+
202
+    /**
203
+     * @param Schema $targetSchema
204
+     * @param \Doctrine\DBAL\Connection $connection
205
+     * @return \Doctrine\DBAL\Schema\SchemaDiff
206
+     * @throws DBALException
207
+     */
208
+    protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) {
209
+        // adjust varchar columns with a length higher then getVarcharMaxLength to clob
210
+        foreach ($targetSchema->getTables() as $table) {
211
+            foreach ($table->getColumns() as $column) {
212
+                if ($column->getType() instanceof StringType) {
213
+                    if ($column->getLength() > $connection->getDatabasePlatform()->getVarcharMaxLength()) {
214
+                        $column->setType(Type::getType('text'));
215
+                        $column->setLength(null);
216
+                    }
217
+                }
218
+            }
219
+        }
220
+
221
+        $filterExpression = $this->getFilterExpression();
222
+        $this->connection->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression);
223
+        $sourceSchema = $connection->getSchemaManager()->createSchema();
224
+
225
+        // remove tables we don't know about
226
+        /** @var $table \Doctrine\DBAL\Schema\Table */
227
+        foreach ($sourceSchema->getTables() as $table) {
228
+            if (!$targetSchema->hasTable($table->getName())) {
229
+                $sourceSchema->dropTable($table->getName());
230
+            }
231
+        }
232
+        // remove sequences we don't know about
233
+        foreach ($sourceSchema->getSequences() as $table) {
234
+            if (!$targetSchema->hasSequence($table->getName())) {
235
+                $sourceSchema->dropSequence($table->getName());
236
+            }
237
+        }
238
+
239
+        $comparator = new Comparator();
240
+        return $comparator->compare($sourceSchema, $targetSchema);
241
+    }
242
+
243
+    /**
244
+     * @param \Doctrine\DBAL\Schema\Schema $targetSchema
245
+     * @param \Doctrine\DBAL\Connection $connection
246
+     */
247
+    protected function applySchema(Schema $targetSchema, \Doctrine\DBAL\Connection $connection = null) {
248
+        if (is_null($connection)) {
249
+            $connection = $this->connection;
250
+        }
251
+
252
+        $schemaDiff = $this->getDiff($targetSchema, $connection);
253
+
254
+        $connection->beginTransaction();
255
+        $sqls = $schemaDiff->toSql($connection->getDatabasePlatform());
256
+        $step = 0;
257
+        foreach ($sqls as $sql) {
258
+            $this->emit($sql, $step++, count($sqls));
259
+            $connection->query($sql);
260
+        }
261
+        $connection->commit();
262
+    }
263
+
264
+    /**
265
+     * @param string $sourceName
266
+     * @param string $targetName
267
+     */
268
+    protected function copyTable($sourceName, $targetName) {
269
+        $quotedSource = $this->connection->quoteIdentifier($sourceName);
270
+        $quotedTarget = $this->connection->quoteIdentifier($targetName);
271
+
272
+        $this->connection->exec('CREATE TABLE ' . $quotedTarget . ' (LIKE ' . $quotedSource . ')');
273
+        $this->connection->exec('INSERT INTO ' . $quotedTarget . ' SELECT * FROM ' . $quotedSource);
274
+    }
275
+
276
+    /**
277
+     * @param string $name
278
+     */
279
+    protected function dropTable($name) {
280
+        $this->connection->exec('DROP TABLE ' . $this->connection->quoteIdentifier($name));
281
+    }
282
+
283
+    /**
284
+     * @param $statement
285
+     * @return string
286
+     */
287
+    protected function convertStatementToScript($statement) {
288
+        $script = $statement . ';';
289
+        $script .= PHP_EOL;
290
+        $script .= PHP_EOL;
291
+        return $script;
292
+    }
293
+
294
+    protected function getFilterExpression() {
295
+        return '/^' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/';
296
+    }
297
+
298
+    protected function emit($sql, $step, $max) {
299
+        if ($this->noEmit) {
300
+            return;
301
+        }
302
+        if(is_null($this->dispatcher)) {
303
+            return;
304
+        }
305
+        $this->dispatcher->dispatch('\OC\DB\Migrator::executeSql', new GenericEvent($sql, [$step+1, $max]));
306
+    }
307
+
308
+    private function emitCheckStep($tableName, $step, $max) {
309
+        if(is_null($this->dispatcher)) {
310
+            return;
311
+        }
312
+        $this->dispatcher->dispatch('\OC\DB\Migrator::checkTable', new GenericEvent($tableName, [$step+1, $max]));
313
+    }
314 314
 }
Please login to merge, or discard this patch.
lib/private/Migration/SimpleOutput.php 1 patch
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -36,49 +36,49 @@
 block discarded – undo
36 36
  */
37 37
 class SimpleOutput implements IOutput {
38 38
 
39
-	/** @var ILogger */
40
-	private $logger;
41
-	private $appName;
39
+    /** @var ILogger */
40
+    private $logger;
41
+    private $appName;
42 42
 
43
-	public function __construct(ILogger $logger, $appName) {
44
-		$this->logger = $logger;
45
-		$this->appName = $appName;
46
-	}
43
+    public function __construct(ILogger $logger, $appName) {
44
+        $this->logger = $logger;
45
+        $this->appName = $appName;
46
+    }
47 47
 
48
-	/**
49
-	 * @param string $message
50
-	 * @since 9.1.0
51
-	 */
52
-	public function info($message) {
53
-		$this->logger->info($message, ['app' => $this->appName]);
54
-	}
48
+    /**
49
+     * @param string $message
50
+     * @since 9.1.0
51
+     */
52
+    public function info($message) {
53
+        $this->logger->info($message, ['app' => $this->appName]);
54
+    }
55 55
 
56
-	/**
57
-	 * @param string $message
58
-	 * @since 9.1.0
59
-	 */
60
-	public function warning($message) {
61
-		$this->logger->warning($message, ['app' => $this->appName]);
62
-	}
56
+    /**
57
+     * @param string $message
58
+     * @since 9.1.0
59
+     */
60
+    public function warning($message) {
61
+        $this->logger->warning($message, ['app' => $this->appName]);
62
+    }
63 63
 
64
-	/**
65
-	 * @param int $max
66
-	 * @since 9.1.0
67
-	 */
68
-	public function startProgress($max = 0) {
69
-	}
64
+    /**
65
+     * @param int $max
66
+     * @since 9.1.0
67
+     */
68
+    public function startProgress($max = 0) {
69
+    }
70 70
 
71
-	/**
72
-	 * @param int $step
73
-	 * @param string $description
74
-	 * @since 9.1.0
75
-	 */
76
-	public function advance($step = 1, $description = '') {
77
-	}
71
+    /**
72
+     * @param int $step
73
+     * @param string $description
74
+     * @since 9.1.0
75
+     */
76
+    public function advance($step = 1, $description = '') {
77
+    }
78 78
 
79
-	/**
80
-	 * @since 9.1.0
81
-	 */
82
-	public function finishProgress() {
83
-	}
79
+    /**
80
+     * @since 9.1.0
81
+     */
82
+    public function finishProgress() {
83
+    }
84 84
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/BearerAuth.php 1 patch
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -29,66 +29,66 @@
 block discarded – undo
29 29
 use Sabre\HTTP\ResponseInterface;
30 30
 
31 31
 class BearerAuth extends AbstractBearer {
32
-	/** @var IUserSession */
33
-	private $userSession;
34
-	/** @var ISession */
35
-	private $session;
36
-	/** @var IRequest */
37
-	private $request;
38
-	/** @var string */
39
-	private $principalPrefix;
32
+    /** @var IUserSession */
33
+    private $userSession;
34
+    /** @var ISession */
35
+    private $session;
36
+    /** @var IRequest */
37
+    private $request;
38
+    /** @var string */
39
+    private $principalPrefix;
40 40
 
41
-	/**
42
-	 * @param IUserSession $userSession
43
-	 * @param ISession $session
44
-	 * @param string $principalPrefix
45
-	 * @param IRequest $request
46
-	 */
47
-	public function __construct(IUserSession $userSession,
48
-								ISession $session,
49
-								IRequest $request,
50
-								$principalPrefix = 'principals/users/') {
51
-		$this->userSession = $userSession;
52
-		$this->session = $session;
53
-		$this->request = $request;
54
-		$this->principalPrefix = $principalPrefix;
41
+    /**
42
+     * @param IUserSession $userSession
43
+     * @param ISession $session
44
+     * @param string $principalPrefix
45
+     * @param IRequest $request
46
+     */
47
+    public function __construct(IUserSession $userSession,
48
+                                ISession $session,
49
+                                IRequest $request,
50
+                                $principalPrefix = 'principals/users/') {
51
+        $this->userSession = $userSession;
52
+        $this->session = $session;
53
+        $this->request = $request;
54
+        $this->principalPrefix = $principalPrefix;
55 55
 
56
-		// setup realm
57
-		$defaults = new \OCP\Defaults();
58
-		$this->realm = $defaults->getName();
59
-	}
56
+        // setup realm
57
+        $defaults = new \OCP\Defaults();
58
+        $this->realm = $defaults->getName();
59
+    }
60 60
 
61
-	private function setupUserFs($userId) {
62
-		\OC_Util::setupFS($userId);
63
-		$this->session->close();
64
-		return $this->principalPrefix . $userId;
65
-	}
61
+    private function setupUserFs($userId) {
62
+        \OC_Util::setupFS($userId);
63
+        $this->session->close();
64
+        return $this->principalPrefix . $userId;
65
+    }
66 66
 
67
-	/**
68
-	 * {@inheritdoc}
69
-	 */
70
-	public function validateBearerToken($bearerToken) {
71
-		\OC_Util::setupFS();
67
+    /**
68
+     * {@inheritdoc}
69
+     */
70
+    public function validateBearerToken($bearerToken) {
71
+        \OC_Util::setupFS();
72 72
 
73
-		if(!$this->userSession->isLoggedIn()) {
74
-			$this->userSession->tryTokenLogin($this->request);
75
-		}
76
-		if($this->userSession->isLoggedIn()) {
77
-			return $this->setupUserFs($this->userSession->getUser()->getUID());
78
-		}
73
+        if(!$this->userSession->isLoggedIn()) {
74
+            $this->userSession->tryTokenLogin($this->request);
75
+        }
76
+        if($this->userSession->isLoggedIn()) {
77
+            return $this->setupUserFs($this->userSession->getUser()->getUID());
78
+        }
79 79
 
80
-		return false;
81
-	}
80
+        return false;
81
+    }
82 82
 
83
-	/**
84
-	 * \Sabre\DAV\Auth\Backend\AbstractBearer::challenge sets an WWW-Authenticate
85
-	 * header which some DAV clients can't handle. Thus we override this function
86
-	 * and make it simply return a 401.
87
-	 *
88
-	 * @param RequestInterface $request
89
-	 * @param ResponseInterface $response
90
-	 */
91
-	public function challenge(RequestInterface $request, ResponseInterface $response) {
92
-		$response->setStatus(401);
93
-	}
83
+    /**
84
+     * \Sabre\DAV\Auth\Backend\AbstractBearer::challenge sets an WWW-Authenticate
85
+     * header which some DAV clients can't handle. Thus we override this function
86
+     * and make it simply return a 401.
87
+     *
88
+     * @param RequestInterface $request
89
+     * @param ResponseInterface $response
90
+     */
91
+    public function challenge(RequestInterface $request, ResponseInterface $response) {
92
+        $response->setStatus(401);
93
+    }
94 94
 }
Please login to merge, or discard this patch.
lib/private/Comments/ManagerFactory.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -30,33 +30,33 @@
 block discarded – undo
30 30
 
31 31
 class ManagerFactory implements ICommentsManagerFactory {
32 32
 
33
-	/**
34
-	 * Server container
35
-	 *
36
-	 * @var IServerContainer
37
-	 */
38
-	private $serverContainer;
33
+    /**
34
+     * Server container
35
+     *
36
+     * @var IServerContainer
37
+     */
38
+    private $serverContainer;
39 39
 
40
-	/**
41
-	 * Constructor for the comments manager factory
42
-	 *
43
-	 * @param IServerContainer $serverContainer server container
44
-	 */
45
-	public function __construct(IServerContainer $serverContainer) {
46
-		$this->serverContainer = $serverContainer;
47
-	}
40
+    /**
41
+     * Constructor for the comments manager factory
42
+     *
43
+     * @param IServerContainer $serverContainer server container
44
+     */
45
+    public function __construct(IServerContainer $serverContainer) {
46
+        $this->serverContainer = $serverContainer;
47
+    }
48 48
 
49
-	/**
50
-	 * creates and returns an instance of the ICommentsManager
51
-	 *
52
-	 * @return ICommentsManager
53
-	 * @since 9.0.0
54
-	 */
55
-	public function getManager() {
56
-		return new Manager(
57
-			$this->serverContainer->getDatabaseConnection(),
58
-			$this->serverContainer->getLogger(),
59
-			$this->serverContainer->getConfig()
60
-		);
61
-	}
49
+    /**
50
+     * creates and returns an instance of the ICommentsManager
51
+     *
52
+     * @return ICommentsManager
53
+     * @since 9.0.0
54
+     */
55
+    public function getManager() {
56
+        return new Manager(
57
+            $this->serverContainer->getDatabaseConnection(),
58
+            $this->serverContainer->getLogger(),
59
+            $this->serverContainer->getConfig()
60
+        );
61
+    }
62 62
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/CachingTree.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -24,16 +24,16 @@
 block discarded – undo
24 24
 use Sabre\DAV\Tree;
25 25
 
26 26
 class CachingTree extends Tree {
27
-	/**
28
-	 * Store a node in the cache
29
-	 *
30
-	 * @param Node $node
31
-	 * @param null|string $path
32
-	 */
33
-	public function cacheNode(Node $node, $path = null) {
34
-		if (is_null($path)) {
35
-			$path = $node->getPath();
36
-		}
37
-		$this->cache[trim($path, '/')] = $node;
38
-	}
27
+    /**
28
+     * Store a node in the cache
29
+     *
30
+     * @param Node $node
31
+     * @param null|string $path
32
+     */
33
+    public function cacheNode(Node $node, $path = null) {
34
+        if (is_null($path)) {
35
+            $path = $node->getPath();
36
+        }
37
+        $this->cache[trim($path, '/')] = $node;
38
+    }
39 39
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/Server.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -33,14 +33,14 @@
 block discarded – undo
33 33
  * @see \Sabre\DAV\Server
34 34
  */
35 35
 class Server extends \Sabre\DAV\Server {
36
-	/** @var CachingTree $tree */
36
+    /** @var CachingTree $tree */
37 37
 
38
-	/**
39
-	 * @see \Sabre\DAV\Server
40
-	 */
41
-	public function __construct($treeOrNode = null) {
42
-		parent::__construct($treeOrNode);
43
-		self::$exposeVersion = false;
44
-		$this->enablePropfindDepthInfinity = true;
45
-	}
38
+    /**
39
+     * @see \Sabre\DAV\Server
40
+     */
41
+    public function __construct($treeOrNode = null) {
42
+        parent::__construct($treeOrNode);
43
+        self::$exposeVersion = false;
44
+        $this->enablePropfindDepthInfinity = true;
45
+    }
46 46
 }
Please login to merge, or discard this patch.
apps/sharebymail/lib/Activity.php 1 patch
Indentation   +300 added lines, -300 removed lines patch added patch discarded remove patch
@@ -33,304 +33,304 @@
 block discarded – undo
33 33
 
34 34
 class Activity implements IProvider {
35 35
 
36
-	/** @var IFactory */
37
-	protected $languageFactory;
38
-
39
-	/** @var IL10N */
40
-	protected $l;
41
-
42
-	/** @var IURLGenerator */
43
-	protected $url;
44
-
45
-	/** @var IManager */
46
-	protected $activityManager;
47
-
48
-	/** @var IUserManager */
49
-	protected $userManager;
50
-	/** @var IContactsManager */
51
-	protected $contactsManager;
52
-
53
-	/** @var array */
54
-	protected $displayNames = [];
55
-
56
-	/** @var array */
57
-	protected $contactNames = [];
58
-
59
-	const SUBJECT_SHARED_EMAIL_SELF = 'shared_with_email_self';
60
-	const SUBJECT_SHARED_EMAIL_BY = 'shared_with_email_by';
61
-	const SUBJECT_SHARED_EMAIL_PASSWORD_SEND = 'shared_with_email_password_send';
62
-	const SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF = 'shared_with_email_password_send_self';
63
-
64
-	/**
65
-	 * @param IFactory $languageFactory
66
-	 * @param IURLGenerator $url
67
-	 * @param IManager $activityManager
68
-	 * @param IUserManager $userManager
69
-	 * @param IContactsManager $contactsManager
70
-	 */
71
-	public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IContactsManager $contactsManager) {
72
-		$this->languageFactory = $languageFactory;
73
-		$this->url = $url;
74
-		$this->activityManager = $activityManager;
75
-		$this->userManager = $userManager;
76
-		$this->contactsManager = $contactsManager;
77
-	}
78
-
79
-	/**
80
-	 * @param string $language
81
-	 * @param IEvent $event
82
-	 * @param IEvent|null $previousEvent
83
-	 * @return IEvent
84
-	 * @throws \InvalidArgumentException
85
-	 * @since 11.0.0
86
-	 */
87
-	public function parse($language, IEvent $event, IEvent $previousEvent = null) {
88
-		if ($event->getApp() !== 'sharebymail') {
89
-			throw new \InvalidArgumentException();
90
-		}
91
-
92
-		$this->l = $this->languageFactory->get('sharebymail', $language);
93
-
94
-		if ($this->activityManager->isFormattingFilteredObject()) {
95
-			try {
96
-				return $this->parseShortVersion($event);
97
-			} catch (\InvalidArgumentException $e) {
98
-				// Ignore and simply use the long version...
99
-			}
100
-		}
101
-
102
-		return $this->parseLongVersion($event);
103
-	}
104
-
105
-	/**
106
-	 * @param IEvent $event
107
-	 * @return IEvent
108
-	 * @throws \InvalidArgumentException
109
-	 * @since 11.0.0
110
-	 */
111
-	public function parseShortVersion(IEvent $event) {
112
-		$parsedParameters = $this->getParsedParameters($event);
113
-
114
-		if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_SELF) {
115
-			$event->setParsedSubject($this->l->t('Shared with %1$s', [
116
-					$parsedParameters['email']['name'],
117
-				]))
118
-				->setRichSubject($this->l->t('Shared with {email}'), [
119
-					'email' => $parsedParameters['email'],
120
-				]);
121
-			if ($this->activityManager->getRequirePNG()) {
122
-				$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
123
-			} else {
124
-				$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
125
-			}
126
-		} else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_BY) {
127
-			$event->setParsedSubject($this->l->t('Shared with %1$s by %2$s', [
128
-				$parsedParameters['email']['name'],
129
-				$parsedParameters['actor']['name'],
130
-			]))
131
-				->setRichSubject($this->l->t('Shared with {email} by {actor}'), [
132
-					'email' => $parsedParameters['email'],
133
-					'actor' => $parsedParameters['actor'],
134
-				]);
135
-			if ($this->activityManager->getRequirePNG()) {
136
-				$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
137
-			} else {
138
-				$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
139
-			}
140
-		} else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND) {
141
-			$event->setParsedSubject($this->l->t('Password for mail share sent to %1$s', [
142
-				$parsedParameters['email']['name']
143
-			]))
144
-				->setRichSubject($this->l->t('Password for mail share sent to {email}'), [
145
-					'email' => $parsedParameters['email']
146
-				]);
147
-			if ($this->activityManager->getRequirePNG()) {
148
-				$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
149
-			} else {
150
-				$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
151
-			}
152
-		} else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF) {
153
-			$event->setParsedSubject($this->l->t('Password for mail share sent to you'))
154
-				->setRichSubject($this->l->t('Password for mail share sent to you'));
155
-			if ($this->activityManager->getRequirePNG()) {
156
-				$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
157
-			} else {
158
-				$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
159
-			}
160
-		} else {
161
-			throw new \InvalidArgumentException();
162
-		}
163
-
164
-		return $event;
165
-	}
166
-
167
-	/**
168
-	 * @param IEvent $event
169
-	 * @return IEvent
170
-	 * @throws \InvalidArgumentException
171
-	 * @since 11.0.0
172
-	 */
173
-	public function parseLongVersion(IEvent $event) {
174
-		$parsedParameters = $this->getParsedParameters($event);
175
-
176
-		if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_SELF) {
177
-			$event->setParsedSubject($this->l->t('You shared %1$s with %2$s by mail', [
178
-					$parsedParameters['file']['path'],
179
-					$parsedParameters['email']['name'],
180
-				]))
181
-				->setRichSubject($this->l->t('You shared {file} with {email} by mail'), $parsedParameters);
182
-			if ($this->activityManager->getRequirePNG()) {
183
-				$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
184
-			} else {
185
-				$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
186
-			}
187
-		} else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_BY) {
188
-			$event->setParsedSubject($this->l->t('%3$s shared %1$s with %2$s by mail', [
189
-				$parsedParameters['file']['path'],
190
-				$parsedParameters['email']['name'],
191
-				$parsedParameters['actor']['name'],
192
-			]))
193
-				->setRichSubject($this->l->t('{actor} shared {file} with {email} by mail'), $parsedParameters);
194
-			if ($this->activityManager->getRequirePNG()) {
195
-				$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
196
-			} else {
197
-				$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
198
-			}
199
-		} else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND) {
200
-			$event->setParsedSubject($this->l->t('Password to access %1$s was sent to %2s', [
201
-				$parsedParameters['file']['path'],
202
-				$parsedParameters['email']['name']
203
-			]))
204
-				->setRichSubject($this->l->t('Password to access {file} was sent to {email}'), $parsedParameters);
205
-			if ($this->activityManager->getRequirePNG()) {
206
-				$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
207
-			} else {
208
-				$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
209
-			}
210
-		} else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF) {
211
-			$event->setParsedSubject(
212
-				$this->l->t('Password to access %1$s was sent to you',
213
-					[$parsedParameters['file']['path']]))
214
-				->setRichSubject($this->l->t('Password to access {file} was sent to you'), $parsedParameters);
215
-			if ($this->activityManager->getRequirePNG()) {
216
-				$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
217
-			} else {
218
-				$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
219
-			}
220
-
221
-		} else {
222
-			throw new \InvalidArgumentException();
223
-		}
224
-
225
-		return $event;
226
-	}
227
-
228
-	protected function getParsedParameters(IEvent $event) {
229
-		$subject = $event->getSubject();
230
-		$parameters = $event->getSubjectParameters();
231
-
232
-		switch ($subject) {
233
-			case self::SUBJECT_SHARED_EMAIL_SELF:
234
-				return [
235
-					'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]),
236
-					'email' => $this->generateEmailParameter($parameters[1]),
237
-				];
238
-			case self::SUBJECT_SHARED_EMAIL_BY:
239
-				return [
240
-					'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]),
241
-					'email' => $this->generateEmailParameter($parameters[1]),
242
-					'actor' => $this->generateUserParameter($parameters[2]),
243
-				];
244
-			case self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND:
245
-				return [
246
-					'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]),
247
-					'email' => $this->generateEmailParameter($parameters[1]),
248
-				];
249
-			case self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF:
250
-				return [
251
-					'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]),
252
-				];
253
-		}
254
-		throw new \InvalidArgumentException();
255
-	}
256
-
257
-	/**
258
-	 * @param int $id
259
-	 * @param string $path
260
-	 * @return array
261
-	 */
262
-	protected function generateFileParameter($id, $path) {
263
-		return [
264
-			'type' => 'file',
265
-			'id' => $id,
266
-			'name' => basename($path),
267
-			'path' => trim($path, '/'),
268
-			'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]),
269
-		];
270
-	}
271
-
272
-	/**
273
-	 * @param string $email
274
-	 * @return array
275
-	 */
276
-	protected function generateEmailParameter($email) {
277
-		if (!isset($this->contactNames[$email])) {
278
-			$this->contactNames[$email] = $this->getContactName($email);
279
-		}
280
-
281
-		return [
282
-			'type' => 'email',
283
-			'id' => $email,
284
-			'name' => $this->contactNames[$email],
285
-		];
286
-	}
287
-
288
-	/**
289
-	 * @param string $uid
290
-	 * @return array
291
-	 */
292
-	protected function generateUserParameter($uid) {
293
-		if (!isset($this->displayNames[$uid])) {
294
-			$this->displayNames[$uid] = $this->getDisplayName($uid);
295
-		}
296
-
297
-		return [
298
-			'type' => 'user',
299
-			'id' => $uid,
300
-			'name' => $this->displayNames[$uid],
301
-		];
302
-	}
303
-
304
-	/**
305
-	 * @param string $email
306
-	 * @return string
307
-	 */
308
-	protected function getContactName($email) {
309
-		$addressBookContacts = $this->contactsManager->search($email, ['EMAIL']);
310
-
311
-		foreach ($addressBookContacts as $contact) {
312
-			if (isset($contact['isLocalSystemBook'])) {
313
-				continue;
314
-			}
315
-
316
-			if (in_array($email, $contact['EMAIL'])) {
317
-				return $contact['FN'];
318
-			}
319
-		}
320
-
321
-		return $email;
322
-	}
323
-
324
-	/**
325
-	 * @param string $uid
326
-	 * @return string
327
-	 */
328
-	protected function getDisplayName($uid) {
329
-		$user = $this->userManager->get($uid);
330
-		if ($user instanceof IUser) {
331
-			return $user->getDisplayName();
332
-		} else {
333
-			return $uid;
334
-		}
335
-	}
36
+    /** @var IFactory */
37
+    protected $languageFactory;
38
+
39
+    /** @var IL10N */
40
+    protected $l;
41
+
42
+    /** @var IURLGenerator */
43
+    protected $url;
44
+
45
+    /** @var IManager */
46
+    protected $activityManager;
47
+
48
+    /** @var IUserManager */
49
+    protected $userManager;
50
+    /** @var IContactsManager */
51
+    protected $contactsManager;
52
+
53
+    /** @var array */
54
+    protected $displayNames = [];
55
+
56
+    /** @var array */
57
+    protected $contactNames = [];
58
+
59
+    const SUBJECT_SHARED_EMAIL_SELF = 'shared_with_email_self';
60
+    const SUBJECT_SHARED_EMAIL_BY = 'shared_with_email_by';
61
+    const SUBJECT_SHARED_EMAIL_PASSWORD_SEND = 'shared_with_email_password_send';
62
+    const SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF = 'shared_with_email_password_send_self';
63
+
64
+    /**
65
+     * @param IFactory $languageFactory
66
+     * @param IURLGenerator $url
67
+     * @param IManager $activityManager
68
+     * @param IUserManager $userManager
69
+     * @param IContactsManager $contactsManager
70
+     */
71
+    public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IContactsManager $contactsManager) {
72
+        $this->languageFactory = $languageFactory;
73
+        $this->url = $url;
74
+        $this->activityManager = $activityManager;
75
+        $this->userManager = $userManager;
76
+        $this->contactsManager = $contactsManager;
77
+    }
78
+
79
+    /**
80
+     * @param string $language
81
+     * @param IEvent $event
82
+     * @param IEvent|null $previousEvent
83
+     * @return IEvent
84
+     * @throws \InvalidArgumentException
85
+     * @since 11.0.0
86
+     */
87
+    public function parse($language, IEvent $event, IEvent $previousEvent = null) {
88
+        if ($event->getApp() !== 'sharebymail') {
89
+            throw new \InvalidArgumentException();
90
+        }
91
+
92
+        $this->l = $this->languageFactory->get('sharebymail', $language);
93
+
94
+        if ($this->activityManager->isFormattingFilteredObject()) {
95
+            try {
96
+                return $this->parseShortVersion($event);
97
+            } catch (\InvalidArgumentException $e) {
98
+                // Ignore and simply use the long version...
99
+            }
100
+        }
101
+
102
+        return $this->parseLongVersion($event);
103
+    }
104
+
105
+    /**
106
+     * @param IEvent $event
107
+     * @return IEvent
108
+     * @throws \InvalidArgumentException
109
+     * @since 11.0.0
110
+     */
111
+    public function parseShortVersion(IEvent $event) {
112
+        $parsedParameters = $this->getParsedParameters($event);
113
+
114
+        if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_SELF) {
115
+            $event->setParsedSubject($this->l->t('Shared with %1$s', [
116
+                    $parsedParameters['email']['name'],
117
+                ]))
118
+                ->setRichSubject($this->l->t('Shared with {email}'), [
119
+                    'email' => $parsedParameters['email'],
120
+                ]);
121
+            if ($this->activityManager->getRequirePNG()) {
122
+                $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
123
+            } else {
124
+                $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
125
+            }
126
+        } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_BY) {
127
+            $event->setParsedSubject($this->l->t('Shared with %1$s by %2$s', [
128
+                $parsedParameters['email']['name'],
129
+                $parsedParameters['actor']['name'],
130
+            ]))
131
+                ->setRichSubject($this->l->t('Shared with {email} by {actor}'), [
132
+                    'email' => $parsedParameters['email'],
133
+                    'actor' => $parsedParameters['actor'],
134
+                ]);
135
+            if ($this->activityManager->getRequirePNG()) {
136
+                $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
137
+            } else {
138
+                $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
139
+            }
140
+        } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND) {
141
+            $event->setParsedSubject($this->l->t('Password for mail share sent to %1$s', [
142
+                $parsedParameters['email']['name']
143
+            ]))
144
+                ->setRichSubject($this->l->t('Password for mail share sent to {email}'), [
145
+                    'email' => $parsedParameters['email']
146
+                ]);
147
+            if ($this->activityManager->getRequirePNG()) {
148
+                $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
149
+            } else {
150
+                $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
151
+            }
152
+        } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF) {
153
+            $event->setParsedSubject($this->l->t('Password for mail share sent to you'))
154
+                ->setRichSubject($this->l->t('Password for mail share sent to you'));
155
+            if ($this->activityManager->getRequirePNG()) {
156
+                $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
157
+            } else {
158
+                $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
159
+            }
160
+        } else {
161
+            throw new \InvalidArgumentException();
162
+        }
163
+
164
+        return $event;
165
+    }
166
+
167
+    /**
168
+     * @param IEvent $event
169
+     * @return IEvent
170
+     * @throws \InvalidArgumentException
171
+     * @since 11.0.0
172
+     */
173
+    public function parseLongVersion(IEvent $event) {
174
+        $parsedParameters = $this->getParsedParameters($event);
175
+
176
+        if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_SELF) {
177
+            $event->setParsedSubject($this->l->t('You shared %1$s with %2$s by mail', [
178
+                    $parsedParameters['file']['path'],
179
+                    $parsedParameters['email']['name'],
180
+                ]))
181
+                ->setRichSubject($this->l->t('You shared {file} with {email} by mail'), $parsedParameters);
182
+            if ($this->activityManager->getRequirePNG()) {
183
+                $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
184
+            } else {
185
+                $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
186
+            }
187
+        } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_BY) {
188
+            $event->setParsedSubject($this->l->t('%3$s shared %1$s with %2$s by mail', [
189
+                $parsedParameters['file']['path'],
190
+                $parsedParameters['email']['name'],
191
+                $parsedParameters['actor']['name'],
192
+            ]))
193
+                ->setRichSubject($this->l->t('{actor} shared {file} with {email} by mail'), $parsedParameters);
194
+            if ($this->activityManager->getRequirePNG()) {
195
+                $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
196
+            } else {
197
+                $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
198
+            }
199
+        } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND) {
200
+            $event->setParsedSubject($this->l->t('Password to access %1$s was sent to %2s', [
201
+                $parsedParameters['file']['path'],
202
+                $parsedParameters['email']['name']
203
+            ]))
204
+                ->setRichSubject($this->l->t('Password to access {file} was sent to {email}'), $parsedParameters);
205
+            if ($this->activityManager->getRequirePNG()) {
206
+                $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
207
+            } else {
208
+                $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
209
+            }
210
+        } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF) {
211
+            $event->setParsedSubject(
212
+                $this->l->t('Password to access %1$s was sent to you',
213
+                    [$parsedParameters['file']['path']]))
214
+                ->setRichSubject($this->l->t('Password to access {file} was sent to you'), $parsedParameters);
215
+            if ($this->activityManager->getRequirePNG()) {
216
+                $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
217
+            } else {
218
+                $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
219
+            }
220
+
221
+        } else {
222
+            throw new \InvalidArgumentException();
223
+        }
224
+
225
+        return $event;
226
+    }
227
+
228
+    protected function getParsedParameters(IEvent $event) {
229
+        $subject = $event->getSubject();
230
+        $parameters = $event->getSubjectParameters();
231
+
232
+        switch ($subject) {
233
+            case self::SUBJECT_SHARED_EMAIL_SELF:
234
+                return [
235
+                    'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]),
236
+                    'email' => $this->generateEmailParameter($parameters[1]),
237
+                ];
238
+            case self::SUBJECT_SHARED_EMAIL_BY:
239
+                return [
240
+                    'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]),
241
+                    'email' => $this->generateEmailParameter($parameters[1]),
242
+                    'actor' => $this->generateUserParameter($parameters[2]),
243
+                ];
244
+            case self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND:
245
+                return [
246
+                    'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]),
247
+                    'email' => $this->generateEmailParameter($parameters[1]),
248
+                ];
249
+            case self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF:
250
+                return [
251
+                    'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]),
252
+                ];
253
+        }
254
+        throw new \InvalidArgumentException();
255
+    }
256
+
257
+    /**
258
+     * @param int $id
259
+     * @param string $path
260
+     * @return array
261
+     */
262
+    protected function generateFileParameter($id, $path) {
263
+        return [
264
+            'type' => 'file',
265
+            'id' => $id,
266
+            'name' => basename($path),
267
+            'path' => trim($path, '/'),
268
+            'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]),
269
+        ];
270
+    }
271
+
272
+    /**
273
+     * @param string $email
274
+     * @return array
275
+     */
276
+    protected function generateEmailParameter($email) {
277
+        if (!isset($this->contactNames[$email])) {
278
+            $this->contactNames[$email] = $this->getContactName($email);
279
+        }
280
+
281
+        return [
282
+            'type' => 'email',
283
+            'id' => $email,
284
+            'name' => $this->contactNames[$email],
285
+        ];
286
+    }
287
+
288
+    /**
289
+     * @param string $uid
290
+     * @return array
291
+     */
292
+    protected function generateUserParameter($uid) {
293
+        if (!isset($this->displayNames[$uid])) {
294
+            $this->displayNames[$uid] = $this->getDisplayName($uid);
295
+        }
296
+
297
+        return [
298
+            'type' => 'user',
299
+            'id' => $uid,
300
+            'name' => $this->displayNames[$uid],
301
+        ];
302
+    }
303
+
304
+    /**
305
+     * @param string $email
306
+     * @return string
307
+     */
308
+    protected function getContactName($email) {
309
+        $addressBookContacts = $this->contactsManager->search($email, ['EMAIL']);
310
+
311
+        foreach ($addressBookContacts as $contact) {
312
+            if (isset($contact['isLocalSystemBook'])) {
313
+                continue;
314
+            }
315
+
316
+            if (in_array($email, $contact['EMAIL'])) {
317
+                return $contact['FN'];
318
+            }
319
+        }
320
+
321
+        return $email;
322
+    }
323
+
324
+    /**
325
+     * @param string $uid
326
+     * @return string
327
+     */
328
+    protected function getDisplayName($uid) {
329
+        $user = $this->userManager->get($uid);
330
+        if ($user instanceof IUser) {
331
+            return $user->getDisplayName();
332
+        } else {
333
+            return $uid;
334
+        }
335
+    }
336 336
 }
Please login to merge, or discard this patch.
apps/twofactor_backupcodes/lib/Activity/Provider.php 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -31,47 +31,47 @@
 block discarded – undo
31 31
 
32 32
 class Provider implements IProvider {
33 33
 
34
-	/** @var L10nFactory */
35
-	private $l10n;
34
+    /** @var L10nFactory */
35
+    private $l10n;
36 36
 
37
-	/** @var IURLGenerator */
38
-	private $urlGenerator;
37
+    /** @var IURLGenerator */
38
+    private $urlGenerator;
39 39
 
40
-	/** @var IManager */
41
-	private $activityManager;
40
+    /** @var IManager */
41
+    private $activityManager;
42 42
 
43
-	/**
44
-	 * @param L10nFactory $l10n
45
-	 * @param IURLGenerator $urlGenerator
46
-	 * @param IManager $activityManager
47
-	 */
48
-	public function __construct(L10nFactory $l10n, IURLGenerator $urlGenerator, IManager $activityManager) {
49
-		$this->urlGenerator = $urlGenerator;
50
-		$this->activityManager = $activityManager;
51
-		$this->l10n = $l10n;
52
-	}
43
+    /**
44
+     * @param L10nFactory $l10n
45
+     * @param IURLGenerator $urlGenerator
46
+     * @param IManager $activityManager
47
+     */
48
+    public function __construct(L10nFactory $l10n, IURLGenerator $urlGenerator, IManager $activityManager) {
49
+        $this->urlGenerator = $urlGenerator;
50
+        $this->activityManager = $activityManager;
51
+        $this->l10n = $l10n;
52
+    }
53 53
 
54
-	public function parse($language, IEvent $event, IEvent $previousEvent = null) {
55
-		if ($event->getApp() !== 'twofactor_backupcodes') {
56
-			throw new InvalidArgumentException();
57
-		}
54
+    public function parse($language, IEvent $event, IEvent $previousEvent = null) {
55
+        if ($event->getApp() !== 'twofactor_backupcodes') {
56
+            throw new InvalidArgumentException();
57
+        }
58 58
 
59
-		$l = $this->l10n->get('twofactor_backupcodes', $language);
59
+        $l = $this->l10n->get('twofactor_backupcodes', $language);
60 60
 
61
-		switch ($event->getSubject()) {
62
-			case 'codes_generated':
63
-				$event->setParsedSubject($l->t('You created two-factor backup codes for your account'));
61
+        switch ($event->getSubject()) {
62
+            case 'codes_generated':
63
+                $event->setParsedSubject($l->t('You created two-factor backup codes for your account'));
64 64
 
65
-				if ($this->activityManager->getRequirePNG()) {
66
-					$event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.png')));
67
-				} else {
68
-					$event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.svg')));
69
-				}
70
-				break;
71
-			default:
72
-				throw new InvalidArgumentException();
73
-		}
74
-		return $event;
75
-	}
65
+                if ($this->activityManager->getRequirePNG()) {
66
+                    $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.png')));
67
+                } else {
68
+                    $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.svg')));
69
+                }
70
+                break;
71
+            default:
72
+                throw new InvalidArgumentException();
73
+        }
74
+        return $event;
75
+    }
76 76
 
77 77
 }
Please login to merge, or discard this patch.
apps/systemtags/lib/Activity/Provider.php 1 patch
Indentation   +307 added lines, -307 removed lines patch added patch discarded remove patch
@@ -32,311 +32,311 @@
 block discarded – undo
32 32
 
33 33
 class Provider implements IProvider {
34 34
 
35
-	const CREATE_TAG = 'create_tag';
36
-	const UPDATE_TAG = 'update_tag';
37
-	const DELETE_TAG = 'delete_tag';
38
-
39
-	const ASSIGN_TAG = 'assign_tag';
40
-	const UNASSIGN_TAG = 'unassign_tag';
41
-
42
-	/** @var IFactory */
43
-	protected $languageFactory;
44
-
45
-	/** @var IL10N */
46
-	protected $l;
47
-
48
-	/** @var IURLGenerator */
49
-	protected $url;
50
-
51
-	/** @var IManager */
52
-	protected $activityManager;
53
-
54
-	/** @var IUserManager */
55
-	protected $userManager;
56
-
57
-	/** @var string[] */
58
-	protected $displayNames = [];
59
-
60
-	/**
61
-	 * @param IFactory $languageFactory
62
-	 * @param IURLGenerator $url
63
-	 * @param IManager $activityManager
64
-	 * @param IUserManager $userManager
65
-	 */
66
-	public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager) {
67
-		$this->languageFactory = $languageFactory;
68
-		$this->url = $url;
69
-		$this->activityManager = $activityManager;
70
-		$this->userManager = $userManager;
71
-	}
72
-
73
-	/**
74
-	 * @param string $language
75
-	 * @param IEvent $event
76
-	 * @param IEvent|null $previousEvent
77
-	 * @return IEvent
78
-	 * @throws \InvalidArgumentException
79
-	 * @since 11.0.0
80
-	 */
81
-	public function parse($language, IEvent $event, IEvent $previousEvent = null) {
82
-		if ($event->getApp() !== 'systemtags') {
83
-			throw new \InvalidArgumentException();
84
-		}
85
-
86
-		$this->l = $this->languageFactory->get('systemtags', $language);
87
-
88
-		if ($this->activityManager->isFormattingFilteredObject()) {
89
-			try {
90
-				return $this->parseShortVersion($event);
91
-			} catch (\InvalidArgumentException $e) {
92
-				// Ignore and simply use the long version...
93
-			}
94
-		}
95
-
96
-		return $this->parseLongVersion($event);
97
-	}
98
-
99
-	/**
100
-	 * @param IEvent $event
101
-	 * @return IEvent
102
-	 * @throws \InvalidArgumentException
103
-	 * @since 11.0.0
104
-	 */
105
-	public function parseShortVersion(IEvent $event) {
106
-		$parsedParameters = $this->getParameters($event);
107
-
108
-		if ($this->activityManager->getRequirePNG()) {
109
-			$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/tag.png')));
110
-		} else {
111
-			$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/tag.svg')));
112
-		}
113
-
114
-		if ($event->getSubject() === self::ASSIGN_TAG) {
115
-			if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) {
116
-				$event->setParsedSubject($this->l->t('Added system tag %1$s', [
117
-						$this->generatePlainSystemTag($parsedParameters['systemtag']),
118
-					]))
119
-					->setRichSubject($this->l->t('Added system tag {systemtag}'), [
120
-						'systemtag' => $parsedParameters['systemtag'],
121
-					]);
122
-			} else {
123
-				$event->setParsedSubject($this->l->t('%1$s added system tag %2$s', [
124
-						$parsedParameters['actor']['name'],
125
-						$this->generatePlainSystemTag($parsedParameters['systemtag']),
126
-					]))
127
-					->setRichSubject($this->l->t('{actor} added system tag {systemtag}'), [
128
-						'actor' => $parsedParameters['actor'],
129
-						'systemtag' => $parsedParameters['systemtag'],
130
-					]);
131
-			}
132
-		} else if ($event->getSubject() === self::UNASSIGN_TAG) {
133
-			if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) {
134
-				$event->setParsedSubject($this->l->t('Removed system tag %1$s', [
135
-						$this->generatePlainSystemTag($parsedParameters['systemtag']),
136
-					]))
137
-					->setRichSubject($this->l->t('Removed system tag {systemtag}'), [
138
-						'systemtag' => $parsedParameters['systemtag'],
139
-					]);
140
-			} else {
141
-				$event->setParsedSubject($this->l->t('%1$s removed system tag %2$s', [
142
-						$parsedParameters['actor']['name'],
143
-						$this->generatePlainSystemTag($parsedParameters['systemtag']),
144
-					]))
145
-					->setRichSubject($this->l->t('{actor} removed system tag {systemtag}'), [
146
-						'actor' => $parsedParameters['actor'],
147
-						'systemtag' => $parsedParameters['systemtag'],
148
-					]);
149
-			}
150
-		} else {
151
-			throw new \InvalidArgumentException();
152
-		}
153
-
154
-		return $event;
155
-	}
156
-
157
-	/**
158
-	 * @param IEvent $event
159
-	 * @return IEvent
160
-	 * @throws \InvalidArgumentException
161
-	 * @since 11.0.0
162
-	 */
163
-	public function parseLongVersion(IEvent $event) {
164
-		$parsedParameters = $this->getParameters($event);
165
-
166
-		if ($this->activityManager->getRequirePNG()) {
167
-			$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/tag.png')));
168
-		} else {
169
-			$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/tag.svg')));
170
-		}
171
-
172
-		if ($event->getSubject() === self::CREATE_TAG) {
173
-			if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) {
174
-				$event->setParsedSubject($this->l->t('You created system tag %1$s', [
175
-						$this->generatePlainSystemTag($parsedParameters['systemtag']),
176
-					]))
177
-					->setRichSubject($this->l->t('You created system tag {systemtag}'), $parsedParameters);
178
-			} else {
179
-				$event->setParsedSubject($this->l->t('%1$s created system tag %2$s', [
180
-						$parsedParameters['actor']['name'],
181
-						$this->generatePlainSystemTag($parsedParameters['systemtag']),
182
-					]))
183
-					->setRichSubject($this->l->t('{actor} created system tag {systemtag}'), $parsedParameters);
184
-			}
185
-		} else if ($event->getSubject() === self::DELETE_TAG) {
186
-			if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) {
187
-				$event->setParsedSubject($this->l->t('You deleted system tag %1$s', [
188
-						$this->generatePlainSystemTag($parsedParameters['systemtag']),
189
-					]))
190
-					->setRichSubject($this->l->t('You deleted system tag {systemtag}'), $parsedParameters);
191
-			} else {
192
-				$event->setParsedSubject($this->l->t('%1$s deleted system tag %2$s', [
193
-						$parsedParameters['actor']['name'],
194
-						$this->generatePlainSystemTag($parsedParameters['systemtag']),
195
-					]))
196
-					->setRichSubject($this->l->t('{actor} deleted system tag {systemtag}'), $parsedParameters);
197
-			}
198
-		} else if ($event->getSubject() === self::UPDATE_TAG) {
199
-			if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) {
200
-				$event->setParsedSubject($this->l->t('You updated system tag %2$s to %1$s', [
201
-						$this->generatePlainSystemTag($parsedParameters['newsystemtag']),
202
-						$this->generatePlainSystemTag($parsedParameters['oldsystemtag']),
203
-					]))
204
-					->setRichSubject($this->l->t('You updated system tag {oldsystemtag} to {newsystemtag}'), $parsedParameters);
205
-			} else {
206
-				$event->setParsedSubject($this->l->t('%1$s updated system tag %3$s to %2$s', [
207
-						$parsedParameters['actor']['name'],
208
-						$this->generatePlainSystemTag($parsedParameters['newsystemtag']),
209
-						$this->generatePlainSystemTag($parsedParameters['oldsystemtag']),
210
-					]))
211
-					->setRichSubject($this->l->t('{actor} updated system tag {oldsystemtag} to {newsystemtag}'), $parsedParameters);
212
-			}
213
-		} else if ($event->getSubject() === self::ASSIGN_TAG) {
214
-			if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) {
215
-				$event->setParsedSubject($this->l->t('You added system tag %2$s to %1$s', [
216
-						$parsedParameters['file']['path'],
217
-						$this->generatePlainSystemTag($parsedParameters['systemtag']),
218
-					]))
219
-					->setRichSubject($this->l->t('You added system tag {systemtag} to {file}'), $parsedParameters);
220
-			} else {
221
-				$event->setParsedSubject($this->l->t('%1$s added system tag %3$s to %2$s', [
222
-						$parsedParameters['actor']['name'],
223
-						$parsedParameters['file']['path'],
224
-						$this->generatePlainSystemTag($parsedParameters['systemtag']),
225
-					]))
226
-					->setRichSubject($this->l->t('{actor} added system tag {systemtag} to {file}'), $parsedParameters);
227
-			}
228
-		} else if ($event->getSubject() === self::UNASSIGN_TAG) {
229
-			if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) {
230
-				$event->setParsedSubject($this->l->t('You removed system tag %2$s from %1$s', [
231
-						$parsedParameters['file']['path'],
232
-						$this->generatePlainSystemTag($parsedParameters['systemtag']),
233
-					]))
234
-					->setRichSubject($this->l->t('You removed system tag {systemtag} from {file}'), $parsedParameters);
235
-			} else {
236
-				$event->setParsedSubject($this->l->t('%1$s removed system tag %3$s from %2$s', [
237
-						$parsedParameters['actor']['name'],
238
-						$parsedParameters['file']['path'],
239
-						$this->generatePlainSystemTag($parsedParameters['systemtag']),
240
-					]))
241
-					->setRichSubject($this->l->t('{actor} removed system tag {systemtag} from {file}'), $parsedParameters);
242
-			}
243
-		} else {
244
-			throw new \InvalidArgumentException();
245
-		}
246
-
247
-		return $event;
248
-	}
249
-
250
-	protected function getParameters(IEvent $event) {
251
-		$subject = $event->getSubject();
252
-		$parameters = $event->getSubjectParameters();
253
-
254
-		switch ($subject) {
255
-			case self::CREATE_TAG:
256
-			case self::DELETE_TAG:
257
-				return [
258
-					'actor' => $this->getUserParameter($parameters[0]),
259
-					'systemtag' => $this->getSystemTagParameter($parameters[1]),
260
-				];
261
-			case self::UPDATE_TAG:
262
-				return [
263
-					'actor' => $this->getUserParameter($parameters[0]),
264
-					'newsystemtag' => $this->getSystemTagParameter($parameters[1]),
265
-					'oldsystemtag' => $this->getSystemTagParameter($parameters[2]),
266
-				];
267
-			case self::ASSIGN_TAG:
268
-			case self::UNASSIGN_TAG:
269
-				return [
270
-					'actor' => $this->getUserParameter($parameters[0]),
271
-					'file' => $this->getFileParameter($event->getObjectId(), $parameters[1]),
272
-					'systemtag' => $this->getSystemTagParameter($parameters[2]),
273
-				];
274
-		}
275
-		return [];
276
-	}
277
-
278
-	protected function getFileParameter($id, $path) {
279
-		return [
280
-			'type' => 'file',
281
-			'id' => $id,
282
-			'name' => basename($path),
283
-			'path' => trim($path, '/'),
284
-		];
285
-	}
286
-
287
-	protected function getSystemTagParameter($parameter) {
288
-		$tagData = json_decode($parameter, true);
289
-		if ($tagData === null) {
290
-			list($name, $status) = explode('|||', substr($parameter, 3, -3));
291
-			$tagData = [
292
-				'id' => 0,// No way to recover the ID
293
-				'name' => $name,
294
-				'assignable' => $status === 'assignable',
295
-				'visible' => $status !== 'invisible',
296
-			];
297
-		}
298
-
299
-		return [
300
-			'type' => 'systemtag',
301
-			'id' => (int) $tagData['id'],
302
-			'name' => $tagData['name'],
303
-			'assignable' => $tagData['assignable'] ? '1' : '0',
304
-			'visibility' => $tagData['visible'] ? '1' : '0',
305
-		];
306
-	}
307
-
308
-	protected function getUserParameter($uid) {
309
-		if (!isset($this->displayNames[$uid])) {
310
-			$this->displayNames[$uid] = $this->getDisplayName($uid);
311
-		}
312
-
313
-		return [
314
-			'type' => 'user',
315
-			'id' => $uid,
316
-			'name' => $this->displayNames[$uid],
317
-		];
318
-	}
319
-
320
-	protected function generatePlainSystemTag(array $parameter) {
321
-		if ($parameter['assignable'] === '1') {
322
-			return $parameter['name'];
323
-		} else if ($parameter['visibility'] === '1') {
324
-			return $this->l->t('%s (restricted)', $parameter['name']);
325
-		} else {
326
-			return $this->l->t('%s (invisible)', $parameter['name']);
327
-		}
328
-	}
329
-
330
-	/**
331
-	 * @param string $uid
332
-	 * @return string
333
-	 */
334
-	protected function getDisplayName($uid) {
335
-		$user = $this->userManager->get($uid);
336
-		if ($user instanceof IUser) {
337
-			return $user->getDisplayName();
338
-		} else {
339
-			return $uid;
340
-		}
341
-	}
35
+    const CREATE_TAG = 'create_tag';
36
+    const UPDATE_TAG = 'update_tag';
37
+    const DELETE_TAG = 'delete_tag';
38
+
39
+    const ASSIGN_TAG = 'assign_tag';
40
+    const UNASSIGN_TAG = 'unassign_tag';
41
+
42
+    /** @var IFactory */
43
+    protected $languageFactory;
44
+
45
+    /** @var IL10N */
46
+    protected $l;
47
+
48
+    /** @var IURLGenerator */
49
+    protected $url;
50
+
51
+    /** @var IManager */
52
+    protected $activityManager;
53
+
54
+    /** @var IUserManager */
55
+    protected $userManager;
56
+
57
+    /** @var string[] */
58
+    protected $displayNames = [];
59
+
60
+    /**
61
+     * @param IFactory $languageFactory
62
+     * @param IURLGenerator $url
63
+     * @param IManager $activityManager
64
+     * @param IUserManager $userManager
65
+     */
66
+    public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager) {
67
+        $this->languageFactory = $languageFactory;
68
+        $this->url = $url;
69
+        $this->activityManager = $activityManager;
70
+        $this->userManager = $userManager;
71
+    }
72
+
73
+    /**
74
+     * @param string $language
75
+     * @param IEvent $event
76
+     * @param IEvent|null $previousEvent
77
+     * @return IEvent
78
+     * @throws \InvalidArgumentException
79
+     * @since 11.0.0
80
+     */
81
+    public function parse($language, IEvent $event, IEvent $previousEvent = null) {
82
+        if ($event->getApp() !== 'systemtags') {
83
+            throw new \InvalidArgumentException();
84
+        }
85
+
86
+        $this->l = $this->languageFactory->get('systemtags', $language);
87
+
88
+        if ($this->activityManager->isFormattingFilteredObject()) {
89
+            try {
90
+                return $this->parseShortVersion($event);
91
+            } catch (\InvalidArgumentException $e) {
92
+                // Ignore and simply use the long version...
93
+            }
94
+        }
95
+
96
+        return $this->parseLongVersion($event);
97
+    }
98
+
99
+    /**
100
+     * @param IEvent $event
101
+     * @return IEvent
102
+     * @throws \InvalidArgumentException
103
+     * @since 11.0.0
104
+     */
105
+    public function parseShortVersion(IEvent $event) {
106
+        $parsedParameters = $this->getParameters($event);
107
+
108
+        if ($this->activityManager->getRequirePNG()) {
109
+            $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/tag.png')));
110
+        } else {
111
+            $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/tag.svg')));
112
+        }
113
+
114
+        if ($event->getSubject() === self::ASSIGN_TAG) {
115
+            if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) {
116
+                $event->setParsedSubject($this->l->t('Added system tag %1$s', [
117
+                        $this->generatePlainSystemTag($parsedParameters['systemtag']),
118
+                    ]))
119
+                    ->setRichSubject($this->l->t('Added system tag {systemtag}'), [
120
+                        'systemtag' => $parsedParameters['systemtag'],
121
+                    ]);
122
+            } else {
123
+                $event->setParsedSubject($this->l->t('%1$s added system tag %2$s', [
124
+                        $parsedParameters['actor']['name'],
125
+                        $this->generatePlainSystemTag($parsedParameters['systemtag']),
126
+                    ]))
127
+                    ->setRichSubject($this->l->t('{actor} added system tag {systemtag}'), [
128
+                        'actor' => $parsedParameters['actor'],
129
+                        'systemtag' => $parsedParameters['systemtag'],
130
+                    ]);
131
+            }
132
+        } else if ($event->getSubject() === self::UNASSIGN_TAG) {
133
+            if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) {
134
+                $event->setParsedSubject($this->l->t('Removed system tag %1$s', [
135
+                        $this->generatePlainSystemTag($parsedParameters['systemtag']),
136
+                    ]))
137
+                    ->setRichSubject($this->l->t('Removed system tag {systemtag}'), [
138
+                        'systemtag' => $parsedParameters['systemtag'],
139
+                    ]);
140
+            } else {
141
+                $event->setParsedSubject($this->l->t('%1$s removed system tag %2$s', [
142
+                        $parsedParameters['actor']['name'],
143
+                        $this->generatePlainSystemTag($parsedParameters['systemtag']),
144
+                    ]))
145
+                    ->setRichSubject($this->l->t('{actor} removed system tag {systemtag}'), [
146
+                        'actor' => $parsedParameters['actor'],
147
+                        'systemtag' => $parsedParameters['systemtag'],
148
+                    ]);
149
+            }
150
+        } else {
151
+            throw new \InvalidArgumentException();
152
+        }
153
+
154
+        return $event;
155
+    }
156
+
157
+    /**
158
+     * @param IEvent $event
159
+     * @return IEvent
160
+     * @throws \InvalidArgumentException
161
+     * @since 11.0.0
162
+     */
163
+    public function parseLongVersion(IEvent $event) {
164
+        $parsedParameters = $this->getParameters($event);
165
+
166
+        if ($this->activityManager->getRequirePNG()) {
167
+            $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/tag.png')));
168
+        } else {
169
+            $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/tag.svg')));
170
+        }
171
+
172
+        if ($event->getSubject() === self::CREATE_TAG) {
173
+            if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) {
174
+                $event->setParsedSubject($this->l->t('You created system tag %1$s', [
175
+                        $this->generatePlainSystemTag($parsedParameters['systemtag']),
176
+                    ]))
177
+                    ->setRichSubject($this->l->t('You created system tag {systemtag}'), $parsedParameters);
178
+            } else {
179
+                $event->setParsedSubject($this->l->t('%1$s created system tag %2$s', [
180
+                        $parsedParameters['actor']['name'],
181
+                        $this->generatePlainSystemTag($parsedParameters['systemtag']),
182
+                    ]))
183
+                    ->setRichSubject($this->l->t('{actor} created system tag {systemtag}'), $parsedParameters);
184
+            }
185
+        } else if ($event->getSubject() === self::DELETE_TAG) {
186
+            if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) {
187
+                $event->setParsedSubject($this->l->t('You deleted system tag %1$s', [
188
+                        $this->generatePlainSystemTag($parsedParameters['systemtag']),
189
+                    ]))
190
+                    ->setRichSubject($this->l->t('You deleted system tag {systemtag}'), $parsedParameters);
191
+            } else {
192
+                $event->setParsedSubject($this->l->t('%1$s deleted system tag %2$s', [
193
+                        $parsedParameters['actor']['name'],
194
+                        $this->generatePlainSystemTag($parsedParameters['systemtag']),
195
+                    ]))
196
+                    ->setRichSubject($this->l->t('{actor} deleted system tag {systemtag}'), $parsedParameters);
197
+            }
198
+        } else if ($event->getSubject() === self::UPDATE_TAG) {
199
+            if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) {
200
+                $event->setParsedSubject($this->l->t('You updated system tag %2$s to %1$s', [
201
+                        $this->generatePlainSystemTag($parsedParameters['newsystemtag']),
202
+                        $this->generatePlainSystemTag($parsedParameters['oldsystemtag']),
203
+                    ]))
204
+                    ->setRichSubject($this->l->t('You updated system tag {oldsystemtag} to {newsystemtag}'), $parsedParameters);
205
+            } else {
206
+                $event->setParsedSubject($this->l->t('%1$s updated system tag %3$s to %2$s', [
207
+                        $parsedParameters['actor']['name'],
208
+                        $this->generatePlainSystemTag($parsedParameters['newsystemtag']),
209
+                        $this->generatePlainSystemTag($parsedParameters['oldsystemtag']),
210
+                    ]))
211
+                    ->setRichSubject($this->l->t('{actor} updated system tag {oldsystemtag} to {newsystemtag}'), $parsedParameters);
212
+            }
213
+        } else if ($event->getSubject() === self::ASSIGN_TAG) {
214
+            if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) {
215
+                $event->setParsedSubject($this->l->t('You added system tag %2$s to %1$s', [
216
+                        $parsedParameters['file']['path'],
217
+                        $this->generatePlainSystemTag($parsedParameters['systemtag']),
218
+                    ]))
219
+                    ->setRichSubject($this->l->t('You added system tag {systemtag} to {file}'), $parsedParameters);
220
+            } else {
221
+                $event->setParsedSubject($this->l->t('%1$s added system tag %3$s to %2$s', [
222
+                        $parsedParameters['actor']['name'],
223
+                        $parsedParameters['file']['path'],
224
+                        $this->generatePlainSystemTag($parsedParameters['systemtag']),
225
+                    ]))
226
+                    ->setRichSubject($this->l->t('{actor} added system tag {systemtag} to {file}'), $parsedParameters);
227
+            }
228
+        } else if ($event->getSubject() === self::UNASSIGN_TAG) {
229
+            if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) {
230
+                $event->setParsedSubject($this->l->t('You removed system tag %2$s from %1$s', [
231
+                        $parsedParameters['file']['path'],
232
+                        $this->generatePlainSystemTag($parsedParameters['systemtag']),
233
+                    ]))
234
+                    ->setRichSubject($this->l->t('You removed system tag {systemtag} from {file}'), $parsedParameters);
235
+            } else {
236
+                $event->setParsedSubject($this->l->t('%1$s removed system tag %3$s from %2$s', [
237
+                        $parsedParameters['actor']['name'],
238
+                        $parsedParameters['file']['path'],
239
+                        $this->generatePlainSystemTag($parsedParameters['systemtag']),
240
+                    ]))
241
+                    ->setRichSubject($this->l->t('{actor} removed system tag {systemtag} from {file}'), $parsedParameters);
242
+            }
243
+        } else {
244
+            throw new \InvalidArgumentException();
245
+        }
246
+
247
+        return $event;
248
+    }
249
+
250
+    protected function getParameters(IEvent $event) {
251
+        $subject = $event->getSubject();
252
+        $parameters = $event->getSubjectParameters();
253
+
254
+        switch ($subject) {
255
+            case self::CREATE_TAG:
256
+            case self::DELETE_TAG:
257
+                return [
258
+                    'actor' => $this->getUserParameter($parameters[0]),
259
+                    'systemtag' => $this->getSystemTagParameter($parameters[1]),
260
+                ];
261
+            case self::UPDATE_TAG:
262
+                return [
263
+                    'actor' => $this->getUserParameter($parameters[0]),
264
+                    'newsystemtag' => $this->getSystemTagParameter($parameters[1]),
265
+                    'oldsystemtag' => $this->getSystemTagParameter($parameters[2]),
266
+                ];
267
+            case self::ASSIGN_TAG:
268
+            case self::UNASSIGN_TAG:
269
+                return [
270
+                    'actor' => $this->getUserParameter($parameters[0]),
271
+                    'file' => $this->getFileParameter($event->getObjectId(), $parameters[1]),
272
+                    'systemtag' => $this->getSystemTagParameter($parameters[2]),
273
+                ];
274
+        }
275
+        return [];
276
+    }
277
+
278
+    protected function getFileParameter($id, $path) {
279
+        return [
280
+            'type' => 'file',
281
+            'id' => $id,
282
+            'name' => basename($path),
283
+            'path' => trim($path, '/'),
284
+        ];
285
+    }
286
+
287
+    protected function getSystemTagParameter($parameter) {
288
+        $tagData = json_decode($parameter, true);
289
+        if ($tagData === null) {
290
+            list($name, $status) = explode('|||', substr($parameter, 3, -3));
291
+            $tagData = [
292
+                'id' => 0,// No way to recover the ID
293
+                'name' => $name,
294
+                'assignable' => $status === 'assignable',
295
+                'visible' => $status !== 'invisible',
296
+            ];
297
+        }
298
+
299
+        return [
300
+            'type' => 'systemtag',
301
+            'id' => (int) $tagData['id'],
302
+            'name' => $tagData['name'],
303
+            'assignable' => $tagData['assignable'] ? '1' : '0',
304
+            'visibility' => $tagData['visible'] ? '1' : '0',
305
+        ];
306
+    }
307
+
308
+    protected function getUserParameter($uid) {
309
+        if (!isset($this->displayNames[$uid])) {
310
+            $this->displayNames[$uid] = $this->getDisplayName($uid);
311
+        }
312
+
313
+        return [
314
+            'type' => 'user',
315
+            'id' => $uid,
316
+            'name' => $this->displayNames[$uid],
317
+        ];
318
+    }
319
+
320
+    protected function generatePlainSystemTag(array $parameter) {
321
+        if ($parameter['assignable'] === '1') {
322
+            return $parameter['name'];
323
+        } else if ($parameter['visibility'] === '1') {
324
+            return $this->l->t('%s (restricted)', $parameter['name']);
325
+        } else {
326
+            return $this->l->t('%s (invisible)', $parameter['name']);
327
+        }
328
+    }
329
+
330
+    /**
331
+     * @param string $uid
332
+     * @return string
333
+     */
334
+    protected function getDisplayName($uid) {
335
+        $user = $this->userManager->get($uid);
336
+        if ($user instanceof IUser) {
337
+            return $user->getDisplayName();
338
+        } else {
339
+            return $uid;
340
+        }
341
+    }
342 342
 }
Please login to merge, or discard this patch.