@@ -78,7 +78,7 @@ |
||
78 | 78 | $olderVersions = $ms->getMigratedVersions(); |
79 | 79 | $olderVersions[] = '0'; |
80 | 80 | $olderVersions[] = 'prev'; |
81 | - if (in_array($version, $olderVersions, true)) { |
|
81 | + if (in_array($version, $olderVersions, true)) { |
|
82 | 82 | $output->writeln('<error>Can not go back to previous migration without debug enabled</error>'); |
83 | 83 | return 1; |
84 | 84 | } |
@@ -38,95 +38,95 @@ |
||
38 | 38 | |
39 | 39 | class ExecuteCommand extends Command implements CompletionAwareInterface { |
40 | 40 | |
41 | - /** @var IDBConnection */ |
|
42 | - private $connection; |
|
43 | - |
|
44 | - /** @var IConfig */ |
|
45 | - private $config; |
|
46 | - |
|
47 | - /** @var IAppManager */ |
|
48 | - protected $appManager; |
|
49 | - |
|
50 | - /** |
|
51 | - * ExecuteCommand constructor. |
|
52 | - * |
|
53 | - * @param IDBConnection $connection |
|
54 | - * @param IConfig $config |
|
55 | - * @param IAppManager $appManager |
|
56 | - */ |
|
57 | - public function __construct(IDBConnection $connection, IAppManager $appManager, IConfig $config) { |
|
58 | - $this->connection = $connection; |
|
59 | - $this->config = $config; |
|
60 | - |
|
61 | - parent::__construct(); |
|
62 | - } |
|
63 | - |
|
64 | - protected function configure() { |
|
65 | - $this |
|
66 | - ->setName('migrations:execute') |
|
67 | - ->setDescription('Execute a single migration version manually.') |
|
68 | - ->addArgument('app', InputArgument::REQUIRED, 'Name of the app this migration command shall work on') |
|
69 | - ->addArgument('version', InputArgument::REQUIRED, 'The version to execute.', null); |
|
70 | - |
|
71 | - parent::configure(); |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * @param InputInterface $input |
|
76 | - * @param OutputInterface $output |
|
77 | - * @return int |
|
78 | - */ |
|
79 | - public function execute(InputInterface $input, OutputInterface $output) { |
|
80 | - $appName = $input->getArgument('app'); |
|
81 | - $ms = new MigrationService($appName, $this->connection, new ConsoleOutput($output)); |
|
82 | - $version = $input->getArgument('version'); |
|
83 | - |
|
84 | - if ($this->config->getSystemValue('debug', false) === false) { |
|
85 | - $olderVersions = $ms->getMigratedVersions(); |
|
86 | - $olderVersions[] = '0'; |
|
87 | - $olderVersions[] = 'prev'; |
|
88 | - if (in_array($version, $olderVersions, true)) { |
|
89 | - $output->writeln('<error>Can not go back to previous migration without debug enabled</error>'); |
|
90 | - return 1; |
|
91 | - } |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - $ms->executeStep($version); |
|
96 | - return 0; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * @param string $optionName |
|
101 | - * @param CompletionContext $context |
|
102 | - * @return string[] |
|
103 | - */ |
|
104 | - public function completeOptionValues($optionName, CompletionContext $context) { |
|
105 | - return []; |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * @param string $argumentName |
|
110 | - * @param CompletionContext $context |
|
111 | - * @return string[] |
|
112 | - */ |
|
113 | - public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
114 | - if ($argumentName === 'app') { |
|
115 | - $allApps = \OC_App::getAllApps(); |
|
116 | - return array_diff($allApps, \OC_App::getEnabledApps(true, true)); |
|
117 | - } |
|
118 | - |
|
119 | - if ($argumentName === 'version') { |
|
120 | - $appName = $context->getWordAtIndex($context->getWordIndex() - 1); |
|
121 | - |
|
122 | - $ms = new MigrationService($appName, $this->connection); |
|
123 | - $migrations = $ms->getAvailableVersions(); |
|
124 | - |
|
125 | - array_unshift($migrations, 'next', 'latest'); |
|
126 | - return $migrations; |
|
127 | - } |
|
128 | - |
|
129 | - return []; |
|
130 | - } |
|
41 | + /** @var IDBConnection */ |
|
42 | + private $connection; |
|
43 | + |
|
44 | + /** @var IConfig */ |
|
45 | + private $config; |
|
46 | + |
|
47 | + /** @var IAppManager */ |
|
48 | + protected $appManager; |
|
49 | + |
|
50 | + /** |
|
51 | + * ExecuteCommand constructor. |
|
52 | + * |
|
53 | + * @param IDBConnection $connection |
|
54 | + * @param IConfig $config |
|
55 | + * @param IAppManager $appManager |
|
56 | + */ |
|
57 | + public function __construct(IDBConnection $connection, IAppManager $appManager, IConfig $config) { |
|
58 | + $this->connection = $connection; |
|
59 | + $this->config = $config; |
|
60 | + |
|
61 | + parent::__construct(); |
|
62 | + } |
|
63 | + |
|
64 | + protected function configure() { |
|
65 | + $this |
|
66 | + ->setName('migrations:execute') |
|
67 | + ->setDescription('Execute a single migration version manually.') |
|
68 | + ->addArgument('app', InputArgument::REQUIRED, 'Name of the app this migration command shall work on') |
|
69 | + ->addArgument('version', InputArgument::REQUIRED, 'The version to execute.', null); |
|
70 | + |
|
71 | + parent::configure(); |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * @param InputInterface $input |
|
76 | + * @param OutputInterface $output |
|
77 | + * @return int |
|
78 | + */ |
|
79 | + public function execute(InputInterface $input, OutputInterface $output) { |
|
80 | + $appName = $input->getArgument('app'); |
|
81 | + $ms = new MigrationService($appName, $this->connection, new ConsoleOutput($output)); |
|
82 | + $version = $input->getArgument('version'); |
|
83 | + |
|
84 | + if ($this->config->getSystemValue('debug', false) === false) { |
|
85 | + $olderVersions = $ms->getMigratedVersions(); |
|
86 | + $olderVersions[] = '0'; |
|
87 | + $olderVersions[] = 'prev'; |
|
88 | + if (in_array($version, $olderVersions, true)) { |
|
89 | + $output->writeln('<error>Can not go back to previous migration without debug enabled</error>'); |
|
90 | + return 1; |
|
91 | + } |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + $ms->executeStep($version); |
|
96 | + return 0; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * @param string $optionName |
|
101 | + * @param CompletionContext $context |
|
102 | + * @return string[] |
|
103 | + */ |
|
104 | + public function completeOptionValues($optionName, CompletionContext $context) { |
|
105 | + return []; |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * @param string $argumentName |
|
110 | + * @param CompletionContext $context |
|
111 | + * @return string[] |
|
112 | + */ |
|
113 | + public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
114 | + if ($argumentName === 'app') { |
|
115 | + $allApps = \OC_App::getAllApps(); |
|
116 | + return array_diff($allApps, \OC_App::getEnabledApps(true, true)); |
|
117 | + } |
|
118 | + |
|
119 | + if ($argumentName === 'version') { |
|
120 | + $appName = $context->getWordAtIndex($context->getWordIndex() - 1); |
|
121 | + |
|
122 | + $ms = new MigrationService($appName, $this->connection); |
|
123 | + $migrations = $ms->getAvailableVersions(); |
|
124 | + |
|
125 | + array_unshift($migrations, 'next', 'latest'); |
|
126 | + return $migrations; |
|
127 | + } |
|
128 | + |
|
129 | + return []; |
|
130 | + } |
|
131 | 131 | |
132 | 132 | } |
@@ -26,80 +26,80 @@ |
||
26 | 26 | namespace OC\DB; |
27 | 27 | |
28 | 28 | class OracleConnection extends Connection { |
29 | - /** |
|
30 | - * Quote the keys of the array |
|
31 | - */ |
|
32 | - private function quoteKeys(array $data) { |
|
33 | - $return = []; |
|
34 | - $c = $this->getDatabasePlatform()->getIdentifierQuoteCharacter(); |
|
35 | - foreach($data as $key => $value) { |
|
36 | - if ($key[0] !== $c) { |
|
37 | - $return[$this->quoteIdentifier($key)] = $value; |
|
38 | - } else { |
|
39 | - $return[$key] = $value; |
|
40 | - } |
|
41 | - } |
|
42 | - return $return; |
|
43 | - } |
|
29 | + /** |
|
30 | + * Quote the keys of the array |
|
31 | + */ |
|
32 | + private function quoteKeys(array $data) { |
|
33 | + $return = []; |
|
34 | + $c = $this->getDatabasePlatform()->getIdentifierQuoteCharacter(); |
|
35 | + foreach($data as $key => $value) { |
|
36 | + if ($key[0] !== $c) { |
|
37 | + $return[$this->quoteIdentifier($key)] = $value; |
|
38 | + } else { |
|
39 | + $return[$key] = $value; |
|
40 | + } |
|
41 | + } |
|
42 | + return $return; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * {@inheritDoc} |
|
47 | - */ |
|
48 | - public function insert($tableName, array $data, array $types = array()) { |
|
49 | - if ($tableName[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
50 | - $tableName = $this->quoteIdentifier($tableName); |
|
51 | - } |
|
52 | - $data = $this->quoteKeys($data); |
|
53 | - return parent::insert($tableName, $data, $types); |
|
54 | - } |
|
45 | + /** |
|
46 | + * {@inheritDoc} |
|
47 | + */ |
|
48 | + public function insert($tableName, array $data, array $types = array()) { |
|
49 | + if ($tableName[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
50 | + $tableName = $this->quoteIdentifier($tableName); |
|
51 | + } |
|
52 | + $data = $this->quoteKeys($data); |
|
53 | + return parent::insert($tableName, $data, $types); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * {@inheritDoc} |
|
58 | - */ |
|
59 | - public function update($tableName, array $data, array $identifier, array $types = array()) { |
|
60 | - if ($tableName[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
61 | - $tableName = $this->quoteIdentifier($tableName); |
|
62 | - } |
|
63 | - $data = $this->quoteKeys($data); |
|
64 | - $identifier = $this->quoteKeys($identifier); |
|
65 | - return parent::update($tableName, $data, $identifier, $types); |
|
66 | - } |
|
56 | + /** |
|
57 | + * {@inheritDoc} |
|
58 | + */ |
|
59 | + public function update($tableName, array $data, array $identifier, array $types = array()) { |
|
60 | + if ($tableName[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
61 | + $tableName = $this->quoteIdentifier($tableName); |
|
62 | + } |
|
63 | + $data = $this->quoteKeys($data); |
|
64 | + $identifier = $this->quoteKeys($identifier); |
|
65 | + return parent::update($tableName, $data, $identifier, $types); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * {@inheritDoc} |
|
70 | - */ |
|
71 | - public function delete($tableExpression, array $identifier, array $types = array()) { |
|
72 | - if ($tableExpression[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
73 | - $tableExpression = $this->quoteIdentifier($tableExpression); |
|
74 | - } |
|
75 | - $identifier = $this->quoteKeys($identifier); |
|
76 | - return parent::delete($tableExpression, $identifier); |
|
77 | - } |
|
68 | + /** |
|
69 | + * {@inheritDoc} |
|
70 | + */ |
|
71 | + public function delete($tableExpression, array $identifier, array $types = array()) { |
|
72 | + if ($tableExpression[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
73 | + $tableExpression = $this->quoteIdentifier($tableExpression); |
|
74 | + } |
|
75 | + $identifier = $this->quoteKeys($identifier); |
|
76 | + return parent::delete($tableExpression, $identifier); |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * Drop a table from the database if it exists |
|
81 | - * |
|
82 | - * @param string $table table name without the prefix |
|
83 | - */ |
|
84 | - public function dropTable($table) { |
|
85 | - $table = $this->tablePrefix . trim($table); |
|
86 | - $table = $this->quoteIdentifier($table); |
|
87 | - $schema = $this->getSchemaManager(); |
|
88 | - if($schema->tablesExist(array($table))) { |
|
89 | - $schema->dropTable($table); |
|
90 | - } |
|
91 | - } |
|
79 | + /** |
|
80 | + * Drop a table from the database if it exists |
|
81 | + * |
|
82 | + * @param string $table table name without the prefix |
|
83 | + */ |
|
84 | + public function dropTable($table) { |
|
85 | + $table = $this->tablePrefix . trim($table); |
|
86 | + $table = $this->quoteIdentifier($table); |
|
87 | + $schema = $this->getSchemaManager(); |
|
88 | + if($schema->tablesExist(array($table))) { |
|
89 | + $schema->dropTable($table); |
|
90 | + } |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * Check if a table exists |
|
95 | - * |
|
96 | - * @param string $table table name without the prefix |
|
97 | - * @return bool |
|
98 | - */ |
|
99 | - public function tableExists($table){ |
|
100 | - $table = $this->tablePrefix . trim($table); |
|
101 | - $table = $this->quoteIdentifier($table); |
|
102 | - $schema = $this->getSchemaManager(); |
|
103 | - return $schema->tablesExist(array($table)); |
|
104 | - } |
|
93 | + /** |
|
94 | + * Check if a table exists |
|
95 | + * |
|
96 | + * @param string $table table name without the prefix |
|
97 | + * @return bool |
|
98 | + */ |
|
99 | + public function tableExists($table){ |
|
100 | + $table = $this->tablePrefix . trim($table); |
|
101 | + $table = $this->quoteIdentifier($table); |
|
102 | + $schema = $this->getSchemaManager(); |
|
103 | + return $schema->tablesExist(array($table)); |
|
104 | + } |
|
105 | 105 | } |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | private function quoteKeys(array $data) { |
33 | 33 | $return = []; |
34 | 34 | $c = $this->getDatabasePlatform()->getIdentifierQuoteCharacter(); |
35 | - foreach($data as $key => $value) { |
|
35 | + foreach ($data as $key => $value) { |
|
36 | 36 | if ($key[0] !== $c) { |
37 | 37 | $return[$this->quoteIdentifier($key)] = $value; |
38 | 38 | } else { |
@@ -82,10 +82,10 @@ discard block |
||
82 | 82 | * @param string $table table name without the prefix |
83 | 83 | */ |
84 | 84 | public function dropTable($table) { |
85 | - $table = $this->tablePrefix . trim($table); |
|
85 | + $table = $this->tablePrefix.trim($table); |
|
86 | 86 | $table = $this->quoteIdentifier($table); |
87 | 87 | $schema = $this->getSchemaManager(); |
88 | - if($schema->tablesExist(array($table))) { |
|
88 | + if ($schema->tablesExist(array($table))) { |
|
89 | 89 | $schema->dropTable($table); |
90 | 90 | } |
91 | 91 | } |
@@ -96,8 +96,8 @@ discard block |
||
96 | 96 | * @param string $table table name without the prefix |
97 | 97 | * @return bool |
98 | 98 | */ |
99 | - public function tableExists($table){ |
|
100 | - $table = $this->tablePrefix . trim($table); |
|
99 | + public function tableExists($table) { |
|
100 | + $table = $this->tablePrefix.trim($table); |
|
101 | 101 | $table = $this->quoteIdentifier($table); |
102 | 102 | $schema = $this->getSchemaManager(); |
103 | 103 | return $schema->tablesExist(array($table)); |
@@ -36,49 +36,49 @@ |
||
36 | 36 | */ |
37 | 37 | class SimpleOutput implements IOutput { |
38 | 38 | |
39 | - /** @var ILogger */ |
|
40 | - private $logger; |
|
41 | - private $appName; |
|
39 | + /** @var ILogger */ |
|
40 | + private $logger; |
|
41 | + private $appName; |
|
42 | 42 | |
43 | - public function __construct(ILogger $logger, $appName) { |
|
44 | - $this->logger = $logger; |
|
45 | - $this->appName = $appName; |
|
46 | - } |
|
43 | + public function __construct(ILogger $logger, $appName) { |
|
44 | + $this->logger = $logger; |
|
45 | + $this->appName = $appName; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @param string $message |
|
50 | - * @since 9.1.0 |
|
51 | - */ |
|
52 | - public function info($message) { |
|
53 | - $this->logger->info($message, ['app' => $this->appName]); |
|
54 | - } |
|
48 | + /** |
|
49 | + * @param string $message |
|
50 | + * @since 9.1.0 |
|
51 | + */ |
|
52 | + public function info($message) { |
|
53 | + $this->logger->info($message, ['app' => $this->appName]); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * @param string $message |
|
58 | - * @since 9.1.0 |
|
59 | - */ |
|
60 | - public function warning($message) { |
|
61 | - $this->logger->warning($message, ['app' => $this->appName]); |
|
62 | - } |
|
56 | + /** |
|
57 | + * @param string $message |
|
58 | + * @since 9.1.0 |
|
59 | + */ |
|
60 | + public function warning($message) { |
|
61 | + $this->logger->warning($message, ['app' => $this->appName]); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @param int $max |
|
66 | - * @since 9.1.0 |
|
67 | - */ |
|
68 | - public function startProgress($max = 0) { |
|
69 | - } |
|
64 | + /** |
|
65 | + * @param int $max |
|
66 | + * @since 9.1.0 |
|
67 | + */ |
|
68 | + public function startProgress($max = 0) { |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * @param int $step |
|
73 | - * @param string $description |
|
74 | - * @since 9.1.0 |
|
75 | - */ |
|
76 | - public function advance($step = 1, $description = '') { |
|
77 | - } |
|
71 | + /** |
|
72 | + * @param int $step |
|
73 | + * @param string $description |
|
74 | + * @since 9.1.0 |
|
75 | + */ |
|
76 | + public function advance($step = 1, $description = '') { |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * @since 9.1.0 |
|
81 | - */ |
|
82 | - public function finishProgress() { |
|
83 | - } |
|
79 | + /** |
|
80 | + * @since 9.1.0 |
|
81 | + */ |
|
82 | + public function finishProgress() { |
|
83 | + } |
|
84 | 84 | } |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * @throws \Doctrine\DBAL\Schema\SchemaException |
81 | 81 | */ |
82 | 82 | public function getTable($tableName) { |
83 | - return $this->schema->getTable($this->connection->getPrefix() . $tableName); |
|
83 | + return $this->schema->getTable($this->connection->getPrefix().$tableName); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | * @return boolean |
92 | 92 | */ |
93 | 93 | public function hasTable($tableName) { |
94 | - return $this->schema->hasTable($this->connection->getPrefix() . $tableName); |
|
94 | + return $this->schema->hasTable($this->connection->getPrefix().$tableName); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | * @return \Doctrine\DBAL\Schema\Table |
102 | 102 | */ |
103 | 103 | public function createTable($tableName) { |
104 | - return $this->schema->createTable($this->connection->getPrefix() . $tableName); |
|
104 | + return $this->schema->createTable($this->connection->getPrefix().$tableName); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | */ |
126 | 126 | public function dropTable($tableName) { |
127 | 127 | $this->tablesToDelete[$tableName] = true; |
128 | - return $this->schema->dropTable($this->connection->getPrefix() . $tableName); |
|
128 | + return $this->schema->dropTable($this->connection->getPrefix().$tableName); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -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 | } |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | } |
111 | 111 | |
112 | 112 | public function getACL() { |
113 | - $acl = [ |
|
113 | + $acl = [ |
|
114 | 114 | [ |
115 | 115 | 'privilege' => '{DAV:}read', |
116 | 116 | 'principal' => $this->getOwner(), |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | } |
132 | 132 | |
133 | 133 | if ($this->getOwner() !== parent::getOwner()) { |
134 | - $acl[] = [ |
|
134 | + $acl[] = [ |
|
135 | 135 | 'privilege' => '{DAV:}read', |
136 | 136 | 'principal' => parent::getOwner(), |
137 | 137 | 'protected' => true, |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | public function delete() { |
179 | 179 | if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal']) && |
180 | 180 | $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']) { |
181 | - $principal = 'principal:' . parent::getOwner(); |
|
181 | + $principal = 'principal:'.parent::getOwner(); |
|
182 | 182 | $shares = $this->caldavBackend->getShares($this->getResourceId()); |
183 | 183 | $shares = array_filter($shares, function($share) use ($principal){ |
184 | 184 | return $share['href'] === $principal; |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | |
268 | 268 | $uris = $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters); |
269 | 269 | if ($this->isShared()) { |
270 | - return array_filter($uris, function ($uri) { |
|
270 | + return array_filter($uris, function($uri) { |
|
271 | 271 | return $this->childExists($uri); |
272 | 272 | }); |
273 | 273 | } |
@@ -42,301 +42,301 @@ |
||
42 | 42 | */ |
43 | 43 | class Calendar extends \Sabre\CalDAV\Calendar implements IShareable { |
44 | 44 | |
45 | - /** @var IConfig */ |
|
46 | - private $config; |
|
47 | - |
|
48 | - public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n, IConfig $config) { |
|
49 | - parent::__construct($caldavBackend, $calendarInfo); |
|
50 | - |
|
51 | - if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) { |
|
52 | - $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Contact birthdays'); |
|
53 | - } |
|
54 | - if ($this->getName() === CalDavBackend::PERSONAL_CALENDAR_URI && |
|
55 | - $this->calendarInfo['{DAV:}displayname'] === CalDavBackend::PERSONAL_CALENDAR_NAME) { |
|
56 | - $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Personal'); |
|
57 | - } |
|
58 | - |
|
59 | - $this->config = $config; |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Updates the list of shares. |
|
64 | - * |
|
65 | - * The first array is a list of people that are to be added to the |
|
66 | - * resource. |
|
67 | - * |
|
68 | - * Every element in the add array has the following properties: |
|
69 | - * * href - A url. Usually a mailto: address |
|
70 | - * * commonName - Usually a first and last name, or false |
|
71 | - * * summary - A description of the share, can also be false |
|
72 | - * * readOnly - A boolean value |
|
73 | - * |
|
74 | - * Every element in the remove array is just the address string. |
|
75 | - * |
|
76 | - * @param array $add |
|
77 | - * @param array $remove |
|
78 | - * @return void |
|
79 | - * @throws Forbidden |
|
80 | - */ |
|
81 | - public function updateShares(array $add, array $remove) { |
|
82 | - if ($this->isShared()) { |
|
83 | - throw new Forbidden(); |
|
84 | - } |
|
85 | - $this->caldavBackend->updateShares($this, $add, $remove); |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Returns the list of people whom this resource is shared with. |
|
90 | - * |
|
91 | - * Every element in this array should have the following properties: |
|
92 | - * * href - Often a mailto: address |
|
93 | - * * commonName - Optional, for example a first + last name |
|
94 | - * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
95 | - * * readOnly - boolean |
|
96 | - * * summary - Optional, a description for the share |
|
97 | - * |
|
98 | - * @return array |
|
99 | - */ |
|
100 | - public function getShares() { |
|
101 | - if ($this->isShared()) { |
|
102 | - return []; |
|
103 | - } |
|
104 | - return $this->caldavBackend->getShares($this->getResourceId()); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @return int |
|
109 | - */ |
|
110 | - public function getResourceId() { |
|
111 | - return $this->calendarInfo['id']; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * @return string |
|
116 | - */ |
|
117 | - public function getPrincipalURI() { |
|
118 | - return $this->calendarInfo['principaluri']; |
|
119 | - } |
|
120 | - |
|
121 | - public function getACL() { |
|
122 | - $acl = [ |
|
123 | - [ |
|
124 | - 'privilege' => '{DAV:}read', |
|
125 | - 'principal' => $this->getOwner(), |
|
126 | - 'protected' => true, |
|
127 | - ]]; |
|
128 | - if ($this->getName() !== BirthdayService::BIRTHDAY_CALENDAR_URI) { |
|
129 | - $acl[] = [ |
|
130 | - 'privilege' => '{DAV:}write', |
|
131 | - 'principal' => $this->getOwner(), |
|
132 | - 'protected' => true, |
|
133 | - ]; |
|
134 | - } else { |
|
135 | - $acl[] = [ |
|
136 | - 'privilege' => '{DAV:}write-properties', |
|
137 | - 'principal' => $this->getOwner(), |
|
138 | - 'protected' => true, |
|
139 | - ]; |
|
140 | - } |
|
141 | - |
|
142 | - if (!$this->isShared()) { |
|
143 | - return $acl; |
|
144 | - } |
|
145 | - |
|
146 | - if ($this->getOwner() !== parent::getOwner()) { |
|
147 | - $acl[] = [ |
|
148 | - 'privilege' => '{DAV:}read', |
|
149 | - 'principal' => parent::getOwner(), |
|
150 | - 'protected' => true, |
|
151 | - ]; |
|
152 | - if ($this->canWrite()) { |
|
153 | - $acl[] = [ |
|
154 | - 'privilege' => '{DAV:}write', |
|
155 | - 'principal' => parent::getOwner(), |
|
156 | - 'protected' => true, |
|
157 | - ]; |
|
158 | - } else { |
|
159 | - $acl[] = [ |
|
160 | - 'privilege' => '{DAV:}write-properties', |
|
161 | - 'principal' => parent::getOwner(), |
|
162 | - 'protected' => true, |
|
163 | - ]; |
|
164 | - } |
|
165 | - } |
|
166 | - if ($this->isPublic()) { |
|
167 | - $acl[] = [ |
|
168 | - 'privilege' => '{DAV:}read', |
|
169 | - 'principal' => 'principals/system/public', |
|
170 | - 'protected' => true, |
|
171 | - ]; |
|
172 | - } |
|
173 | - |
|
174 | - $acl = $this->caldavBackend->applyShareAcl($this->getResourceId(), $acl); |
|
175 | - $allowedPrincipals = [$this->getOwner(), parent::getOwner(), 'principals/system/public']; |
|
176 | - return array_filter($acl, function($rule) use ($allowedPrincipals) { |
|
177 | - return \in_array($rule['principal'], $allowedPrincipals, true); |
|
178 | - }); |
|
179 | - } |
|
180 | - |
|
181 | - public function getChildACL() { |
|
182 | - return $this->getACL(); |
|
183 | - } |
|
184 | - |
|
185 | - public function getOwner() { |
|
186 | - if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
187 | - return $this->calendarInfo['{http://owncloud.org/ns}owner-principal']; |
|
188 | - } |
|
189 | - return parent::getOwner(); |
|
190 | - } |
|
191 | - |
|
192 | - public function delete() { |
|
193 | - if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal']) && |
|
194 | - $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']) { |
|
195 | - $principal = 'principal:' . parent::getOwner(); |
|
196 | - $shares = $this->caldavBackend->getShares($this->getResourceId()); |
|
197 | - $shares = array_filter($shares, function($share) use ($principal){ |
|
198 | - return $share['href'] === $principal; |
|
199 | - }); |
|
200 | - if (empty($shares)) { |
|
201 | - throw new Forbidden(); |
|
202 | - } |
|
203 | - |
|
204 | - $this->caldavBackend->updateShares($this, [], [ |
|
205 | - $principal |
|
206 | - ]); |
|
207 | - return; |
|
208 | - } |
|
209 | - |
|
210 | - // Remember when a user deleted their birthday calendar |
|
211 | - // in order to not regenerate it on the next contacts change |
|
212 | - if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) { |
|
213 | - $principalURI = $this->getPrincipalURI(); |
|
214 | - $userId = substr($principalURI, 17); |
|
215 | - |
|
216 | - $this->config->setUserValue($userId, 'dav', 'generateBirthdayCalendar', 'no'); |
|
217 | - } |
|
218 | - |
|
219 | - parent::delete(); |
|
220 | - } |
|
221 | - |
|
222 | - public function propPatch(PropPatch $propPatch) { |
|
223 | - // parent::propPatch will only update calendars table |
|
224 | - // if calendar is shared, changes have to be made to the properties table |
|
225 | - if (!$this->isShared()) { |
|
226 | - parent::propPatch($propPatch); |
|
227 | - } |
|
228 | - } |
|
229 | - |
|
230 | - public function getChild($name) { |
|
231 | - |
|
232 | - $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name); |
|
233 | - |
|
234 | - if (!$obj) { |
|
235 | - throw new NotFound('Calendar object not found'); |
|
236 | - } |
|
237 | - |
|
238 | - if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { |
|
239 | - throw new NotFound('Calendar object not found'); |
|
240 | - } |
|
241 | - |
|
242 | - $obj['acl'] = $this->getChildACL(); |
|
243 | - |
|
244 | - return new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
245 | - |
|
246 | - } |
|
247 | - |
|
248 | - public function getChildren() { |
|
249 | - |
|
250 | - $objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id']); |
|
251 | - $children = []; |
|
252 | - foreach ($objs as $obj) { |
|
253 | - if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { |
|
254 | - continue; |
|
255 | - } |
|
256 | - $obj['acl'] = $this->getChildACL(); |
|
257 | - $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
258 | - } |
|
259 | - return $children; |
|
260 | - |
|
261 | - } |
|
262 | - |
|
263 | - public function getMultipleChildren(array $paths) { |
|
264 | - |
|
265 | - $objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths); |
|
266 | - $children = []; |
|
267 | - foreach ($objs as $obj) { |
|
268 | - if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { |
|
269 | - continue; |
|
270 | - } |
|
271 | - $obj['acl'] = $this->getChildACL(); |
|
272 | - $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
273 | - } |
|
274 | - return $children; |
|
275 | - |
|
276 | - } |
|
277 | - |
|
278 | - public function childExists($name) { |
|
279 | - $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name); |
|
280 | - if (!$obj) { |
|
281 | - return false; |
|
282 | - } |
|
283 | - if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { |
|
284 | - return false; |
|
285 | - } |
|
286 | - |
|
287 | - return true; |
|
288 | - } |
|
289 | - |
|
290 | - public function calendarQuery(array $filters) { |
|
291 | - |
|
292 | - $uris = $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters); |
|
293 | - if ($this->isShared()) { |
|
294 | - return array_filter($uris, function ($uri) { |
|
295 | - return $this->childExists($uri); |
|
296 | - }); |
|
297 | - } |
|
298 | - |
|
299 | - return $uris; |
|
300 | - } |
|
301 | - |
|
302 | - /** |
|
303 | - * @param boolean $value |
|
304 | - * @return string|null |
|
305 | - */ |
|
306 | - public function setPublishStatus($value) { |
|
307 | - $publicUri = $this->caldavBackend->setPublishStatus($value, $this); |
|
308 | - $this->calendarInfo['publicuri'] = $publicUri; |
|
309 | - return $publicUri; |
|
310 | - } |
|
311 | - |
|
312 | - /** |
|
313 | - * @return mixed $value |
|
314 | - */ |
|
315 | - public function getPublishStatus() { |
|
316 | - return $this->caldavBackend->getPublishStatus($this); |
|
317 | - } |
|
318 | - |
|
319 | - private function canWrite() { |
|
320 | - if (isset($this->calendarInfo['{http://owncloud.org/ns}read-only'])) { |
|
321 | - return !$this->calendarInfo['{http://owncloud.org/ns}read-only']; |
|
322 | - } |
|
323 | - return true; |
|
324 | - } |
|
325 | - |
|
326 | - private function isPublic() { |
|
327 | - return isset($this->calendarInfo['{http://owncloud.org/ns}public']); |
|
328 | - } |
|
329 | - |
|
330 | - protected function isShared() { |
|
331 | - if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
332 | - return false; |
|
333 | - } |
|
334 | - |
|
335 | - return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']; |
|
336 | - } |
|
337 | - |
|
338 | - public function isSubscription() { |
|
339 | - return isset($this->calendarInfo['{http://calendarserver.org/ns/}source']); |
|
340 | - } |
|
45 | + /** @var IConfig */ |
|
46 | + private $config; |
|
47 | + |
|
48 | + public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n, IConfig $config) { |
|
49 | + parent::__construct($caldavBackend, $calendarInfo); |
|
50 | + |
|
51 | + if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) { |
|
52 | + $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Contact birthdays'); |
|
53 | + } |
|
54 | + if ($this->getName() === CalDavBackend::PERSONAL_CALENDAR_URI && |
|
55 | + $this->calendarInfo['{DAV:}displayname'] === CalDavBackend::PERSONAL_CALENDAR_NAME) { |
|
56 | + $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Personal'); |
|
57 | + } |
|
58 | + |
|
59 | + $this->config = $config; |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Updates the list of shares. |
|
64 | + * |
|
65 | + * The first array is a list of people that are to be added to the |
|
66 | + * resource. |
|
67 | + * |
|
68 | + * Every element in the add array has the following properties: |
|
69 | + * * href - A url. Usually a mailto: address |
|
70 | + * * commonName - Usually a first and last name, or false |
|
71 | + * * summary - A description of the share, can also be false |
|
72 | + * * readOnly - A boolean value |
|
73 | + * |
|
74 | + * Every element in the remove array is just the address string. |
|
75 | + * |
|
76 | + * @param array $add |
|
77 | + * @param array $remove |
|
78 | + * @return void |
|
79 | + * @throws Forbidden |
|
80 | + */ |
|
81 | + public function updateShares(array $add, array $remove) { |
|
82 | + if ($this->isShared()) { |
|
83 | + throw new Forbidden(); |
|
84 | + } |
|
85 | + $this->caldavBackend->updateShares($this, $add, $remove); |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Returns the list of people whom this resource is shared with. |
|
90 | + * |
|
91 | + * Every element in this array should have the following properties: |
|
92 | + * * href - Often a mailto: address |
|
93 | + * * commonName - Optional, for example a first + last name |
|
94 | + * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
95 | + * * readOnly - boolean |
|
96 | + * * summary - Optional, a description for the share |
|
97 | + * |
|
98 | + * @return array |
|
99 | + */ |
|
100 | + public function getShares() { |
|
101 | + if ($this->isShared()) { |
|
102 | + return []; |
|
103 | + } |
|
104 | + return $this->caldavBackend->getShares($this->getResourceId()); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @return int |
|
109 | + */ |
|
110 | + public function getResourceId() { |
|
111 | + return $this->calendarInfo['id']; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * @return string |
|
116 | + */ |
|
117 | + public function getPrincipalURI() { |
|
118 | + return $this->calendarInfo['principaluri']; |
|
119 | + } |
|
120 | + |
|
121 | + public function getACL() { |
|
122 | + $acl = [ |
|
123 | + [ |
|
124 | + 'privilege' => '{DAV:}read', |
|
125 | + 'principal' => $this->getOwner(), |
|
126 | + 'protected' => true, |
|
127 | + ]]; |
|
128 | + if ($this->getName() !== BirthdayService::BIRTHDAY_CALENDAR_URI) { |
|
129 | + $acl[] = [ |
|
130 | + 'privilege' => '{DAV:}write', |
|
131 | + 'principal' => $this->getOwner(), |
|
132 | + 'protected' => true, |
|
133 | + ]; |
|
134 | + } else { |
|
135 | + $acl[] = [ |
|
136 | + 'privilege' => '{DAV:}write-properties', |
|
137 | + 'principal' => $this->getOwner(), |
|
138 | + 'protected' => true, |
|
139 | + ]; |
|
140 | + } |
|
141 | + |
|
142 | + if (!$this->isShared()) { |
|
143 | + return $acl; |
|
144 | + } |
|
145 | + |
|
146 | + if ($this->getOwner() !== parent::getOwner()) { |
|
147 | + $acl[] = [ |
|
148 | + 'privilege' => '{DAV:}read', |
|
149 | + 'principal' => parent::getOwner(), |
|
150 | + 'protected' => true, |
|
151 | + ]; |
|
152 | + if ($this->canWrite()) { |
|
153 | + $acl[] = [ |
|
154 | + 'privilege' => '{DAV:}write', |
|
155 | + 'principal' => parent::getOwner(), |
|
156 | + 'protected' => true, |
|
157 | + ]; |
|
158 | + } else { |
|
159 | + $acl[] = [ |
|
160 | + 'privilege' => '{DAV:}write-properties', |
|
161 | + 'principal' => parent::getOwner(), |
|
162 | + 'protected' => true, |
|
163 | + ]; |
|
164 | + } |
|
165 | + } |
|
166 | + if ($this->isPublic()) { |
|
167 | + $acl[] = [ |
|
168 | + 'privilege' => '{DAV:}read', |
|
169 | + 'principal' => 'principals/system/public', |
|
170 | + 'protected' => true, |
|
171 | + ]; |
|
172 | + } |
|
173 | + |
|
174 | + $acl = $this->caldavBackend->applyShareAcl($this->getResourceId(), $acl); |
|
175 | + $allowedPrincipals = [$this->getOwner(), parent::getOwner(), 'principals/system/public']; |
|
176 | + return array_filter($acl, function($rule) use ($allowedPrincipals) { |
|
177 | + return \in_array($rule['principal'], $allowedPrincipals, true); |
|
178 | + }); |
|
179 | + } |
|
180 | + |
|
181 | + public function getChildACL() { |
|
182 | + return $this->getACL(); |
|
183 | + } |
|
184 | + |
|
185 | + public function getOwner() { |
|
186 | + if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
187 | + return $this->calendarInfo['{http://owncloud.org/ns}owner-principal']; |
|
188 | + } |
|
189 | + return parent::getOwner(); |
|
190 | + } |
|
191 | + |
|
192 | + public function delete() { |
|
193 | + if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal']) && |
|
194 | + $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']) { |
|
195 | + $principal = 'principal:' . parent::getOwner(); |
|
196 | + $shares = $this->caldavBackend->getShares($this->getResourceId()); |
|
197 | + $shares = array_filter($shares, function($share) use ($principal){ |
|
198 | + return $share['href'] === $principal; |
|
199 | + }); |
|
200 | + if (empty($shares)) { |
|
201 | + throw new Forbidden(); |
|
202 | + } |
|
203 | + |
|
204 | + $this->caldavBackend->updateShares($this, [], [ |
|
205 | + $principal |
|
206 | + ]); |
|
207 | + return; |
|
208 | + } |
|
209 | + |
|
210 | + // Remember when a user deleted their birthday calendar |
|
211 | + // in order to not regenerate it on the next contacts change |
|
212 | + if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) { |
|
213 | + $principalURI = $this->getPrincipalURI(); |
|
214 | + $userId = substr($principalURI, 17); |
|
215 | + |
|
216 | + $this->config->setUserValue($userId, 'dav', 'generateBirthdayCalendar', 'no'); |
|
217 | + } |
|
218 | + |
|
219 | + parent::delete(); |
|
220 | + } |
|
221 | + |
|
222 | + public function propPatch(PropPatch $propPatch) { |
|
223 | + // parent::propPatch will only update calendars table |
|
224 | + // if calendar is shared, changes have to be made to the properties table |
|
225 | + if (!$this->isShared()) { |
|
226 | + parent::propPatch($propPatch); |
|
227 | + } |
|
228 | + } |
|
229 | + |
|
230 | + public function getChild($name) { |
|
231 | + |
|
232 | + $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name); |
|
233 | + |
|
234 | + if (!$obj) { |
|
235 | + throw new NotFound('Calendar object not found'); |
|
236 | + } |
|
237 | + |
|
238 | + if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { |
|
239 | + throw new NotFound('Calendar object not found'); |
|
240 | + } |
|
241 | + |
|
242 | + $obj['acl'] = $this->getChildACL(); |
|
243 | + |
|
244 | + return new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
245 | + |
|
246 | + } |
|
247 | + |
|
248 | + public function getChildren() { |
|
249 | + |
|
250 | + $objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id']); |
|
251 | + $children = []; |
|
252 | + foreach ($objs as $obj) { |
|
253 | + if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { |
|
254 | + continue; |
|
255 | + } |
|
256 | + $obj['acl'] = $this->getChildACL(); |
|
257 | + $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
258 | + } |
|
259 | + return $children; |
|
260 | + |
|
261 | + } |
|
262 | + |
|
263 | + public function getMultipleChildren(array $paths) { |
|
264 | + |
|
265 | + $objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths); |
|
266 | + $children = []; |
|
267 | + foreach ($objs as $obj) { |
|
268 | + if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { |
|
269 | + continue; |
|
270 | + } |
|
271 | + $obj['acl'] = $this->getChildACL(); |
|
272 | + $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
273 | + } |
|
274 | + return $children; |
|
275 | + |
|
276 | + } |
|
277 | + |
|
278 | + public function childExists($name) { |
|
279 | + $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name); |
|
280 | + if (!$obj) { |
|
281 | + return false; |
|
282 | + } |
|
283 | + if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { |
|
284 | + return false; |
|
285 | + } |
|
286 | + |
|
287 | + return true; |
|
288 | + } |
|
289 | + |
|
290 | + public function calendarQuery(array $filters) { |
|
291 | + |
|
292 | + $uris = $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters); |
|
293 | + if ($this->isShared()) { |
|
294 | + return array_filter($uris, function ($uri) { |
|
295 | + return $this->childExists($uri); |
|
296 | + }); |
|
297 | + } |
|
298 | + |
|
299 | + return $uris; |
|
300 | + } |
|
301 | + |
|
302 | + /** |
|
303 | + * @param boolean $value |
|
304 | + * @return string|null |
|
305 | + */ |
|
306 | + public function setPublishStatus($value) { |
|
307 | + $publicUri = $this->caldavBackend->setPublishStatus($value, $this); |
|
308 | + $this->calendarInfo['publicuri'] = $publicUri; |
|
309 | + return $publicUri; |
|
310 | + } |
|
311 | + |
|
312 | + /** |
|
313 | + * @return mixed $value |
|
314 | + */ |
|
315 | + public function getPublishStatus() { |
|
316 | + return $this->caldavBackend->getPublishStatus($this); |
|
317 | + } |
|
318 | + |
|
319 | + private function canWrite() { |
|
320 | + if (isset($this->calendarInfo['{http://owncloud.org/ns}read-only'])) { |
|
321 | + return !$this->calendarInfo['{http://owncloud.org/ns}read-only']; |
|
322 | + } |
|
323 | + return true; |
|
324 | + } |
|
325 | + |
|
326 | + private function isPublic() { |
|
327 | + return isset($this->calendarInfo['{http://owncloud.org/ns}public']); |
|
328 | + } |
|
329 | + |
|
330 | + protected function isShared() { |
|
331 | + if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
332 | + return false; |
|
333 | + } |
|
334 | + |
|
335 | + return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']; |
|
336 | + } |
|
337 | + |
|
338 | + public function isSubscription() { |
|
339 | + return isset($this->calendarInfo['{http://calendarserver.org/ns/}source']); |
|
340 | + } |
|
341 | 341 | |
342 | 342 | } |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | $this->config = $config; |
97 | 97 | |
98 | 98 | $this->excludedPaths[] = 'files_encryption'; |
99 | - $this->excludedPaths[] = 'appdata_' . $config->getSystemValue('instanceid', null); |
|
99 | + $this->excludedPaths[] = 'appdata_'.$config->getSystemValue('instanceid', null); |
|
100 | 100 | $this->excludedPaths[] = 'files_external'; |
101 | 101 | } |
102 | 102 | |
@@ -136,12 +136,12 @@ discard block |
||
136 | 136 | * @throws EncryptionHeaderKeyExistsException if header key is already in use |
137 | 137 | */ |
138 | 138 | public function createHeader(array $headerData, IEncryptionModule $encryptionModule) { |
139 | - $header = self::HEADER_START . ':' . self::HEADER_ENCRYPTION_MODULE_KEY . ':' . $encryptionModule->getId() . ':'; |
|
139 | + $header = self::HEADER_START.':'.self::HEADER_ENCRYPTION_MODULE_KEY.':'.$encryptionModule->getId().':'; |
|
140 | 140 | foreach ($headerData as $key => $value) { |
141 | 141 | if (in_array($key, $this->ocHeaderKeys)) { |
142 | 142 | throw new EncryptionHeaderKeyExistsException($key); |
143 | 143 | } |
144 | - $header .= $key . ':' . $value . ':'; |
|
144 | + $header .= $key.':'.$value.':'; |
|
145 | 145 | } |
146 | 146 | $header .= self::HEADER_END; |
147 | 147 | |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | if ($c->getType() === 'dir') { |
173 | 173 | $dirList[] = $c->getPath(); |
174 | 174 | } else { |
175 | - $result[] = $c->getPath(); |
|
175 | + $result[] = $c->getPath(); |
|
176 | 176 | } |
177 | 177 | } |
178 | 178 | |
@@ -249,15 +249,15 @@ discard block |
||
249 | 249 | public function stripPartialFileExtension($path) { |
250 | 250 | $extension = pathinfo($path, PATHINFO_EXTENSION); |
251 | 251 | |
252 | - if ( $extension === 'part') { |
|
252 | + if ($extension === 'part') { |
|
253 | 253 | |
254 | 254 | $newLength = strlen($path) - 5; // 5 = strlen(".part") |
255 | 255 | $fPath = substr($path, 0, $newLength); |
256 | 256 | |
257 | 257 | // if path also contains a transaction id, we remove it too |
258 | 258 | $extension = pathinfo($fPath, PATHINFO_EXTENSION); |
259 | - if(substr($extension, 0, 12) === 'ocTransferId') { // 12 = strlen("ocTransferId") |
|
260 | - $newLength = strlen($fPath) - strlen($extension) -1; |
|
259 | + if (substr($extension, 0, 12) === 'ocTransferId') { // 12 = strlen("ocTransferId") |
|
260 | + $newLength = strlen($fPath) - strlen($extension) - 1; |
|
261 | 261 | $fPath = substr($fPath, 0, $newLength); |
262 | 262 | } |
263 | 263 | return $fPath; |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | if (\OCP\App::isEnabled("files_external")) { |
302 | 302 | $mounts = \OC_Mount_Config::getSystemMountPoints(); |
303 | 303 | foreach ($mounts as $mount) { |
304 | - if (strpos($path, '/files/' . $mount['mountpoint']) === 0) { |
|
304 | + if (strpos($path, '/files/'.$mount['mountpoint']) === 0) { |
|
305 | 305 | if ($this->isMountPointApplicableToUser($mount, $uid)) { |
306 | 306 | return true; |
307 | 307 | } |
@@ -39,374 +39,374 @@ |
||
39 | 39 | |
40 | 40 | class Util { |
41 | 41 | |
42 | - const HEADER_START = 'HBEGIN'; |
|
43 | - const HEADER_END = 'HEND'; |
|
44 | - const HEADER_PADDING_CHAR = '-'; |
|
45 | - |
|
46 | - const HEADER_ENCRYPTION_MODULE_KEY = 'oc_encryption_module'; |
|
47 | - |
|
48 | - /** |
|
49 | - * block size will always be 8192 for a PHP stream |
|
50 | - * @see https://bugs.php.net/bug.php?id=21641 |
|
51 | - * @var integer |
|
52 | - */ |
|
53 | - protected $headerSize = 8192; |
|
54 | - |
|
55 | - /** |
|
56 | - * block size will always be 8192 for a PHP stream |
|
57 | - * @see https://bugs.php.net/bug.php?id=21641 |
|
58 | - * @var integer |
|
59 | - */ |
|
60 | - protected $blockSize = 8192; |
|
61 | - |
|
62 | - /** @var View */ |
|
63 | - protected $rootView; |
|
64 | - |
|
65 | - /** @var array */ |
|
66 | - protected $ocHeaderKeys; |
|
67 | - |
|
68 | - /** @var \OC\User\Manager */ |
|
69 | - protected $userManager; |
|
70 | - |
|
71 | - /** @var IConfig */ |
|
72 | - protected $config; |
|
73 | - |
|
74 | - /** @var array paths excluded from encryption */ |
|
75 | - protected $excludedPaths; |
|
76 | - |
|
77 | - /** @var \OC\Group\Manager $manager */ |
|
78 | - protected $groupManager; |
|
79 | - |
|
80 | - /** |
|
81 | - * |
|
82 | - * @param View $rootView |
|
83 | - * @param \OC\User\Manager $userManager |
|
84 | - * @param \OC\Group\Manager $groupManager |
|
85 | - * @param IConfig $config |
|
86 | - */ |
|
87 | - public function __construct( |
|
88 | - View $rootView, |
|
89 | - \OC\User\Manager $userManager, |
|
90 | - \OC\Group\Manager $groupManager, |
|
91 | - IConfig $config) { |
|
92 | - |
|
93 | - $this->ocHeaderKeys = [ |
|
94 | - self::HEADER_ENCRYPTION_MODULE_KEY |
|
95 | - ]; |
|
96 | - |
|
97 | - $this->rootView = $rootView; |
|
98 | - $this->userManager = $userManager; |
|
99 | - $this->groupManager = $groupManager; |
|
100 | - $this->config = $config; |
|
101 | - |
|
102 | - $this->excludedPaths[] = 'files_encryption'; |
|
103 | - $this->excludedPaths[] = 'appdata_' . $config->getSystemValue('instanceid', null); |
|
104 | - $this->excludedPaths[] = 'files_external'; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * read encryption module ID from header |
|
109 | - * |
|
110 | - * @param array $header |
|
111 | - * @return string |
|
112 | - * @throws ModuleDoesNotExistsException |
|
113 | - */ |
|
114 | - public function getEncryptionModuleId(array $header = null) { |
|
115 | - $id = ''; |
|
116 | - $encryptionModuleKey = self::HEADER_ENCRYPTION_MODULE_KEY; |
|
117 | - |
|
118 | - if (isset($header[$encryptionModuleKey])) { |
|
119 | - $id = $header[$encryptionModuleKey]; |
|
120 | - } elseif (isset($header['cipher'])) { |
|
121 | - if (class_exists('\OCA\Encryption\Crypto\Encryption')) { |
|
122 | - // fall back to default encryption if the user migrated from |
|
123 | - // ownCloud <= 8.0 with the old encryption |
|
124 | - $id = \OCA\Encryption\Crypto\Encryption::ID; |
|
125 | - } else { |
|
126 | - throw new ModuleDoesNotExistsException('Default encryption module missing'); |
|
127 | - } |
|
128 | - } |
|
129 | - |
|
130 | - return $id; |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * create header for encrypted file |
|
135 | - * |
|
136 | - * @param array $headerData |
|
137 | - * @param IEncryptionModule $encryptionModule |
|
138 | - * @return string |
|
139 | - * @throws EncryptionHeaderToLargeException if header has to many arguments |
|
140 | - * @throws EncryptionHeaderKeyExistsException if header key is already in use |
|
141 | - */ |
|
142 | - public function createHeader(array $headerData, IEncryptionModule $encryptionModule) { |
|
143 | - $header = self::HEADER_START . ':' . self::HEADER_ENCRYPTION_MODULE_KEY . ':' . $encryptionModule->getId() . ':'; |
|
144 | - foreach ($headerData as $key => $value) { |
|
145 | - if (in_array($key, $this->ocHeaderKeys)) { |
|
146 | - throw new EncryptionHeaderKeyExistsException($key); |
|
147 | - } |
|
148 | - $header .= $key . ':' . $value . ':'; |
|
149 | - } |
|
150 | - $header .= self::HEADER_END; |
|
151 | - |
|
152 | - if (strlen($header) > $this->getHeaderSize()) { |
|
153 | - throw new EncryptionHeaderToLargeException(); |
|
154 | - } |
|
155 | - |
|
156 | - $paddedHeader = str_pad($header, $this->headerSize, self::HEADER_PADDING_CHAR, STR_PAD_RIGHT); |
|
157 | - |
|
158 | - return $paddedHeader; |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * go recursively through a dir and collect all files and sub files. |
|
163 | - * |
|
164 | - * @param string $dir relative to the users files folder |
|
165 | - * @return array with list of files relative to the users files folder |
|
166 | - */ |
|
167 | - public function getAllFiles($dir) { |
|
168 | - $result = array(); |
|
169 | - $dirList = array($dir); |
|
170 | - |
|
171 | - while ($dirList) { |
|
172 | - $dir = array_pop($dirList); |
|
173 | - $content = $this->rootView->getDirectoryContent($dir); |
|
174 | - |
|
175 | - foreach ($content as $c) { |
|
176 | - if ($c->getType() === 'dir') { |
|
177 | - $dirList[] = $c->getPath(); |
|
178 | - } else { |
|
179 | - $result[] = $c->getPath(); |
|
180 | - } |
|
181 | - } |
|
182 | - |
|
183 | - } |
|
184 | - |
|
185 | - return $result; |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * check if it is a file uploaded by the user stored in data/user/files |
|
190 | - * or a metadata file |
|
191 | - * |
|
192 | - * @param string $path relative to the data/ folder |
|
193 | - * @return boolean |
|
194 | - */ |
|
195 | - public function isFile($path) { |
|
196 | - $parts = explode('/', Filesystem::normalizePath($path), 4); |
|
197 | - if (isset($parts[2]) && $parts[2] === 'files') { |
|
198 | - return true; |
|
199 | - } |
|
200 | - return false; |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * return size of encryption header |
|
205 | - * |
|
206 | - * @return integer |
|
207 | - */ |
|
208 | - public function getHeaderSize() { |
|
209 | - return $this->headerSize; |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * return size of block read by a PHP stream |
|
214 | - * |
|
215 | - * @return integer |
|
216 | - */ |
|
217 | - public function getBlockSize() { |
|
218 | - return $this->blockSize; |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * get the owner and the path for the file relative to the owners files folder |
|
223 | - * |
|
224 | - * @param string $path |
|
225 | - * @return array |
|
226 | - * @throws \BadMethodCallException |
|
227 | - */ |
|
228 | - public function getUidAndFilename($path) { |
|
229 | - |
|
230 | - $parts = explode('/', $path); |
|
231 | - $uid = ''; |
|
232 | - if (count($parts) > 2) { |
|
233 | - $uid = $parts[1]; |
|
234 | - } |
|
235 | - if (!$this->userManager->userExists($uid)) { |
|
236 | - throw new \BadMethodCallException( |
|
237 | - 'path needs to be relative to the system wide data folder and point to a user specific file' |
|
238 | - ); |
|
239 | - } |
|
240 | - |
|
241 | - $ownerPath = implode('/', array_slice($parts, 2)); |
|
242 | - |
|
243 | - return array($uid, Filesystem::normalizePath($ownerPath)); |
|
244 | - |
|
245 | - } |
|
246 | - |
|
247 | - /** |
|
248 | - * Remove .path extension from a file path |
|
249 | - * @param string $path Path that may identify a .part file |
|
250 | - * @return string File path without .part extension |
|
251 | - * @note this is needed for reusing keys |
|
252 | - */ |
|
253 | - public function stripPartialFileExtension($path) { |
|
254 | - $extension = pathinfo($path, PATHINFO_EXTENSION); |
|
255 | - |
|
256 | - if ( $extension === 'part') { |
|
257 | - |
|
258 | - $newLength = strlen($path) - 5; // 5 = strlen(".part") |
|
259 | - $fPath = substr($path, 0, $newLength); |
|
260 | - |
|
261 | - // if path also contains a transaction id, we remove it too |
|
262 | - $extension = pathinfo($fPath, PATHINFO_EXTENSION); |
|
263 | - if(substr($extension, 0, 12) === 'ocTransferId') { // 12 = strlen("ocTransferId") |
|
264 | - $newLength = strlen($fPath) - strlen($extension) -1; |
|
265 | - $fPath = substr($fPath, 0, $newLength); |
|
266 | - } |
|
267 | - return $fPath; |
|
268 | - |
|
269 | - } else { |
|
270 | - return $path; |
|
271 | - } |
|
272 | - } |
|
273 | - |
|
274 | - public function getUserWithAccessToMountPoint($users, $groups) { |
|
275 | - $result = []; |
|
276 | - if (in_array('all', $users)) { |
|
277 | - $users = $this->userManager->search('', null, null); |
|
278 | - $result = array_map(function(IUser $user) { |
|
279 | - return $user->getUID(); |
|
280 | - }, $users); |
|
281 | - } else { |
|
282 | - $result = array_merge($result, $users); |
|
283 | - |
|
284 | - $groupManager = \OC::$server->getGroupManager(); |
|
285 | - foreach ($groups as $group) { |
|
286 | - $groupObject = $groupManager->get($group); |
|
287 | - if ($groupObject) { |
|
288 | - $foundUsers = $groupObject->searchUsers('', -1, 0); |
|
289 | - $userIds = []; |
|
290 | - foreach ($foundUsers as $user) { |
|
291 | - $userIds[] = $user->getUID(); |
|
292 | - } |
|
293 | - $result = array_merge($result, $userIds); |
|
294 | - } |
|
295 | - } |
|
296 | - } |
|
297 | - |
|
298 | - return $result; |
|
299 | - } |
|
300 | - |
|
301 | - /** |
|
302 | - * check if the file is stored on a system wide mount point |
|
303 | - * @param string $path relative to /data/user with leading '/' |
|
304 | - * @param string $uid |
|
305 | - * @return boolean |
|
306 | - */ |
|
307 | - public function isSystemWideMountPoint($path, $uid) { |
|
308 | - if (\OCP\App::isEnabled("files_external")) { |
|
309 | - $mounts = \OC_Mount_Config::getSystemMountPoints(); |
|
310 | - foreach ($mounts as $mount) { |
|
311 | - if (strpos($path, '/files/' . $mount['mountpoint']) === 0) { |
|
312 | - if ($this->isMountPointApplicableToUser($mount, $uid)) { |
|
313 | - return true; |
|
314 | - } |
|
315 | - } |
|
316 | - } |
|
317 | - } |
|
318 | - return false; |
|
319 | - } |
|
320 | - |
|
321 | - /** |
|
322 | - * check if mount point is applicable to user |
|
323 | - * |
|
324 | - * @param array $mount contains $mount['applicable']['users'], $mount['applicable']['groups'] |
|
325 | - * @param string $uid |
|
326 | - * @return boolean |
|
327 | - */ |
|
328 | - private function isMountPointApplicableToUser($mount, $uid) { |
|
329 | - $acceptedUids = array('all', $uid); |
|
330 | - // check if mount point is applicable for the user |
|
331 | - $intersection = array_intersect($acceptedUids, $mount['applicable']['users']); |
|
332 | - if (!empty($intersection)) { |
|
333 | - return true; |
|
334 | - } |
|
335 | - // check if mount point is applicable for group where the user is a member |
|
336 | - foreach ($mount['applicable']['groups'] as $gid) { |
|
337 | - if ($this->groupManager->isInGroup($uid, $gid)) { |
|
338 | - return true; |
|
339 | - } |
|
340 | - } |
|
341 | - return false; |
|
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * check if it is a path which is excluded by ownCloud from encryption |
|
346 | - * |
|
347 | - * @param string $path |
|
348 | - * @return boolean |
|
349 | - */ |
|
350 | - public function isExcluded($path) { |
|
351 | - $normalizedPath = Filesystem::normalizePath($path); |
|
352 | - $root = explode('/', $normalizedPath, 4); |
|
353 | - if (count($root) > 1) { |
|
354 | - |
|
355 | - // detect alternative key storage root |
|
356 | - $rootDir = $this->getKeyStorageRoot(); |
|
357 | - if ($rootDir !== '' && |
|
358 | - 0 === strpos( |
|
359 | - Filesystem::normalizePath($path), |
|
360 | - Filesystem::normalizePath($rootDir) |
|
361 | - ) |
|
362 | - ) { |
|
363 | - return true; |
|
364 | - } |
|
365 | - |
|
366 | - |
|
367 | - //detect system wide folders |
|
368 | - if (in_array($root[1], $this->excludedPaths)) { |
|
369 | - return true; |
|
370 | - } |
|
371 | - |
|
372 | - // detect user specific folders |
|
373 | - if ($this->userManager->userExists($root[1]) |
|
374 | - && in_array($root[2], $this->excludedPaths)) { |
|
375 | - |
|
376 | - return true; |
|
377 | - } |
|
378 | - } |
|
379 | - return false; |
|
380 | - } |
|
381 | - |
|
382 | - /** |
|
383 | - * check if recovery key is enabled for user |
|
384 | - * |
|
385 | - * @param string $uid |
|
386 | - * @return boolean |
|
387 | - */ |
|
388 | - public function recoveryEnabled($uid) { |
|
389 | - $enabled = $this->config->getUserValue($uid, 'encryption', 'recovery_enabled', '0'); |
|
390 | - |
|
391 | - return $enabled === '1'; |
|
392 | - } |
|
393 | - |
|
394 | - /** |
|
395 | - * set new key storage root |
|
396 | - * |
|
397 | - * @param string $root new key store root relative to the data folder |
|
398 | - */ |
|
399 | - public function setKeyStorageRoot($root) { |
|
400 | - $this->config->setAppValue('core', 'encryption_key_storage_root', $root); |
|
401 | - } |
|
402 | - |
|
403 | - /** |
|
404 | - * get key storage root |
|
405 | - * |
|
406 | - * @return string key storage root |
|
407 | - */ |
|
408 | - public function getKeyStorageRoot() { |
|
409 | - return $this->config->getAppValue('core', 'encryption_key_storage_root', ''); |
|
410 | - } |
|
42 | + const HEADER_START = 'HBEGIN'; |
|
43 | + const HEADER_END = 'HEND'; |
|
44 | + const HEADER_PADDING_CHAR = '-'; |
|
45 | + |
|
46 | + const HEADER_ENCRYPTION_MODULE_KEY = 'oc_encryption_module'; |
|
47 | + |
|
48 | + /** |
|
49 | + * block size will always be 8192 for a PHP stream |
|
50 | + * @see https://bugs.php.net/bug.php?id=21641 |
|
51 | + * @var integer |
|
52 | + */ |
|
53 | + protected $headerSize = 8192; |
|
54 | + |
|
55 | + /** |
|
56 | + * block size will always be 8192 for a PHP stream |
|
57 | + * @see https://bugs.php.net/bug.php?id=21641 |
|
58 | + * @var integer |
|
59 | + */ |
|
60 | + protected $blockSize = 8192; |
|
61 | + |
|
62 | + /** @var View */ |
|
63 | + protected $rootView; |
|
64 | + |
|
65 | + /** @var array */ |
|
66 | + protected $ocHeaderKeys; |
|
67 | + |
|
68 | + /** @var \OC\User\Manager */ |
|
69 | + protected $userManager; |
|
70 | + |
|
71 | + /** @var IConfig */ |
|
72 | + protected $config; |
|
73 | + |
|
74 | + /** @var array paths excluded from encryption */ |
|
75 | + protected $excludedPaths; |
|
76 | + |
|
77 | + /** @var \OC\Group\Manager $manager */ |
|
78 | + protected $groupManager; |
|
79 | + |
|
80 | + /** |
|
81 | + * |
|
82 | + * @param View $rootView |
|
83 | + * @param \OC\User\Manager $userManager |
|
84 | + * @param \OC\Group\Manager $groupManager |
|
85 | + * @param IConfig $config |
|
86 | + */ |
|
87 | + public function __construct( |
|
88 | + View $rootView, |
|
89 | + \OC\User\Manager $userManager, |
|
90 | + \OC\Group\Manager $groupManager, |
|
91 | + IConfig $config) { |
|
92 | + |
|
93 | + $this->ocHeaderKeys = [ |
|
94 | + self::HEADER_ENCRYPTION_MODULE_KEY |
|
95 | + ]; |
|
96 | + |
|
97 | + $this->rootView = $rootView; |
|
98 | + $this->userManager = $userManager; |
|
99 | + $this->groupManager = $groupManager; |
|
100 | + $this->config = $config; |
|
101 | + |
|
102 | + $this->excludedPaths[] = 'files_encryption'; |
|
103 | + $this->excludedPaths[] = 'appdata_' . $config->getSystemValue('instanceid', null); |
|
104 | + $this->excludedPaths[] = 'files_external'; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * read encryption module ID from header |
|
109 | + * |
|
110 | + * @param array $header |
|
111 | + * @return string |
|
112 | + * @throws ModuleDoesNotExistsException |
|
113 | + */ |
|
114 | + public function getEncryptionModuleId(array $header = null) { |
|
115 | + $id = ''; |
|
116 | + $encryptionModuleKey = self::HEADER_ENCRYPTION_MODULE_KEY; |
|
117 | + |
|
118 | + if (isset($header[$encryptionModuleKey])) { |
|
119 | + $id = $header[$encryptionModuleKey]; |
|
120 | + } elseif (isset($header['cipher'])) { |
|
121 | + if (class_exists('\OCA\Encryption\Crypto\Encryption')) { |
|
122 | + // fall back to default encryption if the user migrated from |
|
123 | + // ownCloud <= 8.0 with the old encryption |
|
124 | + $id = \OCA\Encryption\Crypto\Encryption::ID; |
|
125 | + } else { |
|
126 | + throw new ModuleDoesNotExistsException('Default encryption module missing'); |
|
127 | + } |
|
128 | + } |
|
129 | + |
|
130 | + return $id; |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * create header for encrypted file |
|
135 | + * |
|
136 | + * @param array $headerData |
|
137 | + * @param IEncryptionModule $encryptionModule |
|
138 | + * @return string |
|
139 | + * @throws EncryptionHeaderToLargeException if header has to many arguments |
|
140 | + * @throws EncryptionHeaderKeyExistsException if header key is already in use |
|
141 | + */ |
|
142 | + public function createHeader(array $headerData, IEncryptionModule $encryptionModule) { |
|
143 | + $header = self::HEADER_START . ':' . self::HEADER_ENCRYPTION_MODULE_KEY . ':' . $encryptionModule->getId() . ':'; |
|
144 | + foreach ($headerData as $key => $value) { |
|
145 | + if (in_array($key, $this->ocHeaderKeys)) { |
|
146 | + throw new EncryptionHeaderKeyExistsException($key); |
|
147 | + } |
|
148 | + $header .= $key . ':' . $value . ':'; |
|
149 | + } |
|
150 | + $header .= self::HEADER_END; |
|
151 | + |
|
152 | + if (strlen($header) > $this->getHeaderSize()) { |
|
153 | + throw new EncryptionHeaderToLargeException(); |
|
154 | + } |
|
155 | + |
|
156 | + $paddedHeader = str_pad($header, $this->headerSize, self::HEADER_PADDING_CHAR, STR_PAD_RIGHT); |
|
157 | + |
|
158 | + return $paddedHeader; |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * go recursively through a dir and collect all files and sub files. |
|
163 | + * |
|
164 | + * @param string $dir relative to the users files folder |
|
165 | + * @return array with list of files relative to the users files folder |
|
166 | + */ |
|
167 | + public function getAllFiles($dir) { |
|
168 | + $result = array(); |
|
169 | + $dirList = array($dir); |
|
170 | + |
|
171 | + while ($dirList) { |
|
172 | + $dir = array_pop($dirList); |
|
173 | + $content = $this->rootView->getDirectoryContent($dir); |
|
174 | + |
|
175 | + foreach ($content as $c) { |
|
176 | + if ($c->getType() === 'dir') { |
|
177 | + $dirList[] = $c->getPath(); |
|
178 | + } else { |
|
179 | + $result[] = $c->getPath(); |
|
180 | + } |
|
181 | + } |
|
182 | + |
|
183 | + } |
|
184 | + |
|
185 | + return $result; |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * check if it is a file uploaded by the user stored in data/user/files |
|
190 | + * or a metadata file |
|
191 | + * |
|
192 | + * @param string $path relative to the data/ folder |
|
193 | + * @return boolean |
|
194 | + */ |
|
195 | + public function isFile($path) { |
|
196 | + $parts = explode('/', Filesystem::normalizePath($path), 4); |
|
197 | + if (isset($parts[2]) && $parts[2] === 'files') { |
|
198 | + return true; |
|
199 | + } |
|
200 | + return false; |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * return size of encryption header |
|
205 | + * |
|
206 | + * @return integer |
|
207 | + */ |
|
208 | + public function getHeaderSize() { |
|
209 | + return $this->headerSize; |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * return size of block read by a PHP stream |
|
214 | + * |
|
215 | + * @return integer |
|
216 | + */ |
|
217 | + public function getBlockSize() { |
|
218 | + return $this->blockSize; |
|
219 | + } |
|
220 | + |
|
221 | + /** |
|
222 | + * get the owner and the path for the file relative to the owners files folder |
|
223 | + * |
|
224 | + * @param string $path |
|
225 | + * @return array |
|
226 | + * @throws \BadMethodCallException |
|
227 | + */ |
|
228 | + public function getUidAndFilename($path) { |
|
229 | + |
|
230 | + $parts = explode('/', $path); |
|
231 | + $uid = ''; |
|
232 | + if (count($parts) > 2) { |
|
233 | + $uid = $parts[1]; |
|
234 | + } |
|
235 | + if (!$this->userManager->userExists($uid)) { |
|
236 | + throw new \BadMethodCallException( |
|
237 | + 'path needs to be relative to the system wide data folder and point to a user specific file' |
|
238 | + ); |
|
239 | + } |
|
240 | + |
|
241 | + $ownerPath = implode('/', array_slice($parts, 2)); |
|
242 | + |
|
243 | + return array($uid, Filesystem::normalizePath($ownerPath)); |
|
244 | + |
|
245 | + } |
|
246 | + |
|
247 | + /** |
|
248 | + * Remove .path extension from a file path |
|
249 | + * @param string $path Path that may identify a .part file |
|
250 | + * @return string File path without .part extension |
|
251 | + * @note this is needed for reusing keys |
|
252 | + */ |
|
253 | + public function stripPartialFileExtension($path) { |
|
254 | + $extension = pathinfo($path, PATHINFO_EXTENSION); |
|
255 | + |
|
256 | + if ( $extension === 'part') { |
|
257 | + |
|
258 | + $newLength = strlen($path) - 5; // 5 = strlen(".part") |
|
259 | + $fPath = substr($path, 0, $newLength); |
|
260 | + |
|
261 | + // if path also contains a transaction id, we remove it too |
|
262 | + $extension = pathinfo($fPath, PATHINFO_EXTENSION); |
|
263 | + if(substr($extension, 0, 12) === 'ocTransferId') { // 12 = strlen("ocTransferId") |
|
264 | + $newLength = strlen($fPath) - strlen($extension) -1; |
|
265 | + $fPath = substr($fPath, 0, $newLength); |
|
266 | + } |
|
267 | + return $fPath; |
|
268 | + |
|
269 | + } else { |
|
270 | + return $path; |
|
271 | + } |
|
272 | + } |
|
273 | + |
|
274 | + public function getUserWithAccessToMountPoint($users, $groups) { |
|
275 | + $result = []; |
|
276 | + if (in_array('all', $users)) { |
|
277 | + $users = $this->userManager->search('', null, null); |
|
278 | + $result = array_map(function(IUser $user) { |
|
279 | + return $user->getUID(); |
|
280 | + }, $users); |
|
281 | + } else { |
|
282 | + $result = array_merge($result, $users); |
|
283 | + |
|
284 | + $groupManager = \OC::$server->getGroupManager(); |
|
285 | + foreach ($groups as $group) { |
|
286 | + $groupObject = $groupManager->get($group); |
|
287 | + if ($groupObject) { |
|
288 | + $foundUsers = $groupObject->searchUsers('', -1, 0); |
|
289 | + $userIds = []; |
|
290 | + foreach ($foundUsers as $user) { |
|
291 | + $userIds[] = $user->getUID(); |
|
292 | + } |
|
293 | + $result = array_merge($result, $userIds); |
|
294 | + } |
|
295 | + } |
|
296 | + } |
|
297 | + |
|
298 | + return $result; |
|
299 | + } |
|
300 | + |
|
301 | + /** |
|
302 | + * check if the file is stored on a system wide mount point |
|
303 | + * @param string $path relative to /data/user with leading '/' |
|
304 | + * @param string $uid |
|
305 | + * @return boolean |
|
306 | + */ |
|
307 | + public function isSystemWideMountPoint($path, $uid) { |
|
308 | + if (\OCP\App::isEnabled("files_external")) { |
|
309 | + $mounts = \OC_Mount_Config::getSystemMountPoints(); |
|
310 | + foreach ($mounts as $mount) { |
|
311 | + if (strpos($path, '/files/' . $mount['mountpoint']) === 0) { |
|
312 | + if ($this->isMountPointApplicableToUser($mount, $uid)) { |
|
313 | + return true; |
|
314 | + } |
|
315 | + } |
|
316 | + } |
|
317 | + } |
|
318 | + return false; |
|
319 | + } |
|
320 | + |
|
321 | + /** |
|
322 | + * check if mount point is applicable to user |
|
323 | + * |
|
324 | + * @param array $mount contains $mount['applicable']['users'], $mount['applicable']['groups'] |
|
325 | + * @param string $uid |
|
326 | + * @return boolean |
|
327 | + */ |
|
328 | + private function isMountPointApplicableToUser($mount, $uid) { |
|
329 | + $acceptedUids = array('all', $uid); |
|
330 | + // check if mount point is applicable for the user |
|
331 | + $intersection = array_intersect($acceptedUids, $mount['applicable']['users']); |
|
332 | + if (!empty($intersection)) { |
|
333 | + return true; |
|
334 | + } |
|
335 | + // check if mount point is applicable for group where the user is a member |
|
336 | + foreach ($mount['applicable']['groups'] as $gid) { |
|
337 | + if ($this->groupManager->isInGroup($uid, $gid)) { |
|
338 | + return true; |
|
339 | + } |
|
340 | + } |
|
341 | + return false; |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * check if it is a path which is excluded by ownCloud from encryption |
|
346 | + * |
|
347 | + * @param string $path |
|
348 | + * @return boolean |
|
349 | + */ |
|
350 | + public function isExcluded($path) { |
|
351 | + $normalizedPath = Filesystem::normalizePath($path); |
|
352 | + $root = explode('/', $normalizedPath, 4); |
|
353 | + if (count($root) > 1) { |
|
354 | + |
|
355 | + // detect alternative key storage root |
|
356 | + $rootDir = $this->getKeyStorageRoot(); |
|
357 | + if ($rootDir !== '' && |
|
358 | + 0 === strpos( |
|
359 | + Filesystem::normalizePath($path), |
|
360 | + Filesystem::normalizePath($rootDir) |
|
361 | + ) |
|
362 | + ) { |
|
363 | + return true; |
|
364 | + } |
|
365 | + |
|
366 | + |
|
367 | + //detect system wide folders |
|
368 | + if (in_array($root[1], $this->excludedPaths)) { |
|
369 | + return true; |
|
370 | + } |
|
371 | + |
|
372 | + // detect user specific folders |
|
373 | + if ($this->userManager->userExists($root[1]) |
|
374 | + && in_array($root[2], $this->excludedPaths)) { |
|
375 | + |
|
376 | + return true; |
|
377 | + } |
|
378 | + } |
|
379 | + return false; |
|
380 | + } |
|
381 | + |
|
382 | + /** |
|
383 | + * check if recovery key is enabled for user |
|
384 | + * |
|
385 | + * @param string $uid |
|
386 | + * @return boolean |
|
387 | + */ |
|
388 | + public function recoveryEnabled($uid) { |
|
389 | + $enabled = $this->config->getUserValue($uid, 'encryption', 'recovery_enabled', '0'); |
|
390 | + |
|
391 | + return $enabled === '1'; |
|
392 | + } |
|
393 | + |
|
394 | + /** |
|
395 | + * set new key storage root |
|
396 | + * |
|
397 | + * @param string $root new key store root relative to the data folder |
|
398 | + */ |
|
399 | + public function setKeyStorageRoot($root) { |
|
400 | + $this->config->setAppValue('core', 'encryption_key_storage_root', $root); |
|
401 | + } |
|
402 | + |
|
403 | + /** |
|
404 | + * get key storage root |
|
405 | + * |
|
406 | + * @return string key storage root |
|
407 | + */ |
|
408 | + public function getKeyStorageRoot() { |
|
409 | + return $this->config->getAppValue('core', 'encryption_key_storage_root', ''); |
|
410 | + } |
|
411 | 411 | |
412 | 412 | } |
@@ -30,33 +30,33 @@ |
||
30 | 30 | |
31 | 31 | class ManagerFactory implements ICommentsManagerFactory { |
32 | 32 | |
33 | - /** |
|
34 | - * Server container |
|
35 | - * |
|
36 | - * @var IServerContainer |
|
37 | - */ |
|
38 | - private $serverContainer; |
|
33 | + /** |
|
34 | + * Server container |
|
35 | + * |
|
36 | + * @var IServerContainer |
|
37 | + */ |
|
38 | + private $serverContainer; |
|
39 | 39 | |
40 | - /** |
|
41 | - * Constructor for the comments manager factory |
|
42 | - * |
|
43 | - * @param IServerContainer $serverContainer server container |
|
44 | - */ |
|
45 | - public function __construct(IServerContainer $serverContainer) { |
|
46 | - $this->serverContainer = $serverContainer; |
|
47 | - } |
|
40 | + /** |
|
41 | + * Constructor for the comments manager factory |
|
42 | + * |
|
43 | + * @param IServerContainer $serverContainer server container |
|
44 | + */ |
|
45 | + public function __construct(IServerContainer $serverContainer) { |
|
46 | + $this->serverContainer = $serverContainer; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * creates and returns an instance of the ICommentsManager |
|
51 | - * |
|
52 | - * @return ICommentsManager |
|
53 | - * @since 9.0.0 |
|
54 | - */ |
|
55 | - public function getManager() { |
|
56 | - return new Manager( |
|
57 | - $this->serverContainer->getDatabaseConnection(), |
|
58 | - $this->serverContainer->getLogger(), |
|
59 | - $this->serverContainer->getConfig() |
|
60 | - ); |
|
61 | - } |
|
49 | + /** |
|
50 | + * creates and returns an instance of the ICommentsManager |
|
51 | + * |
|
52 | + * @return ICommentsManager |
|
53 | + * @since 9.0.0 |
|
54 | + */ |
|
55 | + public function getManager() { |
|
56 | + return new Manager( |
|
57 | + $this->serverContainer->getDatabaseConnection(), |
|
58 | + $this->serverContainer->getLogger(), |
|
59 | + $this->serverContainer->getConfig() |
|
60 | + ); |
|
61 | + } |
|
62 | 62 | } |
@@ -24,16 +24,16 @@ |
||
24 | 24 | use Sabre\DAV\Tree; |
25 | 25 | |
26 | 26 | class CachingTree extends Tree { |
27 | - /** |
|
28 | - * Store a node in the cache |
|
29 | - * |
|
30 | - * @param Node $node |
|
31 | - * @param null|string $path |
|
32 | - */ |
|
33 | - public function cacheNode(Node $node, $path = null) { |
|
34 | - if (is_null($path)) { |
|
35 | - $path = $node->getPath(); |
|
36 | - } |
|
37 | - $this->cache[trim($path, '/')] = $node; |
|
38 | - } |
|
27 | + /** |
|
28 | + * Store a node in the cache |
|
29 | + * |
|
30 | + * @param Node $node |
|
31 | + * @param null|string $path |
|
32 | + */ |
|
33 | + public function cacheNode(Node $node, $path = null) { |
|
34 | + if (is_null($path)) { |
|
35 | + $path = $node->getPath(); |
|
36 | + } |
|
37 | + $this->cache[trim($path, '/')] = $node; |
|
38 | + } |
|
39 | 39 | } |
@@ -33,14 +33,14 @@ |
||
33 | 33 | * @see \Sabre\DAV\Server |
34 | 34 | */ |
35 | 35 | class Server extends \Sabre\DAV\Server { |
36 | - /** @var CachingTree $tree */ |
|
36 | + /** @var CachingTree $tree */ |
|
37 | 37 | |
38 | - /** |
|
39 | - * @see \Sabre\DAV\Server |
|
40 | - */ |
|
41 | - public function __construct($treeOrNode = null) { |
|
42 | - parent::__construct($treeOrNode); |
|
43 | - self::$exposeVersion = false; |
|
44 | - $this->enablePropfindDepthInfinity = true; |
|
45 | - } |
|
38 | + /** |
|
39 | + * @see \Sabre\DAV\Server |
|
40 | + */ |
|
41 | + public function __construct($treeOrNode = null) { |
|
42 | + parent::__construct($treeOrNode); |
|
43 | + self::$exposeVersion = false; |
|
44 | + $this->enablePropfindDepthInfinity = true; |
|
45 | + } |
|
46 | 46 | } |