@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | * @param array $params |
34 | 34 | */ |
35 | 35 | public function __construct($params) { |
36 | - if (! isset($params['user']) || ! $params['user'] instanceof User) { |
|
36 | + if (!isset($params['user']) || !$params['user'] instanceof User) { |
|
37 | 37 | throw new \Exception('missing user object in parameters'); |
38 | 38 | } |
39 | 39 | $this->user = $params['user']; |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | } |
42 | 42 | |
43 | 43 | public function getId() { |
44 | - return 'object::user:' . $this->user->getUID(); |
|
44 | + return 'object::user:'.$this->user->getUID(); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -28,40 +28,40 @@ |
||
28 | 28 | use OC\User\User; |
29 | 29 | |
30 | 30 | class HomeObjectStoreStorage extends ObjectStoreStorage implements \OCP\Files\IHomeStorage { |
31 | - /** |
|
32 | - * The home user storage requires a user object to create a unique storage id |
|
33 | - * @param array $params |
|
34 | - */ |
|
35 | - public function __construct($params) { |
|
36 | - if (! isset($params['user']) || ! $params['user'] instanceof User) { |
|
37 | - throw new \Exception('missing user object in parameters'); |
|
38 | - } |
|
39 | - $this->user = $params['user']; |
|
40 | - parent::__construct($params); |
|
41 | - } |
|
31 | + /** |
|
32 | + * The home user storage requires a user object to create a unique storage id |
|
33 | + * @param array $params |
|
34 | + */ |
|
35 | + public function __construct($params) { |
|
36 | + if (! isset($params['user']) || ! $params['user'] instanceof User) { |
|
37 | + throw new \Exception('missing user object in parameters'); |
|
38 | + } |
|
39 | + $this->user = $params['user']; |
|
40 | + parent::__construct($params); |
|
41 | + } |
|
42 | 42 | |
43 | - public function getId() { |
|
44 | - return 'object::user:' . $this->user->getUID(); |
|
45 | - } |
|
43 | + public function getId() { |
|
44 | + return 'object::user:' . $this->user->getUID(); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * get the owner of a path |
|
49 | - * |
|
50 | - * @param string $path The path to get the owner |
|
51 | - * @return false|string uid |
|
52 | - */ |
|
53 | - public function getOwner($path) { |
|
54 | - if (is_object($this->user)) { |
|
55 | - return $this->user->getUID(); |
|
56 | - } |
|
57 | - return false; |
|
58 | - } |
|
47 | + /** |
|
48 | + * get the owner of a path |
|
49 | + * |
|
50 | + * @param string $path The path to get the owner |
|
51 | + * @return false|string uid |
|
52 | + */ |
|
53 | + public function getOwner($path) { |
|
54 | + if (is_object($this->user)) { |
|
55 | + return $this->user->getUID(); |
|
56 | + } |
|
57 | + return false; |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * @param string $path, optional |
|
62 | - * @return \OC\User\User |
|
63 | - */ |
|
64 | - public function getUser($path = null) { |
|
65 | - return $this->user; |
|
66 | - } |
|
60 | + /** |
|
61 | + * @param string $path, optional |
|
62 | + * @return \OC\User\User |
|
63 | + */ |
|
64 | + public function getUser($path = null) { |
|
65 | + return $this->user; |
|
66 | + } |
|
67 | 67 | } |
@@ -24,17 +24,17 @@ |
||
24 | 24 | namespace OC\DB; |
25 | 25 | |
26 | 26 | class MigrationException extends \Exception { |
27 | - private $table; |
|
27 | + private $table; |
|
28 | 28 | |
29 | - public function __construct($table, $message) { |
|
30 | - $this->table = $table; |
|
31 | - parent::__construct($message); |
|
32 | - } |
|
29 | + public function __construct($table, $message) { |
|
30 | + $this->table = $table; |
|
31 | + parent::__construct($message); |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * @return string |
|
36 | - */ |
|
37 | - public function getTable() { |
|
38 | - return $this->table; |
|
39 | - } |
|
34 | + /** |
|
35 | + * @return string |
|
36 | + */ |
|
37 | + public function getTable() { |
|
38 | + return $this->table; |
|
39 | + } |
|
40 | 40 | } |
@@ -25,17 +25,17 @@ |
||
25 | 25 | use OCP\DB\QueryBuilder\ILiteral; |
26 | 26 | |
27 | 27 | class Literal implements ILiteral { |
28 | - /** @var mixed */ |
|
29 | - protected $literal; |
|
28 | + /** @var mixed */ |
|
29 | + protected $literal; |
|
30 | 30 | |
31 | - public function __construct($literal) { |
|
32 | - $this->literal = $literal; |
|
33 | - } |
|
31 | + public function __construct($literal) { |
|
32 | + $this->literal = $literal; |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * @return string |
|
37 | - */ |
|
38 | - public function __toString() { |
|
39 | - return (string) $this->literal; |
|
40 | - } |
|
35 | + /** |
|
36 | + * @return string |
|
37 | + */ |
|
38 | + public function __toString() { |
|
39 | + return (string) $this->literal; |
|
40 | + } |
|
41 | 41 | } |
@@ -64,14 +64,14 @@ |
||
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 | 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 | 73 | foreach ($compare as $key) { |
74 | - $query .= '`' . $key . '`'; |
|
74 | + $query .= '`'.$key.'`'; |
|
75 | 75 | if (is_null($input[$key])) { |
76 | 76 | $query .= ' IS NULL AND '; |
77 | 77 | } else { |
@@ -29,70 +29,70 @@ |
||
29 | 29 | use Doctrine\DBAL\Exception\UniqueConstraintViolationException; |
30 | 30 | |
31 | 31 | class AdapterSqlite extends Adapter { |
32 | - /** |
|
33 | - * @param string $tableName |
|
34 | - */ |
|
35 | - public function lockTable($tableName) { |
|
36 | - $this->conn->executeUpdate('BEGIN EXCLUSIVE TRANSACTION'); |
|
37 | - } |
|
32 | + /** |
|
33 | + * @param string $tableName |
|
34 | + */ |
|
35 | + public function lockTable($tableName) { |
|
36 | + $this->conn->executeUpdate('BEGIN EXCLUSIVE TRANSACTION'); |
|
37 | + } |
|
38 | 38 | |
39 | - public function unlockTable() { |
|
40 | - $this->conn->executeUpdate('COMMIT TRANSACTION'); |
|
41 | - } |
|
39 | + public function unlockTable() { |
|
40 | + $this->conn->executeUpdate('COMMIT TRANSACTION'); |
|
41 | + } |
|
42 | 42 | |
43 | - public function fixupStatement($statement) { |
|
44 | - $statement = preg_replace('/`(\w+)` ILIKE \?/', 'LOWER($1) LIKE LOWER(?)', $statement); |
|
45 | - $statement = str_replace('`', '"', $statement); |
|
46 | - $statement = str_ireplace('NOW()', 'datetime(\'now\')', $statement); |
|
47 | - $statement = str_ireplace('GREATEST(', 'MAX(', $statement); |
|
48 | - $statement = str_ireplace('UNIX_TIMESTAMP()', 'strftime(\'%s\',\'now\')', $statement); |
|
49 | - return $statement; |
|
50 | - } |
|
43 | + public function fixupStatement($statement) { |
|
44 | + $statement = preg_replace('/`(\w+)` ILIKE \?/', 'LOWER($1) LIKE LOWER(?)', $statement); |
|
45 | + $statement = str_replace('`', '"', $statement); |
|
46 | + $statement = str_ireplace('NOW()', 'datetime(\'now\')', $statement); |
|
47 | + $statement = str_ireplace('GREATEST(', 'MAX(', $statement); |
|
48 | + $statement = str_ireplace('UNIX_TIMESTAMP()', 'strftime(\'%s\',\'now\')', $statement); |
|
49 | + return $statement; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Insert a row if the matching row does not exists. To accomplish proper race condition avoidance |
|
54 | - * it is needed that there is also a unique constraint on the values. Then this method will |
|
55 | - * catch the exception and return 0. |
|
56 | - * |
|
57 | - * @param string $table The table name (will replace *PREFIX* with the actual prefix) |
|
58 | - * @param array $input data that should be inserted into the table (column name => value) |
|
59 | - * @param array|null $compare List of values that should be checked for "if not exists" |
|
60 | - * If this is null or an empty array, all keys of $input will be compared |
|
61 | - * Please note: text fields (clob) must not be used in the compare array |
|
62 | - * @return int number of inserted rows |
|
63 | - * @throws \Doctrine\DBAL\Exception |
|
64 | - * @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 |
|
65 | - */ |
|
66 | - public function insertIfNotExist($table, $input, array $compare = null) { |
|
67 | - if (empty($compare)) { |
|
68 | - $compare = array_keys($input); |
|
69 | - } |
|
70 | - $fieldList = '`' . implode('`,`', array_keys($input)) . '`'; |
|
71 | - $query = "INSERT INTO `$table` ($fieldList) SELECT " |
|
72 | - . str_repeat('?,', count($input) - 1).'? ' |
|
73 | - . " WHERE NOT EXISTS (SELECT 1 FROM `$table` WHERE "; |
|
52 | + /** |
|
53 | + * Insert a row if the matching row does not exists. To accomplish proper race condition avoidance |
|
54 | + * it is needed that there is also a unique constraint on the values. Then this method will |
|
55 | + * catch the exception and return 0. |
|
56 | + * |
|
57 | + * @param string $table The table name (will replace *PREFIX* with the actual prefix) |
|
58 | + * @param array $input data that should be inserted into the table (column name => value) |
|
59 | + * @param array|null $compare List of values that should be checked for "if not exists" |
|
60 | + * If this is null or an empty array, all keys of $input will be compared |
|
61 | + * Please note: text fields (clob) must not be used in the compare array |
|
62 | + * @return int number of inserted rows |
|
63 | + * @throws \Doctrine\DBAL\Exception |
|
64 | + * @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 |
|
65 | + */ |
|
66 | + public function insertIfNotExist($table, $input, array $compare = null) { |
|
67 | + if (empty($compare)) { |
|
68 | + $compare = array_keys($input); |
|
69 | + } |
|
70 | + $fieldList = '`' . implode('`,`', array_keys($input)) . '`'; |
|
71 | + $query = "INSERT INTO `$table` ($fieldList) SELECT " |
|
72 | + . str_repeat('?,', count($input) - 1).'? ' |
|
73 | + . " WHERE NOT EXISTS (SELECT 1 FROM `$table` WHERE "; |
|
74 | 74 | |
75 | - $inserts = array_values($input); |
|
76 | - foreach ($compare as $key) { |
|
77 | - $query .= '`' . $key . '`'; |
|
78 | - if (is_null($input[$key])) { |
|
79 | - $query .= ' IS NULL AND '; |
|
80 | - } else { |
|
81 | - $inserts[] = $input[$key]; |
|
82 | - $query .= ' = ? AND '; |
|
83 | - } |
|
84 | - } |
|
85 | - $query = substr($query, 0, -5); |
|
86 | - $query .= ')'; |
|
75 | + $inserts = array_values($input); |
|
76 | + foreach ($compare as $key) { |
|
77 | + $query .= '`' . $key . '`'; |
|
78 | + if (is_null($input[$key])) { |
|
79 | + $query .= ' IS NULL AND '; |
|
80 | + } else { |
|
81 | + $inserts[] = $input[$key]; |
|
82 | + $query .= ' = ? AND '; |
|
83 | + } |
|
84 | + } |
|
85 | + $query = substr($query, 0, -5); |
|
86 | + $query .= ')'; |
|
87 | 87 | |
88 | - try { |
|
89 | - return $this->conn->executeUpdate($query, $inserts); |
|
90 | - } catch (UniqueConstraintViolationException $e) { |
|
91 | - // if this is thrown then a concurrent insert happened between the insert and the sub-select in the insert, that should have avoided it |
|
92 | - // it's fine to ignore this then |
|
93 | - // |
|
94 | - // more discussions about this can be found at https://github.com/nextcloud/server/pull/12315 |
|
95 | - return 0; |
|
96 | - } |
|
97 | - } |
|
88 | + try { |
|
89 | + return $this->conn->executeUpdate($query, $inserts); |
|
90 | + } catch (UniqueConstraintViolationException $e) { |
|
91 | + // if this is thrown then a concurrent insert happened between the insert and the sub-select in the insert, that should have avoided it |
|
92 | + // it's fine to ignore this then |
|
93 | + // |
|
94 | + // more discussions about this can be found at https://github.com/nextcloud/server/pull/12315 |
|
95 | + return 0; |
|
96 | + } |
|
97 | + } |
|
98 | 98 | } |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function lockTable($tableName) { |
68 | 68 | $this->conn->beginTransaction(); |
69 | - $this->conn->executeUpdate('LOCK TABLE `' .$tableName . '` IN EXCLUSIVE MODE'); |
|
69 | + $this->conn->executeUpdate('LOCK TABLE `'.$tableName.'` IN EXCLUSIVE MODE'); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -93,14 +93,14 @@ discard block |
||
93 | 93 | if (empty($compare)) { |
94 | 94 | $compare = array_keys($input); |
95 | 95 | } |
96 | - $query = 'INSERT INTO `' .$table . '` (`' |
|
97 | - . implode('`,`', array_keys($input)) . '`) SELECT ' |
|
96 | + $query = 'INSERT INTO `'.$table.'` (`' |
|
97 | + . implode('`,`', array_keys($input)).'`) SELECT ' |
|
98 | 98 | . str_repeat('?,', count($input) - 1).'? ' // Is there a prettier alternative? |
99 | - . 'FROM `' . $table . '` WHERE '; |
|
99 | + . 'FROM `'.$table.'` WHERE '; |
|
100 | 100 | |
101 | 101 | $inserts = array_values($input); |
102 | 102 | foreach ($compare as $key) { |
103 | - $query .= '`' . $key . '`'; |
|
103 | + $query .= '`'.$key.'`'; |
|
104 | 104 | if (is_null($input[$key])) { |
105 | 105 | $query .= ' IS NULL AND '; |
106 | 106 | } else { |
@@ -36,115 +36,115 @@ |
||
36 | 36 | * handled by the database abstraction layer. |
37 | 37 | */ |
38 | 38 | class Adapter { |
39 | - /** |
|
40 | - * @var \OC\DB\Connection $conn |
|
41 | - */ |
|
42 | - protected $conn; |
|
39 | + /** |
|
40 | + * @var \OC\DB\Connection $conn |
|
41 | + */ |
|
42 | + protected $conn; |
|
43 | 43 | |
44 | - public function __construct($conn) { |
|
45 | - $this->conn = $conn; |
|
46 | - } |
|
44 | + public function __construct($conn) { |
|
45 | + $this->conn = $conn; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @param string $table name |
|
50 | - * |
|
51 | - * @return int id of last insert statement |
|
52 | - * @throws Exception |
|
53 | - */ |
|
54 | - public function lastInsertId($table) { |
|
55 | - return (int) $this->conn->realLastInsertId($table); |
|
56 | - } |
|
48 | + /** |
|
49 | + * @param string $table name |
|
50 | + * |
|
51 | + * @return int id of last insert statement |
|
52 | + * @throws Exception |
|
53 | + */ |
|
54 | + public function lastInsertId($table) { |
|
55 | + return (int) $this->conn->realLastInsertId($table); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * @param string $statement that needs to be changed so the db can handle it |
|
60 | - * @return string changed statement |
|
61 | - */ |
|
62 | - public function fixupStatement($statement) { |
|
63 | - return $statement; |
|
64 | - } |
|
58 | + /** |
|
59 | + * @param string $statement that needs to be changed so the db can handle it |
|
60 | + * @return string changed statement |
|
61 | + */ |
|
62 | + public function fixupStatement($statement) { |
|
63 | + return $statement; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * Create an exclusive read+write lock on a table |
|
68 | - * |
|
69 | - * @param string $tableName |
|
70 | - * @throws Exception |
|
71 | - * @since 9.1.0 |
|
72 | - */ |
|
73 | - public function lockTable($tableName) { |
|
74 | - $this->conn->beginTransaction(); |
|
75 | - $this->conn->executeUpdate('LOCK TABLE `' .$tableName . '` IN EXCLUSIVE MODE'); |
|
76 | - } |
|
66 | + /** |
|
67 | + * Create an exclusive read+write lock on a table |
|
68 | + * |
|
69 | + * @param string $tableName |
|
70 | + * @throws Exception |
|
71 | + * @since 9.1.0 |
|
72 | + */ |
|
73 | + public function lockTable($tableName) { |
|
74 | + $this->conn->beginTransaction(); |
|
75 | + $this->conn->executeUpdate('LOCK TABLE `' .$tableName . '` IN EXCLUSIVE MODE'); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * Release a previous acquired lock again |
|
80 | - * |
|
81 | - * @throws Exception |
|
82 | - * @since 9.1.0 |
|
83 | - */ |
|
84 | - public function unlockTable() { |
|
85 | - $this->conn->commit(); |
|
86 | - } |
|
78 | + /** |
|
79 | + * Release a previous acquired lock again |
|
80 | + * |
|
81 | + * @throws Exception |
|
82 | + * @since 9.1.0 |
|
83 | + */ |
|
84 | + public function unlockTable() { |
|
85 | + $this->conn->commit(); |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * Insert a row if the matching row does not exists. To accomplish proper race condition avoidance |
|
90 | - * it is needed that there is also a unique constraint on the values. Then this method will |
|
91 | - * catch the exception and return 0. |
|
92 | - * |
|
93 | - * @param string $table The table name (will replace *PREFIX* with the actual prefix) |
|
94 | - * @param array $input data that should be inserted into the table (column name => value) |
|
95 | - * @param array|null $compare List of values that should be checked for "if not exists" |
|
96 | - * If this is null or an empty array, all keys of $input will be compared |
|
97 | - * Please note: text fields (clob) must not be used in the compare array |
|
98 | - * @return int number of inserted rows |
|
99 | - * @throws Exception |
|
100 | - * @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 |
|
101 | - */ |
|
102 | - public function insertIfNotExist($table, $input, array $compare = null) { |
|
103 | - if (empty($compare)) { |
|
104 | - $compare = array_keys($input); |
|
105 | - } |
|
106 | - $query = 'INSERT INTO `' .$table . '` (`' |
|
107 | - . implode('`,`', array_keys($input)) . '`) SELECT ' |
|
108 | - . str_repeat('?,', count($input) - 1).'? ' // Is there a prettier alternative? |
|
109 | - . 'FROM `' . $table . '` WHERE '; |
|
88 | + /** |
|
89 | + * Insert a row if the matching row does not exists. To accomplish proper race condition avoidance |
|
90 | + * it is needed that there is also a unique constraint on the values. Then this method will |
|
91 | + * catch the exception and return 0. |
|
92 | + * |
|
93 | + * @param string $table The table name (will replace *PREFIX* with the actual prefix) |
|
94 | + * @param array $input data that should be inserted into the table (column name => value) |
|
95 | + * @param array|null $compare List of values that should be checked for "if not exists" |
|
96 | + * If this is null or an empty array, all keys of $input will be compared |
|
97 | + * Please note: text fields (clob) must not be used in the compare array |
|
98 | + * @return int number of inserted rows |
|
99 | + * @throws Exception |
|
100 | + * @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 |
|
101 | + */ |
|
102 | + public function insertIfNotExist($table, $input, array $compare = null) { |
|
103 | + if (empty($compare)) { |
|
104 | + $compare = array_keys($input); |
|
105 | + } |
|
106 | + $query = 'INSERT INTO `' .$table . '` (`' |
|
107 | + . implode('`,`', array_keys($input)) . '`) SELECT ' |
|
108 | + . str_repeat('?,', count($input) - 1).'? ' // Is there a prettier alternative? |
|
109 | + . 'FROM `' . $table . '` WHERE '; |
|
110 | 110 | |
111 | - $inserts = array_values($input); |
|
112 | - foreach ($compare as $key) { |
|
113 | - $query .= '`' . $key . '`'; |
|
114 | - if (is_null($input[$key])) { |
|
115 | - $query .= ' IS NULL AND '; |
|
116 | - } else { |
|
117 | - $inserts[] = $input[$key]; |
|
118 | - $query .= ' = ? AND '; |
|
119 | - } |
|
120 | - } |
|
121 | - $query = substr($query, 0, -5); |
|
122 | - $query .= ' HAVING COUNT(*) = 0'; |
|
111 | + $inserts = array_values($input); |
|
112 | + foreach ($compare as $key) { |
|
113 | + $query .= '`' . $key . '`'; |
|
114 | + if (is_null($input[$key])) { |
|
115 | + $query .= ' IS NULL AND '; |
|
116 | + } else { |
|
117 | + $inserts[] = $input[$key]; |
|
118 | + $query .= ' = ? AND '; |
|
119 | + } |
|
120 | + } |
|
121 | + $query = substr($query, 0, -5); |
|
122 | + $query .= ' HAVING COUNT(*) = 0'; |
|
123 | 123 | |
124 | - try { |
|
125 | - return $this->conn->executeUpdate($query, $inserts); |
|
126 | - } catch (UniqueConstraintViolationException $e) { |
|
127 | - // if this is thrown then a concurrent insert happened between the insert and the sub-select in the insert, that should have avoided it |
|
128 | - // it's fine to ignore this then |
|
129 | - // |
|
130 | - // more discussions about this can be found at https://github.com/nextcloud/server/pull/12315 |
|
131 | - return 0; |
|
132 | - } |
|
133 | - } |
|
124 | + try { |
|
125 | + return $this->conn->executeUpdate($query, $inserts); |
|
126 | + } catch (UniqueConstraintViolationException $e) { |
|
127 | + // if this is thrown then a concurrent insert happened between the insert and the sub-select in the insert, that should have avoided it |
|
128 | + // it's fine to ignore this then |
|
129 | + // |
|
130 | + // more discussions about this can be found at https://github.com/nextcloud/server/pull/12315 |
|
131 | + return 0; |
|
132 | + } |
|
133 | + } |
|
134 | 134 | |
135 | - /** |
|
136 | - * @throws \OCP\DB\Exception |
|
137 | - */ |
|
138 | - public function insertIgnoreConflict(string $table, array $values) : int { |
|
139 | - try { |
|
140 | - $builder = $this->conn->getQueryBuilder(); |
|
141 | - $builder->insert($table); |
|
142 | - foreach ($values as $key => $value) { |
|
143 | - $builder->setValue($key, $builder->createNamedParameter($value)); |
|
144 | - } |
|
145 | - return $builder->execute(); |
|
146 | - } catch (UniqueConstraintViolationException $e) { |
|
147 | - return 0; |
|
148 | - } |
|
149 | - } |
|
135 | + /** |
|
136 | + * @throws \OCP\DB\Exception |
|
137 | + */ |
|
138 | + public function insertIgnoreConflict(string $table, array $values) : int { |
|
139 | + try { |
|
140 | + $builder = $this->conn->getQueryBuilder(); |
|
141 | + $builder->insert($table); |
|
142 | + foreach ($values as $key => $value) { |
|
143 | + $builder->setValue($key, $builder->createNamedParameter($value)); |
|
144 | + } |
|
145 | + return $builder->execute(); |
|
146 | + } catch (UniqueConstraintViolationException $e) { |
|
147 | + return 0; |
|
148 | + } |
|
149 | + } |
|
150 | 150 | } |
@@ -82,7 +82,7 @@ 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 | 88 | if ($schema->tablesExist([$table])) { |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | * @return bool |
98 | 98 | */ |
99 | 99 | public function tableExists($table) { |
100 | - $table = $this->tablePrefix . trim($table); |
|
100 | + $table = $this->tablePrefix.trim($table); |
|
101 | 101 | $table = $this->quoteIdentifier($table); |
102 | 102 | $schema = $this->getSchemaManager(); |
103 | 103 | return $schema->tablesExist([$table]); |
@@ -28,80 +28,80 @@ |
||
28 | 28 | namespace OC\DB; |
29 | 29 | |
30 | 30 | class OracleConnection extends Connection { |
31 | - /** |
|
32 | - * Quote the keys of the array |
|
33 | - */ |
|
34 | - private function quoteKeys(array $data) { |
|
35 | - $return = []; |
|
36 | - $c = $this->getDatabasePlatform()->getIdentifierQuoteCharacter(); |
|
37 | - foreach ($data as $key => $value) { |
|
38 | - if ($key[0] !== $c) { |
|
39 | - $return[$this->quoteIdentifier($key)] = $value; |
|
40 | - } else { |
|
41 | - $return[$key] = $value; |
|
42 | - } |
|
43 | - } |
|
44 | - return $return; |
|
45 | - } |
|
31 | + /** |
|
32 | + * Quote the keys of the array |
|
33 | + */ |
|
34 | + private function quoteKeys(array $data) { |
|
35 | + $return = []; |
|
36 | + $c = $this->getDatabasePlatform()->getIdentifierQuoteCharacter(); |
|
37 | + foreach ($data as $key => $value) { |
|
38 | + if ($key[0] !== $c) { |
|
39 | + $return[$this->quoteIdentifier($key)] = $value; |
|
40 | + } else { |
|
41 | + $return[$key] = $value; |
|
42 | + } |
|
43 | + } |
|
44 | + return $return; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * {@inheritDoc} |
|
49 | - */ |
|
50 | - public function insert($table, array $data, array $types = []) { |
|
51 | - if ($table[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
52 | - $table = $this->quoteIdentifier($table); |
|
53 | - } |
|
54 | - $data = $this->quoteKeys($data); |
|
55 | - return parent::insert($table, $data, $types); |
|
56 | - } |
|
47 | + /** |
|
48 | + * {@inheritDoc} |
|
49 | + */ |
|
50 | + public function insert($table, array $data, array $types = []) { |
|
51 | + if ($table[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
52 | + $table = $this->quoteIdentifier($table); |
|
53 | + } |
|
54 | + $data = $this->quoteKeys($data); |
|
55 | + return parent::insert($table, $data, $types); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * {@inheritDoc} |
|
60 | - */ |
|
61 | - public function update($table, array $data, array $criteria, array $types = []) { |
|
62 | - if ($table[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
63 | - $table = $this->quoteIdentifier($table); |
|
64 | - } |
|
65 | - $data = $this->quoteKeys($data); |
|
66 | - $criteria = $this->quoteKeys($criteria); |
|
67 | - return parent::update($table, $data, $criteria, $types); |
|
68 | - } |
|
58 | + /** |
|
59 | + * {@inheritDoc} |
|
60 | + */ |
|
61 | + public function update($table, array $data, array $criteria, array $types = []) { |
|
62 | + if ($table[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
63 | + $table = $this->quoteIdentifier($table); |
|
64 | + } |
|
65 | + $data = $this->quoteKeys($data); |
|
66 | + $criteria = $this->quoteKeys($criteria); |
|
67 | + return parent::update($table, $data, $criteria, $types); |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * {@inheritDoc} |
|
72 | - */ |
|
73 | - public function delete($table, array $criteria, array $types = []) { |
|
74 | - if ($table[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
75 | - $table = $this->quoteIdentifier($table); |
|
76 | - } |
|
77 | - $criteria = $this->quoteKeys($criteria); |
|
78 | - return parent::delete($table, $criteria); |
|
79 | - } |
|
70 | + /** |
|
71 | + * {@inheritDoc} |
|
72 | + */ |
|
73 | + public function delete($table, array $criteria, array $types = []) { |
|
74 | + if ($table[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
75 | + $table = $this->quoteIdentifier($table); |
|
76 | + } |
|
77 | + $criteria = $this->quoteKeys($criteria); |
|
78 | + return parent::delete($table, $criteria); |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * Drop a table from the database if it exists |
|
83 | - * |
|
84 | - * @param string $table table name without the prefix |
|
85 | - */ |
|
86 | - public function dropTable($table) { |
|
87 | - $table = $this->tablePrefix . trim($table); |
|
88 | - $table = $this->quoteIdentifier($table); |
|
89 | - $schema = $this->getSchemaManager(); |
|
90 | - if ($schema->tablesExist([$table])) { |
|
91 | - $schema->dropTable($table); |
|
92 | - } |
|
93 | - } |
|
81 | + /** |
|
82 | + * Drop a table from the database if it exists |
|
83 | + * |
|
84 | + * @param string $table table name without the prefix |
|
85 | + */ |
|
86 | + public function dropTable($table) { |
|
87 | + $table = $this->tablePrefix . trim($table); |
|
88 | + $table = $this->quoteIdentifier($table); |
|
89 | + $schema = $this->getSchemaManager(); |
|
90 | + if ($schema->tablesExist([$table])) { |
|
91 | + $schema->dropTable($table); |
|
92 | + } |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * Check if a table exists |
|
97 | - * |
|
98 | - * @param string $table table name without the prefix |
|
99 | - * @return bool |
|
100 | - */ |
|
101 | - public function tableExists($table) { |
|
102 | - $table = $this->tablePrefix . trim($table); |
|
103 | - $table = $this->quoteIdentifier($table); |
|
104 | - $schema = $this->getSchemaManager(); |
|
105 | - return $schema->tablesExist([$table]); |
|
106 | - } |
|
95 | + /** |
|
96 | + * Check if a table exists |
|
97 | + * |
|
98 | + * @param string $table table name without the prefix |
|
99 | + * @return bool |
|
100 | + */ |
|
101 | + public function tableExists($table) { |
|
102 | + $table = $this->tablePrefix . trim($table); |
|
103 | + $table = $this->quoteIdentifier($table); |
|
104 | + $schema = $this->getSchemaManager(); |
|
105 | + return $schema->tablesExist([$table]); |
|
106 | + } |
|
107 | 107 | } |
@@ -25,12 +25,12 @@ |
||
25 | 25 | use OCP\IUser; |
26 | 26 | |
27 | 27 | trait FileAccess { |
28 | - protected function setupFS(IUser $user) { |
|
29 | - \OC_Util::setupFS($user->getUID()); |
|
30 | - } |
|
28 | + protected function setupFS(IUser $user) { |
|
29 | + \OC_Util::setupFS($user->getUID()); |
|
30 | + } |
|
31 | 31 | |
32 | - protected function getUserFolder(IUser $user) { |
|
33 | - $this->setupFS($user); |
|
34 | - return \OC::$server->getUserFolder($user->getUID()); |
|
35 | - } |
|
32 | + protected function getUserFolder(IUser $user) { |
|
33 | + $this->setupFS($user); |
|
34 | + return \OC::$server->getUserFolder($user->getUID()); |
|
35 | + } |
|
36 | 36 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | use CADTrait; |
38 | 38 | |
39 | 39 | public function get($key) { |
40 | - $result = apcu_fetch($this->getPrefix() . $key, $success); |
|
40 | + $result = apcu_fetch($this->getPrefix().$key, $success); |
|
41 | 41 | if (!$success) { |
42 | 42 | return null; |
43 | 43 | } |
@@ -45,24 +45,24 @@ discard block |
||
45 | 45 | } |
46 | 46 | |
47 | 47 | public function set($key, $value, $ttl = 0) { |
48 | - return apcu_store($this->getPrefix() . $key, $value, $ttl); |
|
48 | + return apcu_store($this->getPrefix().$key, $value, $ttl); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | public function hasKey($key) { |
52 | - return apcu_exists($this->getPrefix() . $key); |
|
52 | + return apcu_exists($this->getPrefix().$key); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | public function remove($key) { |
56 | - return apcu_delete($this->getPrefix() . $key); |
|
56 | + return apcu_delete($this->getPrefix().$key); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | public function clear($prefix = '') { |
60 | - $ns = $this->getPrefix() . $prefix; |
|
60 | + $ns = $this->getPrefix().$prefix; |
|
61 | 61 | $ns = preg_quote($ns, '/'); |
62 | 62 | if (class_exists('\APCIterator')) { |
63 | - $iter = new \APCIterator('user', '/^' . $ns . '/', APC_ITER_KEY); |
|
63 | + $iter = new \APCIterator('user', '/^'.$ns.'/', APC_ITER_KEY); |
|
64 | 64 | } else { |
65 | - $iter = new \APCUIterator('/^' . $ns . '/', APC_ITER_KEY); |
|
65 | + $iter = new \APCUIterator('/^'.$ns.'/', APC_ITER_KEY); |
|
66 | 66 | } |
67 | 67 | return apcu_delete($iter); |
68 | 68 | } |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | * @return bool |
77 | 77 | */ |
78 | 78 | public function add($key, $value, $ttl = 0) { |
79 | - return apcu_add($this->getPrefix() . $key, $value, $ttl); |
|
79 | + return apcu_add($this->getPrefix().$key, $value, $ttl); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
@@ -100,8 +100,8 @@ discard block |
||
100 | 100 | * see https://github.com/krakjoe/apcu/issues/183#issuecomment-244038221 |
101 | 101 | * for details |
102 | 102 | */ |
103 | - return apcu_exists($this->getPrefix() . $key) |
|
104 | - ? apcu_inc($this->getPrefix() . $key, $step) |
|
103 | + return apcu_exists($this->getPrefix().$key) |
|
104 | + ? apcu_inc($this->getPrefix().$key, $step) |
|
105 | 105 | : false; |
106 | 106 | } |
107 | 107 | |
@@ -125,8 +125,8 @@ discard block |
||
125 | 125 | * see https://github.com/krakjoe/apcu/issues/183#issuecomment-244038221 |
126 | 126 | * for details |
127 | 127 | */ |
128 | - return apcu_exists($this->getPrefix() . $key) |
|
129 | - ? apcu_dec($this->getPrefix() . $key, $step) |
|
128 | + return apcu_exists($this->getPrefix().$key) |
|
129 | + ? apcu_dec($this->getPrefix().$key, $step) |
|
130 | 130 | : false; |
131 | 131 | } |
132 | 132 | |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | public function cas($key, $old, $new) { |
142 | 142 | // apc only does cas for ints |
143 | 143 | if (is_int($old) and is_int($new)) { |
144 | - return apcu_cas($this->getPrefix() . $key, $old, $new); |
|
144 | + return apcu_cas($this->getPrefix().$key, $old, $new); |
|
145 | 145 | } else { |
146 | 146 | return $this->casEmulated($key, $old, $new); |
147 | 147 | } |
@@ -31,137 +31,137 @@ |
||
31 | 31 | use OCP\IMemcache; |
32 | 32 | |
33 | 33 | class APCu extends Cache implements IMemcache { |
34 | - use CASTrait { |
|
35 | - cas as casEmulated; |
|
36 | - } |
|
34 | + use CASTrait { |
|
35 | + cas as casEmulated; |
|
36 | + } |
|
37 | 37 | |
38 | - use CADTrait; |
|
38 | + use CADTrait; |
|
39 | 39 | |
40 | - public function get($key) { |
|
41 | - $result = apcu_fetch($this->getPrefix() . $key, $success); |
|
42 | - if (!$success) { |
|
43 | - return null; |
|
44 | - } |
|
45 | - return $result; |
|
46 | - } |
|
40 | + public function get($key) { |
|
41 | + $result = apcu_fetch($this->getPrefix() . $key, $success); |
|
42 | + if (!$success) { |
|
43 | + return null; |
|
44 | + } |
|
45 | + return $result; |
|
46 | + } |
|
47 | 47 | |
48 | - public function set($key, $value, $ttl = 0) { |
|
49 | - return apcu_store($this->getPrefix() . $key, $value, $ttl); |
|
50 | - } |
|
48 | + public function set($key, $value, $ttl = 0) { |
|
49 | + return apcu_store($this->getPrefix() . $key, $value, $ttl); |
|
50 | + } |
|
51 | 51 | |
52 | - public function hasKey($key) { |
|
53 | - return apcu_exists($this->getPrefix() . $key); |
|
54 | - } |
|
52 | + public function hasKey($key) { |
|
53 | + return apcu_exists($this->getPrefix() . $key); |
|
54 | + } |
|
55 | 55 | |
56 | - public function remove($key) { |
|
57 | - return apcu_delete($this->getPrefix() . $key); |
|
58 | - } |
|
56 | + public function remove($key) { |
|
57 | + return apcu_delete($this->getPrefix() . $key); |
|
58 | + } |
|
59 | 59 | |
60 | - public function clear($prefix = '') { |
|
61 | - $ns = $this->getPrefix() . $prefix; |
|
62 | - $ns = preg_quote($ns, '/'); |
|
63 | - if (class_exists('\APCIterator')) { |
|
64 | - $iter = new \APCIterator('user', '/^' . $ns . '/', APC_ITER_KEY); |
|
65 | - } else { |
|
66 | - $iter = new \APCUIterator('/^' . $ns . '/', APC_ITER_KEY); |
|
67 | - } |
|
68 | - return apcu_delete($iter); |
|
69 | - } |
|
60 | + public function clear($prefix = '') { |
|
61 | + $ns = $this->getPrefix() . $prefix; |
|
62 | + $ns = preg_quote($ns, '/'); |
|
63 | + if (class_exists('\APCIterator')) { |
|
64 | + $iter = new \APCIterator('user', '/^' . $ns . '/', APC_ITER_KEY); |
|
65 | + } else { |
|
66 | + $iter = new \APCUIterator('/^' . $ns . '/', APC_ITER_KEY); |
|
67 | + } |
|
68 | + return apcu_delete($iter); |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Set a value in the cache if it's not already stored |
|
73 | - * |
|
74 | - * @param string $key |
|
75 | - * @param mixed $value |
|
76 | - * @param int $ttl Time To Live in seconds. Defaults to 60*60*24 |
|
77 | - * @return bool |
|
78 | - */ |
|
79 | - public function add($key, $value, $ttl = 0) { |
|
80 | - return apcu_add($this->getPrefix() . $key, $value, $ttl); |
|
81 | - } |
|
71 | + /** |
|
72 | + * Set a value in the cache if it's not already stored |
|
73 | + * |
|
74 | + * @param string $key |
|
75 | + * @param mixed $value |
|
76 | + * @param int $ttl Time To Live in seconds. Defaults to 60*60*24 |
|
77 | + * @return bool |
|
78 | + */ |
|
79 | + public function add($key, $value, $ttl = 0) { |
|
80 | + return apcu_add($this->getPrefix() . $key, $value, $ttl); |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Increase a stored number |
|
85 | - * |
|
86 | - * @param string $key |
|
87 | - * @param int $step |
|
88 | - * @return int | bool |
|
89 | - */ |
|
90 | - public function inc($key, $step = 1) { |
|
91 | - $this->add($key, 0); |
|
92 | - /** |
|
93 | - * TODO - hack around a PHP 7 specific issue in APCu |
|
94 | - * |
|
95 | - * on PHP 7 the apcu_inc method on a non-existing object will increment |
|
96 | - * "0" and result in "1" as value - therefore we check for existence |
|
97 | - * first |
|
98 | - * |
|
99 | - * on PHP 5.6 this is not the case |
|
100 | - * |
|
101 | - * see https://github.com/krakjoe/apcu/issues/183#issuecomment-244038221 |
|
102 | - * for details |
|
103 | - */ |
|
104 | - return apcu_exists($this->getPrefix() . $key) |
|
105 | - ? apcu_inc($this->getPrefix() . $key, $step) |
|
106 | - : false; |
|
107 | - } |
|
83 | + /** |
|
84 | + * Increase a stored number |
|
85 | + * |
|
86 | + * @param string $key |
|
87 | + * @param int $step |
|
88 | + * @return int | bool |
|
89 | + */ |
|
90 | + public function inc($key, $step = 1) { |
|
91 | + $this->add($key, 0); |
|
92 | + /** |
|
93 | + * TODO - hack around a PHP 7 specific issue in APCu |
|
94 | + * |
|
95 | + * on PHP 7 the apcu_inc method on a non-existing object will increment |
|
96 | + * "0" and result in "1" as value - therefore we check for existence |
|
97 | + * first |
|
98 | + * |
|
99 | + * on PHP 5.6 this is not the case |
|
100 | + * |
|
101 | + * see https://github.com/krakjoe/apcu/issues/183#issuecomment-244038221 |
|
102 | + * for details |
|
103 | + */ |
|
104 | + return apcu_exists($this->getPrefix() . $key) |
|
105 | + ? apcu_inc($this->getPrefix() . $key, $step) |
|
106 | + : false; |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * Decrease a stored number |
|
111 | - * |
|
112 | - * @param string $key |
|
113 | - * @param int $step |
|
114 | - * @return int | bool |
|
115 | - */ |
|
116 | - public function dec($key, $step = 1) { |
|
117 | - /** |
|
118 | - * TODO - hack around a PHP 7 specific issue in APCu |
|
119 | - * |
|
120 | - * on PHP 7 the apcu_dec method on a non-existing object will decrement |
|
121 | - * "0" and result in "-1" as value - therefore we check for existence |
|
122 | - * first |
|
123 | - * |
|
124 | - * on PHP 5.6 this is not the case |
|
125 | - * |
|
126 | - * see https://github.com/krakjoe/apcu/issues/183#issuecomment-244038221 |
|
127 | - * for details |
|
128 | - */ |
|
129 | - return apcu_exists($this->getPrefix() . $key) |
|
130 | - ? apcu_dec($this->getPrefix() . $key, $step) |
|
131 | - : false; |
|
132 | - } |
|
109 | + /** |
|
110 | + * Decrease a stored number |
|
111 | + * |
|
112 | + * @param string $key |
|
113 | + * @param int $step |
|
114 | + * @return int | bool |
|
115 | + */ |
|
116 | + public function dec($key, $step = 1) { |
|
117 | + /** |
|
118 | + * TODO - hack around a PHP 7 specific issue in APCu |
|
119 | + * |
|
120 | + * on PHP 7 the apcu_dec method on a non-existing object will decrement |
|
121 | + * "0" and result in "-1" as value - therefore we check for existence |
|
122 | + * first |
|
123 | + * |
|
124 | + * on PHP 5.6 this is not the case |
|
125 | + * |
|
126 | + * see https://github.com/krakjoe/apcu/issues/183#issuecomment-244038221 |
|
127 | + * for details |
|
128 | + */ |
|
129 | + return apcu_exists($this->getPrefix() . $key) |
|
130 | + ? apcu_dec($this->getPrefix() . $key, $step) |
|
131 | + : false; |
|
132 | + } |
|
133 | 133 | |
134 | - /** |
|
135 | - * Compare and set |
|
136 | - * |
|
137 | - * @param string $key |
|
138 | - * @param mixed $old |
|
139 | - * @param mixed $new |
|
140 | - * @return bool |
|
141 | - */ |
|
142 | - public function cas($key, $old, $new) { |
|
143 | - // apc only does cas for ints |
|
144 | - if (is_int($old) and is_int($new)) { |
|
145 | - return apcu_cas($this->getPrefix() . $key, $old, $new); |
|
146 | - } else { |
|
147 | - return $this->casEmulated($key, $old, $new); |
|
148 | - } |
|
149 | - } |
|
134 | + /** |
|
135 | + * Compare and set |
|
136 | + * |
|
137 | + * @param string $key |
|
138 | + * @param mixed $old |
|
139 | + * @param mixed $new |
|
140 | + * @return bool |
|
141 | + */ |
|
142 | + public function cas($key, $old, $new) { |
|
143 | + // apc only does cas for ints |
|
144 | + if (is_int($old) and is_int($new)) { |
|
145 | + return apcu_cas($this->getPrefix() . $key, $old, $new); |
|
146 | + } else { |
|
147 | + return $this->casEmulated($key, $old, $new); |
|
148 | + } |
|
149 | + } |
|
150 | 150 | |
151 | - public static function isAvailable(): bool { |
|
152 | - if (!extension_loaded('apcu')) { |
|
153 | - return false; |
|
154 | - } elseif (!\OC::$server->get(IniGetWrapper::class)->getBool('apc.enabled')) { |
|
155 | - return false; |
|
156 | - } elseif (!\OC::$server->get(IniGetWrapper::class)->getBool('apc.enable_cli') && \OC::$CLI) { |
|
157 | - return false; |
|
158 | - } elseif ( |
|
159 | - version_compare(phpversion('apc') ?: '0.0.0', '4.0.6') === -1 && |
|
160 | - version_compare(phpversion('apcu') ?: '0.0.0', '5.1.0') === -1 |
|
161 | - ) { |
|
162 | - return false; |
|
163 | - } else { |
|
164 | - return true; |
|
165 | - } |
|
166 | - } |
|
151 | + public static function isAvailable(): bool { |
|
152 | + if (!extension_loaded('apcu')) { |
|
153 | + return false; |
|
154 | + } elseif (!\OC::$server->get(IniGetWrapper::class)->getBool('apc.enabled')) { |
|
155 | + return false; |
|
156 | + } elseif (!\OC::$server->get(IniGetWrapper::class)->getBool('apc.enable_cli') && \OC::$CLI) { |
|
157 | + return false; |
|
158 | + } elseif ( |
|
159 | + version_compare(phpversion('apc') ?: '0.0.0', '4.0.6') === -1 && |
|
160 | + version_compare(phpversion('apcu') ?: '0.0.0', '5.1.0') === -1 |
|
161 | + ) { |
|
162 | + return false; |
|
163 | + } else { |
|
164 | + return true; |
|
165 | + } |
|
166 | + } |
|
167 | 167 | } |
@@ -67,7 +67,7 @@ |
||
67 | 67 | * compared with \OC\Group\Backend::CREATE_GROUP etc. |
68 | 68 | */ |
69 | 69 | public function implementsActions($actions) { |
70 | - return (bool)($this->getSupportedActions() & $actions); |
|
70 | + return (bool) ($this->getSupportedActions() & $actions); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
@@ -28,107 +28,107 @@ |
||
28 | 28 | * Abstract base class for user management |
29 | 29 | */ |
30 | 30 | abstract class Backend implements \OCP\GroupInterface { |
31 | - /** |
|
32 | - * error code for functions not provided by the group backend |
|
33 | - */ |
|
34 | - public const NOT_IMPLEMENTED = -501; |
|
31 | + /** |
|
32 | + * error code for functions not provided by the group backend |
|
33 | + */ |
|
34 | + public const NOT_IMPLEMENTED = -501; |
|
35 | 35 | |
36 | - protected $possibleActions = [ |
|
37 | - self::CREATE_GROUP => 'createGroup', |
|
38 | - self::DELETE_GROUP => 'deleteGroup', |
|
39 | - self::ADD_TO_GROUP => 'addToGroup', |
|
40 | - self::REMOVE_FROM_GOUP => 'removeFromGroup', |
|
41 | - self::COUNT_USERS => 'countUsersInGroup', |
|
42 | - self::GROUP_DETAILS => 'getGroupDetails', |
|
43 | - self::IS_ADMIN => 'isAdmin', |
|
44 | - ]; |
|
36 | + protected $possibleActions = [ |
|
37 | + self::CREATE_GROUP => 'createGroup', |
|
38 | + self::DELETE_GROUP => 'deleteGroup', |
|
39 | + self::ADD_TO_GROUP => 'addToGroup', |
|
40 | + self::REMOVE_FROM_GOUP => 'removeFromGroup', |
|
41 | + self::COUNT_USERS => 'countUsersInGroup', |
|
42 | + self::GROUP_DETAILS => 'getGroupDetails', |
|
43 | + self::IS_ADMIN => 'isAdmin', |
|
44 | + ]; |
|
45 | 45 | |
46 | - /** |
|
47 | - * Get all supported actions |
|
48 | - * @return int bitwise-or'ed actions |
|
49 | - * |
|
50 | - * Returns the supported actions as int to be |
|
51 | - * compared with \OC\Group\Backend::CREATE_GROUP etc. |
|
52 | - */ |
|
53 | - public function getSupportedActions() { |
|
54 | - $actions = 0; |
|
55 | - foreach ($this->possibleActions as $action => $methodName) { |
|
56 | - if (method_exists($this, $methodName)) { |
|
57 | - $actions |= $action; |
|
58 | - } |
|
59 | - } |
|
46 | + /** |
|
47 | + * Get all supported actions |
|
48 | + * @return int bitwise-or'ed actions |
|
49 | + * |
|
50 | + * Returns the supported actions as int to be |
|
51 | + * compared with \OC\Group\Backend::CREATE_GROUP etc. |
|
52 | + */ |
|
53 | + public function getSupportedActions() { |
|
54 | + $actions = 0; |
|
55 | + foreach ($this->possibleActions as $action => $methodName) { |
|
56 | + if (method_exists($this, $methodName)) { |
|
57 | + $actions |= $action; |
|
58 | + } |
|
59 | + } |
|
60 | 60 | |
61 | - return $actions; |
|
62 | - } |
|
61 | + return $actions; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Check if backend implements actions |
|
66 | - * @param int $actions bitwise-or'ed actions |
|
67 | - * @return bool |
|
68 | - * |
|
69 | - * Returns the supported actions as int to be |
|
70 | - * compared with \OC\Group\Backend::CREATE_GROUP etc. |
|
71 | - */ |
|
72 | - public function implementsActions($actions) { |
|
73 | - return (bool)($this->getSupportedActions() & $actions); |
|
74 | - } |
|
64 | + /** |
|
65 | + * Check if backend implements actions |
|
66 | + * @param int $actions bitwise-or'ed actions |
|
67 | + * @return bool |
|
68 | + * |
|
69 | + * Returns the supported actions as int to be |
|
70 | + * compared with \OC\Group\Backend::CREATE_GROUP etc. |
|
71 | + */ |
|
72 | + public function implementsActions($actions) { |
|
73 | + return (bool)($this->getSupportedActions() & $actions); |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * is user in group? |
|
78 | - * @param string $uid uid of the user |
|
79 | - * @param string $gid gid of the group |
|
80 | - * @return bool |
|
81 | - * |
|
82 | - * Checks whether the user is member of a group or not. |
|
83 | - */ |
|
84 | - public function inGroup($uid, $gid) { |
|
85 | - return in_array($gid, $this->getUserGroups($uid)); |
|
86 | - } |
|
76 | + /** |
|
77 | + * is user in group? |
|
78 | + * @param string $uid uid of the user |
|
79 | + * @param string $gid gid of the group |
|
80 | + * @return bool |
|
81 | + * |
|
82 | + * Checks whether the user is member of a group or not. |
|
83 | + */ |
|
84 | + public function inGroup($uid, $gid) { |
|
85 | + return in_array($gid, $this->getUserGroups($uid)); |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * Get all groups a user belongs to |
|
90 | - * @param string $uid Name of the user |
|
91 | - * @return array an array of group names |
|
92 | - * |
|
93 | - * This function fetches all groups a user belongs to. It does not check |
|
94 | - * if the user exists at all. |
|
95 | - */ |
|
96 | - public function getUserGroups($uid) { |
|
97 | - return []; |
|
98 | - } |
|
88 | + /** |
|
89 | + * Get all groups a user belongs to |
|
90 | + * @param string $uid Name of the user |
|
91 | + * @return array an array of group names |
|
92 | + * |
|
93 | + * This function fetches all groups a user belongs to. It does not check |
|
94 | + * if the user exists at all. |
|
95 | + */ |
|
96 | + public function getUserGroups($uid) { |
|
97 | + return []; |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * get a list of all groups |
|
102 | - * @param string $search |
|
103 | - * @param int $limit |
|
104 | - * @param int $offset |
|
105 | - * @return array an array of group names |
|
106 | - * |
|
107 | - * Returns a list with all groups |
|
108 | - */ |
|
100 | + /** |
|
101 | + * get a list of all groups |
|
102 | + * @param string $search |
|
103 | + * @param int $limit |
|
104 | + * @param int $offset |
|
105 | + * @return array an array of group names |
|
106 | + * |
|
107 | + * Returns a list with all groups |
|
108 | + */ |
|
109 | 109 | |
110 | - public function getGroups($search = '', $limit = -1, $offset = 0) { |
|
111 | - return []; |
|
112 | - } |
|
110 | + public function getGroups($search = '', $limit = -1, $offset = 0) { |
|
111 | + return []; |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * check if a group exists |
|
116 | - * @param string $gid |
|
117 | - * @return bool |
|
118 | - */ |
|
119 | - public function groupExists($gid) { |
|
120 | - return in_array($gid, $this->getGroups($gid, 1)); |
|
121 | - } |
|
114 | + /** |
|
115 | + * check if a group exists |
|
116 | + * @param string $gid |
|
117 | + * @return bool |
|
118 | + */ |
|
119 | + public function groupExists($gid) { |
|
120 | + return in_array($gid, $this->getGroups($gid, 1)); |
|
121 | + } |
|
122 | 122 | |
123 | - /** |
|
124 | - * get a list of all users in a group |
|
125 | - * @param string $gid |
|
126 | - * @param string $search |
|
127 | - * @param int $limit |
|
128 | - * @param int $offset |
|
129 | - * @return array<int,string> an array of user ids |
|
130 | - */ |
|
131 | - public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) { |
|
132 | - return []; |
|
133 | - } |
|
123 | + /** |
|
124 | + * get a list of all users in a group |
|
125 | + * @param string $gid |
|
126 | + * @param string $search |
|
127 | + * @param int $limit |
|
128 | + * @param int $offset |
|
129 | + * @return array<int,string> an array of user ids |
|
130 | + */ |
|
131 | + public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) { |
|
132 | + return []; |
|
133 | + } |
|
134 | 134 | } |