@@ -32,93 +32,93 @@ |
||
32 | 32 | */ |
33 | 33 | class Version13000Date20170919121250 extends SimpleMigrationStep { |
34 | 34 | |
35 | - /** |
|
36 | - * @param IOutput $output |
|
37 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
38 | - * @param array $options |
|
39 | - * @since 13.0.0 |
|
40 | - */ |
|
41 | - public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { |
|
42 | - } |
|
43 | - |
|
44 | - /** |
|
45 | - * @param IOutput $output |
|
46 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
47 | - * @param array $options |
|
48 | - * @return null|ISchemaWrapper |
|
49 | - * @since 13.0.0 |
|
50 | - */ |
|
51 | - public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
52 | - /** @var ISchemaWrapper $schema */ |
|
53 | - $schema = $schemaClosure(); |
|
54 | - |
|
55 | - $table = $schema->getTable('jobs'); |
|
56 | - $column = $table->getColumn('id'); |
|
57 | - $column->setUnsigned(true); |
|
58 | - |
|
59 | - $table = $schema->getTable('authtoken'); |
|
60 | - $column = $table->getColumn('id'); |
|
61 | - $column->setUnsigned(true); |
|
62 | - $column = $table->getColumn('type'); |
|
63 | - $column->setUnsigned(true); |
|
64 | - $column = $table->getColumn('remember'); |
|
65 | - $column->setUnsigned(true); |
|
66 | - $column = $table->getColumn('last_activity'); |
|
67 | - $column->setUnsigned(true); |
|
68 | - $column = $table->getColumn('last_check'); |
|
69 | - $column->setUnsigned(true); |
|
70 | - |
|
71 | - $table = $schema->getTable('bruteforce_attempts'); |
|
72 | - $column = $table->getColumn('id'); |
|
73 | - $column->setUnsigned(true); |
|
74 | - $column = $table->getColumn('occurred'); |
|
75 | - $column->setUnsigned(true); |
|
76 | - |
|
77 | - $table = $schema->getTable('comments'); |
|
78 | - $column = $table->getColumn('id'); |
|
79 | - $column->setUnsigned(true); |
|
80 | - $column = $table->getColumn('parent_id'); |
|
81 | - $column->setUnsigned(true); |
|
82 | - $column = $table->getColumn('topmost_parent_id'); |
|
83 | - $column->setUnsigned(true); |
|
84 | - $column = $table->getColumn('children_count'); |
|
85 | - $column->setUnsigned(true); |
|
86 | - |
|
87 | - $table = $schema->getTable('file_locks'); |
|
88 | - $column = $table->getColumn('id'); |
|
89 | - $column->setUnsigned(true); |
|
90 | - |
|
91 | - $table = $schema->getTable('systemtag'); |
|
92 | - $column = $table->getColumn('id'); |
|
93 | - $column->setUnsigned(true); |
|
94 | - |
|
95 | - $table = $schema->getTable('systemtag_object_mapping'); |
|
96 | - $column = $table->getColumn('systemtagid'); |
|
97 | - $column->setUnsigned(true); |
|
98 | - |
|
99 | - $table = $schema->getTable('systemtag_group'); |
|
100 | - $column = $table->getColumn('systemtagid'); |
|
101 | - $column->setUnsigned(true); |
|
102 | - |
|
103 | - $table = $schema->getTable('vcategory'); |
|
104 | - $column = $table->getColumn('id'); |
|
105 | - $column->setUnsigned(true); |
|
106 | - |
|
107 | - $table = $schema->getTable('vcategory_to_object'); |
|
108 | - $column = $table->getColumn('objid'); |
|
109 | - $column->setUnsigned(true); |
|
110 | - $column = $table->getColumn('categoryid'); |
|
111 | - $column->setUnsigned(true); |
|
112 | - |
|
113 | - return $schema; |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * @param IOutput $output |
|
118 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
119 | - * @param array $options |
|
120 | - * @since 13.0.0 |
|
121 | - */ |
|
122 | - public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { |
|
123 | - } |
|
35 | + /** |
|
36 | + * @param IOutput $output |
|
37 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
38 | + * @param array $options |
|
39 | + * @since 13.0.0 |
|
40 | + */ |
|
41 | + public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { |
|
42 | + } |
|
43 | + |
|
44 | + /** |
|
45 | + * @param IOutput $output |
|
46 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
47 | + * @param array $options |
|
48 | + * @return null|ISchemaWrapper |
|
49 | + * @since 13.0.0 |
|
50 | + */ |
|
51 | + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
52 | + /** @var ISchemaWrapper $schema */ |
|
53 | + $schema = $schemaClosure(); |
|
54 | + |
|
55 | + $table = $schema->getTable('jobs'); |
|
56 | + $column = $table->getColumn('id'); |
|
57 | + $column->setUnsigned(true); |
|
58 | + |
|
59 | + $table = $schema->getTable('authtoken'); |
|
60 | + $column = $table->getColumn('id'); |
|
61 | + $column->setUnsigned(true); |
|
62 | + $column = $table->getColumn('type'); |
|
63 | + $column->setUnsigned(true); |
|
64 | + $column = $table->getColumn('remember'); |
|
65 | + $column->setUnsigned(true); |
|
66 | + $column = $table->getColumn('last_activity'); |
|
67 | + $column->setUnsigned(true); |
|
68 | + $column = $table->getColumn('last_check'); |
|
69 | + $column->setUnsigned(true); |
|
70 | + |
|
71 | + $table = $schema->getTable('bruteforce_attempts'); |
|
72 | + $column = $table->getColumn('id'); |
|
73 | + $column->setUnsigned(true); |
|
74 | + $column = $table->getColumn('occurred'); |
|
75 | + $column->setUnsigned(true); |
|
76 | + |
|
77 | + $table = $schema->getTable('comments'); |
|
78 | + $column = $table->getColumn('id'); |
|
79 | + $column->setUnsigned(true); |
|
80 | + $column = $table->getColumn('parent_id'); |
|
81 | + $column->setUnsigned(true); |
|
82 | + $column = $table->getColumn('topmost_parent_id'); |
|
83 | + $column->setUnsigned(true); |
|
84 | + $column = $table->getColumn('children_count'); |
|
85 | + $column->setUnsigned(true); |
|
86 | + |
|
87 | + $table = $schema->getTable('file_locks'); |
|
88 | + $column = $table->getColumn('id'); |
|
89 | + $column->setUnsigned(true); |
|
90 | + |
|
91 | + $table = $schema->getTable('systemtag'); |
|
92 | + $column = $table->getColumn('id'); |
|
93 | + $column->setUnsigned(true); |
|
94 | + |
|
95 | + $table = $schema->getTable('systemtag_object_mapping'); |
|
96 | + $column = $table->getColumn('systemtagid'); |
|
97 | + $column->setUnsigned(true); |
|
98 | + |
|
99 | + $table = $schema->getTable('systemtag_group'); |
|
100 | + $column = $table->getColumn('systemtagid'); |
|
101 | + $column->setUnsigned(true); |
|
102 | + |
|
103 | + $table = $schema->getTable('vcategory'); |
|
104 | + $column = $table->getColumn('id'); |
|
105 | + $column->setUnsigned(true); |
|
106 | + |
|
107 | + $table = $schema->getTable('vcategory_to_object'); |
|
108 | + $column = $table->getColumn('objid'); |
|
109 | + $column->setUnsigned(true); |
|
110 | + $column = $table->getColumn('categoryid'); |
|
111 | + $column->setUnsigned(true); |
|
112 | + |
|
113 | + return $schema; |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * @param IOutput $output |
|
118 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
119 | + * @param array $options |
|
120 | + * @since 13.0.0 |
|
121 | + */ |
|
122 | + public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { |
|
123 | + } |
|
124 | 124 | } |
@@ -31,75 +31,75 @@ |
||
31 | 31 | |
32 | 32 | class Version1002Date20170607113030 extends SimpleMigrationStep { |
33 | 33 | |
34 | - /** @var IDBConnection */ |
|
35 | - protected $connection; |
|
34 | + /** @var IDBConnection */ |
|
35 | + protected $connection; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @param IDBConnection $connection |
|
39 | - */ |
|
40 | - public function __construct(IDBConnection $connection) { |
|
41 | - $this->connection = $connection; |
|
42 | - } |
|
37 | + /** |
|
38 | + * @param IDBConnection $connection |
|
39 | + */ |
|
40 | + public function __construct(IDBConnection $connection) { |
|
41 | + $this->connection = $connection; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @param IOutput $output |
|
46 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
47 | - * @param array $options |
|
48 | - * @since 13.0.0 |
|
49 | - */ |
|
50 | - public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { |
|
51 | - /** @var ISchemaWrapper $schema */ |
|
52 | - $schema = $schemaClosure(); |
|
44 | + /** |
|
45 | + * @param IOutput $output |
|
46 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
47 | + * @param array $options |
|
48 | + * @since 13.0.0 |
|
49 | + */ |
|
50 | + public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { |
|
51 | + /** @var ISchemaWrapper $schema */ |
|
52 | + $schema = $schemaClosure(); |
|
53 | 53 | |
54 | - if (!$schema->hasTable('twofactor_backup_codes')) { |
|
55 | - // Legacy table does not exist |
|
56 | - return; |
|
57 | - } |
|
54 | + if (!$schema->hasTable('twofactor_backup_codes')) { |
|
55 | + // Legacy table does not exist |
|
56 | + return; |
|
57 | + } |
|
58 | 58 | |
59 | - $insert = $this->connection->getQueryBuilder(); |
|
60 | - $insert->insert('twofactor_backupcodes') |
|
61 | - ->values([ |
|
62 | - // Inserting with id might fail: 'id' => $insert->createParameter('id'), |
|
63 | - 'user_id' => $insert->createParameter('user_id'), |
|
64 | - 'code' => $insert->createParameter('code'), |
|
65 | - 'used' => $insert->createParameter('used'), |
|
66 | - ]); |
|
59 | + $insert = $this->connection->getQueryBuilder(); |
|
60 | + $insert->insert('twofactor_backupcodes') |
|
61 | + ->values([ |
|
62 | + // Inserting with id might fail: 'id' => $insert->createParameter('id'), |
|
63 | + 'user_id' => $insert->createParameter('user_id'), |
|
64 | + 'code' => $insert->createParameter('code'), |
|
65 | + 'used' => $insert->createParameter('used'), |
|
66 | + ]); |
|
67 | 67 | |
68 | - $query = $this->connection->getQueryBuilder(); |
|
69 | - $query->select('*') |
|
70 | - ->from('twofactor_backup_codes') |
|
71 | - ->orderBy('id', 'ASC'); |
|
72 | - $result = $query->execute(); |
|
68 | + $query = $this->connection->getQueryBuilder(); |
|
69 | + $query->select('*') |
|
70 | + ->from('twofactor_backup_codes') |
|
71 | + ->orderBy('id', 'ASC'); |
|
72 | + $result = $query->execute(); |
|
73 | 73 | |
74 | - $output->startProgress(); |
|
75 | - while ($row = $result->fetch()) { |
|
76 | - $output->advance(); |
|
74 | + $output->startProgress(); |
|
75 | + while ($row = $result->fetch()) { |
|
76 | + $output->advance(); |
|
77 | 77 | |
78 | - $insert |
|
79 | - // Inserting with id might fail: ->setParameter('id', $row['id'], IQueryBuilder::PARAM_INT) |
|
80 | - ->setParameter('user_id', $row['user_id'], IQueryBuilder::PARAM_STR) |
|
81 | - ->setParameter('code', $row['code'], IQueryBuilder::PARAM_STR) |
|
82 | - ->setParameter('used', $row['used'], IQueryBuilder::PARAM_INT) |
|
83 | - ->execute(); |
|
84 | - } |
|
85 | - $output->finishProgress(); |
|
86 | - } |
|
78 | + $insert |
|
79 | + // Inserting with id might fail: ->setParameter('id', $row['id'], IQueryBuilder::PARAM_INT) |
|
80 | + ->setParameter('user_id', $row['user_id'], IQueryBuilder::PARAM_STR) |
|
81 | + ->setParameter('code', $row['code'], IQueryBuilder::PARAM_STR) |
|
82 | + ->setParameter('used', $row['used'], IQueryBuilder::PARAM_INT) |
|
83 | + ->execute(); |
|
84 | + } |
|
85 | + $output->finishProgress(); |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * @param IOutput $output |
|
90 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
91 | - * @param array $options |
|
92 | - * @return null|ISchemaWrapper |
|
93 | - * @since 13.0.0 |
|
94 | - */ |
|
95 | - public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
96 | - /** @var ISchemaWrapper $schema */ |
|
97 | - $schema = $schemaClosure(); |
|
88 | + /** |
|
89 | + * @param IOutput $output |
|
90 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
91 | + * @param array $options |
|
92 | + * @return null|ISchemaWrapper |
|
93 | + * @since 13.0.0 |
|
94 | + */ |
|
95 | + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
96 | + /** @var ISchemaWrapper $schema */ |
|
97 | + $schema = $schemaClosure(); |
|
98 | 98 | |
99 | - if ($schema->hasTable('twofactor_backup_codes')) { |
|
100 | - $schema->dropTable('twofactor_backup_codes'); |
|
101 | - return $schema; |
|
102 | - } |
|
103 | - return null; |
|
104 | - } |
|
99 | + if ($schema->hasTable('twofactor_backup_codes')) { |
|
100 | + $schema->dropTable('twofactor_backup_codes'); |
|
101 | + return $schema; |
|
102 | + } |
|
103 | + return null; |
|
104 | + } |
|
105 | 105 | } |
@@ -29,30 +29,30 @@ |
||
29 | 29 | |
30 | 30 | class Version1004Date20170919104507 extends SimpleMigrationStep { |
31 | 31 | |
32 | - /** |
|
33 | - * @param IOutput $output |
|
34 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
35 | - * @param array $options |
|
36 | - * @return null|ISchemaWrapper |
|
37 | - * @since 13.0.0 |
|
38 | - */ |
|
39 | - public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
40 | - /** @var ISchemaWrapper $schema */ |
|
41 | - $schema = $schemaClosure(); |
|
42 | - |
|
43 | - $table = $schema->getTable('addressbooks'); |
|
44 | - $column = $table->getColumn('id'); |
|
45 | - $column->setUnsigned(true); |
|
46 | - |
|
47 | - $table = $schema->getTable('calendarobjects'); |
|
48 | - $column = $table->getColumn('id'); |
|
49 | - $column->setUnsigned(true); |
|
50 | - |
|
51 | - $table = $schema->getTable('calendarchanges'); |
|
52 | - $column = $table->getColumn('id'); |
|
53 | - $column->setUnsigned(true); |
|
54 | - |
|
55 | - return $schema; |
|
56 | - } |
|
32 | + /** |
|
33 | + * @param IOutput $output |
|
34 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
35 | + * @param array $options |
|
36 | + * @return null|ISchemaWrapper |
|
37 | + * @since 13.0.0 |
|
38 | + */ |
|
39 | + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
40 | + /** @var ISchemaWrapper $schema */ |
|
41 | + $schema = $schemaClosure(); |
|
42 | + |
|
43 | + $table = $schema->getTable('addressbooks'); |
|
44 | + $column = $table->getColumn('id'); |
|
45 | + $column->setUnsigned(true); |
|
46 | + |
|
47 | + $table = $schema->getTable('calendarobjects'); |
|
48 | + $column = $table->getColumn('id'); |
|
49 | + $column->setUnsigned(true); |
|
50 | + |
|
51 | + $table = $schema->getTable('calendarchanges'); |
|
52 | + $column = $table->getColumn('id'); |
|
53 | + $column->setUnsigned(true); |
|
54 | + |
|
55 | + return $schema; |
|
56 | + } |
|
57 | 57 | |
58 | 58 | } |
@@ -29,64 +29,64 @@ |
||
29 | 29 | */ |
30 | 30 | interface ISchemaWrapper { |
31 | 31 | |
32 | - /** |
|
33 | - * @param string $tableName |
|
34 | - * |
|
35 | - * @return \Doctrine\DBAL\Schema\Table |
|
36 | - * @throws \Doctrine\DBAL\Schema\SchemaException |
|
37 | - * @since 13.0.0 |
|
38 | - */ |
|
39 | - public function getTable($tableName); |
|
32 | + /** |
|
33 | + * @param string $tableName |
|
34 | + * |
|
35 | + * @return \Doctrine\DBAL\Schema\Table |
|
36 | + * @throws \Doctrine\DBAL\Schema\SchemaException |
|
37 | + * @since 13.0.0 |
|
38 | + */ |
|
39 | + public function getTable($tableName); |
|
40 | 40 | |
41 | - /** |
|
42 | - * Does this schema have a table with the given name? |
|
43 | - * |
|
44 | - * @param string $tableName Prefix is automatically prepended |
|
45 | - * |
|
46 | - * @return boolean |
|
47 | - * @since 13.0.0 |
|
48 | - */ |
|
49 | - public function hasTable($tableName); |
|
41 | + /** |
|
42 | + * Does this schema have a table with the given name? |
|
43 | + * |
|
44 | + * @param string $tableName Prefix is automatically prepended |
|
45 | + * |
|
46 | + * @return boolean |
|
47 | + * @since 13.0.0 |
|
48 | + */ |
|
49 | + public function hasTable($tableName); |
|
50 | 50 | |
51 | - /** |
|
52 | - * Creates a new table. |
|
53 | - * |
|
54 | - * @param string $tableName Prefix is automatically prepended |
|
55 | - * @return \Doctrine\DBAL\Schema\Table |
|
56 | - * @since 13.0.0 |
|
57 | - */ |
|
58 | - public function createTable($tableName); |
|
51 | + /** |
|
52 | + * Creates a new table. |
|
53 | + * |
|
54 | + * @param string $tableName Prefix is automatically prepended |
|
55 | + * @return \Doctrine\DBAL\Schema\Table |
|
56 | + * @since 13.0.0 |
|
57 | + */ |
|
58 | + public function createTable($tableName); |
|
59 | 59 | |
60 | - /** |
|
61 | - * Drops a table from the schema. |
|
62 | - * |
|
63 | - * @param string $tableName Prefix is automatically prepended |
|
64 | - * @return \Doctrine\DBAL\Schema\Schema |
|
65 | - * @since 13.0.0 |
|
66 | - */ |
|
67 | - public function dropTable($tableName); |
|
60 | + /** |
|
61 | + * Drops a table from the schema. |
|
62 | + * |
|
63 | + * @param string $tableName Prefix is automatically prepended |
|
64 | + * @return \Doctrine\DBAL\Schema\Schema |
|
65 | + * @since 13.0.0 |
|
66 | + */ |
|
67 | + public function dropTable($tableName); |
|
68 | 68 | |
69 | - /** |
|
70 | - * Gets all tables of this schema. |
|
71 | - * |
|
72 | - * @return \Doctrine\DBAL\Schema\Table[] |
|
73 | - * @since 13.0.0 |
|
74 | - */ |
|
75 | - public function getTables(); |
|
69 | + /** |
|
70 | + * Gets all tables of this schema. |
|
71 | + * |
|
72 | + * @return \Doctrine\DBAL\Schema\Table[] |
|
73 | + * @since 13.0.0 |
|
74 | + */ |
|
75 | + public function getTables(); |
|
76 | 76 | |
77 | - /** |
|
78 | - * Gets all table names, prefixed with table prefix |
|
79 | - * |
|
80 | - * @return array |
|
81 | - * @since 13.0.0 |
|
82 | - */ |
|
83 | - public function getTableNames(); |
|
77 | + /** |
|
78 | + * Gets all table names, prefixed with table prefix |
|
79 | + * |
|
80 | + * @return array |
|
81 | + * @since 13.0.0 |
|
82 | + */ |
|
83 | + public function getTableNames(); |
|
84 | 84 | |
85 | - /** |
|
86 | - * Gets all table names |
|
87 | - * |
|
88 | - * @return array |
|
89 | - * @since 13.0.0 |
|
90 | - */ |
|
91 | - public function getTableNamesWithoutPrefix(); |
|
85 | + /** |
|
86 | + * Gets all table names |
|
87 | + * |
|
88 | + * @return array |
|
89 | + * @since 13.0.0 |
|
90 | + */ |
|
91 | + public function getTableNamesWithoutPrefix(); |
|
92 | 92 | } |
@@ -72,17 +72,17 @@ discard block |
||
72 | 72 | } |
73 | 73 | |
74 | 74 | protected function getStorageConfigFromDBMount(array $mount) { |
75 | - $applicableUsers = array_filter($mount['applicable'], function ($applicable) { |
|
75 | + $applicableUsers = array_filter($mount['applicable'], function($applicable) { |
|
76 | 76 | return $applicable['type'] === DBConfigService::APPLICABLE_TYPE_USER; |
77 | 77 | }); |
78 | - $applicableUsers = array_map(function ($applicable) { |
|
78 | + $applicableUsers = array_map(function($applicable) { |
|
79 | 79 | return $applicable['value']; |
80 | 80 | }, $applicableUsers); |
81 | 81 | |
82 | - $applicableGroups = array_filter($mount['applicable'], function ($applicable) { |
|
82 | + $applicableGroups = array_filter($mount['applicable'], function($applicable) { |
|
83 | 83 | return $applicable['type'] === DBConfigService::APPLICABLE_TYPE_GROUP; |
84 | 84 | }); |
85 | - $applicableGroups = array_map(function ($applicable) { |
|
85 | + $applicableGroups = array_map(function($applicable) { |
|
86 | 86 | return $applicable['value']; |
87 | 87 | }, $applicableGroups); |
88 | 88 | |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | $mount['priority'] |
99 | 99 | ); |
100 | 100 | $config->setType($mount['type']); |
101 | - $config->setId((int)$mount['mount_id']); |
|
101 | + $config->setId((int) $mount['mount_id']); |
|
102 | 102 | return $config; |
103 | 103 | } catch (\UnexpectedValueException $e) { |
104 | 104 | // don't die if a storage backend doesn't exist |
@@ -126,11 +126,11 @@ discard block |
||
126 | 126 | protected function readConfig() { |
127 | 127 | $mounts = $this->readDBConfig(); |
128 | 128 | $configs = array_map([$this, 'getStorageConfigFromDBMount'], $mounts); |
129 | - $configs = array_filter($configs, function ($config) { |
|
129 | + $configs = array_filter($configs, function($config) { |
|
130 | 130 | return $config instanceof StorageConfig; |
131 | 131 | }); |
132 | 132 | |
133 | - $keys = array_map(function (StorageConfig $config) { |
|
133 | + $keys = array_map(function(StorageConfig $config) { |
|
134 | 134 | return $config->getId(); |
135 | 135 | }, $configs); |
136 | 136 | |
@@ -149,14 +149,14 @@ discard block |
||
149 | 149 | $mount = $this->dbConfig->getMountById($id); |
150 | 150 | |
151 | 151 | if (!is_array($mount)) { |
152 | - throw new NotFoundException('Storage with ID "' . $id . '" not found'); |
|
152 | + throw new NotFoundException('Storage with ID "'.$id.'" not found'); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | $config = $this->getStorageConfigFromDBMount($mount); |
156 | 156 | if ($this->isApplicable($config)) { |
157 | 157 | return $config; |
158 | 158 | } else { |
159 | - throw new NotFoundException('Storage with ID "' . $id . '" not found'); |
|
159 | + throw new NotFoundException('Storage with ID "'.$id.'" not found'); |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | |
@@ -379,13 +379,13 @@ discard block |
||
379 | 379 | $existingMount = $this->dbConfig->getMountById($id); |
380 | 380 | |
381 | 381 | if (!is_array($existingMount)) { |
382 | - throw new NotFoundException('Storage with ID "' . $id . '" not found while updating storage'); |
|
382 | + throw new NotFoundException('Storage with ID "'.$id.'" not found while updating storage'); |
|
383 | 383 | } |
384 | 384 | |
385 | 385 | $oldStorage = $this->getStorageConfigFromDBMount($existingMount); |
386 | 386 | |
387 | 387 | if ($oldStorage->getBackend() instanceof InvalidBackend) { |
388 | - throw new NotFoundException('Storage with id "' . $id . '" cannot be edited due to missing backend'); |
|
388 | + throw new NotFoundException('Storage with id "'.$id.'" cannot be edited due to missing backend'); |
|
389 | 389 | } |
390 | 390 | |
391 | 391 | $removedUsers = array_diff($oldStorage->getApplicableUsers(), $updatedStorage->getApplicableUsers()); |
@@ -462,7 +462,7 @@ discard block |
||
462 | 462 | $existingMount = $this->dbConfig->getMountById($id); |
463 | 463 | |
464 | 464 | if (!is_array($existingMount)) { |
465 | - throw new NotFoundException('Storage with ID "' . $id . '" not found'); |
|
465 | + throw new NotFoundException('Storage with ID "'.$id.'" not found'); |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | $this->dbConfig->removeMount($id); |
@@ -48,495 +48,495 @@ |
||
48 | 48 | */ |
49 | 49 | abstract class StoragesService { |
50 | 50 | |
51 | - /** @var BackendService */ |
|
52 | - protected $backendService; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var DBConfigService |
|
56 | - */ |
|
57 | - protected $dbConfig; |
|
58 | - |
|
59 | - /** |
|
60 | - * @var IUserMountCache |
|
61 | - */ |
|
62 | - protected $userMountCache; |
|
63 | - |
|
64 | - /** |
|
65 | - * @param BackendService $backendService |
|
66 | - * @param DBConfigService $dbConfigService |
|
67 | - * @param IUserMountCache $userMountCache |
|
68 | - */ |
|
69 | - public function __construct(BackendService $backendService, DBConfigService $dbConfigService, IUserMountCache $userMountCache) { |
|
70 | - $this->backendService = $backendService; |
|
71 | - $this->dbConfig = $dbConfigService; |
|
72 | - $this->userMountCache = $userMountCache; |
|
73 | - } |
|
74 | - |
|
75 | - protected function readDBConfig() { |
|
76 | - return $this->dbConfig->getAdminMounts(); |
|
77 | - } |
|
78 | - |
|
79 | - protected function getStorageConfigFromDBMount(array $mount) { |
|
80 | - $applicableUsers = array_filter($mount['applicable'], function ($applicable) { |
|
81 | - return $applicable['type'] === DBConfigService::APPLICABLE_TYPE_USER; |
|
82 | - }); |
|
83 | - $applicableUsers = array_map(function ($applicable) { |
|
84 | - return $applicable['value']; |
|
85 | - }, $applicableUsers); |
|
86 | - |
|
87 | - $applicableGroups = array_filter($mount['applicable'], function ($applicable) { |
|
88 | - return $applicable['type'] === DBConfigService::APPLICABLE_TYPE_GROUP; |
|
89 | - }); |
|
90 | - $applicableGroups = array_map(function ($applicable) { |
|
91 | - return $applicable['value']; |
|
92 | - }, $applicableGroups); |
|
93 | - |
|
94 | - try { |
|
95 | - $config = $this->createStorage( |
|
96 | - $mount['mount_point'], |
|
97 | - $mount['storage_backend'], |
|
98 | - $mount['auth_backend'], |
|
99 | - $mount['config'], |
|
100 | - $mount['options'], |
|
101 | - array_values($applicableUsers), |
|
102 | - array_values($applicableGroups), |
|
103 | - $mount['priority'] |
|
104 | - ); |
|
105 | - $config->setType($mount['type']); |
|
106 | - $config->setId((int)$mount['mount_id']); |
|
107 | - return $config; |
|
108 | - } catch (\UnexpectedValueException $e) { |
|
109 | - // don't die if a storage backend doesn't exist |
|
110 | - \OC::$server->getLogger()->logException($e, [ |
|
111 | - 'message' => 'Could not load storage.', |
|
112 | - 'level' => ILogger::ERROR, |
|
113 | - 'app' => 'files_external', |
|
114 | - ]); |
|
115 | - return null; |
|
116 | - } catch (\InvalidArgumentException $e) { |
|
117 | - \OC::$server->getLogger()->logException($e, [ |
|
118 | - 'message' => 'Could not load storage.', |
|
119 | - 'level' => ILogger::ERROR, |
|
120 | - 'app' => 'files_external', |
|
121 | - ]); |
|
122 | - return null; |
|
123 | - } |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * Read the external storages config |
|
128 | - * |
|
129 | - * @return array map of storage id to storage config |
|
130 | - */ |
|
131 | - protected function readConfig() { |
|
132 | - $mounts = $this->readDBConfig(); |
|
133 | - $configs = array_map([$this, 'getStorageConfigFromDBMount'], $mounts); |
|
134 | - $configs = array_filter($configs, function ($config) { |
|
135 | - return $config instanceof StorageConfig; |
|
136 | - }); |
|
137 | - |
|
138 | - $keys = array_map(function (StorageConfig $config) { |
|
139 | - return $config->getId(); |
|
140 | - }, $configs); |
|
141 | - |
|
142 | - return array_combine($keys, $configs); |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * Get a storage with status |
|
147 | - * |
|
148 | - * @param int $id storage id |
|
149 | - * |
|
150 | - * @return StorageConfig |
|
151 | - * @throws NotFoundException if the storage with the given id was not found |
|
152 | - */ |
|
153 | - public function getStorage($id) { |
|
154 | - $mount = $this->dbConfig->getMountById($id); |
|
155 | - |
|
156 | - if (!is_array($mount)) { |
|
157 | - throw new NotFoundException('Storage with ID "' . $id . '" not found'); |
|
158 | - } |
|
159 | - |
|
160 | - $config = $this->getStorageConfigFromDBMount($mount); |
|
161 | - if ($this->isApplicable($config)) { |
|
162 | - return $config; |
|
163 | - } else { |
|
164 | - throw new NotFoundException('Storage with ID "' . $id . '" not found'); |
|
165 | - } |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Check whether this storage service should provide access to a storage |
|
170 | - * |
|
171 | - * @param StorageConfig $config |
|
172 | - * @return bool |
|
173 | - */ |
|
174 | - abstract protected function isApplicable(StorageConfig $config); |
|
175 | - |
|
176 | - /** |
|
177 | - * Gets all storages, valid or not |
|
178 | - * |
|
179 | - * @return StorageConfig[] array of storage configs |
|
180 | - */ |
|
181 | - public function getAllStorages() { |
|
182 | - return $this->readConfig(); |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * Gets all valid storages |
|
187 | - * |
|
188 | - * @return StorageConfig[] |
|
189 | - */ |
|
190 | - public function getStorages() { |
|
191 | - return array_filter($this->getAllStorages(), [$this, 'validateStorage']); |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Validate storage |
|
196 | - * FIXME: De-duplicate with StoragesController::validate() |
|
197 | - * |
|
198 | - * @param StorageConfig $storage |
|
199 | - * @return bool |
|
200 | - */ |
|
201 | - protected function validateStorage(StorageConfig $storage) { |
|
202 | - /** @var Backend */ |
|
203 | - $backend = $storage->getBackend(); |
|
204 | - /** @var AuthMechanism */ |
|
205 | - $authMechanism = $storage->getAuthMechanism(); |
|
206 | - |
|
207 | - if (!$backend->isVisibleFor($this->getVisibilityType())) { |
|
208 | - // not permitted to use backend |
|
209 | - return false; |
|
210 | - } |
|
211 | - if (!$authMechanism->isVisibleFor($this->getVisibilityType())) { |
|
212 | - // not permitted to use auth mechanism |
|
213 | - return false; |
|
214 | - } |
|
215 | - |
|
216 | - return true; |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * Get the visibility type for this controller, used in validation |
|
221 | - * |
|
222 | - * @return string BackendService::VISIBILITY_* constants |
|
223 | - */ |
|
224 | - abstract public function getVisibilityType(); |
|
225 | - |
|
226 | - /** |
|
227 | - * @return integer |
|
228 | - */ |
|
229 | - protected function getType() { |
|
230 | - return DBConfigService::MOUNT_TYPE_ADMIN; |
|
231 | - } |
|
232 | - |
|
233 | - /** |
|
234 | - * Add new storage to the configuration |
|
235 | - * |
|
236 | - * @param StorageConfig $newStorage storage attributes |
|
237 | - * |
|
238 | - * @return StorageConfig storage config, with added id |
|
239 | - */ |
|
240 | - public function addStorage(StorageConfig $newStorage) { |
|
241 | - $allStorages = $this->readConfig(); |
|
242 | - |
|
243 | - $configId = $this->dbConfig->addMount( |
|
244 | - $newStorage->getMountPoint(), |
|
245 | - $newStorage->getBackend()->getIdentifier(), |
|
246 | - $newStorage->getAuthMechanism()->getIdentifier(), |
|
247 | - $newStorage->getPriority(), |
|
248 | - $this->getType() |
|
249 | - ); |
|
250 | - |
|
251 | - $newStorage->setId($configId); |
|
252 | - |
|
253 | - foreach ($newStorage->getApplicableUsers() as $user) { |
|
254 | - $this->dbConfig->addApplicable($configId, DBConfigService::APPLICABLE_TYPE_USER, $user); |
|
255 | - } |
|
256 | - foreach ($newStorage->getApplicableGroups() as $group) { |
|
257 | - $this->dbConfig->addApplicable($configId, DBConfigService::APPLICABLE_TYPE_GROUP, $group); |
|
258 | - } |
|
259 | - foreach ($newStorage->getBackendOptions() as $key => $value) { |
|
260 | - $this->dbConfig->setConfig($configId, $key, $value); |
|
261 | - } |
|
262 | - foreach ($newStorage->getMountOptions() as $key => $value) { |
|
263 | - $this->dbConfig->setOption($configId, $key, $value); |
|
264 | - } |
|
265 | - |
|
266 | - if (count($newStorage->getApplicableUsers()) === 0 && count($newStorage->getApplicableGroups()) === 0) { |
|
267 | - $this->dbConfig->addApplicable($configId, DBConfigService::APPLICABLE_TYPE_GLOBAL, null); |
|
268 | - } |
|
269 | - |
|
270 | - // add new storage |
|
271 | - $allStorages[$configId] = $newStorage; |
|
272 | - |
|
273 | - $this->triggerHooks($newStorage, Filesystem::signal_create_mount); |
|
274 | - |
|
275 | - $newStorage->setStatus(StorageNotAvailableException::STATUS_SUCCESS); |
|
276 | - return $newStorage; |
|
277 | - } |
|
278 | - |
|
279 | - /** |
|
280 | - * Create a storage from its parameters |
|
281 | - * |
|
282 | - * @param string $mountPoint storage mount point |
|
283 | - * @param string $backendIdentifier backend identifier |
|
284 | - * @param string $authMechanismIdentifier authentication mechanism identifier |
|
285 | - * @param array $backendOptions backend-specific options |
|
286 | - * @param array|null $mountOptions mount-specific options |
|
287 | - * @param array|null $applicableUsers users for which to mount the storage |
|
288 | - * @param array|null $applicableGroups groups for which to mount the storage |
|
289 | - * @param int|null $priority priority |
|
290 | - * |
|
291 | - * @return StorageConfig |
|
292 | - */ |
|
293 | - public function createStorage( |
|
294 | - $mountPoint, |
|
295 | - $backendIdentifier, |
|
296 | - $authMechanismIdentifier, |
|
297 | - $backendOptions, |
|
298 | - $mountOptions = null, |
|
299 | - $applicableUsers = null, |
|
300 | - $applicableGroups = null, |
|
301 | - $priority = null |
|
302 | - ) { |
|
303 | - $backend = $this->backendService->getBackend($backendIdentifier); |
|
304 | - if (!$backend) { |
|
305 | - $backend = new InvalidBackend($backendIdentifier); |
|
306 | - } |
|
307 | - $authMechanism = $this->backendService->getAuthMechanism($authMechanismIdentifier); |
|
308 | - if (!$authMechanism) { |
|
309 | - $authMechanism = new InvalidAuth($authMechanismIdentifier); |
|
310 | - } |
|
311 | - $newStorage = new StorageConfig(); |
|
312 | - $newStorage->setMountPoint($mountPoint); |
|
313 | - $newStorage->setBackend($backend); |
|
314 | - $newStorage->setAuthMechanism($authMechanism); |
|
315 | - $newStorage->setBackendOptions($backendOptions); |
|
316 | - if (isset($mountOptions)) { |
|
317 | - $newStorage->setMountOptions($mountOptions); |
|
318 | - } |
|
319 | - if (isset($applicableUsers)) { |
|
320 | - $newStorage->setApplicableUsers($applicableUsers); |
|
321 | - } |
|
322 | - if (isset($applicableGroups)) { |
|
323 | - $newStorage->setApplicableGroups($applicableGroups); |
|
324 | - } |
|
325 | - if (isset($priority)) { |
|
326 | - $newStorage->setPriority($priority); |
|
327 | - } |
|
328 | - |
|
329 | - return $newStorage; |
|
330 | - } |
|
331 | - |
|
332 | - /** |
|
333 | - * Triggers the given hook signal for all the applicables given |
|
334 | - * |
|
335 | - * @param string $signal signal |
|
336 | - * @param string $mountPoint hook mount pount param |
|
337 | - * @param string $mountType hook mount type param |
|
338 | - * @param array $applicableArray array of applicable users/groups for which to trigger the hook |
|
339 | - */ |
|
340 | - protected function triggerApplicableHooks($signal, $mountPoint, $mountType, $applicableArray) { |
|
341 | - foreach ($applicableArray as $applicable) { |
|
342 | - \OCP\Util::emitHook( |
|
343 | - Filesystem::CLASSNAME, |
|
344 | - $signal, |
|
345 | - [ |
|
346 | - Filesystem::signal_param_path => $mountPoint, |
|
347 | - Filesystem::signal_param_mount_type => $mountType, |
|
348 | - Filesystem::signal_param_users => $applicable, |
|
349 | - ] |
|
350 | - ); |
|
351 | - } |
|
352 | - } |
|
353 | - |
|
354 | - /** |
|
355 | - * Triggers $signal for all applicable users of the given |
|
356 | - * storage |
|
357 | - * |
|
358 | - * @param StorageConfig $storage storage data |
|
359 | - * @param string $signal signal to trigger |
|
360 | - */ |
|
361 | - abstract protected function triggerHooks(StorageConfig $storage, $signal); |
|
362 | - |
|
363 | - /** |
|
364 | - * Triggers signal_create_mount or signal_delete_mount to |
|
365 | - * accommodate for additions/deletions in applicableUsers |
|
366 | - * and applicableGroups fields. |
|
367 | - * |
|
368 | - * @param StorageConfig $oldStorage old storage data |
|
369 | - * @param StorageConfig $newStorage new storage data |
|
370 | - */ |
|
371 | - abstract protected function triggerChangeHooks(StorageConfig $oldStorage, StorageConfig $newStorage); |
|
372 | - |
|
373 | - /** |
|
374 | - * Update storage to the configuration |
|
375 | - * |
|
376 | - * @param StorageConfig $updatedStorage storage attributes |
|
377 | - * |
|
378 | - * @return StorageConfig storage config |
|
379 | - * @throws NotFoundException if the given storage does not exist in the config |
|
380 | - */ |
|
381 | - public function updateStorage(StorageConfig $updatedStorage) { |
|
382 | - $id = $updatedStorage->getId(); |
|
383 | - |
|
384 | - $existingMount = $this->dbConfig->getMountById($id); |
|
385 | - |
|
386 | - if (!is_array($existingMount)) { |
|
387 | - throw new NotFoundException('Storage with ID "' . $id . '" not found while updating storage'); |
|
388 | - } |
|
389 | - |
|
390 | - $oldStorage = $this->getStorageConfigFromDBMount($existingMount); |
|
391 | - |
|
392 | - if ($oldStorage->getBackend() instanceof InvalidBackend) { |
|
393 | - throw new NotFoundException('Storage with id "' . $id . '" cannot be edited due to missing backend'); |
|
394 | - } |
|
395 | - |
|
396 | - $removedUsers = array_diff($oldStorage->getApplicableUsers(), $updatedStorage->getApplicableUsers()); |
|
397 | - $removedGroups = array_diff($oldStorage->getApplicableGroups(), $updatedStorage->getApplicableGroups()); |
|
398 | - $addedUsers = array_diff($updatedStorage->getApplicableUsers(), $oldStorage->getApplicableUsers()); |
|
399 | - $addedGroups = array_diff($updatedStorage->getApplicableGroups(), $oldStorage->getApplicableGroups()); |
|
400 | - |
|
401 | - $oldUserCount = count($oldStorage->getApplicableUsers()); |
|
402 | - $oldGroupCount = count($oldStorage->getApplicableGroups()); |
|
403 | - $newUserCount = count($updatedStorage->getApplicableUsers()); |
|
404 | - $newGroupCount = count($updatedStorage->getApplicableGroups()); |
|
405 | - $wasGlobal = ($oldUserCount + $oldGroupCount) === 0; |
|
406 | - $isGlobal = ($newUserCount + $newGroupCount) === 0; |
|
407 | - |
|
408 | - foreach ($removedUsers as $user) { |
|
409 | - $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, $user); |
|
410 | - } |
|
411 | - foreach ($removedGroups as $group) { |
|
412 | - $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_GROUP, $group); |
|
413 | - } |
|
414 | - foreach ($addedUsers as $user) { |
|
415 | - $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, $user); |
|
416 | - } |
|
417 | - foreach ($addedGroups as $group) { |
|
418 | - $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GROUP, $group); |
|
419 | - } |
|
420 | - |
|
421 | - if ($wasGlobal && !$isGlobal) { |
|
422 | - $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null); |
|
423 | - } elseif (!$wasGlobal && $isGlobal) { |
|
424 | - $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null); |
|
425 | - } |
|
426 | - |
|
427 | - $changedConfig = array_diff_assoc($updatedStorage->getBackendOptions(), $oldStorage->getBackendOptions()); |
|
428 | - $changedOptions = array_diff_assoc($updatedStorage->getMountOptions(), $oldStorage->getMountOptions()); |
|
429 | - |
|
430 | - foreach ($changedConfig as $key => $value) { |
|
431 | - if ($value !== DefinitionParameter::UNMODIFIED_PLACEHOLDER) { |
|
432 | - $this->dbConfig->setConfig($id, $key, $value); |
|
433 | - } |
|
434 | - } |
|
435 | - foreach ($changedOptions as $key => $value) { |
|
436 | - $this->dbConfig->setOption($id, $key, $value); |
|
437 | - } |
|
438 | - |
|
439 | - if ($updatedStorage->getMountPoint() !== $oldStorage->getMountPoint()) { |
|
440 | - $this->dbConfig->setMountPoint($id, $updatedStorage->getMountPoint()); |
|
441 | - } |
|
442 | - |
|
443 | - if ($updatedStorage->getAuthMechanism()->getIdentifier() !== $oldStorage->getAuthMechanism()->getIdentifier()) { |
|
444 | - $this->dbConfig->setAuthBackend($id, $updatedStorage->getAuthMechanism()->getIdentifier()); |
|
445 | - } |
|
446 | - |
|
447 | - $this->triggerChangeHooks($oldStorage, $updatedStorage); |
|
448 | - |
|
449 | - if (($wasGlobal && !$isGlobal) || count($removedGroups) > 0) { // to expensive to properly handle these on the fly |
|
450 | - $this->userMountCache->remoteStorageMounts($this->getStorageId($updatedStorage)); |
|
451 | - } else { |
|
452 | - $storageId = $this->getStorageId($updatedStorage); |
|
453 | - foreach ($removedUsers as $userId) { |
|
454 | - $this->userMountCache->removeUserStorageMount($storageId, $userId); |
|
455 | - } |
|
456 | - } |
|
457 | - |
|
458 | - return $this->getStorage($id); |
|
459 | - } |
|
460 | - |
|
461 | - /** |
|
462 | - * Delete the storage with the given id. |
|
463 | - * |
|
464 | - * @param int $id storage id |
|
465 | - * |
|
466 | - * @throws NotFoundException if no storage was found with the given id |
|
467 | - */ |
|
468 | - public function removeStorage($id) { |
|
469 | - $existingMount = $this->dbConfig->getMountById($id); |
|
470 | - |
|
471 | - if (!is_array($existingMount)) { |
|
472 | - throw new NotFoundException('Storage with ID "' . $id . '" not found'); |
|
473 | - } |
|
474 | - |
|
475 | - $this->dbConfig->removeMount($id); |
|
476 | - |
|
477 | - $deletedStorage = $this->getStorageConfigFromDBMount($existingMount); |
|
478 | - $this->triggerHooks($deletedStorage, Filesystem::signal_delete_mount); |
|
479 | - |
|
480 | - // delete oc_storages entries and oc_filecache |
|
481 | - try { |
|
482 | - $rustyStorageId = $this->getRustyStorageIdFromConfig($deletedStorage); |
|
483 | - \OC\Files\Cache\Storage::remove($rustyStorageId); |
|
484 | - } catch (\Exception $e) { |
|
485 | - // can happen either for invalid configs where the storage could not |
|
486 | - // be instantiated or whenever $user vars where used, in which case |
|
487 | - // the storage id could not be computed |
|
488 | - \OC::$server->getLogger()->logException($e, [ |
|
489 | - 'level' => ILogger::ERROR, |
|
490 | - 'app' => 'files_external', |
|
491 | - ]); |
|
492 | - } |
|
493 | - } |
|
494 | - |
|
495 | - /** |
|
496 | - * Returns the rusty storage id from oc_storages from the given storage config. |
|
497 | - * |
|
498 | - * @param StorageConfig $storageConfig |
|
499 | - * @return string rusty storage id |
|
500 | - */ |
|
501 | - private function getRustyStorageIdFromConfig(StorageConfig $storageConfig) { |
|
502 | - // if any of the storage options contains $user, it is not possible |
|
503 | - // to compute the possible storage id as we don't know which users |
|
504 | - // mounted it already (and we certainly don't want to iterate over ALL users) |
|
505 | - foreach ($storageConfig->getBackendOptions() as $value) { |
|
506 | - if (strpos($value, '$user') !== false) { |
|
507 | - throw new \Exception('Cannot compute storage id for deletion due to $user vars in the configuration'); |
|
508 | - } |
|
509 | - } |
|
510 | - |
|
511 | - // note: similar to ConfigAdapter->prepateStorageConfig() |
|
512 | - $storageConfig->getAuthMechanism()->manipulateStorageConfig($storageConfig); |
|
513 | - $storageConfig->getBackend()->manipulateStorageConfig($storageConfig); |
|
514 | - |
|
515 | - $class = $storageConfig->getBackend()->getStorageClass(); |
|
516 | - $storageImpl = new $class($storageConfig->getBackendOptions()); |
|
517 | - |
|
518 | - return $storageImpl->getId(); |
|
519 | - } |
|
520 | - |
|
521 | - /** |
|
522 | - * Construct the storage implementation |
|
523 | - * |
|
524 | - * @param StorageConfig $storageConfig |
|
525 | - * @return int |
|
526 | - */ |
|
527 | - private function getStorageId(StorageConfig $storageConfig) { |
|
528 | - try { |
|
529 | - $class = $storageConfig->getBackend()->getStorageClass(); |
|
530 | - /** @var \OC\Files\Storage\Storage $storage */ |
|
531 | - $storage = new $class($storageConfig->getBackendOptions()); |
|
532 | - |
|
533 | - // auth mechanism should fire first |
|
534 | - $storage = $storageConfig->getBackend()->wrapStorage($storage); |
|
535 | - $storage = $storageConfig->getAuthMechanism()->wrapStorage($storage); |
|
536 | - |
|
537 | - return $storage->getStorageCache()->getNumericId(); |
|
538 | - } catch (\Exception $e) { |
|
539 | - return -1; |
|
540 | - } |
|
541 | - } |
|
51 | + /** @var BackendService */ |
|
52 | + protected $backendService; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var DBConfigService |
|
56 | + */ |
|
57 | + protected $dbConfig; |
|
58 | + |
|
59 | + /** |
|
60 | + * @var IUserMountCache |
|
61 | + */ |
|
62 | + protected $userMountCache; |
|
63 | + |
|
64 | + /** |
|
65 | + * @param BackendService $backendService |
|
66 | + * @param DBConfigService $dbConfigService |
|
67 | + * @param IUserMountCache $userMountCache |
|
68 | + */ |
|
69 | + public function __construct(BackendService $backendService, DBConfigService $dbConfigService, IUserMountCache $userMountCache) { |
|
70 | + $this->backendService = $backendService; |
|
71 | + $this->dbConfig = $dbConfigService; |
|
72 | + $this->userMountCache = $userMountCache; |
|
73 | + } |
|
74 | + |
|
75 | + protected function readDBConfig() { |
|
76 | + return $this->dbConfig->getAdminMounts(); |
|
77 | + } |
|
78 | + |
|
79 | + protected function getStorageConfigFromDBMount(array $mount) { |
|
80 | + $applicableUsers = array_filter($mount['applicable'], function ($applicable) { |
|
81 | + return $applicable['type'] === DBConfigService::APPLICABLE_TYPE_USER; |
|
82 | + }); |
|
83 | + $applicableUsers = array_map(function ($applicable) { |
|
84 | + return $applicable['value']; |
|
85 | + }, $applicableUsers); |
|
86 | + |
|
87 | + $applicableGroups = array_filter($mount['applicable'], function ($applicable) { |
|
88 | + return $applicable['type'] === DBConfigService::APPLICABLE_TYPE_GROUP; |
|
89 | + }); |
|
90 | + $applicableGroups = array_map(function ($applicable) { |
|
91 | + return $applicable['value']; |
|
92 | + }, $applicableGroups); |
|
93 | + |
|
94 | + try { |
|
95 | + $config = $this->createStorage( |
|
96 | + $mount['mount_point'], |
|
97 | + $mount['storage_backend'], |
|
98 | + $mount['auth_backend'], |
|
99 | + $mount['config'], |
|
100 | + $mount['options'], |
|
101 | + array_values($applicableUsers), |
|
102 | + array_values($applicableGroups), |
|
103 | + $mount['priority'] |
|
104 | + ); |
|
105 | + $config->setType($mount['type']); |
|
106 | + $config->setId((int)$mount['mount_id']); |
|
107 | + return $config; |
|
108 | + } catch (\UnexpectedValueException $e) { |
|
109 | + // don't die if a storage backend doesn't exist |
|
110 | + \OC::$server->getLogger()->logException($e, [ |
|
111 | + 'message' => 'Could not load storage.', |
|
112 | + 'level' => ILogger::ERROR, |
|
113 | + 'app' => 'files_external', |
|
114 | + ]); |
|
115 | + return null; |
|
116 | + } catch (\InvalidArgumentException $e) { |
|
117 | + \OC::$server->getLogger()->logException($e, [ |
|
118 | + 'message' => 'Could not load storage.', |
|
119 | + 'level' => ILogger::ERROR, |
|
120 | + 'app' => 'files_external', |
|
121 | + ]); |
|
122 | + return null; |
|
123 | + } |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * Read the external storages config |
|
128 | + * |
|
129 | + * @return array map of storage id to storage config |
|
130 | + */ |
|
131 | + protected function readConfig() { |
|
132 | + $mounts = $this->readDBConfig(); |
|
133 | + $configs = array_map([$this, 'getStorageConfigFromDBMount'], $mounts); |
|
134 | + $configs = array_filter($configs, function ($config) { |
|
135 | + return $config instanceof StorageConfig; |
|
136 | + }); |
|
137 | + |
|
138 | + $keys = array_map(function (StorageConfig $config) { |
|
139 | + return $config->getId(); |
|
140 | + }, $configs); |
|
141 | + |
|
142 | + return array_combine($keys, $configs); |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * Get a storage with status |
|
147 | + * |
|
148 | + * @param int $id storage id |
|
149 | + * |
|
150 | + * @return StorageConfig |
|
151 | + * @throws NotFoundException if the storage with the given id was not found |
|
152 | + */ |
|
153 | + public function getStorage($id) { |
|
154 | + $mount = $this->dbConfig->getMountById($id); |
|
155 | + |
|
156 | + if (!is_array($mount)) { |
|
157 | + throw new NotFoundException('Storage with ID "' . $id . '" not found'); |
|
158 | + } |
|
159 | + |
|
160 | + $config = $this->getStorageConfigFromDBMount($mount); |
|
161 | + if ($this->isApplicable($config)) { |
|
162 | + return $config; |
|
163 | + } else { |
|
164 | + throw new NotFoundException('Storage with ID "' . $id . '" not found'); |
|
165 | + } |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Check whether this storage service should provide access to a storage |
|
170 | + * |
|
171 | + * @param StorageConfig $config |
|
172 | + * @return bool |
|
173 | + */ |
|
174 | + abstract protected function isApplicable(StorageConfig $config); |
|
175 | + |
|
176 | + /** |
|
177 | + * Gets all storages, valid or not |
|
178 | + * |
|
179 | + * @return StorageConfig[] array of storage configs |
|
180 | + */ |
|
181 | + public function getAllStorages() { |
|
182 | + return $this->readConfig(); |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * Gets all valid storages |
|
187 | + * |
|
188 | + * @return StorageConfig[] |
|
189 | + */ |
|
190 | + public function getStorages() { |
|
191 | + return array_filter($this->getAllStorages(), [$this, 'validateStorage']); |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Validate storage |
|
196 | + * FIXME: De-duplicate with StoragesController::validate() |
|
197 | + * |
|
198 | + * @param StorageConfig $storage |
|
199 | + * @return bool |
|
200 | + */ |
|
201 | + protected function validateStorage(StorageConfig $storage) { |
|
202 | + /** @var Backend */ |
|
203 | + $backend = $storage->getBackend(); |
|
204 | + /** @var AuthMechanism */ |
|
205 | + $authMechanism = $storage->getAuthMechanism(); |
|
206 | + |
|
207 | + if (!$backend->isVisibleFor($this->getVisibilityType())) { |
|
208 | + // not permitted to use backend |
|
209 | + return false; |
|
210 | + } |
|
211 | + if (!$authMechanism->isVisibleFor($this->getVisibilityType())) { |
|
212 | + // not permitted to use auth mechanism |
|
213 | + return false; |
|
214 | + } |
|
215 | + |
|
216 | + return true; |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * Get the visibility type for this controller, used in validation |
|
221 | + * |
|
222 | + * @return string BackendService::VISIBILITY_* constants |
|
223 | + */ |
|
224 | + abstract public function getVisibilityType(); |
|
225 | + |
|
226 | + /** |
|
227 | + * @return integer |
|
228 | + */ |
|
229 | + protected function getType() { |
|
230 | + return DBConfigService::MOUNT_TYPE_ADMIN; |
|
231 | + } |
|
232 | + |
|
233 | + /** |
|
234 | + * Add new storage to the configuration |
|
235 | + * |
|
236 | + * @param StorageConfig $newStorage storage attributes |
|
237 | + * |
|
238 | + * @return StorageConfig storage config, with added id |
|
239 | + */ |
|
240 | + public function addStorage(StorageConfig $newStorage) { |
|
241 | + $allStorages = $this->readConfig(); |
|
242 | + |
|
243 | + $configId = $this->dbConfig->addMount( |
|
244 | + $newStorage->getMountPoint(), |
|
245 | + $newStorage->getBackend()->getIdentifier(), |
|
246 | + $newStorage->getAuthMechanism()->getIdentifier(), |
|
247 | + $newStorage->getPriority(), |
|
248 | + $this->getType() |
|
249 | + ); |
|
250 | + |
|
251 | + $newStorage->setId($configId); |
|
252 | + |
|
253 | + foreach ($newStorage->getApplicableUsers() as $user) { |
|
254 | + $this->dbConfig->addApplicable($configId, DBConfigService::APPLICABLE_TYPE_USER, $user); |
|
255 | + } |
|
256 | + foreach ($newStorage->getApplicableGroups() as $group) { |
|
257 | + $this->dbConfig->addApplicable($configId, DBConfigService::APPLICABLE_TYPE_GROUP, $group); |
|
258 | + } |
|
259 | + foreach ($newStorage->getBackendOptions() as $key => $value) { |
|
260 | + $this->dbConfig->setConfig($configId, $key, $value); |
|
261 | + } |
|
262 | + foreach ($newStorage->getMountOptions() as $key => $value) { |
|
263 | + $this->dbConfig->setOption($configId, $key, $value); |
|
264 | + } |
|
265 | + |
|
266 | + if (count($newStorage->getApplicableUsers()) === 0 && count($newStorage->getApplicableGroups()) === 0) { |
|
267 | + $this->dbConfig->addApplicable($configId, DBConfigService::APPLICABLE_TYPE_GLOBAL, null); |
|
268 | + } |
|
269 | + |
|
270 | + // add new storage |
|
271 | + $allStorages[$configId] = $newStorage; |
|
272 | + |
|
273 | + $this->triggerHooks($newStorage, Filesystem::signal_create_mount); |
|
274 | + |
|
275 | + $newStorage->setStatus(StorageNotAvailableException::STATUS_SUCCESS); |
|
276 | + return $newStorage; |
|
277 | + } |
|
278 | + |
|
279 | + /** |
|
280 | + * Create a storage from its parameters |
|
281 | + * |
|
282 | + * @param string $mountPoint storage mount point |
|
283 | + * @param string $backendIdentifier backend identifier |
|
284 | + * @param string $authMechanismIdentifier authentication mechanism identifier |
|
285 | + * @param array $backendOptions backend-specific options |
|
286 | + * @param array|null $mountOptions mount-specific options |
|
287 | + * @param array|null $applicableUsers users for which to mount the storage |
|
288 | + * @param array|null $applicableGroups groups for which to mount the storage |
|
289 | + * @param int|null $priority priority |
|
290 | + * |
|
291 | + * @return StorageConfig |
|
292 | + */ |
|
293 | + public function createStorage( |
|
294 | + $mountPoint, |
|
295 | + $backendIdentifier, |
|
296 | + $authMechanismIdentifier, |
|
297 | + $backendOptions, |
|
298 | + $mountOptions = null, |
|
299 | + $applicableUsers = null, |
|
300 | + $applicableGroups = null, |
|
301 | + $priority = null |
|
302 | + ) { |
|
303 | + $backend = $this->backendService->getBackend($backendIdentifier); |
|
304 | + if (!$backend) { |
|
305 | + $backend = new InvalidBackend($backendIdentifier); |
|
306 | + } |
|
307 | + $authMechanism = $this->backendService->getAuthMechanism($authMechanismIdentifier); |
|
308 | + if (!$authMechanism) { |
|
309 | + $authMechanism = new InvalidAuth($authMechanismIdentifier); |
|
310 | + } |
|
311 | + $newStorage = new StorageConfig(); |
|
312 | + $newStorage->setMountPoint($mountPoint); |
|
313 | + $newStorage->setBackend($backend); |
|
314 | + $newStorage->setAuthMechanism($authMechanism); |
|
315 | + $newStorage->setBackendOptions($backendOptions); |
|
316 | + if (isset($mountOptions)) { |
|
317 | + $newStorage->setMountOptions($mountOptions); |
|
318 | + } |
|
319 | + if (isset($applicableUsers)) { |
|
320 | + $newStorage->setApplicableUsers($applicableUsers); |
|
321 | + } |
|
322 | + if (isset($applicableGroups)) { |
|
323 | + $newStorage->setApplicableGroups($applicableGroups); |
|
324 | + } |
|
325 | + if (isset($priority)) { |
|
326 | + $newStorage->setPriority($priority); |
|
327 | + } |
|
328 | + |
|
329 | + return $newStorage; |
|
330 | + } |
|
331 | + |
|
332 | + /** |
|
333 | + * Triggers the given hook signal for all the applicables given |
|
334 | + * |
|
335 | + * @param string $signal signal |
|
336 | + * @param string $mountPoint hook mount pount param |
|
337 | + * @param string $mountType hook mount type param |
|
338 | + * @param array $applicableArray array of applicable users/groups for which to trigger the hook |
|
339 | + */ |
|
340 | + protected function triggerApplicableHooks($signal, $mountPoint, $mountType, $applicableArray) { |
|
341 | + foreach ($applicableArray as $applicable) { |
|
342 | + \OCP\Util::emitHook( |
|
343 | + Filesystem::CLASSNAME, |
|
344 | + $signal, |
|
345 | + [ |
|
346 | + Filesystem::signal_param_path => $mountPoint, |
|
347 | + Filesystem::signal_param_mount_type => $mountType, |
|
348 | + Filesystem::signal_param_users => $applicable, |
|
349 | + ] |
|
350 | + ); |
|
351 | + } |
|
352 | + } |
|
353 | + |
|
354 | + /** |
|
355 | + * Triggers $signal for all applicable users of the given |
|
356 | + * storage |
|
357 | + * |
|
358 | + * @param StorageConfig $storage storage data |
|
359 | + * @param string $signal signal to trigger |
|
360 | + */ |
|
361 | + abstract protected function triggerHooks(StorageConfig $storage, $signal); |
|
362 | + |
|
363 | + /** |
|
364 | + * Triggers signal_create_mount or signal_delete_mount to |
|
365 | + * accommodate for additions/deletions in applicableUsers |
|
366 | + * and applicableGroups fields. |
|
367 | + * |
|
368 | + * @param StorageConfig $oldStorage old storage data |
|
369 | + * @param StorageConfig $newStorage new storage data |
|
370 | + */ |
|
371 | + abstract protected function triggerChangeHooks(StorageConfig $oldStorage, StorageConfig $newStorage); |
|
372 | + |
|
373 | + /** |
|
374 | + * Update storage to the configuration |
|
375 | + * |
|
376 | + * @param StorageConfig $updatedStorage storage attributes |
|
377 | + * |
|
378 | + * @return StorageConfig storage config |
|
379 | + * @throws NotFoundException if the given storage does not exist in the config |
|
380 | + */ |
|
381 | + public function updateStorage(StorageConfig $updatedStorage) { |
|
382 | + $id = $updatedStorage->getId(); |
|
383 | + |
|
384 | + $existingMount = $this->dbConfig->getMountById($id); |
|
385 | + |
|
386 | + if (!is_array($existingMount)) { |
|
387 | + throw new NotFoundException('Storage with ID "' . $id . '" not found while updating storage'); |
|
388 | + } |
|
389 | + |
|
390 | + $oldStorage = $this->getStorageConfigFromDBMount($existingMount); |
|
391 | + |
|
392 | + if ($oldStorage->getBackend() instanceof InvalidBackend) { |
|
393 | + throw new NotFoundException('Storage with id "' . $id . '" cannot be edited due to missing backend'); |
|
394 | + } |
|
395 | + |
|
396 | + $removedUsers = array_diff($oldStorage->getApplicableUsers(), $updatedStorage->getApplicableUsers()); |
|
397 | + $removedGroups = array_diff($oldStorage->getApplicableGroups(), $updatedStorage->getApplicableGroups()); |
|
398 | + $addedUsers = array_diff($updatedStorage->getApplicableUsers(), $oldStorage->getApplicableUsers()); |
|
399 | + $addedGroups = array_diff($updatedStorage->getApplicableGroups(), $oldStorage->getApplicableGroups()); |
|
400 | + |
|
401 | + $oldUserCount = count($oldStorage->getApplicableUsers()); |
|
402 | + $oldGroupCount = count($oldStorage->getApplicableGroups()); |
|
403 | + $newUserCount = count($updatedStorage->getApplicableUsers()); |
|
404 | + $newGroupCount = count($updatedStorage->getApplicableGroups()); |
|
405 | + $wasGlobal = ($oldUserCount + $oldGroupCount) === 0; |
|
406 | + $isGlobal = ($newUserCount + $newGroupCount) === 0; |
|
407 | + |
|
408 | + foreach ($removedUsers as $user) { |
|
409 | + $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, $user); |
|
410 | + } |
|
411 | + foreach ($removedGroups as $group) { |
|
412 | + $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_GROUP, $group); |
|
413 | + } |
|
414 | + foreach ($addedUsers as $user) { |
|
415 | + $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, $user); |
|
416 | + } |
|
417 | + foreach ($addedGroups as $group) { |
|
418 | + $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GROUP, $group); |
|
419 | + } |
|
420 | + |
|
421 | + if ($wasGlobal && !$isGlobal) { |
|
422 | + $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null); |
|
423 | + } elseif (!$wasGlobal && $isGlobal) { |
|
424 | + $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null); |
|
425 | + } |
|
426 | + |
|
427 | + $changedConfig = array_diff_assoc($updatedStorage->getBackendOptions(), $oldStorage->getBackendOptions()); |
|
428 | + $changedOptions = array_diff_assoc($updatedStorage->getMountOptions(), $oldStorage->getMountOptions()); |
|
429 | + |
|
430 | + foreach ($changedConfig as $key => $value) { |
|
431 | + if ($value !== DefinitionParameter::UNMODIFIED_PLACEHOLDER) { |
|
432 | + $this->dbConfig->setConfig($id, $key, $value); |
|
433 | + } |
|
434 | + } |
|
435 | + foreach ($changedOptions as $key => $value) { |
|
436 | + $this->dbConfig->setOption($id, $key, $value); |
|
437 | + } |
|
438 | + |
|
439 | + if ($updatedStorage->getMountPoint() !== $oldStorage->getMountPoint()) { |
|
440 | + $this->dbConfig->setMountPoint($id, $updatedStorage->getMountPoint()); |
|
441 | + } |
|
442 | + |
|
443 | + if ($updatedStorage->getAuthMechanism()->getIdentifier() !== $oldStorage->getAuthMechanism()->getIdentifier()) { |
|
444 | + $this->dbConfig->setAuthBackend($id, $updatedStorage->getAuthMechanism()->getIdentifier()); |
|
445 | + } |
|
446 | + |
|
447 | + $this->triggerChangeHooks($oldStorage, $updatedStorage); |
|
448 | + |
|
449 | + if (($wasGlobal && !$isGlobal) || count($removedGroups) > 0) { // to expensive to properly handle these on the fly |
|
450 | + $this->userMountCache->remoteStorageMounts($this->getStorageId($updatedStorage)); |
|
451 | + } else { |
|
452 | + $storageId = $this->getStorageId($updatedStorage); |
|
453 | + foreach ($removedUsers as $userId) { |
|
454 | + $this->userMountCache->removeUserStorageMount($storageId, $userId); |
|
455 | + } |
|
456 | + } |
|
457 | + |
|
458 | + return $this->getStorage($id); |
|
459 | + } |
|
460 | + |
|
461 | + /** |
|
462 | + * Delete the storage with the given id. |
|
463 | + * |
|
464 | + * @param int $id storage id |
|
465 | + * |
|
466 | + * @throws NotFoundException if no storage was found with the given id |
|
467 | + */ |
|
468 | + public function removeStorage($id) { |
|
469 | + $existingMount = $this->dbConfig->getMountById($id); |
|
470 | + |
|
471 | + if (!is_array($existingMount)) { |
|
472 | + throw new NotFoundException('Storage with ID "' . $id . '" not found'); |
|
473 | + } |
|
474 | + |
|
475 | + $this->dbConfig->removeMount($id); |
|
476 | + |
|
477 | + $deletedStorage = $this->getStorageConfigFromDBMount($existingMount); |
|
478 | + $this->triggerHooks($deletedStorage, Filesystem::signal_delete_mount); |
|
479 | + |
|
480 | + // delete oc_storages entries and oc_filecache |
|
481 | + try { |
|
482 | + $rustyStorageId = $this->getRustyStorageIdFromConfig($deletedStorage); |
|
483 | + \OC\Files\Cache\Storage::remove($rustyStorageId); |
|
484 | + } catch (\Exception $e) { |
|
485 | + // can happen either for invalid configs where the storage could not |
|
486 | + // be instantiated or whenever $user vars where used, in which case |
|
487 | + // the storage id could not be computed |
|
488 | + \OC::$server->getLogger()->logException($e, [ |
|
489 | + 'level' => ILogger::ERROR, |
|
490 | + 'app' => 'files_external', |
|
491 | + ]); |
|
492 | + } |
|
493 | + } |
|
494 | + |
|
495 | + /** |
|
496 | + * Returns the rusty storage id from oc_storages from the given storage config. |
|
497 | + * |
|
498 | + * @param StorageConfig $storageConfig |
|
499 | + * @return string rusty storage id |
|
500 | + */ |
|
501 | + private function getRustyStorageIdFromConfig(StorageConfig $storageConfig) { |
|
502 | + // if any of the storage options contains $user, it is not possible |
|
503 | + // to compute the possible storage id as we don't know which users |
|
504 | + // mounted it already (and we certainly don't want to iterate over ALL users) |
|
505 | + foreach ($storageConfig->getBackendOptions() as $value) { |
|
506 | + if (strpos($value, '$user') !== false) { |
|
507 | + throw new \Exception('Cannot compute storage id for deletion due to $user vars in the configuration'); |
|
508 | + } |
|
509 | + } |
|
510 | + |
|
511 | + // note: similar to ConfigAdapter->prepateStorageConfig() |
|
512 | + $storageConfig->getAuthMechanism()->manipulateStorageConfig($storageConfig); |
|
513 | + $storageConfig->getBackend()->manipulateStorageConfig($storageConfig); |
|
514 | + |
|
515 | + $class = $storageConfig->getBackend()->getStorageClass(); |
|
516 | + $storageImpl = new $class($storageConfig->getBackendOptions()); |
|
517 | + |
|
518 | + return $storageImpl->getId(); |
|
519 | + } |
|
520 | + |
|
521 | + /** |
|
522 | + * Construct the storage implementation |
|
523 | + * |
|
524 | + * @param StorageConfig $storageConfig |
|
525 | + * @return int |
|
526 | + */ |
|
527 | + private function getStorageId(StorageConfig $storageConfig) { |
|
528 | + try { |
|
529 | + $class = $storageConfig->getBackend()->getStorageClass(); |
|
530 | + /** @var \OC\Files\Storage\Storage $storage */ |
|
531 | + $storage = new $class($storageConfig->getBackendOptions()); |
|
532 | + |
|
533 | + // auth mechanism should fire first |
|
534 | + $storage = $storageConfig->getBackend()->wrapStorage($storage); |
|
535 | + $storage = $storageConfig->getAuthMechanism()->wrapStorage($storage); |
|
536 | + |
|
537 | + return $storage->getStorageCache()->getNumericId(); |
|
538 | + } catch (\Exception $e) { |
|
539 | + return -1; |
|
540 | + } |
|
541 | + } |
|
542 | 542 | } |
@@ -31,41 +31,41 @@ |
||
31 | 31 | * @since 7.0.0 |
32 | 32 | */ |
33 | 33 | interface IAppConfig { |
34 | - /** |
|
35 | - * check if a key is set in the appconfig |
|
36 | - * @param string $app |
|
37 | - * @param string $key |
|
38 | - * @return bool |
|
39 | - * @since 7.0.0 |
|
40 | - */ |
|
41 | - public function hasKey($app, $key); |
|
34 | + /** |
|
35 | + * check if a key is set in the appconfig |
|
36 | + * @param string $app |
|
37 | + * @param string $key |
|
38 | + * @return bool |
|
39 | + * @since 7.0.0 |
|
40 | + */ |
|
41 | + public function hasKey($app, $key); |
|
42 | 42 | |
43 | - /** |
|
44 | - * get multiply values, either the app or key can be used as wildcard by setting it to false |
|
45 | - * |
|
46 | - * @param string|false $key |
|
47 | - * @param string|false $app |
|
48 | - * @return array|false |
|
49 | - * @since 7.0.0 |
|
50 | - */ |
|
51 | - public function getValues($app, $key); |
|
43 | + /** |
|
44 | + * get multiply values, either the app or key can be used as wildcard by setting it to false |
|
45 | + * |
|
46 | + * @param string|false $key |
|
47 | + * @param string|false $app |
|
48 | + * @return array|false |
|
49 | + * @since 7.0.0 |
|
50 | + */ |
|
51 | + public function getValues($app, $key); |
|
52 | 52 | |
53 | - /** |
|
54 | - * get all values of the app or and filters out sensitive data |
|
55 | - * |
|
56 | - * @param string $app |
|
57 | - * @return array |
|
58 | - * @since 12.0.0 |
|
59 | - */ |
|
60 | - public function getFilteredValues($app); |
|
53 | + /** |
|
54 | + * get all values of the app or and filters out sensitive data |
|
55 | + * |
|
56 | + * @param string $app |
|
57 | + * @return array |
|
58 | + * @since 12.0.0 |
|
59 | + */ |
|
60 | + public function getFilteredValues($app); |
|
61 | 61 | |
62 | - /** |
|
63 | - * Get all apps using the config |
|
64 | - * @return array an array of app ids |
|
65 | - * |
|
66 | - * This function returns a list of all apps that have at least one |
|
67 | - * entry in the appconfig table. |
|
68 | - * @since 7.0.0 |
|
69 | - */ |
|
70 | - public function getApps(); |
|
62 | + /** |
|
63 | + * Get all apps using the config |
|
64 | + * @return array an array of app ids |
|
65 | + * |
|
66 | + * This function returns a list of all apps that have at least one |
|
67 | + * entry in the appconfig table. |
|
68 | + * @since 7.0.0 |
|
69 | + */ |
|
70 | + public function getApps(); |
|
71 | 71 | } |
@@ -38,63 +38,63 @@ |
||
38 | 38 | use OCP\Util; |
39 | 39 | |
40 | 40 | class AdminController extends Controller { |
41 | - /** @var IJobList */ |
|
42 | - private $jobList; |
|
43 | - /** @var ISecureRandom */ |
|
44 | - private $secureRandom; |
|
45 | - /** @var IConfig */ |
|
46 | - private $config; |
|
47 | - /** @var ITimeFactory */ |
|
48 | - private $timeFactory; |
|
49 | - /** @var IL10N */ |
|
50 | - private $l10n; |
|
41 | + /** @var IJobList */ |
|
42 | + private $jobList; |
|
43 | + /** @var ISecureRandom */ |
|
44 | + private $secureRandom; |
|
45 | + /** @var IConfig */ |
|
46 | + private $config; |
|
47 | + /** @var ITimeFactory */ |
|
48 | + private $timeFactory; |
|
49 | + /** @var IL10N */ |
|
50 | + private $l10n; |
|
51 | 51 | |
52 | - /** |
|
53 | - * @param string $appName |
|
54 | - * @param IRequest $request |
|
55 | - * @param IJobList $jobList |
|
56 | - * @param ISecureRandom $secureRandom |
|
57 | - * @param IConfig $config |
|
58 | - * @param ITimeFactory $timeFactory |
|
59 | - * @param IL10N $l10n |
|
60 | - */ |
|
61 | - public function __construct($appName, |
|
62 | - IRequest $request, |
|
63 | - IJobList $jobList, |
|
64 | - ISecureRandom $secureRandom, |
|
65 | - IConfig $config, |
|
66 | - ITimeFactory $timeFactory, |
|
67 | - IL10N $l10n) { |
|
68 | - parent::__construct($appName, $request); |
|
69 | - $this->jobList = $jobList; |
|
70 | - $this->secureRandom = $secureRandom; |
|
71 | - $this->config = $config; |
|
72 | - $this->timeFactory = $timeFactory; |
|
73 | - $this->l10n = $l10n; |
|
74 | - } |
|
52 | + /** |
|
53 | + * @param string $appName |
|
54 | + * @param IRequest $request |
|
55 | + * @param IJobList $jobList |
|
56 | + * @param ISecureRandom $secureRandom |
|
57 | + * @param IConfig $config |
|
58 | + * @param ITimeFactory $timeFactory |
|
59 | + * @param IL10N $l10n |
|
60 | + */ |
|
61 | + public function __construct($appName, |
|
62 | + IRequest $request, |
|
63 | + IJobList $jobList, |
|
64 | + ISecureRandom $secureRandom, |
|
65 | + IConfig $config, |
|
66 | + ITimeFactory $timeFactory, |
|
67 | + IL10N $l10n) { |
|
68 | + parent::__construct($appName, $request); |
|
69 | + $this->jobList = $jobList; |
|
70 | + $this->secureRandom = $secureRandom; |
|
71 | + $this->config = $config; |
|
72 | + $this->timeFactory = $timeFactory; |
|
73 | + $this->l10n = $l10n; |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * @param string $channel |
|
78 | - * @return DataResponse |
|
79 | - */ |
|
80 | - public function setChannel(string $channel): DataResponse { |
|
81 | - Util::setChannel($channel); |
|
82 | - $this->config->setAppValue('core', 'lastupdatedat', 0); |
|
83 | - return new DataResponse(['status' => 'success', 'data' => ['message' => $this->l10n->t('Channel updated')]]); |
|
84 | - } |
|
76 | + /** |
|
77 | + * @param string $channel |
|
78 | + * @return DataResponse |
|
79 | + */ |
|
80 | + public function setChannel(string $channel): DataResponse { |
|
81 | + Util::setChannel($channel); |
|
82 | + $this->config->setAppValue('core', 'lastupdatedat', 0); |
|
83 | + return new DataResponse(['status' => 'success', 'data' => ['message' => $this->l10n->t('Channel updated')]]); |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * @return DataResponse |
|
88 | - */ |
|
89 | - public function createCredentials(): DataResponse { |
|
90 | - // Create a new job and store the creation date |
|
91 | - $this->jobList->add(ResetTokenBackgroundJob::class); |
|
92 | - $this->config->setAppValue('core', 'updater.secret.created', $this->timeFactory->getTime()); |
|
86 | + /** |
|
87 | + * @return DataResponse |
|
88 | + */ |
|
89 | + public function createCredentials(): DataResponse { |
|
90 | + // Create a new job and store the creation date |
|
91 | + $this->jobList->add(ResetTokenBackgroundJob::class); |
|
92 | + $this->config->setAppValue('core', 'updater.secret.created', $this->timeFactory->getTime()); |
|
93 | 93 | |
94 | - // Create a new token |
|
95 | - $newToken = $this->secureRandom->generate(64); |
|
96 | - $this->config->setSystemValue('updater.secret', password_hash($newToken, PASSWORD_DEFAULT)); |
|
94 | + // Create a new token |
|
95 | + $newToken = $this->secureRandom->generate(64); |
|
96 | + $this->config->setSystemValue('updater.secret', password_hash($newToken, PASSWORD_DEFAULT)); |
|
97 | 97 | |
98 | - return new DataResponse($newToken); |
|
99 | - } |
|
98 | + return new DataResponse($newToken); |
|
99 | + } |
|
100 | 100 | } |
@@ -31,45 +31,45 @@ |
||
31 | 31 | * @package OCA\AdminAudit\Actions |
32 | 32 | */ |
33 | 33 | class Security extends Action { |
34 | - /** |
|
35 | - * Log twofactor auth enabled |
|
36 | - * |
|
37 | - * @param IUser $user |
|
38 | - * @param array $params |
|
39 | - */ |
|
40 | - public function twofactorFailed(IUser $user, array $params) { |
|
41 | - $params['uid'] = $user->getUID(); |
|
42 | - $params['displayName'] = $user->getDisplayName(); |
|
34 | + /** |
|
35 | + * Log twofactor auth enabled |
|
36 | + * |
|
37 | + * @param IUser $user |
|
38 | + * @param array $params |
|
39 | + */ |
|
40 | + public function twofactorFailed(IUser $user, array $params) { |
|
41 | + $params['uid'] = $user->getUID(); |
|
42 | + $params['displayName'] = $user->getDisplayName(); |
|
43 | 43 | |
44 | - $this->log( |
|
45 | - 'Failed two factor attempt by user %s (%s) with provider %s', |
|
46 | - $params, |
|
47 | - [ |
|
48 | - 'displayName', |
|
49 | - 'uid', |
|
50 | - 'provider', |
|
51 | - ] |
|
52 | - ); |
|
53 | - } |
|
44 | + $this->log( |
|
45 | + 'Failed two factor attempt by user %s (%s) with provider %s', |
|
46 | + $params, |
|
47 | + [ |
|
48 | + 'displayName', |
|
49 | + 'uid', |
|
50 | + 'provider', |
|
51 | + ] |
|
52 | + ); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Logs unsharing of data |
|
57 | - * |
|
58 | - * @param IUser $user |
|
59 | - * @param array $params |
|
60 | - */ |
|
61 | - public function twofactorSuccess(IUser $user, array $params) { |
|
62 | - $params['uid'] = $user->getUID(); |
|
63 | - $params['displayName'] = $user->getDisplayName(); |
|
55 | + /** |
|
56 | + * Logs unsharing of data |
|
57 | + * |
|
58 | + * @param IUser $user |
|
59 | + * @param array $params |
|
60 | + */ |
|
61 | + public function twofactorSuccess(IUser $user, array $params) { |
|
62 | + $params['uid'] = $user->getUID(); |
|
63 | + $params['displayName'] = $user->getDisplayName(); |
|
64 | 64 | |
65 | - $this->log( |
|
66 | - 'Successful two factor attempt by user %s (%s) with provider %s', |
|
67 | - $params, |
|
68 | - [ |
|
69 | - 'displayName', |
|
70 | - 'uid', |
|
71 | - 'provider', |
|
72 | - ] |
|
73 | - ); |
|
74 | - } |
|
65 | + $this->log( |
|
66 | + 'Successful two factor attempt by user %s (%s) with provider %s', |
|
67 | + $params, |
|
68 | + [ |
|
69 | + 'displayName', |
|
70 | + 'uid', |
|
71 | + 'provider', |
|
72 | + ] |
|
73 | + ); |
|
74 | + } |
|
75 | 75 | } |
@@ -23,63 +23,63 @@ |
||
23 | 23 | namespace OC\App\CodeChecker; |
24 | 24 | |
25 | 25 | class PrivateCheck extends AbstractCheck { |
26 | - /** |
|
27 | - * @return string |
|
28 | - */ |
|
29 | - protected function getLocalDescription() { |
|
30 | - return 'private'; |
|
31 | - } |
|
26 | + /** |
|
27 | + * @return string |
|
28 | + */ |
|
29 | + protected function getLocalDescription() { |
|
30 | + return 'private'; |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * @return array |
|
35 | - */ |
|
36 | - public function getLocalClasses() { |
|
37 | - return [ |
|
38 | - // classes replaced by the public api |
|
39 | - 'OC_API' => '6.0.0', |
|
40 | - 'OC_App' => '6.0.0', |
|
41 | - 'OC_AppConfig' => '6.0.0', |
|
42 | - 'OC_Avatar' => '6.0.0', |
|
43 | - 'OC_BackgroundJob' => '6.0.0', |
|
44 | - 'OC_Config' => '6.0.0', |
|
45 | - 'OC_DB' => '6.0.0', |
|
46 | - 'OC_Files' => '6.0.0', |
|
47 | - 'OC_Helper' => '6.0.0', |
|
48 | - 'OC_Hook' => '6.0.0', |
|
49 | - 'OC_Image' => '6.0.0', |
|
50 | - 'OC_JSON' => '6.0.0', |
|
51 | - 'OC_L10N' => '6.0.0', |
|
52 | - 'OC_Log' => '6.0.0', |
|
53 | - 'OC_Mail' => '6.0.0', |
|
54 | - 'OC_Preferences' => '6.0.0', |
|
55 | - 'OC_Search_Provider' => '6.0.0', |
|
56 | - 'OC_Search_Result' => '6.0.0', |
|
57 | - 'OC_Request' => '6.0.0', |
|
58 | - 'OC_Response' => '6.0.0', |
|
59 | - 'OC_Template' => '6.0.0', |
|
60 | - 'OC_User' => '6.0.0', |
|
61 | - 'OC_Util' => '6.0.0', |
|
62 | - ]; |
|
63 | - } |
|
33 | + /** |
|
34 | + * @return array |
|
35 | + */ |
|
36 | + public function getLocalClasses() { |
|
37 | + return [ |
|
38 | + // classes replaced by the public api |
|
39 | + 'OC_API' => '6.0.0', |
|
40 | + 'OC_App' => '6.0.0', |
|
41 | + 'OC_AppConfig' => '6.0.0', |
|
42 | + 'OC_Avatar' => '6.0.0', |
|
43 | + 'OC_BackgroundJob' => '6.0.0', |
|
44 | + 'OC_Config' => '6.0.0', |
|
45 | + 'OC_DB' => '6.0.0', |
|
46 | + 'OC_Files' => '6.0.0', |
|
47 | + 'OC_Helper' => '6.0.0', |
|
48 | + 'OC_Hook' => '6.0.0', |
|
49 | + 'OC_Image' => '6.0.0', |
|
50 | + 'OC_JSON' => '6.0.0', |
|
51 | + 'OC_L10N' => '6.0.0', |
|
52 | + 'OC_Log' => '6.0.0', |
|
53 | + 'OC_Mail' => '6.0.0', |
|
54 | + 'OC_Preferences' => '6.0.0', |
|
55 | + 'OC_Search_Provider' => '6.0.0', |
|
56 | + 'OC_Search_Result' => '6.0.0', |
|
57 | + 'OC_Request' => '6.0.0', |
|
58 | + 'OC_Response' => '6.0.0', |
|
59 | + 'OC_Template' => '6.0.0', |
|
60 | + 'OC_User' => '6.0.0', |
|
61 | + 'OC_Util' => '6.0.0', |
|
62 | + ]; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * @return array |
|
67 | - */ |
|
68 | - public function getLocalConstants() { |
|
69 | - return []; |
|
70 | - } |
|
65 | + /** |
|
66 | + * @return array |
|
67 | + */ |
|
68 | + public function getLocalConstants() { |
|
69 | + return []; |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * @return array |
|
74 | - */ |
|
75 | - public function getLocalFunctions() { |
|
76 | - return []; |
|
77 | - } |
|
72 | + /** |
|
73 | + * @return array |
|
74 | + */ |
|
75 | + public function getLocalFunctions() { |
|
76 | + return []; |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * @return array |
|
81 | - */ |
|
82 | - public function getLocalMethods() { |
|
83 | - return []; |
|
84 | - } |
|
79 | + /** |
|
80 | + * @return array |
|
81 | + */ |
|
82 | + public function getLocalMethods() { |
|
83 | + return []; |
|
84 | + } |
|
85 | 85 | } |