@@ -37,15 +37,15 @@ |
||
37 | 37 | */ |
38 | 38 | interface IActivatableByAdmin extends IProvider { |
39 | 39 | |
40 | - /** |
|
41 | - * Enable this provider for the given user. |
|
42 | - * |
|
43 | - * @param IUser $user the user to activate this provider for |
|
44 | - * |
|
45 | - * @return void |
|
46 | - * |
|
47 | - * @since 15.0.0 |
|
48 | - */ |
|
49 | - public function enableFor(IUser $user); |
|
40 | + /** |
|
41 | + * Enable this provider for the given user. |
|
42 | + * |
|
43 | + * @param IUser $user the user to activate this provider for |
|
44 | + * |
|
45 | + * @return void |
|
46 | + * |
|
47 | + * @since 15.0.0 |
|
48 | + */ |
|
49 | + public function enableFor(IUser $user); |
|
50 | 50 | |
51 | 51 | } |
@@ -37,15 +37,15 @@ |
||
37 | 37 | */ |
38 | 38 | interface IDeactivatableByAdmin extends IProvider { |
39 | 39 | |
40 | - /** |
|
41 | - * Disable this provider for the given user. |
|
42 | - * |
|
43 | - * @param IUser $user the user to deactivate this provider for |
|
44 | - * |
|
45 | - * @return void |
|
46 | - * |
|
47 | - * @since 15.0.0 |
|
48 | - */ |
|
49 | - public function disableFor(IUser $user); |
|
40 | + /** |
|
41 | + * Disable this provider for the given user. |
|
42 | + * |
|
43 | + * @param IUser $user the user to deactivate this provider for |
|
44 | + * |
|
45 | + * @return void |
|
46 | + * |
|
47 | + * @since 15.0.0 |
|
48 | + */ |
|
49 | + public function disableFor(IUser $user); |
|
50 | 50 | |
51 | 51 | } |
@@ -38,87 +38,87 @@ |
||
38 | 38 | */ |
39 | 39 | class Validator implements IValidator { |
40 | 40 | |
41 | - /** @var Definitions */ |
|
42 | - protected $definitions; |
|
43 | - |
|
44 | - /** @var array[] */ |
|
45 | - protected $requiredParameters = []; |
|
46 | - |
|
47 | - /** |
|
48 | - * Constructor |
|
49 | - * |
|
50 | - * @param Definitions $definitions |
|
51 | - */ |
|
52 | - public function __construct(Definitions $definitions) { |
|
53 | - $this->definitions = $definitions; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * @param string $subject |
|
58 | - * @param array[] $parameters |
|
59 | - * @throws InvalidObjectExeption |
|
60 | - * @since 11.0.0 |
|
61 | - */ |
|
62 | - public function validate($subject, array $parameters) { |
|
63 | - $matches = []; |
|
64 | - $result = preg_match_all('/\{([a-z0-9]+)\}/i', $subject, $matches); |
|
65 | - |
|
66 | - if ($result === false) { |
|
67 | - throw new InvalidObjectExeption(); |
|
68 | - } |
|
69 | - |
|
70 | - if (!empty($matches[1])) { |
|
71 | - foreach ($matches[1] as $parameter) { |
|
72 | - if (!isset($parameters[$parameter])) { |
|
73 | - throw new InvalidObjectExeption('Parameter is undefined'); |
|
74 | - } |
|
75 | - } |
|
76 | - } |
|
77 | - |
|
78 | - foreach ($parameters as $parameter) { |
|
79 | - if (!\is_array($parameter)) { |
|
80 | - throw new InvalidObjectExeption('Parameter is malformed'); |
|
81 | - } |
|
82 | - |
|
83 | - $this->validateParameter($parameter); |
|
84 | - } |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * @param array $parameter |
|
89 | - * @throws InvalidObjectExeption |
|
90 | - */ |
|
91 | - protected function validateParameter(array $parameter) { |
|
92 | - if (!isset($parameter['type'])) { |
|
93 | - throw new InvalidObjectExeption('Object type is undefined'); |
|
94 | - } |
|
95 | - |
|
96 | - $definition = $this->definitions->getDefinition($parameter['type']); |
|
97 | - $requiredParameters = $this->getRequiredParameters($parameter['type'], $definition); |
|
98 | - |
|
99 | - $missingKeys = array_diff($requiredParameters, array_keys($parameter)); |
|
100 | - if (!empty($missingKeys)) { |
|
101 | - throw new InvalidObjectExeption('Object is invalid'); |
|
102 | - } |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * @param string $type |
|
107 | - * @param array $definition |
|
108 | - * @return string[] |
|
109 | - */ |
|
110 | - protected function getRequiredParameters($type, array $definition) { |
|
111 | - if (isset($this->requiredParameters[$type])) { |
|
112 | - return $this->requiredParameters[$type]; |
|
113 | - } |
|
114 | - |
|
115 | - $this->requiredParameters[$type] = []; |
|
116 | - foreach ($definition['parameters'] as $parameter => $data) { |
|
117 | - if ($data['required']) { |
|
118 | - $this->requiredParameters[$type][] = $parameter; |
|
119 | - } |
|
120 | - } |
|
121 | - |
|
122 | - return $this->requiredParameters[$type]; |
|
123 | - } |
|
41 | + /** @var Definitions */ |
|
42 | + protected $definitions; |
|
43 | + |
|
44 | + /** @var array[] */ |
|
45 | + protected $requiredParameters = []; |
|
46 | + |
|
47 | + /** |
|
48 | + * Constructor |
|
49 | + * |
|
50 | + * @param Definitions $definitions |
|
51 | + */ |
|
52 | + public function __construct(Definitions $definitions) { |
|
53 | + $this->definitions = $definitions; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * @param string $subject |
|
58 | + * @param array[] $parameters |
|
59 | + * @throws InvalidObjectExeption |
|
60 | + * @since 11.0.0 |
|
61 | + */ |
|
62 | + public function validate($subject, array $parameters) { |
|
63 | + $matches = []; |
|
64 | + $result = preg_match_all('/\{([a-z0-9]+)\}/i', $subject, $matches); |
|
65 | + |
|
66 | + if ($result === false) { |
|
67 | + throw new InvalidObjectExeption(); |
|
68 | + } |
|
69 | + |
|
70 | + if (!empty($matches[1])) { |
|
71 | + foreach ($matches[1] as $parameter) { |
|
72 | + if (!isset($parameters[$parameter])) { |
|
73 | + throw new InvalidObjectExeption('Parameter is undefined'); |
|
74 | + } |
|
75 | + } |
|
76 | + } |
|
77 | + |
|
78 | + foreach ($parameters as $parameter) { |
|
79 | + if (!\is_array($parameter)) { |
|
80 | + throw new InvalidObjectExeption('Parameter is malformed'); |
|
81 | + } |
|
82 | + |
|
83 | + $this->validateParameter($parameter); |
|
84 | + } |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * @param array $parameter |
|
89 | + * @throws InvalidObjectExeption |
|
90 | + */ |
|
91 | + protected function validateParameter(array $parameter) { |
|
92 | + if (!isset($parameter['type'])) { |
|
93 | + throw new InvalidObjectExeption('Object type is undefined'); |
|
94 | + } |
|
95 | + |
|
96 | + $definition = $this->definitions->getDefinition($parameter['type']); |
|
97 | + $requiredParameters = $this->getRequiredParameters($parameter['type'], $definition); |
|
98 | + |
|
99 | + $missingKeys = array_diff($requiredParameters, array_keys($parameter)); |
|
100 | + if (!empty($missingKeys)) { |
|
101 | + throw new InvalidObjectExeption('Object is invalid'); |
|
102 | + } |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * @param string $type |
|
107 | + * @param array $definition |
|
108 | + * @return string[] |
|
109 | + */ |
|
110 | + protected function getRequiredParameters($type, array $definition) { |
|
111 | + if (isset($this->requiredParameters[$type])) { |
|
112 | + return $this->requiredParameters[$type]; |
|
113 | + } |
|
114 | + |
|
115 | + $this->requiredParameters[$type] = []; |
|
116 | + foreach ($definition['parameters'] as $parameter => $data) { |
|
117 | + if ($data['required']) { |
|
118 | + $this->requiredParameters[$type][] = $parameter; |
|
119 | + } |
|
120 | + } |
|
121 | + |
|
122 | + return $this->requiredParameters[$type]; |
|
123 | + } |
|
124 | 124 | } |
@@ -84,7 +84,7 @@ |
||
84 | 84 | $column->setType(Type::getType(Type::BIGINT)); |
85 | 85 | $column->setOptions(['length' => 20]); |
86 | 86 | |
87 | - $updates[] = '* ' . $tableName . '.' . $columnName; |
|
87 | + $updates[] = '* '.$tableName.'.'.$columnName; |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 | } |
@@ -38,87 +38,87 @@ |
||
38 | 38 | |
39 | 39 | class ConvertFilecacheBigInt extends Command { |
40 | 40 | |
41 | - /** @var IDBConnection */ |
|
42 | - private $connection; |
|
43 | - |
|
44 | - /** |
|
45 | - * @param IDBConnection $connection |
|
46 | - */ |
|
47 | - public function __construct(IDBConnection $connection) { |
|
48 | - $this->connection = $connection; |
|
49 | - parent::__construct(); |
|
50 | - } |
|
51 | - |
|
52 | - protected function configure() { |
|
53 | - $this |
|
54 | - ->setName('db:convert-filecache-bigint') |
|
55 | - ->setDescription('Convert the ID columns of the filecache to BigInt'); |
|
56 | - } |
|
57 | - |
|
58 | - protected function getColumnsByTable() { |
|
59 | - // also update in CheckSetupController::hasBigIntConversionPendingColumns() |
|
60 | - return [ |
|
61 | - 'activity' => ['activity_id', 'object_id'], |
|
62 | - 'activity_mq' => ['mail_id'], |
|
63 | - 'authtoken' => ['id'], |
|
64 | - 'bruteforce_attempts' => ['id'], |
|
65 | - 'filecache' => ['fileid', 'storage', 'parent', 'mimetype', 'mimepart', 'mtime', 'storage_mtime'], |
|
66 | - 'file_locks' => ['id'], |
|
67 | - 'jobs' => ['id'], |
|
68 | - 'mimetypes' => ['id'], |
|
69 | - 'mounts' => ['id', 'storage_id', 'root_id', 'mount_id'], |
|
70 | - 'storages' => ['numeric_id'], |
|
71 | - ]; |
|
72 | - } |
|
73 | - |
|
74 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
75 | - $schema = new SchemaWrapper($this->connection); |
|
76 | - $isSqlite = $this->connection->getDatabasePlatform() instanceof SqlitePlatform; |
|
77 | - $updates = []; |
|
78 | - |
|
79 | - $tables = $this->getColumnsByTable(); |
|
80 | - foreach ($tables as $tableName => $columns) { |
|
81 | - if (!$schema->hasTable($tableName)) { |
|
82 | - continue; |
|
83 | - } |
|
84 | - |
|
85 | - $table = $schema->getTable($tableName); |
|
86 | - |
|
87 | - foreach ($columns as $columnName) { |
|
88 | - $column = $table->getColumn($columnName); |
|
89 | - $isAutoIncrement = $column->getAutoincrement(); |
|
90 | - $isAutoIncrementOnSqlite = $isSqlite && $isAutoIncrement; |
|
91 | - if ($column->getType()->getName() !== Type::BIGINT && !$isAutoIncrementOnSqlite) { |
|
92 | - $column->setType(Type::getType(Type::BIGINT)); |
|
93 | - $column->setOptions(['length' => 20]); |
|
94 | - |
|
95 | - $updates[] = '* ' . $tableName . '.' . $columnName; |
|
96 | - } |
|
97 | - } |
|
98 | - } |
|
99 | - |
|
100 | - if (empty($updates)) { |
|
101 | - $output->writeln('<info>All tables already up to date!</info>'); |
|
102 | - return 0; |
|
103 | - } |
|
104 | - |
|
105 | - $output->writeln('<comment>Following columns will be updated:</comment>'); |
|
106 | - $output->writeln(''); |
|
107 | - $output->writeln($updates); |
|
108 | - $output->writeln(''); |
|
109 | - $output->writeln('<comment>This can take up to hours, depending on the number of files in your instance!</comment>'); |
|
110 | - |
|
111 | - if ($input->isInteractive()) { |
|
112 | - $helper = $this->getHelper('question'); |
|
113 | - $question = new ConfirmationQuestion('Continue with the conversion (y/n)? [n] ', false); |
|
114 | - |
|
115 | - if (!$helper->ask($input, $output, $question)) { |
|
116 | - return 1; |
|
117 | - } |
|
118 | - } |
|
119 | - |
|
120 | - $this->connection->migrateToSchema($schema->getWrappedSchema()); |
|
121 | - |
|
122 | - return 0; |
|
123 | - } |
|
41 | + /** @var IDBConnection */ |
|
42 | + private $connection; |
|
43 | + |
|
44 | + /** |
|
45 | + * @param IDBConnection $connection |
|
46 | + */ |
|
47 | + public function __construct(IDBConnection $connection) { |
|
48 | + $this->connection = $connection; |
|
49 | + parent::__construct(); |
|
50 | + } |
|
51 | + |
|
52 | + protected function configure() { |
|
53 | + $this |
|
54 | + ->setName('db:convert-filecache-bigint') |
|
55 | + ->setDescription('Convert the ID columns of the filecache to BigInt'); |
|
56 | + } |
|
57 | + |
|
58 | + protected function getColumnsByTable() { |
|
59 | + // also update in CheckSetupController::hasBigIntConversionPendingColumns() |
|
60 | + return [ |
|
61 | + 'activity' => ['activity_id', 'object_id'], |
|
62 | + 'activity_mq' => ['mail_id'], |
|
63 | + 'authtoken' => ['id'], |
|
64 | + 'bruteforce_attempts' => ['id'], |
|
65 | + 'filecache' => ['fileid', 'storage', 'parent', 'mimetype', 'mimepart', 'mtime', 'storage_mtime'], |
|
66 | + 'file_locks' => ['id'], |
|
67 | + 'jobs' => ['id'], |
|
68 | + 'mimetypes' => ['id'], |
|
69 | + 'mounts' => ['id', 'storage_id', 'root_id', 'mount_id'], |
|
70 | + 'storages' => ['numeric_id'], |
|
71 | + ]; |
|
72 | + } |
|
73 | + |
|
74 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
75 | + $schema = new SchemaWrapper($this->connection); |
|
76 | + $isSqlite = $this->connection->getDatabasePlatform() instanceof SqlitePlatform; |
|
77 | + $updates = []; |
|
78 | + |
|
79 | + $tables = $this->getColumnsByTable(); |
|
80 | + foreach ($tables as $tableName => $columns) { |
|
81 | + if (!$schema->hasTable($tableName)) { |
|
82 | + continue; |
|
83 | + } |
|
84 | + |
|
85 | + $table = $schema->getTable($tableName); |
|
86 | + |
|
87 | + foreach ($columns as $columnName) { |
|
88 | + $column = $table->getColumn($columnName); |
|
89 | + $isAutoIncrement = $column->getAutoincrement(); |
|
90 | + $isAutoIncrementOnSqlite = $isSqlite && $isAutoIncrement; |
|
91 | + if ($column->getType()->getName() !== Type::BIGINT && !$isAutoIncrementOnSqlite) { |
|
92 | + $column->setType(Type::getType(Type::BIGINT)); |
|
93 | + $column->setOptions(['length' => 20]); |
|
94 | + |
|
95 | + $updates[] = '* ' . $tableName . '.' . $columnName; |
|
96 | + } |
|
97 | + } |
|
98 | + } |
|
99 | + |
|
100 | + if (empty($updates)) { |
|
101 | + $output->writeln('<info>All tables already up to date!</info>'); |
|
102 | + return 0; |
|
103 | + } |
|
104 | + |
|
105 | + $output->writeln('<comment>Following columns will be updated:</comment>'); |
|
106 | + $output->writeln(''); |
|
107 | + $output->writeln($updates); |
|
108 | + $output->writeln(''); |
|
109 | + $output->writeln('<comment>This can take up to hours, depending on the number of files in your instance!</comment>'); |
|
110 | + |
|
111 | + if ($input->isInteractive()) { |
|
112 | + $helper = $this->getHelper('question'); |
|
113 | + $question = new ConfirmationQuestion('Continue with the conversion (y/n)? [n] ', false); |
|
114 | + |
|
115 | + if (!$helper->ask($input, $output, $question)) { |
|
116 | + return 1; |
|
117 | + } |
|
118 | + } |
|
119 | + |
|
120 | + $this->connection->migrateToSchema($schema->getWrappedSchema()); |
|
121 | + |
|
122 | + return 0; |
|
123 | + } |
|
124 | 124 | } |
@@ -30,62 +30,62 @@ |
||
30 | 30 | |
31 | 31 | class ClientMapper extends QBMapper { |
32 | 32 | |
33 | - /** |
|
34 | - * @param IDBConnection $db |
|
35 | - */ |
|
36 | - public function __construct(IDBConnection $db) { |
|
37 | - parent::__construct($db, 'oauth2_clients'); |
|
38 | - } |
|
33 | + /** |
|
34 | + * @param IDBConnection $db |
|
35 | + */ |
|
36 | + public function __construct(IDBConnection $db) { |
|
37 | + parent::__construct($db, 'oauth2_clients'); |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @param string $clientIdentifier |
|
42 | - * @return Client |
|
43 | - * @throws ClientNotFoundException |
|
44 | - */ |
|
45 | - public function getByIdentifier(string $clientIdentifier): Client { |
|
46 | - $qb = $this->db->getQueryBuilder(); |
|
47 | - $qb |
|
48 | - ->select('*') |
|
49 | - ->from($this->tableName) |
|
50 | - ->where($qb->expr()->eq('client_identifier', $qb->createNamedParameter($clientIdentifier))); |
|
40 | + /** |
|
41 | + * @param string $clientIdentifier |
|
42 | + * @return Client |
|
43 | + * @throws ClientNotFoundException |
|
44 | + */ |
|
45 | + public function getByIdentifier(string $clientIdentifier): Client { |
|
46 | + $qb = $this->db->getQueryBuilder(); |
|
47 | + $qb |
|
48 | + ->select('*') |
|
49 | + ->from($this->tableName) |
|
50 | + ->where($qb->expr()->eq('client_identifier', $qb->createNamedParameter($clientIdentifier))); |
|
51 | 51 | |
52 | - try { |
|
53 | - $client = $this->findEntity($qb); |
|
54 | - } catch (IMapperException $e) { |
|
55 | - throw new ClientNotFoundException('could not find client '.$clientIdentifier, 0, $e); |
|
56 | - } |
|
57 | - return $client; |
|
58 | - } |
|
52 | + try { |
|
53 | + $client = $this->findEntity($qb); |
|
54 | + } catch (IMapperException $e) { |
|
55 | + throw new ClientNotFoundException('could not find client '.$clientIdentifier, 0, $e); |
|
56 | + } |
|
57 | + return $client; |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * @param int $id internal id of the client |
|
62 | - * @return Client |
|
63 | - * @throws ClientNotFoundException |
|
64 | - */ |
|
65 | - public function getByUid(int $id): Client { |
|
66 | - $qb = $this->db->getQueryBuilder(); |
|
67 | - $qb |
|
68 | - ->select('*') |
|
69 | - ->from($this->tableName) |
|
70 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT))); |
|
60 | + /** |
|
61 | + * @param int $id internal id of the client |
|
62 | + * @return Client |
|
63 | + * @throws ClientNotFoundException |
|
64 | + */ |
|
65 | + public function getByUid(int $id): Client { |
|
66 | + $qb = $this->db->getQueryBuilder(); |
|
67 | + $qb |
|
68 | + ->select('*') |
|
69 | + ->from($this->tableName) |
|
70 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT))); |
|
71 | 71 | |
72 | - try { |
|
73 | - $client = $this->findEntity($qb); |
|
74 | - } catch (IMapperException $e) { |
|
75 | - throw new ClientNotFoundException('could not find client with id '.$id, 0, $e); |
|
76 | - } |
|
77 | - return $client; |
|
78 | - } |
|
72 | + try { |
|
73 | + $client = $this->findEntity($qb); |
|
74 | + } catch (IMapperException $e) { |
|
75 | + throw new ClientNotFoundException('could not find client with id '.$id, 0, $e); |
|
76 | + } |
|
77 | + return $client; |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * @return Client[] |
|
82 | - */ |
|
83 | - public function getClients(): array { |
|
84 | - $qb = $this->db->getQueryBuilder(); |
|
85 | - $qb |
|
86 | - ->select('*') |
|
87 | - ->from($this->tableName); |
|
80 | + /** |
|
81 | + * @return Client[] |
|
82 | + */ |
|
83 | + public function getClients(): array { |
|
84 | + $qb = $this->db->getQueryBuilder(); |
|
85 | + $qb |
|
86 | + ->select('*') |
|
87 | + ->from($this->tableName); |
|
88 | 88 | |
89 | - return $this->findEntities($qb); |
|
90 | - } |
|
89 | + return $this->findEntities($qb); |
|
90 | + } |
|
91 | 91 | } |
@@ -30,44 +30,44 @@ |
||
30 | 30 | |
31 | 31 | class AccessTokenMapper extends QBMapper { |
32 | 32 | |
33 | - /** |
|
34 | - * @param IDBConnection $db |
|
35 | - */ |
|
36 | - public function __construct(IDBConnection $db) { |
|
37 | - parent::__construct($db, 'oauth2_access_tokens'); |
|
38 | - } |
|
33 | + /** |
|
34 | + * @param IDBConnection $db |
|
35 | + */ |
|
36 | + public function __construct(IDBConnection $db) { |
|
37 | + parent::__construct($db, 'oauth2_access_tokens'); |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @param string $code |
|
42 | - * @return AccessToken |
|
43 | - * @throws AccessTokenNotFoundException |
|
44 | - */ |
|
45 | - public function getByCode(string $code): AccessToken { |
|
46 | - $qb = $this->db->getQueryBuilder(); |
|
47 | - $qb |
|
48 | - ->select('*') |
|
49 | - ->from($this->tableName) |
|
50 | - ->where($qb->expr()->eq('hashed_code', $qb->createNamedParameter(hash('sha512', $code)))); |
|
40 | + /** |
|
41 | + * @param string $code |
|
42 | + * @return AccessToken |
|
43 | + * @throws AccessTokenNotFoundException |
|
44 | + */ |
|
45 | + public function getByCode(string $code): AccessToken { |
|
46 | + $qb = $this->db->getQueryBuilder(); |
|
47 | + $qb |
|
48 | + ->select('*') |
|
49 | + ->from($this->tableName) |
|
50 | + ->where($qb->expr()->eq('hashed_code', $qb->createNamedParameter(hash('sha512', $code)))); |
|
51 | 51 | |
52 | - try { |
|
53 | - $token = $this->findEntity($qb); |
|
54 | - } catch (IMapperException $e) { |
|
55 | - throw new AccessTokenNotFoundException('Could not find access token', 0, $e); |
|
56 | - } |
|
52 | + try { |
|
53 | + $token = $this->findEntity($qb); |
|
54 | + } catch (IMapperException $e) { |
|
55 | + throw new AccessTokenNotFoundException('Could not find access token', 0, $e); |
|
56 | + } |
|
57 | 57 | |
58 | - return $token; |
|
59 | - } |
|
58 | + return $token; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * delete all access token from a given client |
|
63 | - * |
|
64 | - * @param int $id |
|
65 | - */ |
|
66 | - public function deleteByClientId(int $id) { |
|
67 | - $qb = $this->db->getQueryBuilder(); |
|
68 | - $qb |
|
69 | - ->delete($this->tableName) |
|
70 | - ->where($qb->expr()->eq('client_id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT))); |
|
71 | - $qb->execute(); |
|
72 | - } |
|
61 | + /** |
|
62 | + * delete all access token from a given client |
|
63 | + * |
|
64 | + * @param int $id |
|
65 | + */ |
|
66 | + public function deleteByClientId(int $id) { |
|
67 | + $qb = $this->db->getQueryBuilder(); |
|
68 | + $qb |
|
69 | + ->delete($this->tableName) |
|
70 | + ->where($qb->expr()->eq('client_id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT))); |
|
71 | + $qb->execute(); |
|
72 | + } |
|
73 | 73 | } |
@@ -27,95 +27,95 @@ |
||
27 | 27 | * @since 8.2.0 |
28 | 28 | */ |
29 | 29 | interface IFactory { |
30 | - /** |
|
31 | - * Get a language instance |
|
32 | - * |
|
33 | - * @param string $app |
|
34 | - * @param string|null $lang |
|
35 | - * @param string|null $locale |
|
36 | - * @return \OCP\IL10N |
|
37 | - * @since 8.2.0 |
|
38 | - */ |
|
39 | - public function get($app, $lang = null, $locale = null); |
|
30 | + /** |
|
31 | + * Get a language instance |
|
32 | + * |
|
33 | + * @param string $app |
|
34 | + * @param string|null $lang |
|
35 | + * @param string|null $locale |
|
36 | + * @return \OCP\IL10N |
|
37 | + * @since 8.2.0 |
|
38 | + */ |
|
39 | + public function get($app, $lang = null, $locale = null); |
|
40 | 40 | |
41 | - /** |
|
42 | - * Find the best language |
|
43 | - * |
|
44 | - * @param string|null $app App id or null for core |
|
45 | - * @return string language If nothing works it returns 'en' |
|
46 | - * @since 9.0.0 |
|
47 | - */ |
|
48 | - public function findLanguage($app = null); |
|
41 | + /** |
|
42 | + * Find the best language |
|
43 | + * |
|
44 | + * @param string|null $app App id or null for core |
|
45 | + * @return string language If nothing works it returns 'en' |
|
46 | + * @since 9.0.0 |
|
47 | + */ |
|
48 | + public function findLanguage($app = null); |
|
49 | 49 | |
50 | - /** |
|
51 | - * @param string|null $lang user language as default locale |
|
52 | - * @return string locale If nothing works it returns 'en_US' |
|
53 | - * @since 14.0.0 |
|
54 | - */ |
|
55 | - public function findLocale($lang = null); |
|
50 | + /** |
|
51 | + * @param string|null $lang user language as default locale |
|
52 | + * @return string locale If nothing works it returns 'en_US' |
|
53 | + * @since 14.0.0 |
|
54 | + */ |
|
55 | + public function findLocale($lang = null); |
|
56 | 56 | |
57 | - /** |
|
58 | - * find the matching lang from the locale |
|
59 | - * |
|
60 | - * @param string $app |
|
61 | - * @param string $locale |
|
62 | - * @return null|string |
|
63 | - * @since 14.0.1 |
|
64 | - */ |
|
65 | - public function findLanguageFromLocale(string $app = 'core', string $locale = null); |
|
57 | + /** |
|
58 | + * find the matching lang from the locale |
|
59 | + * |
|
60 | + * @param string $app |
|
61 | + * @param string $locale |
|
62 | + * @return null|string |
|
63 | + * @since 14.0.1 |
|
64 | + */ |
|
65 | + public function findLanguageFromLocale(string $app = 'core', string $locale = null); |
|
66 | 66 | |
67 | - /** |
|
68 | - * Find all available languages for an app |
|
69 | - * |
|
70 | - * @param string|null $app App id or null for core |
|
71 | - * @return string[] an array of available languages |
|
72 | - * @since 9.0.0 |
|
73 | - */ |
|
74 | - public function findAvailableLanguages($app = null); |
|
67 | + /** |
|
68 | + * Find all available languages for an app |
|
69 | + * |
|
70 | + * @param string|null $app App id or null for core |
|
71 | + * @return string[] an array of available languages |
|
72 | + * @since 9.0.0 |
|
73 | + */ |
|
74 | + public function findAvailableLanguages($app = null); |
|
75 | 75 | |
76 | - /** |
|
77 | - * @return array an array of available |
|
78 | - * @since 14.0.0 |
|
79 | - */ |
|
80 | - public function findAvailableLocales(); |
|
76 | + /** |
|
77 | + * @return array an array of available |
|
78 | + * @since 14.0.0 |
|
79 | + */ |
|
80 | + public function findAvailableLocales(); |
|
81 | 81 | |
82 | - /** |
|
83 | - * @param string|null $app App id or null for core |
|
84 | - * @param string $lang |
|
85 | - * @return bool |
|
86 | - * @since 9.0.0 |
|
87 | - */ |
|
88 | - public function languageExists($app, $lang); |
|
82 | + /** |
|
83 | + * @param string|null $app App id or null for core |
|
84 | + * @param string $lang |
|
85 | + * @return bool |
|
86 | + * @since 9.0.0 |
|
87 | + */ |
|
88 | + public function languageExists($app, $lang); |
|
89 | 89 | |
90 | - /** |
|
91 | - * @param string $locale |
|
92 | - * @return bool |
|
93 | - * @since 14.0.0 |
|
94 | - */ |
|
95 | - public function localeExists($locale); |
|
90 | + /** |
|
91 | + * @param string $locale |
|
92 | + * @return bool |
|
93 | + * @since 14.0.0 |
|
94 | + */ |
|
95 | + public function localeExists($locale); |
|
96 | 96 | |
97 | - /** |
|
98 | - * Creates a function from the plural string |
|
99 | - * |
|
100 | - * @param string $string |
|
101 | - * @return string Unique function name |
|
102 | - * @since 14.0.0 |
|
103 | - */ |
|
104 | - public function createPluralFunction($string); |
|
97 | + /** |
|
98 | + * Creates a function from the plural string |
|
99 | + * |
|
100 | + * @param string $string |
|
101 | + * @return string Unique function name |
|
102 | + * @since 14.0.0 |
|
103 | + */ |
|
104 | + public function createPluralFunction($string); |
|
105 | 105 | |
106 | - /** |
|
107 | - * iterate through language settings (if provided) in this order: |
|
108 | - * 1. returns the forced language or: |
|
109 | - * 2. if applicable, the trunk of 1 (e.g. "fu" instead of "fu_BAR" |
|
110 | - * 3. returns the user language or: |
|
111 | - * 4. if applicable, the trunk of 3 |
|
112 | - * 5. returns the system default language or: |
|
113 | - * 6. if applicable, the trunk of 5 |
|
114 | - * 7+∞. returns 'en' |
|
115 | - * |
|
116 | - * Hint: in most cases findLanguage() suits you fine |
|
117 | - * |
|
118 | - * @since 14.0.0 |
|
119 | - */ |
|
120 | - public function getLanguageIterator(IUser $user = null): ILanguageIterator; |
|
106 | + /** |
|
107 | + * iterate through language settings (if provided) in this order: |
|
108 | + * 1. returns the forced language or: |
|
109 | + * 2. if applicable, the trunk of 1 (e.g. "fu" instead of "fu_BAR" |
|
110 | + * 3. returns the user language or: |
|
111 | + * 4. if applicable, the trunk of 3 |
|
112 | + * 5. returns the system default language or: |
|
113 | + * 6. if applicable, the trunk of 5 |
|
114 | + * 7+∞. returns 'en' |
|
115 | + * |
|
116 | + * Hint: in most cases findLanguage() suits you fine |
|
117 | + * |
|
118 | + * @since 14.0.0 |
|
119 | + */ |
|
120 | + public function getLanguageIterator(IUser $user = null): ILanguageIterator; |
|
121 | 121 | } |
@@ -31,68 +31,68 @@ |
||
31 | 31 | |
32 | 32 | class Version010401Date20181207190718 extends SimpleMigrationStep { |
33 | 33 | |
34 | - /** |
|
35 | - * @param IOutput $output |
|
36 | - * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
37 | - * @param array $options |
|
38 | - * @return null|ISchemaWrapper |
|
39 | - */ |
|
40 | - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
|
41 | - /** @var ISchemaWrapper $schema */ |
|
42 | - $schema = $schemaClosure(); |
|
34 | + /** |
|
35 | + * @param IOutput $output |
|
36 | + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
37 | + * @param array $options |
|
38 | + * @return null|ISchemaWrapper |
|
39 | + */ |
|
40 | + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
|
41 | + /** @var ISchemaWrapper $schema */ |
|
42 | + $schema = $schemaClosure(); |
|
43 | 43 | |
44 | - if (!$schema->hasTable('oauth2_clients')) { |
|
45 | - $table = $schema->createTable('oauth2_clients'); |
|
46 | - $table->addColumn('id', 'integer', [ |
|
47 | - 'autoincrement' => true, |
|
48 | - 'notnull' => true, |
|
49 | - 'unsigned' => true, |
|
50 | - ]); |
|
51 | - $table->addColumn('name', 'string', [ |
|
52 | - 'notnull' => true, |
|
53 | - 'length' => 64, |
|
54 | - ]); |
|
55 | - $table->addColumn('redirect_uri', 'string', [ |
|
56 | - 'notnull' => true, |
|
57 | - 'length' => 2000, |
|
58 | - ]); |
|
59 | - $table->addColumn('client_identifier', 'string', [ |
|
60 | - 'notnull' => true, |
|
61 | - 'length' => 64, |
|
62 | - ]); |
|
63 | - $table->addColumn('secret', 'string', [ |
|
64 | - 'notnull' => true, |
|
65 | - 'length' => 64, |
|
66 | - ]); |
|
67 | - $table->setPrimaryKey(['id']); |
|
68 | - $table->addIndex(['client_identifier'], 'oauth2_client_id_idx'); |
|
69 | - } |
|
44 | + if (!$schema->hasTable('oauth2_clients')) { |
|
45 | + $table = $schema->createTable('oauth2_clients'); |
|
46 | + $table->addColumn('id', 'integer', [ |
|
47 | + 'autoincrement' => true, |
|
48 | + 'notnull' => true, |
|
49 | + 'unsigned' => true, |
|
50 | + ]); |
|
51 | + $table->addColumn('name', 'string', [ |
|
52 | + 'notnull' => true, |
|
53 | + 'length' => 64, |
|
54 | + ]); |
|
55 | + $table->addColumn('redirect_uri', 'string', [ |
|
56 | + 'notnull' => true, |
|
57 | + 'length' => 2000, |
|
58 | + ]); |
|
59 | + $table->addColumn('client_identifier', 'string', [ |
|
60 | + 'notnull' => true, |
|
61 | + 'length' => 64, |
|
62 | + ]); |
|
63 | + $table->addColumn('secret', 'string', [ |
|
64 | + 'notnull' => true, |
|
65 | + 'length' => 64, |
|
66 | + ]); |
|
67 | + $table->setPrimaryKey(['id']); |
|
68 | + $table->addIndex(['client_identifier'], 'oauth2_client_id_idx'); |
|
69 | + } |
|
70 | 70 | |
71 | - if (!$schema->hasTable('oauth2_access_tokens')) { |
|
72 | - $table = $schema->createTable('oauth2_access_tokens'); |
|
73 | - $table->addColumn('id', 'integer', [ |
|
74 | - 'autoincrement' => true, |
|
75 | - 'notnull' => true, |
|
76 | - 'unsigned' => true, |
|
77 | - ]); |
|
78 | - $table->addColumn('token_id', 'integer', [ |
|
79 | - 'notnull' => true, |
|
80 | - ]); |
|
81 | - $table->addColumn('client_id', 'integer', [ |
|
82 | - 'notnull' => true, |
|
83 | - ]); |
|
84 | - $table->addColumn('hashed_code', 'string', [ |
|
85 | - 'notnull' => true, |
|
86 | - 'length' => 128, |
|
87 | - ]); |
|
88 | - $table->addColumn('encrypted_token', 'string', [ |
|
89 | - 'notnull' => true, |
|
90 | - 'length' => 786, |
|
91 | - ]); |
|
92 | - $table->setPrimaryKey(['id']); |
|
93 | - $table->addUniqueIndex(['hashed_code'], 'oauth2_access_hash_idx'); |
|
94 | - $table->addIndex(['client_id'], 'oauth2_access_client_id_idx'); |
|
95 | - } |
|
96 | - return $schema; |
|
97 | - } |
|
71 | + if (!$schema->hasTable('oauth2_access_tokens')) { |
|
72 | + $table = $schema->createTable('oauth2_access_tokens'); |
|
73 | + $table->addColumn('id', 'integer', [ |
|
74 | + 'autoincrement' => true, |
|
75 | + 'notnull' => true, |
|
76 | + 'unsigned' => true, |
|
77 | + ]); |
|
78 | + $table->addColumn('token_id', 'integer', [ |
|
79 | + 'notnull' => true, |
|
80 | + ]); |
|
81 | + $table->addColumn('client_id', 'integer', [ |
|
82 | + 'notnull' => true, |
|
83 | + ]); |
|
84 | + $table->addColumn('hashed_code', 'string', [ |
|
85 | + 'notnull' => true, |
|
86 | + 'length' => 128, |
|
87 | + ]); |
|
88 | + $table->addColumn('encrypted_token', 'string', [ |
|
89 | + 'notnull' => true, |
|
90 | + 'length' => 786, |
|
91 | + ]); |
|
92 | + $table->setPrimaryKey(['id']); |
|
93 | + $table->addUniqueIndex(['hashed_code'], 'oauth2_access_hash_idx'); |
|
94 | + $table->addIndex(['client_id'], 'oauth2_access_client_id_idx'); |
|
95 | + } |
|
96 | + return $schema; |
|
97 | + } |
|
98 | 98 | } |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | throw new \RuntimeException('no instance id!'); |
76 | 76 | } |
77 | 77 | |
78 | - return 'appdata_' . $instanceId; |
|
78 | + return 'appdata_'.$instanceId; |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | private function getAppDataRootFolder(): Folder { |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | $name = $this->getAppDataFolderName(); |
104 | 104 | |
105 | 105 | try { |
106 | - $this->folder = $this->rootFolder->get($name . '/' . $this->appId); |
|
106 | + $this->folder = $this->rootFolder->get($name.'/'.$this->appId); |
|
107 | 107 | } catch (NotFoundException $e) { |
108 | 108 | $appDataRootFolder = $this->getAppDataRootFolder(); |
109 | 109 | |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | try { |
114 | 114 | $this->folder = $appDataRootFolder->newFolder($this->appId); |
115 | 115 | } catch (NotPermittedException $e) { |
116 | - throw new \RuntimeException('Could not get appdata folder for ' . $this->appId); |
|
116 | + throw new \RuntimeException('Could not get appdata folder for '.$this->appId); |
|
117 | 117 | } |
118 | 118 | } |
119 | 119 | } |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | } |
124 | 124 | |
125 | 125 | public function getFolder(string $name): ISimpleFolder { |
126 | - $key = $this->appId . '/' . $name; |
|
126 | + $key = $this->appId.'/'.$name; |
|
127 | 127 | if ($cachedFolder = $this->folders->get($key)) { |
128 | 128 | if ($cachedFolder instanceof \Exception) { |
129 | 129 | throw $cachedFolder; |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | if ($name === '/') { |
137 | 137 | $node = $this->getAppDataFolder(); |
138 | 138 | } else { |
139 | - $path = $this->getAppDataFolderName() . '/' . $this->appId . '/' . $name; |
|
139 | + $path = $this->getAppDataFolderName().'/'.$this->appId.'/'.$name; |
|
140 | 140 | $node = $this->rootFolder->get($path); |
141 | 141 | } |
142 | 142 | } catch (NotFoundException $e) { |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | } |
152 | 152 | |
153 | 153 | public function newFolder(string $name): ISimpleFolder { |
154 | - $key = $this->appId . '/' . $name; |
|
154 | + $key = $this->appId.'/'.$name; |
|
155 | 155 | $folder = $this->getAppDataFolder()->newFolder($name); |
156 | 156 | |
157 | 157 | $simpleFolder = new SimpleFolder($folder); |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | public function getDirectoryListing(): array { |
163 | 163 | $listing = $this->getAppDataFolder()->getDirectoryListing(); |
164 | 164 | |
165 | - $fileListing = array_map(function (Node $folder) { |
|
165 | + $fileListing = array_map(function(Node $folder) { |
|
166 | 166 | if ($folder instanceof Folder) { |
167 | 167 | return new SimpleFolder($folder); |
168 | 168 | } |
@@ -40,143 +40,143 @@ |
||
40 | 40 | |
41 | 41 | class AppData implements IAppData { |
42 | 42 | |
43 | - /** @var IRootFolder */ |
|
44 | - private $rootFolder; |
|
45 | - |
|
46 | - /** @var SystemConfig */ |
|
47 | - private $config; |
|
48 | - |
|
49 | - /** @var string */ |
|
50 | - private $appId; |
|
51 | - |
|
52 | - /** @var Folder */ |
|
53 | - private $folder; |
|
54 | - |
|
55 | - /** @var (ISimpleFolder|NotFoundException)[]|CappedMemoryCache */ |
|
56 | - private $folders; |
|
57 | - |
|
58 | - /** |
|
59 | - * AppData constructor. |
|
60 | - * |
|
61 | - * @param IRootFolder $rootFolder |
|
62 | - * @param SystemConfig $systemConfig |
|
63 | - * @param string $appId |
|
64 | - */ |
|
65 | - public function __construct(IRootFolder $rootFolder, |
|
66 | - SystemConfig $systemConfig, |
|
67 | - string $appId) { |
|
68 | - $this->rootFolder = $rootFolder; |
|
69 | - $this->config = $systemConfig; |
|
70 | - $this->appId = $appId; |
|
71 | - $this->folders = new CappedMemoryCache(); |
|
72 | - } |
|
73 | - |
|
74 | - private function getAppDataFolderName() { |
|
75 | - $instanceId = $this->config->getValue('instanceid', null); |
|
76 | - if ($instanceId === null) { |
|
77 | - throw new \RuntimeException('no instance id!'); |
|
78 | - } |
|
79 | - |
|
80 | - return 'appdata_' . $instanceId; |
|
81 | - } |
|
82 | - |
|
83 | - private function getAppDataRootFolder(): Folder { |
|
84 | - $name = $this->getAppDataFolderName(); |
|
85 | - |
|
86 | - try { |
|
87 | - /** @var Folder $node */ |
|
88 | - $node = $this->rootFolder->get($name); |
|
89 | - return $node; |
|
90 | - } catch (NotFoundException $e) { |
|
91 | - try { |
|
92 | - return $this->rootFolder->newFolder($name); |
|
93 | - } catch (NotPermittedException $e) { |
|
94 | - throw new \RuntimeException('Could not get appdata folder'); |
|
95 | - } |
|
96 | - } |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * @return Folder |
|
101 | - * @throws \RuntimeException |
|
102 | - */ |
|
103 | - private function getAppDataFolder(): Folder { |
|
104 | - if ($this->folder === null) { |
|
105 | - $name = $this->getAppDataFolderName(); |
|
106 | - |
|
107 | - try { |
|
108 | - $this->folder = $this->rootFolder->get($name . '/' . $this->appId); |
|
109 | - } catch (NotFoundException $e) { |
|
110 | - $appDataRootFolder = $this->getAppDataRootFolder(); |
|
111 | - |
|
112 | - try { |
|
113 | - $this->folder = $appDataRootFolder->get($this->appId); |
|
114 | - } catch (NotFoundException $e) { |
|
115 | - try { |
|
116 | - $this->folder = $appDataRootFolder->newFolder($this->appId); |
|
117 | - } catch (NotPermittedException $e) { |
|
118 | - throw new \RuntimeException('Could not get appdata folder for ' . $this->appId); |
|
119 | - } |
|
120 | - } |
|
121 | - } |
|
122 | - } |
|
123 | - |
|
124 | - return $this->folder; |
|
125 | - } |
|
126 | - |
|
127 | - public function getFolder(string $name): ISimpleFolder { |
|
128 | - $key = $this->appId . '/' . $name; |
|
129 | - if ($cachedFolder = $this->folders->get($key)) { |
|
130 | - if ($cachedFolder instanceof \Exception) { |
|
131 | - throw $cachedFolder; |
|
132 | - } else { |
|
133 | - return $cachedFolder; |
|
134 | - } |
|
135 | - } |
|
136 | - try { |
|
137 | - // Hardening if somebody wants to retrieve '/' |
|
138 | - if ($name === '/') { |
|
139 | - $node = $this->getAppDataFolder(); |
|
140 | - } else { |
|
141 | - $path = $this->getAppDataFolderName() . '/' . $this->appId . '/' . $name; |
|
142 | - $node = $this->rootFolder->get($path); |
|
143 | - } |
|
144 | - } catch (NotFoundException $e) { |
|
145 | - $this->folders->set($key, $e); |
|
146 | - throw $e; |
|
147 | - } |
|
148 | - |
|
149 | - /** @var Folder $node */ |
|
150 | - $folder = new SimpleFolder($node); |
|
151 | - $this->folders->set($key, $folder); |
|
152 | - return $folder; |
|
153 | - } |
|
154 | - |
|
155 | - public function newFolder(string $name): ISimpleFolder { |
|
156 | - $key = $this->appId . '/' . $name; |
|
157 | - $folder = $this->getAppDataFolder()->newFolder($name); |
|
158 | - |
|
159 | - $simpleFolder = new SimpleFolder($folder); |
|
160 | - $this->folders->set($key, $simpleFolder); |
|
161 | - return $simpleFolder; |
|
162 | - } |
|
163 | - |
|
164 | - public function getDirectoryListing(): array { |
|
165 | - $listing = $this->getAppDataFolder()->getDirectoryListing(); |
|
166 | - |
|
167 | - $fileListing = array_map(function (Node $folder) { |
|
168 | - if ($folder instanceof Folder) { |
|
169 | - return new SimpleFolder($folder); |
|
170 | - } |
|
171 | - return null; |
|
172 | - }, $listing); |
|
173 | - |
|
174 | - $fileListing = array_filter($fileListing); |
|
175 | - |
|
176 | - return array_values($fileListing); |
|
177 | - } |
|
178 | - |
|
179 | - public function getId(): int { |
|
180 | - return $this->getAppDataFolder()->getId(); |
|
181 | - } |
|
43 | + /** @var IRootFolder */ |
|
44 | + private $rootFolder; |
|
45 | + |
|
46 | + /** @var SystemConfig */ |
|
47 | + private $config; |
|
48 | + |
|
49 | + /** @var string */ |
|
50 | + private $appId; |
|
51 | + |
|
52 | + /** @var Folder */ |
|
53 | + private $folder; |
|
54 | + |
|
55 | + /** @var (ISimpleFolder|NotFoundException)[]|CappedMemoryCache */ |
|
56 | + private $folders; |
|
57 | + |
|
58 | + /** |
|
59 | + * AppData constructor. |
|
60 | + * |
|
61 | + * @param IRootFolder $rootFolder |
|
62 | + * @param SystemConfig $systemConfig |
|
63 | + * @param string $appId |
|
64 | + */ |
|
65 | + public function __construct(IRootFolder $rootFolder, |
|
66 | + SystemConfig $systemConfig, |
|
67 | + string $appId) { |
|
68 | + $this->rootFolder = $rootFolder; |
|
69 | + $this->config = $systemConfig; |
|
70 | + $this->appId = $appId; |
|
71 | + $this->folders = new CappedMemoryCache(); |
|
72 | + } |
|
73 | + |
|
74 | + private function getAppDataFolderName() { |
|
75 | + $instanceId = $this->config->getValue('instanceid', null); |
|
76 | + if ($instanceId === null) { |
|
77 | + throw new \RuntimeException('no instance id!'); |
|
78 | + } |
|
79 | + |
|
80 | + return 'appdata_' . $instanceId; |
|
81 | + } |
|
82 | + |
|
83 | + private function getAppDataRootFolder(): Folder { |
|
84 | + $name = $this->getAppDataFolderName(); |
|
85 | + |
|
86 | + try { |
|
87 | + /** @var Folder $node */ |
|
88 | + $node = $this->rootFolder->get($name); |
|
89 | + return $node; |
|
90 | + } catch (NotFoundException $e) { |
|
91 | + try { |
|
92 | + return $this->rootFolder->newFolder($name); |
|
93 | + } catch (NotPermittedException $e) { |
|
94 | + throw new \RuntimeException('Could not get appdata folder'); |
|
95 | + } |
|
96 | + } |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * @return Folder |
|
101 | + * @throws \RuntimeException |
|
102 | + */ |
|
103 | + private function getAppDataFolder(): Folder { |
|
104 | + if ($this->folder === null) { |
|
105 | + $name = $this->getAppDataFolderName(); |
|
106 | + |
|
107 | + try { |
|
108 | + $this->folder = $this->rootFolder->get($name . '/' . $this->appId); |
|
109 | + } catch (NotFoundException $e) { |
|
110 | + $appDataRootFolder = $this->getAppDataRootFolder(); |
|
111 | + |
|
112 | + try { |
|
113 | + $this->folder = $appDataRootFolder->get($this->appId); |
|
114 | + } catch (NotFoundException $e) { |
|
115 | + try { |
|
116 | + $this->folder = $appDataRootFolder->newFolder($this->appId); |
|
117 | + } catch (NotPermittedException $e) { |
|
118 | + throw new \RuntimeException('Could not get appdata folder for ' . $this->appId); |
|
119 | + } |
|
120 | + } |
|
121 | + } |
|
122 | + } |
|
123 | + |
|
124 | + return $this->folder; |
|
125 | + } |
|
126 | + |
|
127 | + public function getFolder(string $name): ISimpleFolder { |
|
128 | + $key = $this->appId . '/' . $name; |
|
129 | + if ($cachedFolder = $this->folders->get($key)) { |
|
130 | + if ($cachedFolder instanceof \Exception) { |
|
131 | + throw $cachedFolder; |
|
132 | + } else { |
|
133 | + return $cachedFolder; |
|
134 | + } |
|
135 | + } |
|
136 | + try { |
|
137 | + // Hardening if somebody wants to retrieve '/' |
|
138 | + if ($name === '/') { |
|
139 | + $node = $this->getAppDataFolder(); |
|
140 | + } else { |
|
141 | + $path = $this->getAppDataFolderName() . '/' . $this->appId . '/' . $name; |
|
142 | + $node = $this->rootFolder->get($path); |
|
143 | + } |
|
144 | + } catch (NotFoundException $e) { |
|
145 | + $this->folders->set($key, $e); |
|
146 | + throw $e; |
|
147 | + } |
|
148 | + |
|
149 | + /** @var Folder $node */ |
|
150 | + $folder = new SimpleFolder($node); |
|
151 | + $this->folders->set($key, $folder); |
|
152 | + return $folder; |
|
153 | + } |
|
154 | + |
|
155 | + public function newFolder(string $name): ISimpleFolder { |
|
156 | + $key = $this->appId . '/' . $name; |
|
157 | + $folder = $this->getAppDataFolder()->newFolder($name); |
|
158 | + |
|
159 | + $simpleFolder = new SimpleFolder($folder); |
|
160 | + $this->folders->set($key, $simpleFolder); |
|
161 | + return $simpleFolder; |
|
162 | + } |
|
163 | + |
|
164 | + public function getDirectoryListing(): array { |
|
165 | + $listing = $this->getAppDataFolder()->getDirectoryListing(); |
|
166 | + |
|
167 | + $fileListing = array_map(function (Node $folder) { |
|
168 | + if ($folder instanceof Folder) { |
|
169 | + return new SimpleFolder($folder); |
|
170 | + } |
|
171 | + return null; |
|
172 | + }, $listing); |
|
173 | + |
|
174 | + $fileListing = array_filter($fileListing); |
|
175 | + |
|
176 | + return array_values($fileListing); |
|
177 | + } |
|
178 | + |
|
179 | + public function getId(): int { |
|
180 | + return $this->getAppDataFolder()->getId(); |
|
181 | + } |
|
182 | 182 | } |