@@ -32,72 +32,72 @@ |
||
32 | 32 | |
33 | 33 | class Personal implements ISettings { |
34 | 34 | |
35 | - /** @var IManager */ |
|
36 | - private $encryptionManager; |
|
35 | + /** @var IManager */ |
|
36 | + private $encryptionManager; |
|
37 | 37 | |
38 | - /** @var UserGlobalStoragesService */ |
|
39 | - private $userGlobalStoragesService; |
|
38 | + /** @var UserGlobalStoragesService */ |
|
39 | + private $userGlobalStoragesService; |
|
40 | 40 | |
41 | - /** @var BackendService */ |
|
42 | - private $backendService; |
|
41 | + /** @var BackendService */ |
|
42 | + private $backendService; |
|
43 | 43 | |
44 | - /** @var GlobalAuth */ |
|
45 | - private $globalAuth; |
|
44 | + /** @var GlobalAuth */ |
|
45 | + private $globalAuth; |
|
46 | 46 | |
47 | - /** @var IUserSession */ |
|
48 | - private $userSession; |
|
47 | + /** @var IUserSession */ |
|
48 | + private $userSession; |
|
49 | 49 | |
50 | - public function __construct( |
|
51 | - IManager $encryptionManager, |
|
52 | - UserGlobalStoragesService $userGlobalStoragesService, |
|
53 | - BackendService $backendService, |
|
54 | - GlobalAuth $globalAuth, |
|
55 | - IUserSession $userSession |
|
56 | - ) { |
|
57 | - $this->encryptionManager = $encryptionManager; |
|
58 | - $this->userGlobalStoragesService = $userGlobalStoragesService; |
|
59 | - $this->backendService = $backendService; |
|
60 | - $this->globalAuth = $globalAuth; |
|
61 | - $this->userSession = $userSession; |
|
62 | - } |
|
50 | + public function __construct( |
|
51 | + IManager $encryptionManager, |
|
52 | + UserGlobalStoragesService $userGlobalStoragesService, |
|
53 | + BackendService $backendService, |
|
54 | + GlobalAuth $globalAuth, |
|
55 | + IUserSession $userSession |
|
56 | + ) { |
|
57 | + $this->encryptionManager = $encryptionManager; |
|
58 | + $this->userGlobalStoragesService = $userGlobalStoragesService; |
|
59 | + $this->backendService = $backendService; |
|
60 | + $this->globalAuth = $globalAuth; |
|
61 | + $this->userSession = $userSession; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @return TemplateResponse |
|
66 | - */ |
|
67 | - public function getForm() { |
|
68 | - $uid = $this->userSession->getUser()->getUID(); |
|
64 | + /** |
|
65 | + * @return TemplateResponse |
|
66 | + */ |
|
67 | + public function getForm() { |
|
68 | + $uid = $this->userSession->getUser()->getUID(); |
|
69 | 69 | |
70 | - $parameters = [ |
|
71 | - 'encryptionEnabled' => $this->encryptionManager->isEnabled(), |
|
72 | - 'visibilityType' => BackendService::VISIBILITY_PERSONAL, |
|
73 | - 'storages' => $this->userGlobalStoragesService->getStorages(), |
|
74 | - 'backends' => $this->backendService->getAvailableBackends(), |
|
75 | - 'authMechanisms' => $this->backendService->getAuthMechanisms(), |
|
76 | - 'dependencies' => \OC_Mount_Config::dependencyMessage($this->backendService->getBackends()), |
|
77 | - 'allowUserMounting' => $this->backendService->isUserMountingAllowed(), |
|
78 | - 'globalCredentials' => $this->globalAuth->getAuth($uid), |
|
79 | - 'globalCredentialsUid' => $uid, |
|
80 | - ]; |
|
70 | + $parameters = [ |
|
71 | + 'encryptionEnabled' => $this->encryptionManager->isEnabled(), |
|
72 | + 'visibilityType' => BackendService::VISIBILITY_PERSONAL, |
|
73 | + 'storages' => $this->userGlobalStoragesService->getStorages(), |
|
74 | + 'backends' => $this->backendService->getAvailableBackends(), |
|
75 | + 'authMechanisms' => $this->backendService->getAuthMechanisms(), |
|
76 | + 'dependencies' => \OC_Mount_Config::dependencyMessage($this->backendService->getBackends()), |
|
77 | + 'allowUserMounting' => $this->backendService->isUserMountingAllowed(), |
|
78 | + 'globalCredentials' => $this->globalAuth->getAuth($uid), |
|
79 | + 'globalCredentialsUid' => $uid, |
|
80 | + ]; |
|
81 | 81 | |
82 | - return new TemplateResponse('files_external', 'settings', $parameters, ''); |
|
83 | - } |
|
82 | + return new TemplateResponse('files_external', 'settings', $parameters, ''); |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * @return string the section ID, e.g. 'sharing' |
|
87 | - */ |
|
88 | - public function getSection() { |
|
89 | - return 'externalstorages'; |
|
90 | - } |
|
85 | + /** |
|
86 | + * @return string the section ID, e.g. 'sharing' |
|
87 | + */ |
|
88 | + public function getSection() { |
|
89 | + return 'externalstorages'; |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * @return int whether the form should be rather on the top or bottom of |
|
94 | - * the admin section. The forms are arranged in ascending order of the |
|
95 | - * priority values. It is required to return a value between 0 and 100. |
|
96 | - * |
|
97 | - * E.g.: 70 |
|
98 | - */ |
|
99 | - public function getPriority() { |
|
100 | - return 40; |
|
101 | - } |
|
92 | + /** |
|
93 | + * @return int whether the form should be rather on the top or bottom of |
|
94 | + * the admin section. The forms are arranged in ascending order of the |
|
95 | + * priority values. It is required to return a value between 0 and 100. |
|
96 | + * |
|
97 | + * E.g.: 70 |
|
98 | + */ |
|
99 | + public function getPriority() { |
|
100 | + return 40; |
|
101 | + } |
|
102 | 102 | |
103 | 103 | } |
@@ -26,80 +26,80 @@ |
||
26 | 26 | namespace OC\DB; |
27 | 27 | |
28 | 28 | class OracleConnection extends Connection { |
29 | - /** |
|
30 | - * Quote the keys of the array |
|
31 | - */ |
|
32 | - private function quoteKeys(array $data) { |
|
33 | - $return = []; |
|
34 | - $c = $this->getDatabasePlatform()->getIdentifierQuoteCharacter(); |
|
35 | - foreach($data as $key => $value) { |
|
36 | - if ($key[0] !== $c) { |
|
37 | - $return[$this->quoteIdentifier($key)] = $value; |
|
38 | - } else { |
|
39 | - $return[$key] = $value; |
|
40 | - } |
|
41 | - } |
|
42 | - return $return; |
|
43 | - } |
|
29 | + /** |
|
30 | + * Quote the keys of the array |
|
31 | + */ |
|
32 | + private function quoteKeys(array $data) { |
|
33 | + $return = []; |
|
34 | + $c = $this->getDatabasePlatform()->getIdentifierQuoteCharacter(); |
|
35 | + foreach($data as $key => $value) { |
|
36 | + if ($key[0] !== $c) { |
|
37 | + $return[$this->quoteIdentifier($key)] = $value; |
|
38 | + } else { |
|
39 | + $return[$key] = $value; |
|
40 | + } |
|
41 | + } |
|
42 | + return $return; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * {@inheritDoc} |
|
47 | - */ |
|
48 | - public function insert($tableName, array $data, array $types = array()) { |
|
49 | - if ($tableName[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
50 | - $tableName = $this->quoteIdentifier($tableName); |
|
51 | - } |
|
52 | - $data = $this->quoteKeys($data); |
|
53 | - return parent::insert($tableName, $data, $types); |
|
54 | - } |
|
45 | + /** |
|
46 | + * {@inheritDoc} |
|
47 | + */ |
|
48 | + public function insert($tableName, array $data, array $types = array()) { |
|
49 | + if ($tableName[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
50 | + $tableName = $this->quoteIdentifier($tableName); |
|
51 | + } |
|
52 | + $data = $this->quoteKeys($data); |
|
53 | + return parent::insert($tableName, $data, $types); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * {@inheritDoc} |
|
58 | - */ |
|
59 | - public function update($tableName, array $data, array $identifier, array $types = array()) { |
|
60 | - if ($tableName[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
61 | - $tableName = $this->quoteIdentifier($tableName); |
|
62 | - } |
|
63 | - $data = $this->quoteKeys($data); |
|
64 | - $identifier = $this->quoteKeys($identifier); |
|
65 | - return parent::update($tableName, $data, $identifier, $types); |
|
66 | - } |
|
56 | + /** |
|
57 | + * {@inheritDoc} |
|
58 | + */ |
|
59 | + public function update($tableName, array $data, array $identifier, array $types = array()) { |
|
60 | + if ($tableName[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
61 | + $tableName = $this->quoteIdentifier($tableName); |
|
62 | + } |
|
63 | + $data = $this->quoteKeys($data); |
|
64 | + $identifier = $this->quoteKeys($identifier); |
|
65 | + return parent::update($tableName, $data, $identifier, $types); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * {@inheritDoc} |
|
70 | - */ |
|
71 | - public function delete($tableExpression, array $identifier, array $types = array()) { |
|
72 | - if ($tableExpression[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
73 | - $tableExpression = $this->quoteIdentifier($tableExpression); |
|
74 | - } |
|
75 | - $identifier = $this->quoteKeys($identifier); |
|
76 | - return parent::delete($tableExpression, $identifier); |
|
77 | - } |
|
68 | + /** |
|
69 | + * {@inheritDoc} |
|
70 | + */ |
|
71 | + public function delete($tableExpression, array $identifier, array $types = array()) { |
|
72 | + if ($tableExpression[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
73 | + $tableExpression = $this->quoteIdentifier($tableExpression); |
|
74 | + } |
|
75 | + $identifier = $this->quoteKeys($identifier); |
|
76 | + return parent::delete($tableExpression, $identifier); |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * Drop a table from the database if it exists |
|
81 | - * |
|
82 | - * @param string $table table name without the prefix |
|
83 | - */ |
|
84 | - public function dropTable($table) { |
|
85 | - $table = $this->tablePrefix . trim($table); |
|
86 | - $table = $this->quoteIdentifier($table); |
|
87 | - $schema = $this->getSchemaManager(); |
|
88 | - if($schema->tablesExist(array($table))) { |
|
89 | - $schema->dropTable($table); |
|
90 | - } |
|
91 | - } |
|
79 | + /** |
|
80 | + * Drop a table from the database if it exists |
|
81 | + * |
|
82 | + * @param string $table table name without the prefix |
|
83 | + */ |
|
84 | + public function dropTable($table) { |
|
85 | + $table = $this->tablePrefix . trim($table); |
|
86 | + $table = $this->quoteIdentifier($table); |
|
87 | + $schema = $this->getSchemaManager(); |
|
88 | + if($schema->tablesExist(array($table))) { |
|
89 | + $schema->dropTable($table); |
|
90 | + } |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * Check if a table exists |
|
95 | - * |
|
96 | - * @param string $table table name without the prefix |
|
97 | - * @return bool |
|
98 | - */ |
|
99 | - public function tableExists($table){ |
|
100 | - $table = $this->tablePrefix . trim($table); |
|
101 | - $table = $this->quoteIdentifier($table); |
|
102 | - $schema = $this->getSchemaManager(); |
|
103 | - return $schema->tablesExist(array($table)); |
|
104 | - } |
|
93 | + /** |
|
94 | + * Check if a table exists |
|
95 | + * |
|
96 | + * @param string $table table name without the prefix |
|
97 | + * @return bool |
|
98 | + */ |
|
99 | + public function tableExists($table){ |
|
100 | + $table = $this->tablePrefix . trim($table); |
|
101 | + $table = $this->quoteIdentifier($table); |
|
102 | + $schema = $this->getSchemaManager(); |
|
103 | + return $schema->tablesExist(array($table)); |
|
104 | + } |
|
105 | 105 | } |
@@ -43,272 +43,272 @@ |
||
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 | } |
@@ -36,49 +36,49 @@ |
||
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 | } |
@@ -29,66 +29,66 @@ |
||
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 | } |
@@ -30,33 +30,33 @@ |
||
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 | } |
@@ -24,16 +24,16 @@ |
||
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 | } |
@@ -33,14 +33,14 @@ |
||
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 | } |
@@ -31,47 +31,47 @@ |
||
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 | } |