@@ -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 | } |
@@ -30,107 +30,107 @@ |
||
30 | 30 | |
31 | 31 | class SchemaWrapper implements ISchemaWrapper { |
32 | 32 | |
33 | - /** @var IDBConnection|Connection */ |
|
34 | - protected $connection; |
|
35 | - |
|
36 | - /** @var Schema */ |
|
37 | - protected $schema; |
|
38 | - |
|
39 | - /** @var array */ |
|
40 | - protected $tablesToDelete = []; |
|
41 | - |
|
42 | - /** |
|
43 | - * @param IDBConnection $connection |
|
44 | - */ |
|
45 | - public function __construct(IDBConnection $connection) { |
|
46 | - $this->connection = $connection; |
|
47 | - $this->schema = $this->connection->createSchema(); |
|
48 | - } |
|
49 | - |
|
50 | - public function getWrappedSchema() { |
|
51 | - return $this->schema; |
|
52 | - } |
|
53 | - |
|
54 | - public function performDropTableCalls() { |
|
55 | - foreach ($this->tablesToDelete as $tableName => $true) { |
|
56 | - $this->connection->dropTable($tableName); |
|
57 | - unset($this->tablesToDelete[$tableName]); |
|
58 | - } |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * Gets all table names |
|
63 | - * |
|
64 | - * @return array |
|
65 | - */ |
|
66 | - public function getTableNamesWithoutPrefix() { |
|
67 | - $tableNames = $this->schema->getTableNames(); |
|
68 | - return array_map(function($tableName) { |
|
69 | - if (strpos($tableName, $this->connection->getPrefix()) === 0) { |
|
70 | - return substr($tableName, strlen($this->connection->getPrefix())); |
|
71 | - } |
|
72 | - |
|
73 | - return $tableName; |
|
74 | - }, $tableNames); |
|
75 | - } |
|
76 | - |
|
77 | - // Overwritten methods |
|
78 | - |
|
79 | - /** |
|
80 | - * @return array |
|
81 | - */ |
|
82 | - public function getTableNames() { |
|
83 | - return $this->schema->getTableNames(); |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * @param string $tableName |
|
88 | - * |
|
89 | - * @return \Doctrine\DBAL\Schema\Table |
|
90 | - * @throws \Doctrine\DBAL\Schema\SchemaException |
|
91 | - */ |
|
92 | - public function getTable($tableName) { |
|
93 | - return $this->schema->getTable($this->connection->getPrefix() . $tableName); |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Does this schema have a table with the given name? |
|
98 | - * |
|
99 | - * @param string $tableName |
|
100 | - * |
|
101 | - * @return boolean |
|
102 | - */ |
|
103 | - public function hasTable($tableName) { |
|
104 | - return $this->schema->hasTable($this->connection->getPrefix() . $tableName); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Creates a new table. |
|
109 | - * |
|
110 | - * @param string $tableName |
|
111 | - * @return \Doctrine\DBAL\Schema\Table |
|
112 | - */ |
|
113 | - public function createTable($tableName) { |
|
114 | - return $this->schema->createTable($this->connection->getPrefix() . $tableName); |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * Drops a table from the schema. |
|
119 | - * |
|
120 | - * @param string $tableName |
|
121 | - * @return \Doctrine\DBAL\Schema\Schema |
|
122 | - */ |
|
123 | - public function dropTable($tableName) { |
|
124 | - $this->tablesToDelete[$tableName] = true; |
|
125 | - return $this->schema->dropTable($this->connection->getPrefix() . $tableName); |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * Gets all tables of this schema. |
|
130 | - * |
|
131 | - * @return \Doctrine\DBAL\Schema\Table[] |
|
132 | - */ |
|
133 | - public function getTables() { |
|
134 | - return $this->schema->getTables(); |
|
135 | - } |
|
33 | + /** @var IDBConnection|Connection */ |
|
34 | + protected $connection; |
|
35 | + |
|
36 | + /** @var Schema */ |
|
37 | + protected $schema; |
|
38 | + |
|
39 | + /** @var array */ |
|
40 | + protected $tablesToDelete = []; |
|
41 | + |
|
42 | + /** |
|
43 | + * @param IDBConnection $connection |
|
44 | + */ |
|
45 | + public function __construct(IDBConnection $connection) { |
|
46 | + $this->connection = $connection; |
|
47 | + $this->schema = $this->connection->createSchema(); |
|
48 | + } |
|
49 | + |
|
50 | + public function getWrappedSchema() { |
|
51 | + return $this->schema; |
|
52 | + } |
|
53 | + |
|
54 | + public function performDropTableCalls() { |
|
55 | + foreach ($this->tablesToDelete as $tableName => $true) { |
|
56 | + $this->connection->dropTable($tableName); |
|
57 | + unset($this->tablesToDelete[$tableName]); |
|
58 | + } |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * Gets all table names |
|
63 | + * |
|
64 | + * @return array |
|
65 | + */ |
|
66 | + public function getTableNamesWithoutPrefix() { |
|
67 | + $tableNames = $this->schema->getTableNames(); |
|
68 | + return array_map(function($tableName) { |
|
69 | + if (strpos($tableName, $this->connection->getPrefix()) === 0) { |
|
70 | + return substr($tableName, strlen($this->connection->getPrefix())); |
|
71 | + } |
|
72 | + |
|
73 | + return $tableName; |
|
74 | + }, $tableNames); |
|
75 | + } |
|
76 | + |
|
77 | + // Overwritten methods |
|
78 | + |
|
79 | + /** |
|
80 | + * @return array |
|
81 | + */ |
|
82 | + public function getTableNames() { |
|
83 | + return $this->schema->getTableNames(); |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * @param string $tableName |
|
88 | + * |
|
89 | + * @return \Doctrine\DBAL\Schema\Table |
|
90 | + * @throws \Doctrine\DBAL\Schema\SchemaException |
|
91 | + */ |
|
92 | + public function getTable($tableName) { |
|
93 | + return $this->schema->getTable($this->connection->getPrefix() . $tableName); |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Does this schema have a table with the given name? |
|
98 | + * |
|
99 | + * @param string $tableName |
|
100 | + * |
|
101 | + * @return boolean |
|
102 | + */ |
|
103 | + public function hasTable($tableName) { |
|
104 | + return $this->schema->hasTable($this->connection->getPrefix() . $tableName); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Creates a new table. |
|
109 | + * |
|
110 | + * @param string $tableName |
|
111 | + * @return \Doctrine\DBAL\Schema\Table |
|
112 | + */ |
|
113 | + public function createTable($tableName) { |
|
114 | + return $this->schema->createTable($this->connection->getPrefix() . $tableName); |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * Drops a table from the schema. |
|
119 | + * |
|
120 | + * @param string $tableName |
|
121 | + * @return \Doctrine\DBAL\Schema\Schema |
|
122 | + */ |
|
123 | + public function dropTable($tableName) { |
|
124 | + $this->tablesToDelete[$tableName] = true; |
|
125 | + return $this->schema->dropTable($this->connection->getPrefix() . $tableName); |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Gets all tables of this schema. |
|
130 | + * |
|
131 | + * @return \Doctrine\DBAL\Schema\Table[] |
|
132 | + */ |
|
133 | + public function getTables() { |
|
134 | + return $this->schema->getTables(); |
|
135 | + } |
|
136 | 136 | } |
@@ -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 | } |
@@ -31,38 +31,38 @@ |
||
31 | 31 | */ |
32 | 32 | abstract class BigIntMigration extends SimpleMigrationStep { |
33 | 33 | |
34 | - /** |
|
35 | - * @return array Returns an array with the following structure |
|
36 | - * ['table1' => ['column1', 'column2'], ...] |
|
37 | - * @since 13.0.0 |
|
38 | - */ |
|
39 | - abstract protected function getColumnsByTable(); |
|
34 | + /** |
|
35 | + * @return array Returns an array with the following structure |
|
36 | + * ['table1' => ['column1', 'column2'], ...] |
|
37 | + * @since 13.0.0 |
|
38 | + */ |
|
39 | + abstract protected function getColumnsByTable(); |
|
40 | 40 | |
41 | - /** |
|
42 | - * @param IOutput $output |
|
43 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
44 | - * @param array $options |
|
45 | - * @return null|ISchemaWrapper |
|
46 | - * @since 13.0.0 |
|
47 | - */ |
|
48 | - public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
49 | - /** @var ISchemaWrapper $schema */ |
|
50 | - $schema = $schemaClosure(); |
|
41 | + /** |
|
42 | + * @param IOutput $output |
|
43 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
44 | + * @param array $options |
|
45 | + * @return null|ISchemaWrapper |
|
46 | + * @since 13.0.0 |
|
47 | + */ |
|
48 | + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
49 | + /** @var ISchemaWrapper $schema */ |
|
50 | + $schema = $schemaClosure(); |
|
51 | 51 | |
52 | - $tables = $this->getColumnsByTable(); |
|
52 | + $tables = $this->getColumnsByTable(); |
|
53 | 53 | |
54 | - foreach ($tables as $tableName => $columns) { |
|
55 | - $table = $schema->getTable($tableName); |
|
54 | + foreach ($tables as $tableName => $columns) { |
|
55 | + $table = $schema->getTable($tableName); |
|
56 | 56 | |
57 | - foreach ($columns as $columnName) { |
|
58 | - $column = $table->getColumn($columnName); |
|
59 | - if ($column->getType()->getName() !== Type::BIGINT) { |
|
60 | - $column->setType(Type::getType(Type::BIGINT)); |
|
61 | - $column->setOptions(['length' => 20]); |
|
62 | - } |
|
63 | - } |
|
64 | - } |
|
57 | + foreach ($columns as $columnName) { |
|
58 | + $column = $table->getColumn($columnName); |
|
59 | + if ($column->getType()->getName() !== Type::BIGINT) { |
|
60 | + $column->setType(Type::getType(Type::BIGINT)); |
|
61 | + $column->setOptions(['length' => 20]); |
|
62 | + } |
|
63 | + } |
|
64 | + } |
|
65 | 65 | |
66 | - return $schema; |
|
67 | - } |
|
66 | + return $schema; |
|
67 | + } |
|
68 | 68 | } |
@@ -31,68 +31,68 @@ |
||
31 | 31 | use OCP\Share; |
32 | 32 | |
33 | 33 | class Search implements ISearch { |
34 | - /** @var IContainer */ |
|
35 | - private $c; |
|
34 | + /** @var IContainer */ |
|
35 | + private $c; |
|
36 | 36 | |
37 | - protected $pluginList = []; |
|
37 | + protected $pluginList = []; |
|
38 | 38 | |
39 | - public function __construct(IContainer $c) { |
|
40 | - $this->c = $c; |
|
41 | - } |
|
39 | + public function __construct(IContainer $c) { |
|
40 | + $this->c = $c; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @param string $search |
|
45 | - * @param array $shareTypes |
|
46 | - * @param bool $lookup |
|
47 | - * @param int|null $limit |
|
48 | - * @param int|null $offset |
|
49 | - * @return array |
|
50 | - * @throws \OCP\AppFramework\QueryException |
|
51 | - */ |
|
52 | - public function search($search, array $shareTypes, $lookup, $limit, $offset) { |
|
53 | - $hasMoreResults = false; |
|
43 | + /** |
|
44 | + * @param string $search |
|
45 | + * @param array $shareTypes |
|
46 | + * @param bool $lookup |
|
47 | + * @param int|null $limit |
|
48 | + * @param int|null $offset |
|
49 | + * @return array |
|
50 | + * @throws \OCP\AppFramework\QueryException |
|
51 | + */ |
|
52 | + public function search($search, array $shareTypes, $lookup, $limit, $offset) { |
|
53 | + $hasMoreResults = false; |
|
54 | 54 | |
55 | - /** @var ISearchResult $searchResult */ |
|
56 | - $searchResult = $this->c->resolve(SearchResult::class); |
|
55 | + /** @var ISearchResult $searchResult */ |
|
56 | + $searchResult = $this->c->resolve(SearchResult::class); |
|
57 | 57 | |
58 | - foreach ($shareTypes as $type) { |
|
59 | - if(!isset($this->pluginList[$type])) { |
|
60 | - continue; |
|
61 | - } |
|
62 | - foreach ($this->pluginList[$type] as $plugin) { |
|
63 | - /** @var ISearchPlugin $searchPlugin */ |
|
64 | - $searchPlugin = $this->c->resolve($plugin); |
|
65 | - $hasMoreResults |= $searchPlugin->search($search, $limit, $offset, $searchResult); |
|
66 | - } |
|
67 | - } |
|
58 | + foreach ($shareTypes as $type) { |
|
59 | + if(!isset($this->pluginList[$type])) { |
|
60 | + continue; |
|
61 | + } |
|
62 | + foreach ($this->pluginList[$type] as $plugin) { |
|
63 | + /** @var ISearchPlugin $searchPlugin */ |
|
64 | + $searchPlugin = $this->c->resolve($plugin); |
|
65 | + $hasMoreResults |= $searchPlugin->search($search, $limit, $offset, $searchResult); |
|
66 | + } |
|
67 | + } |
|
68 | 68 | |
69 | - // Get from lookup server, not a separate share type |
|
70 | - if ($lookup) { |
|
71 | - $searchPlugin = $this->c->resolve(LookupPlugin::class); |
|
72 | - $hasMoreResults |= $searchPlugin->search($search, $limit, $offset, $searchResult); |
|
73 | - } |
|
69 | + // Get from lookup server, not a separate share type |
|
70 | + if ($lookup) { |
|
71 | + $searchPlugin = $this->c->resolve(LookupPlugin::class); |
|
72 | + $hasMoreResults |= $searchPlugin->search($search, $limit, $offset, $searchResult); |
|
73 | + } |
|
74 | 74 | |
75 | - // sanitizing, could go into the plugins as well |
|
75 | + // sanitizing, could go into the plugins as well |
|
76 | 76 | |
77 | - // if we have a exact match, either for the federated cloud id or for the |
|
78 | - // email address we only return the exact match. It is highly unlikely |
|
79 | - // that the exact same email address and federated cloud id exists |
|
80 | - $emailType = new SearchResultType('emails'); |
|
81 | - $remoteType = new SearchResultType('remotes'); |
|
82 | - if($searchResult->hasExactIdMatch($emailType) && !$searchResult->hasExactIdMatch($remoteType)) { |
|
83 | - $searchResult->unsetResult($remoteType); |
|
84 | - } elseif (!$searchResult->hasExactIdMatch($emailType) && $searchResult->hasExactIdMatch($remoteType)) { |
|
85 | - $searchResult->unsetResult($emailType); |
|
86 | - } |
|
77 | + // if we have a exact match, either for the federated cloud id or for the |
|
78 | + // email address we only return the exact match. It is highly unlikely |
|
79 | + // that the exact same email address and federated cloud id exists |
|
80 | + $emailType = new SearchResultType('emails'); |
|
81 | + $remoteType = new SearchResultType('remotes'); |
|
82 | + if($searchResult->hasExactIdMatch($emailType) && !$searchResult->hasExactIdMatch($remoteType)) { |
|
83 | + $searchResult->unsetResult($remoteType); |
|
84 | + } elseif (!$searchResult->hasExactIdMatch($emailType) && $searchResult->hasExactIdMatch($remoteType)) { |
|
85 | + $searchResult->unsetResult($emailType); |
|
86 | + } |
|
87 | 87 | |
88 | - return [$searchResult->asArray(), (bool)$hasMoreResults]; |
|
89 | - } |
|
88 | + return [$searchResult->asArray(), (bool)$hasMoreResults]; |
|
89 | + } |
|
90 | 90 | |
91 | - public function registerPlugin(array $pluginInfo) { |
|
92 | - $shareType = constant(Share::class . '::' . $pluginInfo['shareType']); |
|
93 | - if($shareType === null) { |
|
94 | - throw new \InvalidArgumentException('Provided ShareType is invalid'); |
|
95 | - } |
|
96 | - $this->pluginList[$shareType][] = $pluginInfo['class']; |
|
97 | - } |
|
91 | + public function registerPlugin(array $pluginInfo) { |
|
92 | + $shareType = constant(Share::class . '::' . $pluginInfo['shareType']); |
|
93 | + if($shareType === null) { |
|
94 | + throw new \InvalidArgumentException('Provided ShareType is invalid'); |
|
95 | + } |
|
96 | + $this->pluginList[$shareType][] = $pluginInfo['class']; |
|
97 | + } |
|
98 | 98 | } |
@@ -33,80 +33,80 @@ |
||
33 | 33 | * Specialized version of Local storage for home directory usage |
34 | 34 | */ |
35 | 35 | class Home extends Local implements \OCP\Files\IHomeStorage { |
36 | - /** |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - protected $id; |
|
36 | + /** |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + protected $id; |
|
40 | 40 | |
41 | - /** |
|
42 | - * @var \OC\User\User $user |
|
43 | - */ |
|
44 | - protected $user; |
|
41 | + /** |
|
42 | + * @var \OC\User\User $user |
|
43 | + */ |
|
44 | + protected $user; |
|
45 | 45 | |
46 | - /** |
|
47 | - * Construct a Home storage instance |
|
48 | - * |
|
49 | - * @param array $arguments array with "user" containing the |
|
50 | - * storage owner |
|
51 | - */ |
|
52 | - public function __construct($arguments) { |
|
53 | - $this->user = $arguments['user']; |
|
54 | - $datadir = $this->user->getHome(); |
|
55 | - $this->id = 'home::' . $this->user->getUID(); |
|
46 | + /** |
|
47 | + * Construct a Home storage instance |
|
48 | + * |
|
49 | + * @param array $arguments array with "user" containing the |
|
50 | + * storage owner |
|
51 | + */ |
|
52 | + public function __construct($arguments) { |
|
53 | + $this->user = $arguments['user']; |
|
54 | + $datadir = $this->user->getHome(); |
|
55 | + $this->id = 'home::' . $this->user->getUID(); |
|
56 | 56 | |
57 | - parent::__construct(['datadir' => $datadir]); |
|
58 | - } |
|
57 | + parent::__construct(['datadir' => $datadir]); |
|
58 | + } |
|
59 | 59 | |
60 | - public function getId() { |
|
61 | - return $this->id; |
|
62 | - } |
|
60 | + public function getId() { |
|
61 | + return $this->id; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @return \OC\Files\Cache\HomeCache |
|
66 | - */ |
|
67 | - public function getCache($path = '', $storage = null) { |
|
68 | - if (!$storage) { |
|
69 | - $storage = $this; |
|
70 | - } |
|
71 | - if (!isset($this->cache)) { |
|
72 | - $this->cache = new \OC\Files\Cache\HomeCache($storage); |
|
73 | - } |
|
74 | - return $this->cache; |
|
75 | - } |
|
64 | + /** |
|
65 | + * @return \OC\Files\Cache\HomeCache |
|
66 | + */ |
|
67 | + public function getCache($path = '', $storage = null) { |
|
68 | + if (!$storage) { |
|
69 | + $storage = $this; |
|
70 | + } |
|
71 | + if (!isset($this->cache)) { |
|
72 | + $this->cache = new \OC\Files\Cache\HomeCache($storage); |
|
73 | + } |
|
74 | + return $this->cache; |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * get a propagator instance for the cache |
|
79 | - * |
|
80 | - * @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher |
|
81 | - * @return \OC\Files\Cache\Propagator |
|
82 | - */ |
|
83 | - public function getPropagator($storage = null) { |
|
84 | - if (!$storage) { |
|
85 | - $storage = $this; |
|
86 | - } |
|
87 | - if (!isset($this->propagator)) { |
|
88 | - $this->propagator = new HomePropagator($storage, \OC::$server->getDatabaseConnection()); |
|
89 | - } |
|
90 | - return $this->propagator; |
|
91 | - } |
|
77 | + /** |
|
78 | + * get a propagator instance for the cache |
|
79 | + * |
|
80 | + * @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher |
|
81 | + * @return \OC\Files\Cache\Propagator |
|
82 | + */ |
|
83 | + public function getPropagator($storage = null) { |
|
84 | + if (!$storage) { |
|
85 | + $storage = $this; |
|
86 | + } |
|
87 | + if (!isset($this->propagator)) { |
|
88 | + $this->propagator = new HomePropagator($storage, \OC::$server->getDatabaseConnection()); |
|
89 | + } |
|
90 | + return $this->propagator; |
|
91 | + } |
|
92 | 92 | |
93 | 93 | |
94 | - /** |
|
95 | - * Returns the owner of this home storage |
|
96 | - * |
|
97 | - * @return \OC\User\User owner of this home storage |
|
98 | - */ |
|
99 | - public function getUser() { |
|
100 | - return $this->user; |
|
101 | - } |
|
94 | + /** |
|
95 | + * Returns the owner of this home storage |
|
96 | + * |
|
97 | + * @return \OC\User\User owner of this home storage |
|
98 | + */ |
|
99 | + public function getUser() { |
|
100 | + return $this->user; |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * get the owner of a path |
|
105 | - * |
|
106 | - * @param string $path The path to get the owner |
|
107 | - * @return string uid or false |
|
108 | - */ |
|
109 | - public function getOwner($path) { |
|
110 | - return $this->user->getUID(); |
|
111 | - } |
|
103 | + /** |
|
104 | + * get the owner of a path |
|
105 | + * |
|
106 | + * @param string $path The path to get the owner |
|
107 | + * @return string uid or false |
|
108 | + */ |
|
109 | + public function getOwner($path) { |
|
110 | + return $this->user->getUID(); |
|
111 | + } |
|
112 | 112 | } |
@@ -30,41 +30,41 @@ |
||
30 | 30 | * @var $this \OCP\Route\IRouter |
31 | 31 | **/ |
32 | 32 | \OC_Mount_Config::$app->registerRoutes( |
33 | - $this, |
|
34 | - [ |
|
35 | - 'resources' => [ |
|
36 | - 'global_storages' => ['url' => '/globalstorages'], |
|
37 | - 'user_storages' => ['url' => '/userstorages'], |
|
38 | - 'user_global_storages' => ['url' => '/userglobalstorages'], |
|
39 | - ], |
|
40 | - 'routes' => [ |
|
41 | - [ |
|
42 | - 'name' => 'Ajax#getSshKeys', |
|
43 | - 'url' => '/ajax/public_key.php', |
|
44 | - 'verb' => 'POST', |
|
45 | - 'requirements' => [], |
|
46 | - ], |
|
47 | - [ |
|
48 | - 'name' => 'Ajax#saveGlobalCredentials', |
|
49 | - 'url' => '/globalcredentials', |
|
50 | - 'verb' => 'POST', |
|
51 | - ], |
|
52 | - ], |
|
53 | - 'ocs' => [ |
|
54 | - [ |
|
55 | - 'name' => 'Api#getUserMounts', |
|
56 | - 'url' => '/api/v1/mounts', |
|
57 | - 'verb' => 'GET', |
|
58 | - ], |
|
59 | - ], |
|
60 | - ] |
|
33 | + $this, |
|
34 | + [ |
|
35 | + 'resources' => [ |
|
36 | + 'global_storages' => ['url' => '/globalstorages'], |
|
37 | + 'user_storages' => ['url' => '/userstorages'], |
|
38 | + 'user_global_storages' => ['url' => '/userglobalstorages'], |
|
39 | + ], |
|
40 | + 'routes' => [ |
|
41 | + [ |
|
42 | + 'name' => 'Ajax#getSshKeys', |
|
43 | + 'url' => '/ajax/public_key.php', |
|
44 | + 'verb' => 'POST', |
|
45 | + 'requirements' => [], |
|
46 | + ], |
|
47 | + [ |
|
48 | + 'name' => 'Ajax#saveGlobalCredentials', |
|
49 | + 'url' => '/globalcredentials', |
|
50 | + 'verb' => 'POST', |
|
51 | + ], |
|
52 | + ], |
|
53 | + 'ocs' => [ |
|
54 | + [ |
|
55 | + 'name' => 'Api#getUserMounts', |
|
56 | + 'url' => '/api/v1/mounts', |
|
57 | + 'verb' => 'GET', |
|
58 | + ], |
|
59 | + ], |
|
60 | + ] |
|
61 | 61 | ); |
62 | 62 | |
63 | 63 | $this->create('files_external_oauth1', 'ajax/oauth1.php') |
64 | - ->actionInclude('files_external/ajax/oauth1.php'); |
|
64 | + ->actionInclude('files_external/ajax/oauth1.php'); |
|
65 | 65 | $this->create('files_external_oauth2', 'ajax/oauth2.php') |
66 | - ->actionInclude('files_external/ajax/oauth2.php'); |
|
66 | + ->actionInclude('files_external/ajax/oauth2.php'); |
|
67 | 67 | |
68 | 68 | |
69 | 69 | $this->create('files_external_list_applicable', '/applicable') |
70 | - ->actionInclude('files_external/ajax/applicable.php'); |
|
70 | + ->actionInclude('files_external/ajax/applicable.php'); |
@@ -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 | } |
@@ -37,241 +37,241 @@ |
||
37 | 37 | |
38 | 38 | class BackgroundJob extends TimedJob { |
39 | 39 | |
40 | - protected $connectionNotifications = [3, 7, 14, 30]; |
|
41 | - |
|
42 | - /** @var IConfig */ |
|
43 | - protected $config; |
|
44 | - |
|
45 | - /** @var IManager */ |
|
46 | - protected $notificationManager; |
|
47 | - |
|
48 | - /** @var IGroupManager */ |
|
49 | - protected $groupManager; |
|
50 | - |
|
51 | - /** @var IAppManager */ |
|
52 | - protected $appManager; |
|
53 | - |
|
54 | - /** @var IClientService */ |
|
55 | - protected $client; |
|
56 | - |
|
57 | - /** @var Installer */ |
|
58 | - protected $installer; |
|
59 | - |
|
60 | - /** @var string[] */ |
|
61 | - protected $users; |
|
62 | - |
|
63 | - /** |
|
64 | - * NotificationBackgroundJob constructor. |
|
65 | - * |
|
66 | - * @param IConfig $config |
|
67 | - * @param IManager $notificationManager |
|
68 | - * @param IGroupManager $groupManager |
|
69 | - * @param IAppManager $appManager |
|
70 | - * @param IClientService $client |
|
71 | - * @param Installer $installer |
|
72 | - */ |
|
73 | - public function __construct(IConfig $config, IManager $notificationManager, IGroupManager $groupManager, IAppManager $appManager, IClientService $client, Installer $installer) { |
|
74 | - // Run once a day |
|
75 | - $this->setInterval(60 * 60 * 24); |
|
76 | - |
|
77 | - $this->config = $config; |
|
78 | - $this->notificationManager = $notificationManager; |
|
79 | - $this->groupManager = $groupManager; |
|
80 | - $this->appManager = $appManager; |
|
81 | - $this->client = $client; |
|
82 | - $this->installer = $installer; |
|
83 | - } |
|
84 | - |
|
85 | - protected function run($argument) { |
|
86 | - $this->checkCoreUpdate(); |
|
87 | - $this->checkAppUpdates(); |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Check for ownCloud update |
|
92 | - */ |
|
93 | - protected function checkCoreUpdate() { |
|
94 | - if (\in_array($this->getChannel(), ['daily', 'git'], true)) { |
|
95 | - // "These aren't the update channels you're looking for." - Ben Obi-Wan Kenobi |
|
96 | - return; |
|
97 | - } |
|
98 | - |
|
99 | - $updater = $this->createVersionCheck(); |
|
100 | - |
|
101 | - $status = $updater->check(); |
|
102 | - if ($status === false) { |
|
103 | - $errors = 1 + (int) $this->config->getAppValue('updatenotification', 'update_check_errors', 0); |
|
104 | - $this->config->setAppValue('updatenotification', 'update_check_errors', $errors); |
|
105 | - |
|
106 | - if (\in_array($errors, $this->connectionNotifications, true)) { |
|
107 | - $this->sendErrorNotifications($errors); |
|
108 | - } |
|
109 | - } else if (\is_array($status)) { |
|
110 | - $this->config->setAppValue('updatenotification', 'update_check_errors', 0); |
|
111 | - $this->clearErrorNotifications(); |
|
112 | - |
|
113 | - if (isset($status['version'])) { |
|
114 | - $this->createNotifications('core', $status['version'], $status['versionstring']); |
|
115 | - } |
|
116 | - } |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Send a message to the admin when the update server could not be reached |
|
121 | - * @param int $numDays |
|
122 | - */ |
|
123 | - protected function sendErrorNotifications($numDays) { |
|
124 | - $this->clearErrorNotifications(); |
|
125 | - |
|
126 | - $notification = $this->notificationManager->createNotification(); |
|
127 | - try { |
|
128 | - $notification->setApp('updatenotification') |
|
129 | - ->setDateTime(new \DateTime()) |
|
130 | - ->setObject('updatenotification', 'error') |
|
131 | - ->setSubject('connection_error', ['days' => $numDays]); |
|
132 | - |
|
133 | - foreach ($this->getUsersToNotify() as $uid) { |
|
134 | - $notification->setUser($uid); |
|
135 | - $this->notificationManager->notify($notification); |
|
136 | - } |
|
137 | - } catch (\InvalidArgumentException $e) { |
|
138 | - return; |
|
139 | - } |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Remove error notifications again |
|
144 | - */ |
|
145 | - protected function clearErrorNotifications() { |
|
146 | - $notification = $this->notificationManager->createNotification(); |
|
147 | - try { |
|
148 | - $notification->setApp('updatenotification') |
|
149 | - ->setSubject('connection_error') |
|
150 | - ->setObject('updatenotification', 'error'); |
|
151 | - } catch (\InvalidArgumentException $e) { |
|
152 | - return; |
|
153 | - } |
|
154 | - $this->notificationManager->markProcessed($notification); |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * Check all installed apps for updates |
|
159 | - */ |
|
160 | - protected function checkAppUpdates() { |
|
161 | - $apps = $this->appManager->getInstalledApps(); |
|
162 | - foreach ($apps as $app) { |
|
163 | - $update = $this->isUpdateAvailable($app); |
|
164 | - if ($update !== false) { |
|
165 | - $this->createNotifications($app, $update); |
|
166 | - } |
|
167 | - } |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Create notifications for this app version |
|
172 | - * |
|
173 | - * @param string $app |
|
174 | - * @param string $version |
|
175 | - * @param string $visibleVersion |
|
176 | - */ |
|
177 | - protected function createNotifications($app, $version, $visibleVersion = '') { |
|
178 | - $lastNotification = $this->config->getAppValue('updatenotification', $app, false); |
|
179 | - if ($lastNotification === $version) { |
|
180 | - // We already notified about this update |
|
181 | - return; |
|
182 | - } |
|
183 | - |
|
184 | - if ($lastNotification !== false) { |
|
185 | - // Delete old updates |
|
186 | - $this->deleteOutdatedNotifications($app, $lastNotification); |
|
187 | - } |
|
188 | - |
|
189 | - $notification = $this->notificationManager->createNotification(); |
|
190 | - try { |
|
191 | - $notification->setApp('updatenotification') |
|
192 | - ->setDateTime(new \DateTime()) |
|
193 | - ->setObject($app, $version); |
|
194 | - |
|
195 | - if ($visibleVersion !== '') { |
|
196 | - $notification->setSubject('update_available', ['version' => $visibleVersion]); |
|
197 | - } else { |
|
198 | - $notification->setSubject('update_available'); |
|
199 | - } |
|
200 | - |
|
201 | - foreach ($this->getUsersToNotify() as $uid) { |
|
202 | - $notification->setUser($uid); |
|
203 | - $this->notificationManager->notify($notification); |
|
204 | - } |
|
205 | - } catch (\InvalidArgumentException $e) { |
|
206 | - return; |
|
207 | - } |
|
208 | - |
|
209 | - $this->config->setAppValue('updatenotification', $app, $version); |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * @return string[] |
|
214 | - */ |
|
215 | - protected function getUsersToNotify(): array { |
|
216 | - if ($this->users !== null) { |
|
217 | - return $this->users; |
|
218 | - } |
|
219 | - |
|
220 | - $notifyGroups = (array) json_decode($this->config->getAppValue('updatenotification', 'notify_groups', '["admin"]'), true); |
|
221 | - $this->users = []; |
|
222 | - foreach ($notifyGroups as $group) { |
|
223 | - $groupToNotify = $this->groupManager->get($group); |
|
224 | - if ($groupToNotify instanceof IGroup) { |
|
225 | - foreach ($groupToNotify->getUsers() as $user) { |
|
226 | - $this->users[$user->getUID()] = true; |
|
227 | - } |
|
228 | - } |
|
229 | - } |
|
230 | - |
|
231 | - $this->users = array_keys($this->users); |
|
232 | - |
|
233 | - return $this->users; |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * Delete notifications for old updates |
|
238 | - * |
|
239 | - * @param string $app |
|
240 | - * @param string $version |
|
241 | - */ |
|
242 | - protected function deleteOutdatedNotifications($app, $version) { |
|
243 | - $notification = $this->notificationManager->createNotification(); |
|
244 | - try { |
|
245 | - $notification->setApp('updatenotification') |
|
246 | - ->setObject($app, $version); |
|
247 | - } catch (\InvalidArgumentException $e) { |
|
248 | - return; |
|
249 | - } |
|
250 | - $this->notificationManager->markProcessed($notification); |
|
251 | - } |
|
252 | - |
|
253 | - /** |
|
254 | - * @return VersionCheck |
|
255 | - */ |
|
256 | - protected function createVersionCheck(): VersionCheck { |
|
257 | - return new VersionCheck( |
|
258 | - $this->client, |
|
259 | - $this->config |
|
260 | - ); |
|
261 | - } |
|
262 | - |
|
263 | - /** |
|
264 | - * @return string |
|
265 | - */ |
|
266 | - protected function getChannel(): string { |
|
267 | - return \OC_Util::getChannel(); |
|
268 | - } |
|
269 | - |
|
270 | - /** |
|
271 | - * @param string $app |
|
272 | - * @return string|false |
|
273 | - */ |
|
274 | - protected function isUpdateAvailable($app) { |
|
275 | - return $this->installer->isUpdateAvailable($app); |
|
276 | - } |
|
40 | + protected $connectionNotifications = [3, 7, 14, 30]; |
|
41 | + |
|
42 | + /** @var IConfig */ |
|
43 | + protected $config; |
|
44 | + |
|
45 | + /** @var IManager */ |
|
46 | + protected $notificationManager; |
|
47 | + |
|
48 | + /** @var IGroupManager */ |
|
49 | + protected $groupManager; |
|
50 | + |
|
51 | + /** @var IAppManager */ |
|
52 | + protected $appManager; |
|
53 | + |
|
54 | + /** @var IClientService */ |
|
55 | + protected $client; |
|
56 | + |
|
57 | + /** @var Installer */ |
|
58 | + protected $installer; |
|
59 | + |
|
60 | + /** @var string[] */ |
|
61 | + protected $users; |
|
62 | + |
|
63 | + /** |
|
64 | + * NotificationBackgroundJob constructor. |
|
65 | + * |
|
66 | + * @param IConfig $config |
|
67 | + * @param IManager $notificationManager |
|
68 | + * @param IGroupManager $groupManager |
|
69 | + * @param IAppManager $appManager |
|
70 | + * @param IClientService $client |
|
71 | + * @param Installer $installer |
|
72 | + */ |
|
73 | + public function __construct(IConfig $config, IManager $notificationManager, IGroupManager $groupManager, IAppManager $appManager, IClientService $client, Installer $installer) { |
|
74 | + // Run once a day |
|
75 | + $this->setInterval(60 * 60 * 24); |
|
76 | + |
|
77 | + $this->config = $config; |
|
78 | + $this->notificationManager = $notificationManager; |
|
79 | + $this->groupManager = $groupManager; |
|
80 | + $this->appManager = $appManager; |
|
81 | + $this->client = $client; |
|
82 | + $this->installer = $installer; |
|
83 | + } |
|
84 | + |
|
85 | + protected function run($argument) { |
|
86 | + $this->checkCoreUpdate(); |
|
87 | + $this->checkAppUpdates(); |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Check for ownCloud update |
|
92 | + */ |
|
93 | + protected function checkCoreUpdate() { |
|
94 | + if (\in_array($this->getChannel(), ['daily', 'git'], true)) { |
|
95 | + // "These aren't the update channels you're looking for." - Ben Obi-Wan Kenobi |
|
96 | + return; |
|
97 | + } |
|
98 | + |
|
99 | + $updater = $this->createVersionCheck(); |
|
100 | + |
|
101 | + $status = $updater->check(); |
|
102 | + if ($status === false) { |
|
103 | + $errors = 1 + (int) $this->config->getAppValue('updatenotification', 'update_check_errors', 0); |
|
104 | + $this->config->setAppValue('updatenotification', 'update_check_errors', $errors); |
|
105 | + |
|
106 | + if (\in_array($errors, $this->connectionNotifications, true)) { |
|
107 | + $this->sendErrorNotifications($errors); |
|
108 | + } |
|
109 | + } else if (\is_array($status)) { |
|
110 | + $this->config->setAppValue('updatenotification', 'update_check_errors', 0); |
|
111 | + $this->clearErrorNotifications(); |
|
112 | + |
|
113 | + if (isset($status['version'])) { |
|
114 | + $this->createNotifications('core', $status['version'], $status['versionstring']); |
|
115 | + } |
|
116 | + } |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Send a message to the admin when the update server could not be reached |
|
121 | + * @param int $numDays |
|
122 | + */ |
|
123 | + protected function sendErrorNotifications($numDays) { |
|
124 | + $this->clearErrorNotifications(); |
|
125 | + |
|
126 | + $notification = $this->notificationManager->createNotification(); |
|
127 | + try { |
|
128 | + $notification->setApp('updatenotification') |
|
129 | + ->setDateTime(new \DateTime()) |
|
130 | + ->setObject('updatenotification', 'error') |
|
131 | + ->setSubject('connection_error', ['days' => $numDays]); |
|
132 | + |
|
133 | + foreach ($this->getUsersToNotify() as $uid) { |
|
134 | + $notification->setUser($uid); |
|
135 | + $this->notificationManager->notify($notification); |
|
136 | + } |
|
137 | + } catch (\InvalidArgumentException $e) { |
|
138 | + return; |
|
139 | + } |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Remove error notifications again |
|
144 | + */ |
|
145 | + protected function clearErrorNotifications() { |
|
146 | + $notification = $this->notificationManager->createNotification(); |
|
147 | + try { |
|
148 | + $notification->setApp('updatenotification') |
|
149 | + ->setSubject('connection_error') |
|
150 | + ->setObject('updatenotification', 'error'); |
|
151 | + } catch (\InvalidArgumentException $e) { |
|
152 | + return; |
|
153 | + } |
|
154 | + $this->notificationManager->markProcessed($notification); |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * Check all installed apps for updates |
|
159 | + */ |
|
160 | + protected function checkAppUpdates() { |
|
161 | + $apps = $this->appManager->getInstalledApps(); |
|
162 | + foreach ($apps as $app) { |
|
163 | + $update = $this->isUpdateAvailable($app); |
|
164 | + if ($update !== false) { |
|
165 | + $this->createNotifications($app, $update); |
|
166 | + } |
|
167 | + } |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * Create notifications for this app version |
|
172 | + * |
|
173 | + * @param string $app |
|
174 | + * @param string $version |
|
175 | + * @param string $visibleVersion |
|
176 | + */ |
|
177 | + protected function createNotifications($app, $version, $visibleVersion = '') { |
|
178 | + $lastNotification = $this->config->getAppValue('updatenotification', $app, false); |
|
179 | + if ($lastNotification === $version) { |
|
180 | + // We already notified about this update |
|
181 | + return; |
|
182 | + } |
|
183 | + |
|
184 | + if ($lastNotification !== false) { |
|
185 | + // Delete old updates |
|
186 | + $this->deleteOutdatedNotifications($app, $lastNotification); |
|
187 | + } |
|
188 | + |
|
189 | + $notification = $this->notificationManager->createNotification(); |
|
190 | + try { |
|
191 | + $notification->setApp('updatenotification') |
|
192 | + ->setDateTime(new \DateTime()) |
|
193 | + ->setObject($app, $version); |
|
194 | + |
|
195 | + if ($visibleVersion !== '') { |
|
196 | + $notification->setSubject('update_available', ['version' => $visibleVersion]); |
|
197 | + } else { |
|
198 | + $notification->setSubject('update_available'); |
|
199 | + } |
|
200 | + |
|
201 | + foreach ($this->getUsersToNotify() as $uid) { |
|
202 | + $notification->setUser($uid); |
|
203 | + $this->notificationManager->notify($notification); |
|
204 | + } |
|
205 | + } catch (\InvalidArgumentException $e) { |
|
206 | + return; |
|
207 | + } |
|
208 | + |
|
209 | + $this->config->setAppValue('updatenotification', $app, $version); |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * @return string[] |
|
214 | + */ |
|
215 | + protected function getUsersToNotify(): array { |
|
216 | + if ($this->users !== null) { |
|
217 | + return $this->users; |
|
218 | + } |
|
219 | + |
|
220 | + $notifyGroups = (array) json_decode($this->config->getAppValue('updatenotification', 'notify_groups', '["admin"]'), true); |
|
221 | + $this->users = []; |
|
222 | + foreach ($notifyGroups as $group) { |
|
223 | + $groupToNotify = $this->groupManager->get($group); |
|
224 | + if ($groupToNotify instanceof IGroup) { |
|
225 | + foreach ($groupToNotify->getUsers() as $user) { |
|
226 | + $this->users[$user->getUID()] = true; |
|
227 | + } |
|
228 | + } |
|
229 | + } |
|
230 | + |
|
231 | + $this->users = array_keys($this->users); |
|
232 | + |
|
233 | + return $this->users; |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * Delete notifications for old updates |
|
238 | + * |
|
239 | + * @param string $app |
|
240 | + * @param string $version |
|
241 | + */ |
|
242 | + protected function deleteOutdatedNotifications($app, $version) { |
|
243 | + $notification = $this->notificationManager->createNotification(); |
|
244 | + try { |
|
245 | + $notification->setApp('updatenotification') |
|
246 | + ->setObject($app, $version); |
|
247 | + } catch (\InvalidArgumentException $e) { |
|
248 | + return; |
|
249 | + } |
|
250 | + $this->notificationManager->markProcessed($notification); |
|
251 | + } |
|
252 | + |
|
253 | + /** |
|
254 | + * @return VersionCheck |
|
255 | + */ |
|
256 | + protected function createVersionCheck(): VersionCheck { |
|
257 | + return new VersionCheck( |
|
258 | + $this->client, |
|
259 | + $this->config |
|
260 | + ); |
|
261 | + } |
|
262 | + |
|
263 | + /** |
|
264 | + * @return string |
|
265 | + */ |
|
266 | + protected function getChannel(): string { |
|
267 | + return \OC_Util::getChannel(); |
|
268 | + } |
|
269 | + |
|
270 | + /** |
|
271 | + * @param string $app |
|
272 | + * @return string|false |
|
273 | + */ |
|
274 | + protected function isUpdateAvailable($app) { |
|
275 | + return $this->installer->isUpdateAvailable($app); |
|
276 | + } |
|
277 | 277 | } |