@@ -42,10 +42,10 @@ discard block |
||
42 | 42 | |
43 | 43 | public function fixupStatement($statement) { |
44 | 44 | $statement = preg_replace('/`(\w+)` ILIKE \?/', 'LOWER($1) LIKE LOWER(?)', $statement); |
45 | - $statement = str_replace( '`', '"', $statement ); |
|
46 | - $statement = str_ireplace( 'NOW()', 'datetime(\'now\')', $statement ); |
|
45 | + $statement = str_replace('`', '"', $statement); |
|
46 | + $statement = str_ireplace('NOW()', 'datetime(\'now\')', $statement); |
|
47 | 47 | $statement = str_ireplace('GREATEST(', 'MAX(', $statement); |
48 | - $statement = str_ireplace( 'UNIX_TIMESTAMP()', 'strftime(\'%s\',\'now\')', $statement ); |
|
48 | + $statement = str_ireplace('UNIX_TIMESTAMP()', 'strftime(\'%s\',\'now\')', $statement); |
|
49 | 49 | return $statement; |
50 | 50 | } |
51 | 51 | |
@@ -64,14 +64,14 @@ discard block |
||
64 | 64 | if (empty($compare)) { |
65 | 65 | $compare = array_keys($input); |
66 | 66 | } |
67 | - $fieldList = '`' . implode('`,`', array_keys($input)) . '`'; |
|
67 | + $fieldList = '`'.implode('`,`', array_keys($input)).'`'; |
|
68 | 68 | $query = "INSERT INTO `$table` ($fieldList) SELECT " |
69 | - . str_repeat('?,', count($input)-1).'? ' |
|
69 | + . str_repeat('?,', count($input) - 1).'? ' |
|
70 | 70 | . " WHERE NOT EXISTS (SELECT 1 FROM `$table` WHERE "; |
71 | 71 | |
72 | 72 | $inserts = array_values($input); |
73 | - foreach($compare as $key) { |
|
74 | - $query .= '`' . $key . '`'; |
|
73 | + foreach ($compare as $key) { |
|
74 | + $query .= '`'.$key.'`'; |
|
75 | 75 | if (is_null($input[$key])) { |
76 | 76 | $query .= ' IS NULL AND '; |
77 | 77 | } else { |
@@ -31,70 +31,70 @@ |
||
31 | 31 | |
32 | 32 | class AdapterSqlite extends Adapter { |
33 | 33 | |
34 | - /** |
|
35 | - * @param string $tableName |
|
36 | - */ |
|
37 | - public function lockTable($tableName) { |
|
38 | - $this->conn->executeUpdate('BEGIN EXCLUSIVE TRANSACTION'); |
|
39 | - } |
|
34 | + /** |
|
35 | + * @param string $tableName |
|
36 | + */ |
|
37 | + public function lockTable($tableName) { |
|
38 | + $this->conn->executeUpdate('BEGIN EXCLUSIVE TRANSACTION'); |
|
39 | + } |
|
40 | 40 | |
41 | - public function unlockTable() { |
|
42 | - $this->conn->executeUpdate('COMMIT TRANSACTION'); |
|
43 | - } |
|
41 | + public function unlockTable() { |
|
42 | + $this->conn->executeUpdate('COMMIT TRANSACTION'); |
|
43 | + } |
|
44 | 44 | |
45 | - public function fixupStatement($statement) { |
|
46 | - $statement = preg_replace('/`(\w+)` ILIKE \?/', 'LOWER($1) LIKE LOWER(?)', $statement); |
|
47 | - $statement = str_replace( '`', '"', $statement ); |
|
48 | - $statement = str_ireplace( 'NOW()', 'datetime(\'now\')', $statement ); |
|
49 | - $statement = str_ireplace('GREATEST(', 'MAX(', $statement); |
|
50 | - $statement = str_ireplace( 'UNIX_TIMESTAMP()', 'strftime(\'%s\',\'now\')', $statement ); |
|
51 | - return $statement; |
|
52 | - } |
|
45 | + public function fixupStatement($statement) { |
|
46 | + $statement = preg_replace('/`(\w+)` ILIKE \?/', 'LOWER($1) LIKE LOWER(?)', $statement); |
|
47 | + $statement = str_replace( '`', '"', $statement ); |
|
48 | + $statement = str_ireplace( 'NOW()', 'datetime(\'now\')', $statement ); |
|
49 | + $statement = str_ireplace('GREATEST(', 'MAX(', $statement); |
|
50 | + $statement = str_ireplace( 'UNIX_TIMESTAMP()', 'strftime(\'%s\',\'now\')', $statement ); |
|
51 | + return $statement; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Insert a row if the matching row does not exists. To accomplish proper race condition avoidance |
|
56 | - * it is needed that there is also a unique constraint on the values. Then this method will |
|
57 | - * catch the exception and return 0. |
|
58 | - * |
|
59 | - * @param string $table The table name (will replace *PREFIX* with the actual prefix) |
|
60 | - * @param array $input data that should be inserted into the table (column name => value) |
|
61 | - * @param array|null $compare List of values that should be checked for "if not exists" |
|
62 | - * If this is null or an empty array, all keys of $input will be compared |
|
63 | - * Please note: text fields (clob) must not be used in the compare array |
|
64 | - * @return int number of inserted rows |
|
65 | - * @throws \Doctrine\DBAL\DBALException |
|
66 | - * @deprecated 15.0.0 - use unique index and "try { $db->insert() } catch (UniqueConstraintViolationException $e) {}" instead, because it is more reliable and does not have the risk for deadlocks - see https://github.com/nextcloud/server/pull/12371 |
|
67 | - */ |
|
68 | - public function insertIfNotExist($table, $input, array $compare = null) { |
|
69 | - if (empty($compare)) { |
|
70 | - $compare = array_keys($input); |
|
71 | - } |
|
72 | - $fieldList = '`' . implode('`,`', array_keys($input)) . '`'; |
|
73 | - $query = "INSERT INTO `$table` ($fieldList) SELECT " |
|
74 | - . str_repeat('?,', count($input)-1).'? ' |
|
75 | - . " WHERE NOT EXISTS (SELECT 1 FROM `$table` WHERE "; |
|
54 | + /** |
|
55 | + * Insert a row if the matching row does not exists. To accomplish proper race condition avoidance |
|
56 | + * it is needed that there is also a unique constraint on the values. Then this method will |
|
57 | + * catch the exception and return 0. |
|
58 | + * |
|
59 | + * @param string $table The table name (will replace *PREFIX* with the actual prefix) |
|
60 | + * @param array $input data that should be inserted into the table (column name => value) |
|
61 | + * @param array|null $compare List of values that should be checked for "if not exists" |
|
62 | + * If this is null or an empty array, all keys of $input will be compared |
|
63 | + * Please note: text fields (clob) must not be used in the compare array |
|
64 | + * @return int number of inserted rows |
|
65 | + * @throws \Doctrine\DBAL\DBALException |
|
66 | + * @deprecated 15.0.0 - use unique index and "try { $db->insert() } catch (UniqueConstraintViolationException $e) {}" instead, because it is more reliable and does not have the risk for deadlocks - see https://github.com/nextcloud/server/pull/12371 |
|
67 | + */ |
|
68 | + public function insertIfNotExist($table, $input, array $compare = null) { |
|
69 | + if (empty($compare)) { |
|
70 | + $compare = array_keys($input); |
|
71 | + } |
|
72 | + $fieldList = '`' . implode('`,`', array_keys($input)) . '`'; |
|
73 | + $query = "INSERT INTO `$table` ($fieldList) SELECT " |
|
74 | + . str_repeat('?,', count($input)-1).'? ' |
|
75 | + . " WHERE NOT EXISTS (SELECT 1 FROM `$table` WHERE "; |
|
76 | 76 | |
77 | - $inserts = array_values($input); |
|
78 | - foreach($compare as $key) { |
|
79 | - $query .= '`' . $key . '`'; |
|
80 | - if (is_null($input[$key])) { |
|
81 | - $query .= ' IS NULL AND '; |
|
82 | - } else { |
|
83 | - $inserts[] = $input[$key]; |
|
84 | - $query .= ' = ? AND '; |
|
85 | - } |
|
86 | - } |
|
87 | - $query = substr($query, 0, -5); |
|
88 | - $query .= ')'; |
|
77 | + $inserts = array_values($input); |
|
78 | + foreach($compare as $key) { |
|
79 | + $query .= '`' . $key . '`'; |
|
80 | + if (is_null($input[$key])) { |
|
81 | + $query .= ' IS NULL AND '; |
|
82 | + } else { |
|
83 | + $inserts[] = $input[$key]; |
|
84 | + $query .= ' = ? AND '; |
|
85 | + } |
|
86 | + } |
|
87 | + $query = substr($query, 0, -5); |
|
88 | + $query .= ')'; |
|
89 | 89 | |
90 | - try { |
|
91 | - return $this->conn->executeUpdate($query, $inserts); |
|
92 | - } catch (UniqueConstraintViolationException $e) { |
|
93 | - // if this is thrown then a concurrent insert happened between the insert and the sub-select in the insert, that should have avoided it |
|
94 | - // it's fine to ignore this then |
|
95 | - // |
|
96 | - // more discussions about this can be found at https://github.com/nextcloud/server/pull/12315 |
|
97 | - return 0; |
|
98 | - } |
|
99 | - } |
|
90 | + try { |
|
91 | + return $this->conn->executeUpdate($query, $inserts); |
|
92 | + } catch (UniqueConstraintViolationException $e) { |
|
93 | + // if this is thrown then a concurrent insert happened between the insert and the sub-select in the insert, that should have avoided it |
|
94 | + // it's fine to ignore this then |
|
95 | + // |
|
96 | + // more discussions about this can be found at https://github.com/nextcloud/server/pull/12315 |
|
97 | + return 0; |
|
98 | + } |
|
99 | + } |
|
100 | 100 | } |
@@ -25,22 +25,22 @@ |
||
25 | 25 | * @since 12.0.0 |
26 | 26 | */ |
27 | 27 | interface ISearchOrder { |
28 | - const DIRECTION_ASCENDING = 'asc'; |
|
29 | - const DIRECTION_DESCENDING = 'desc'; |
|
28 | + const DIRECTION_ASCENDING = 'asc'; |
|
29 | + const DIRECTION_DESCENDING = 'desc'; |
|
30 | 30 | |
31 | - /** |
|
32 | - * The direction to sort in, either ISearchOrder::DIRECTION_ASCENDING or ISearchOrder::DIRECTION_DESCENDING |
|
33 | - * |
|
34 | - * @return string |
|
35 | - * @since 12.0.0 |
|
36 | - */ |
|
37 | - public function getDirection(); |
|
31 | + /** |
|
32 | + * The direction to sort in, either ISearchOrder::DIRECTION_ASCENDING or ISearchOrder::DIRECTION_DESCENDING |
|
33 | + * |
|
34 | + * @return string |
|
35 | + * @since 12.0.0 |
|
36 | + */ |
|
37 | + public function getDirection(); |
|
38 | 38 | |
39 | - /** |
|
40 | - * The field to sort on |
|
41 | - * |
|
42 | - * @return string |
|
43 | - * @since 12.0.0 |
|
44 | - */ |
|
45 | - public function getField(); |
|
39 | + /** |
|
40 | + * The field to sort on |
|
41 | + * |
|
42 | + * @return string |
|
43 | + * @since 12.0.0 |
|
44 | + */ |
|
45 | + public function getField(); |
|
46 | 46 | } |
@@ -25,36 +25,36 @@ |
||
25 | 25 | * @since 12.0.0 |
26 | 26 | */ |
27 | 27 | interface ISearchComparison extends ISearchOperator { |
28 | - const COMPARE_EQUAL = 'eq'; |
|
29 | - const COMPARE_GREATER_THAN = 'gt'; |
|
30 | - const COMPARE_GREATER_THAN_EQUAL = 'gte'; |
|
31 | - const COMPARE_LESS_THAN = 'lt'; |
|
32 | - const COMPARE_LESS_THAN_EQUAL = 'lte'; |
|
33 | - const COMPARE_LIKE = 'like'; |
|
28 | + const COMPARE_EQUAL = 'eq'; |
|
29 | + const COMPARE_GREATER_THAN = 'gt'; |
|
30 | + const COMPARE_GREATER_THAN_EQUAL = 'gte'; |
|
31 | + const COMPARE_LESS_THAN = 'lt'; |
|
32 | + const COMPARE_LESS_THAN_EQUAL = 'lte'; |
|
33 | + const COMPARE_LIKE = 'like'; |
|
34 | 34 | |
35 | - /** |
|
36 | - * Get the type of comparison, one of the ISearchComparison::COMPARE_* constants |
|
37 | - * |
|
38 | - * @return string |
|
39 | - * @since 12.0.0 |
|
40 | - */ |
|
41 | - public function getType(); |
|
35 | + /** |
|
36 | + * Get the type of comparison, one of the ISearchComparison::COMPARE_* constants |
|
37 | + * |
|
38 | + * @return string |
|
39 | + * @since 12.0.0 |
|
40 | + */ |
|
41 | + public function getType(); |
|
42 | 42 | |
43 | - /** |
|
44 | - * Get the name of the field to compare with |
|
45 | - * |
|
46 | - * i.e. 'size', 'name' or 'mimetype' |
|
47 | - * |
|
48 | - * @return string |
|
49 | - * @since 12.0.0 |
|
50 | - */ |
|
51 | - public function getField(); |
|
43 | + /** |
|
44 | + * Get the name of the field to compare with |
|
45 | + * |
|
46 | + * i.e. 'size', 'name' or 'mimetype' |
|
47 | + * |
|
48 | + * @return string |
|
49 | + * @since 12.0.0 |
|
50 | + */ |
|
51 | + public function getField(); |
|
52 | 52 | |
53 | - /** |
|
54 | - * Get the value to compare the field with |
|
55 | - * |
|
56 | - * @return string|integer|\DateTime |
|
57 | - * @since 12.0.0 |
|
58 | - */ |
|
59 | - public function getValue(); |
|
53 | + /** |
|
54 | + * Get the value to compare the field with |
|
55 | + * |
|
56 | + * @return string|integer|\DateTime |
|
57 | + * @since 12.0.0 |
|
58 | + */ |
|
59 | + public function getValue(); |
|
60 | 60 | } |
@@ -25,27 +25,27 @@ |
||
25 | 25 | * @since 12.0.0 |
26 | 26 | */ |
27 | 27 | interface ISearchBinaryOperator extends ISearchOperator { |
28 | - const OPERATOR_AND = 'and'; |
|
29 | - const OPERATOR_OR = 'or'; |
|
30 | - const OPERATOR_NOT = 'not'; |
|
28 | + const OPERATOR_AND = 'and'; |
|
29 | + const OPERATOR_OR = 'or'; |
|
30 | + const OPERATOR_NOT = 'not'; |
|
31 | 31 | |
32 | - /** |
|
33 | - * The type of binary operator |
|
34 | - * |
|
35 | - * One of the ISearchBinaryOperator::OPERATOR_* constants |
|
36 | - * |
|
37 | - * @return string |
|
38 | - * @since 12.0.0 |
|
39 | - */ |
|
40 | - public function getType(); |
|
32 | + /** |
|
33 | + * The type of binary operator |
|
34 | + * |
|
35 | + * One of the ISearchBinaryOperator::OPERATOR_* constants |
|
36 | + * |
|
37 | + * @return string |
|
38 | + * @since 12.0.0 |
|
39 | + */ |
|
40 | + public function getType(); |
|
41 | 41 | |
42 | - /** |
|
43 | - * The arguments for the binary operator |
|
44 | - * |
|
45 | - * One argument for the 'not' operator and two for 'and' and 'or' |
|
46 | - * |
|
47 | - * @return ISearchOperator[] |
|
48 | - * @since 12.0.0 |
|
49 | - */ |
|
50 | - public function getArguments(); |
|
42 | + /** |
|
43 | + * The arguments for the binary operator |
|
44 | + * |
|
45 | + * One argument for the 'not' operator and two for 'and' and 'or' |
|
46 | + * |
|
47 | + * @return ISearchOperator[] |
|
48 | + * @since 12.0.0 |
|
49 | + */ |
|
50 | + public function getArguments(); |
|
51 | 51 | } |
@@ -24,44 +24,44 @@ |
||
24 | 24 | use OCP\Files\Search\ISearchComparison; |
25 | 25 | |
26 | 26 | class SearchComparison implements ISearchComparison { |
27 | - /** @var string */ |
|
28 | - private $type; |
|
29 | - /** @var string */ |
|
30 | - private $field; |
|
31 | - /** @var string|integer|\DateTime */ |
|
32 | - private $value; |
|
27 | + /** @var string */ |
|
28 | + private $type; |
|
29 | + /** @var string */ |
|
30 | + private $field; |
|
31 | + /** @var string|integer|\DateTime */ |
|
32 | + private $value; |
|
33 | 33 | |
34 | - /** |
|
35 | - * SearchComparison constructor. |
|
36 | - * |
|
37 | - * @param string $type |
|
38 | - * @param string $field |
|
39 | - * @param \DateTime|int|string $value |
|
40 | - */ |
|
41 | - public function __construct($type, $field, $value) { |
|
42 | - $this->type = $type; |
|
43 | - $this->field = $field; |
|
44 | - $this->value = $value; |
|
45 | - } |
|
34 | + /** |
|
35 | + * SearchComparison constructor. |
|
36 | + * |
|
37 | + * @param string $type |
|
38 | + * @param string $field |
|
39 | + * @param \DateTime|int|string $value |
|
40 | + */ |
|
41 | + public function __construct($type, $field, $value) { |
|
42 | + $this->type = $type; |
|
43 | + $this->field = $field; |
|
44 | + $this->value = $value; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * @return string |
|
49 | - */ |
|
50 | - public function getType() { |
|
51 | - return $this->type; |
|
52 | - } |
|
47 | + /** |
|
48 | + * @return string |
|
49 | + */ |
|
50 | + public function getType() { |
|
51 | + return $this->type; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * @return string |
|
56 | - */ |
|
57 | - public function getField() { |
|
58 | - return $this->field; |
|
59 | - } |
|
54 | + /** |
|
55 | + * @return string |
|
56 | + */ |
|
57 | + public function getField() { |
|
58 | + return $this->field; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @return \DateTime|int|string |
|
63 | - */ |
|
64 | - public function getValue() { |
|
65 | - return $this->value; |
|
66 | - } |
|
61 | + /** |
|
62 | + * @return \DateTime|int|string |
|
63 | + */ |
|
64 | + public function getValue() { |
|
65 | + return $this->value; |
|
66 | + } |
|
67 | 67 | } |
@@ -25,33 +25,33 @@ |
||
25 | 25 | use OCP\Files\Search\ISearchOrder; |
26 | 26 | |
27 | 27 | class SearchOrder implements ISearchOrder { |
28 | - /** @var string */ |
|
29 | - private $direction; |
|
30 | - /** @var string */ |
|
31 | - private $field; |
|
28 | + /** @var string */ |
|
29 | + private $direction; |
|
30 | + /** @var string */ |
|
31 | + private $field; |
|
32 | 32 | |
33 | - /** |
|
34 | - * SearchOrder constructor. |
|
35 | - * |
|
36 | - * @param string $direction |
|
37 | - * @param string $field |
|
38 | - */ |
|
39 | - public function __construct($direction, $field) { |
|
40 | - $this->direction = $direction; |
|
41 | - $this->field = $field; |
|
42 | - } |
|
33 | + /** |
|
34 | + * SearchOrder constructor. |
|
35 | + * |
|
36 | + * @param string $direction |
|
37 | + * @param string $field |
|
38 | + */ |
|
39 | + public function __construct($direction, $field) { |
|
40 | + $this->direction = $direction; |
|
41 | + $this->field = $field; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @return string |
|
46 | - */ |
|
47 | - public function getDirection() { |
|
48 | - return $this->direction; |
|
49 | - } |
|
44 | + /** |
|
45 | + * @return string |
|
46 | + */ |
|
47 | + public function getDirection() { |
|
48 | + return $this->direction; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @return string |
|
53 | - */ |
|
54 | - public function getField() { |
|
55 | - return $this->field; |
|
56 | - } |
|
51 | + /** |
|
52 | + * @return string |
|
53 | + */ |
|
54 | + public function getField() { |
|
55 | + return $this->field; |
|
56 | + } |
|
57 | 57 | } |
@@ -25,33 +25,33 @@ |
||
25 | 25 | use OCP\Files\Search\ISearchOperator; |
26 | 26 | |
27 | 27 | class SearchBinaryOperator implements ISearchBinaryOperator { |
28 | - /** @var string */ |
|
29 | - private $type; |
|
30 | - /** @var ISearchOperator[] */ |
|
31 | - private $arguments; |
|
28 | + /** @var string */ |
|
29 | + private $type; |
|
30 | + /** @var ISearchOperator[] */ |
|
31 | + private $arguments; |
|
32 | 32 | |
33 | - /** |
|
34 | - * SearchBinaryOperator constructor. |
|
35 | - * |
|
36 | - * @param string $type |
|
37 | - * @param ISearchOperator[] $arguments |
|
38 | - */ |
|
39 | - public function __construct($type, array $arguments) { |
|
40 | - $this->type = $type; |
|
41 | - $this->arguments = $arguments; |
|
42 | - } |
|
33 | + /** |
|
34 | + * SearchBinaryOperator constructor. |
|
35 | + * |
|
36 | + * @param string $type |
|
37 | + * @param ISearchOperator[] $arguments |
|
38 | + */ |
|
39 | + public function __construct($type, array $arguments) { |
|
40 | + $this->type = $type; |
|
41 | + $this->arguments = $arguments; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @return string |
|
46 | - */ |
|
47 | - public function getType() { |
|
48 | - return $this->type; |
|
49 | - } |
|
44 | + /** |
|
45 | + * @return string |
|
46 | + */ |
|
47 | + public function getType() { |
|
48 | + return $this->type; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @return ISearchOperator[] |
|
53 | - */ |
|
54 | - public function getArguments() { |
|
55 | - return $this->arguments; |
|
56 | - } |
|
51 | + /** |
|
52 | + * @return ISearchOperator[] |
|
53 | + */ |
|
54 | + public function getArguments() { |
|
55 | + return $this->arguments; |
|
56 | + } |
|
57 | 57 | } |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | |
72 | 72 | $updatedEntries = $builder->execute(); |
73 | 73 | if ($updatedEntries > 0) { |
74 | - $out->info('Fixed file share permissions for ' . $updatedEntries . ' shares'); |
|
74 | + $out->info('Fixed file share permissions for '.$updatedEntries.' shares'); |
|
75 | 75 | } |
76 | 76 | } |
77 | 77 | |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | } |
108 | 108 | |
109 | 109 | if ($deletedEntries) { |
110 | - $out->info('Removed ' . $deletedEntries . ' shares where the parent did not exist'); |
|
110 | + $out->info('Removed '.$deletedEntries.' shares where the parent did not exist'); |
|
111 | 111 | } |
112 | 112 | } |
113 | 113 |
@@ -33,90 +33,90 @@ |
||
33 | 33 | */ |
34 | 34 | class RepairInvalidShares implements IRepairStep { |
35 | 35 | |
36 | - const CHUNK_SIZE = 200; |
|
37 | - |
|
38 | - /** @var \OCP\IConfig */ |
|
39 | - protected $config; |
|
40 | - |
|
41 | - /** @var \OCP\IDBConnection */ |
|
42 | - protected $connection; |
|
43 | - |
|
44 | - /** |
|
45 | - * @param \OCP\IConfig $config |
|
46 | - * @param \OCP\IDBConnection $connection |
|
47 | - */ |
|
48 | - public function __construct($config, $connection) { |
|
49 | - $this->connection = $connection; |
|
50 | - $this->config = $config; |
|
51 | - } |
|
52 | - |
|
53 | - public function getName() { |
|
54 | - return 'Repair invalid shares'; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * Adjust file share permissions |
|
59 | - * @suppress SqlInjectionChecker |
|
60 | - */ |
|
61 | - private function adjustFileSharePermissions(IOutput $out) { |
|
62 | - $mask = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE; |
|
63 | - $builder = $this->connection->getQueryBuilder(); |
|
64 | - |
|
65 | - $permsFunc = $builder->expr()->bitwiseAnd('permissions', $mask); |
|
66 | - $builder |
|
67 | - ->update('share') |
|
68 | - ->set('permissions', $permsFunc) |
|
69 | - ->where($builder->expr()->eq('item_type', $builder->expr()->literal('file'))) |
|
70 | - ->andWhere($builder->expr()->neq('permissions', $permsFunc)); |
|
71 | - |
|
72 | - $updatedEntries = $builder->execute(); |
|
73 | - if ($updatedEntries > 0) { |
|
74 | - $out->info('Fixed file share permissions for ' . $updatedEntries . ' shares'); |
|
75 | - } |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Remove shares where the parent share does not exist anymore |
|
80 | - */ |
|
81 | - private function removeSharesNonExistingParent(IOutput $out) { |
|
82 | - $deletedEntries = 0; |
|
83 | - |
|
84 | - $query = $this->connection->getQueryBuilder(); |
|
85 | - $query->select('s1.parent') |
|
86 | - ->from('share', 's1') |
|
87 | - ->where($query->expr()->isNotNull('s1.parent')) |
|
88 | - ->andWhere($query->expr()->isNull('s2.id')) |
|
89 | - ->leftJoin('s1', 'share', 's2', $query->expr()->eq('s1.parent', 's2.id')) |
|
90 | - ->groupBy('s1.parent') |
|
91 | - ->setMaxResults(self::CHUNK_SIZE); |
|
92 | - |
|
93 | - $deleteQuery = $this->connection->getQueryBuilder(); |
|
94 | - $deleteQuery->delete('share') |
|
95 | - ->where($deleteQuery->expr()->eq('parent', $deleteQuery->createParameter('parent'))); |
|
96 | - |
|
97 | - $deletedInLastChunk = self::CHUNK_SIZE; |
|
98 | - while ($deletedInLastChunk === self::CHUNK_SIZE) { |
|
99 | - $deletedInLastChunk = 0; |
|
100 | - $result = $query->execute(); |
|
101 | - while ($row = $result->fetch()) { |
|
102 | - $deletedInLastChunk++; |
|
103 | - $deletedEntries += $deleteQuery->setParameter('parent', (int) $row['parent']) |
|
104 | - ->execute(); |
|
105 | - } |
|
106 | - $result->closeCursor(); |
|
107 | - } |
|
108 | - |
|
109 | - if ($deletedEntries) { |
|
110 | - $out->info('Removed ' . $deletedEntries . ' shares where the parent did not exist'); |
|
111 | - } |
|
112 | - } |
|
113 | - |
|
114 | - public function run(IOutput $out) { |
|
115 | - $ocVersionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0'); |
|
116 | - if (version_compare($ocVersionFromBeforeUpdate, '12.0.0.11', '<')) { |
|
117 | - $this->adjustFileSharePermissions($out); |
|
118 | - } |
|
119 | - |
|
120 | - $this->removeSharesNonExistingParent($out); |
|
121 | - } |
|
36 | + const CHUNK_SIZE = 200; |
|
37 | + |
|
38 | + /** @var \OCP\IConfig */ |
|
39 | + protected $config; |
|
40 | + |
|
41 | + /** @var \OCP\IDBConnection */ |
|
42 | + protected $connection; |
|
43 | + |
|
44 | + /** |
|
45 | + * @param \OCP\IConfig $config |
|
46 | + * @param \OCP\IDBConnection $connection |
|
47 | + */ |
|
48 | + public function __construct($config, $connection) { |
|
49 | + $this->connection = $connection; |
|
50 | + $this->config = $config; |
|
51 | + } |
|
52 | + |
|
53 | + public function getName() { |
|
54 | + return 'Repair invalid shares'; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * Adjust file share permissions |
|
59 | + * @suppress SqlInjectionChecker |
|
60 | + */ |
|
61 | + private function adjustFileSharePermissions(IOutput $out) { |
|
62 | + $mask = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE; |
|
63 | + $builder = $this->connection->getQueryBuilder(); |
|
64 | + |
|
65 | + $permsFunc = $builder->expr()->bitwiseAnd('permissions', $mask); |
|
66 | + $builder |
|
67 | + ->update('share') |
|
68 | + ->set('permissions', $permsFunc) |
|
69 | + ->where($builder->expr()->eq('item_type', $builder->expr()->literal('file'))) |
|
70 | + ->andWhere($builder->expr()->neq('permissions', $permsFunc)); |
|
71 | + |
|
72 | + $updatedEntries = $builder->execute(); |
|
73 | + if ($updatedEntries > 0) { |
|
74 | + $out->info('Fixed file share permissions for ' . $updatedEntries . ' shares'); |
|
75 | + } |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Remove shares where the parent share does not exist anymore |
|
80 | + */ |
|
81 | + private function removeSharesNonExistingParent(IOutput $out) { |
|
82 | + $deletedEntries = 0; |
|
83 | + |
|
84 | + $query = $this->connection->getQueryBuilder(); |
|
85 | + $query->select('s1.parent') |
|
86 | + ->from('share', 's1') |
|
87 | + ->where($query->expr()->isNotNull('s1.parent')) |
|
88 | + ->andWhere($query->expr()->isNull('s2.id')) |
|
89 | + ->leftJoin('s1', 'share', 's2', $query->expr()->eq('s1.parent', 's2.id')) |
|
90 | + ->groupBy('s1.parent') |
|
91 | + ->setMaxResults(self::CHUNK_SIZE); |
|
92 | + |
|
93 | + $deleteQuery = $this->connection->getQueryBuilder(); |
|
94 | + $deleteQuery->delete('share') |
|
95 | + ->where($deleteQuery->expr()->eq('parent', $deleteQuery->createParameter('parent'))); |
|
96 | + |
|
97 | + $deletedInLastChunk = self::CHUNK_SIZE; |
|
98 | + while ($deletedInLastChunk === self::CHUNK_SIZE) { |
|
99 | + $deletedInLastChunk = 0; |
|
100 | + $result = $query->execute(); |
|
101 | + while ($row = $result->fetch()) { |
|
102 | + $deletedInLastChunk++; |
|
103 | + $deletedEntries += $deleteQuery->setParameter('parent', (int) $row['parent']) |
|
104 | + ->execute(); |
|
105 | + } |
|
106 | + $result->closeCursor(); |
|
107 | + } |
|
108 | + |
|
109 | + if ($deletedEntries) { |
|
110 | + $out->info('Removed ' . $deletedEntries . ' shares where the parent did not exist'); |
|
111 | + } |
|
112 | + } |
|
113 | + |
|
114 | + public function run(IOutput $out) { |
|
115 | + $ocVersionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0'); |
|
116 | + if (version_compare($ocVersionFromBeforeUpdate, '12.0.0.11', '<')) { |
|
117 | + $this->adjustFileSharePermissions($out); |
|
118 | + } |
|
119 | + |
|
120 | + $this->removeSharesNonExistingParent($out); |
|
121 | + } |
|
122 | 122 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | ], |
55 | 55 | ]; |
56 | 56 | |
57 | - if($this->appManager->isEnabledForUser('files_sharing')) { |
|
57 | + if ($this->appManager->isEnabledForUser('files_sharing')) { |
|
58 | 58 | $services['SHARING'] = [ |
59 | 59 | 'version' => 1, |
60 | 60 | 'endpoints' => [ |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | } |
86 | 86 | } |
87 | 87 | |
88 | - if($this->appManager->isEnabledForUser('activity')) { |
|
88 | + if ($this->appManager->isEnabledForUser('activity')) { |
|
89 | 89 | $services['ACTIVITY'] = [ |
90 | 90 | 'version' => 1, |
91 | 91 | 'endpoints' => [ |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | ]; |
95 | 95 | } |
96 | 96 | |
97 | - if($this->appManager->isEnabledForUser('provisioning_api')) { |
|
97 | + if ($this->appManager->isEnabledForUser('provisioning_api')) { |
|
98 | 98 | $services['PROVISIONING'] = [ |
99 | 99 | 'version' => 1, |
100 | 100 | 'endpoints' => [ |
@@ -24,92 +24,92 @@ |
||
24 | 24 | namespace OC\OCS; |
25 | 25 | |
26 | 26 | class Provider extends \OCP\AppFramework\Controller { |
27 | - /** @var \OCP\App\IAppManager */ |
|
28 | - private $appManager; |
|
27 | + /** @var \OCP\App\IAppManager */ |
|
28 | + private $appManager; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @param string $appName |
|
32 | - * @param \OCP\IRequest $request |
|
33 | - * @param \OCP\App\IAppManager $appManager |
|
34 | - */ |
|
35 | - public function __construct($appName, |
|
36 | - \OCP\IRequest $request, |
|
37 | - \OCP\App\IAppManager $appManager) { |
|
38 | - parent::__construct($appName, $request); |
|
39 | - $this->appManager = $appManager; |
|
40 | - } |
|
30 | + /** |
|
31 | + * @param string $appName |
|
32 | + * @param \OCP\IRequest $request |
|
33 | + * @param \OCP\App\IAppManager $appManager |
|
34 | + */ |
|
35 | + public function __construct($appName, |
|
36 | + \OCP\IRequest $request, |
|
37 | + \OCP\App\IAppManager $appManager) { |
|
38 | + parent::__construct($appName, $request); |
|
39 | + $this->appManager = $appManager; |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * @return \OCP\AppFramework\Http\JSONResponse |
|
44 | - */ |
|
45 | - public function buildProviderList() { |
|
46 | - $services = [ |
|
47 | - 'PRIVATE_DATA' => [ |
|
48 | - 'version' => 1, |
|
49 | - 'endpoints' => [ |
|
50 | - 'store' => '/ocs/v2.php/privatedata/setattribute', |
|
51 | - 'read' => '/ocs/v2.php/privatedata/getattribute', |
|
52 | - 'delete' => '/ocs/v2.php/privatedata/deleteattribute', |
|
53 | - ], |
|
54 | - ], |
|
55 | - ]; |
|
42 | + /** |
|
43 | + * @return \OCP\AppFramework\Http\JSONResponse |
|
44 | + */ |
|
45 | + public function buildProviderList() { |
|
46 | + $services = [ |
|
47 | + 'PRIVATE_DATA' => [ |
|
48 | + 'version' => 1, |
|
49 | + 'endpoints' => [ |
|
50 | + 'store' => '/ocs/v2.php/privatedata/setattribute', |
|
51 | + 'read' => '/ocs/v2.php/privatedata/getattribute', |
|
52 | + 'delete' => '/ocs/v2.php/privatedata/deleteattribute', |
|
53 | + ], |
|
54 | + ], |
|
55 | + ]; |
|
56 | 56 | |
57 | - if($this->appManager->isEnabledForUser('files_sharing')) { |
|
58 | - $services['SHARING'] = [ |
|
59 | - 'version' => 1, |
|
60 | - 'endpoints' => [ |
|
61 | - 'share' => '/ocs/v2.php/apps/files_sharing/api/v1/shares', |
|
62 | - ], |
|
63 | - ]; |
|
64 | - $services['FEDERATED_SHARING'] = [ |
|
65 | - 'version' => 1, |
|
66 | - 'endpoints' => [ |
|
67 | - 'share' => '/ocs/v2.php/cloud/shares', |
|
68 | - 'webdav' => '/public.php/webdav/', |
|
69 | - ], |
|
70 | - ]; |
|
71 | - } |
|
57 | + if($this->appManager->isEnabledForUser('files_sharing')) { |
|
58 | + $services['SHARING'] = [ |
|
59 | + 'version' => 1, |
|
60 | + 'endpoints' => [ |
|
61 | + 'share' => '/ocs/v2.php/apps/files_sharing/api/v1/shares', |
|
62 | + ], |
|
63 | + ]; |
|
64 | + $services['FEDERATED_SHARING'] = [ |
|
65 | + 'version' => 1, |
|
66 | + 'endpoints' => [ |
|
67 | + 'share' => '/ocs/v2.php/cloud/shares', |
|
68 | + 'webdav' => '/public.php/webdav/', |
|
69 | + ], |
|
70 | + ]; |
|
71 | + } |
|
72 | 72 | |
73 | - if ($this->appManager->isEnabledForUser('federation')) { |
|
74 | - if (isset($services['FEDERATED_SHARING'])) { |
|
75 | - $services['FEDERATED_SHARING']['endpoints']['shared-secret'] = '/ocs/v2.php/cloud/shared-secret'; |
|
76 | - $services['FEDERATED_SHARING']['endpoints']['system-address-book'] = '/remote.php/dav/addressbooks/system/system/system'; |
|
77 | - $services['FEDERATED_SHARING']['endpoints']['carddav-user'] = 'system'; |
|
78 | - } else { |
|
79 | - $services['FEDERATED_SHARING'] = [ |
|
80 | - 'version' => 1, |
|
81 | - 'endpoints' => [ |
|
82 | - 'shared-secret' => '/ocs/v2.php/cloud/shared-secret', |
|
83 | - 'system-address-book' => '/remote.php/dav/addressbooks/system/system/system', |
|
84 | - 'carddav-user' => 'system' |
|
85 | - ], |
|
86 | - ]; |
|
87 | - } |
|
88 | - } |
|
73 | + if ($this->appManager->isEnabledForUser('federation')) { |
|
74 | + if (isset($services['FEDERATED_SHARING'])) { |
|
75 | + $services['FEDERATED_SHARING']['endpoints']['shared-secret'] = '/ocs/v2.php/cloud/shared-secret'; |
|
76 | + $services['FEDERATED_SHARING']['endpoints']['system-address-book'] = '/remote.php/dav/addressbooks/system/system/system'; |
|
77 | + $services['FEDERATED_SHARING']['endpoints']['carddav-user'] = 'system'; |
|
78 | + } else { |
|
79 | + $services['FEDERATED_SHARING'] = [ |
|
80 | + 'version' => 1, |
|
81 | + 'endpoints' => [ |
|
82 | + 'shared-secret' => '/ocs/v2.php/cloud/shared-secret', |
|
83 | + 'system-address-book' => '/remote.php/dav/addressbooks/system/system/system', |
|
84 | + 'carddav-user' => 'system' |
|
85 | + ], |
|
86 | + ]; |
|
87 | + } |
|
88 | + } |
|
89 | 89 | |
90 | - if($this->appManager->isEnabledForUser('activity')) { |
|
91 | - $services['ACTIVITY'] = [ |
|
92 | - 'version' => 1, |
|
93 | - 'endpoints' => [ |
|
94 | - 'list' => '/ocs/v2.php/cloud/activity', |
|
95 | - ], |
|
96 | - ]; |
|
97 | - } |
|
90 | + if($this->appManager->isEnabledForUser('activity')) { |
|
91 | + $services['ACTIVITY'] = [ |
|
92 | + 'version' => 1, |
|
93 | + 'endpoints' => [ |
|
94 | + 'list' => '/ocs/v2.php/cloud/activity', |
|
95 | + ], |
|
96 | + ]; |
|
97 | + } |
|
98 | 98 | |
99 | - if($this->appManager->isEnabledForUser('provisioning_api')) { |
|
100 | - $services['PROVISIONING'] = [ |
|
101 | - 'version' => 1, |
|
102 | - 'endpoints' => [ |
|
103 | - 'user' => '/ocs/v2.php/cloud/users', |
|
104 | - 'groups' => '/ocs/v2.php/cloud/groups', |
|
105 | - 'apps' => '/ocs/v2.php/cloud/apps', |
|
106 | - ], |
|
107 | - ]; |
|
108 | - } |
|
99 | + if($this->appManager->isEnabledForUser('provisioning_api')) { |
|
100 | + $services['PROVISIONING'] = [ |
|
101 | + 'version' => 1, |
|
102 | + 'endpoints' => [ |
|
103 | + 'user' => '/ocs/v2.php/cloud/users', |
|
104 | + 'groups' => '/ocs/v2.php/cloud/groups', |
|
105 | + 'apps' => '/ocs/v2.php/cloud/apps', |
|
106 | + ], |
|
107 | + ]; |
|
108 | + } |
|
109 | 109 | |
110 | - return new \OCP\AppFramework\Http\JSONResponse([ |
|
111 | - 'version' => 2, |
|
112 | - 'services' => $services, |
|
113 | - ]); |
|
114 | - } |
|
110 | + return new \OCP\AppFramework\Http\JSONResponse([ |
|
111 | + 'version' => 2, |
|
112 | + 'services' => $services, |
|
113 | + ]); |
|
114 | + } |
|
115 | 115 | } |