@@ -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 { |
@@ -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\Exception |
|
| 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\Exception |
|
| 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 | } |
@@ -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 { |
@@ -37,115 +37,115 @@ |
||
| 37 | 37 | */ |
| 38 | 38 | class Adapter { |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @var \OC\DB\Connection $conn |
|
| 42 | - */ |
|
| 43 | - protected $conn; |
|
| 40 | + /** |
|
| 41 | + * @var \OC\DB\Connection $conn |
|
| 42 | + */ |
|
| 43 | + protected $conn; |
|
| 44 | 44 | |
| 45 | - public function __construct($conn) { |
|
| 46 | - $this->conn = $conn; |
|
| 47 | - } |
|
| 45 | + public function __construct($conn) { |
|
| 46 | + $this->conn = $conn; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @param string $table name |
|
| 51 | - * |
|
| 52 | - * @return int id of last insert statement |
|
| 53 | - * @throws Exception |
|
| 54 | - */ |
|
| 55 | - public function lastInsertId($table) { |
|
| 56 | - return (int) $this->conn->realLastInsertId($table); |
|
| 57 | - } |
|
| 49 | + /** |
|
| 50 | + * @param string $table name |
|
| 51 | + * |
|
| 52 | + * @return int id of last insert statement |
|
| 53 | + * @throws Exception |
|
| 54 | + */ |
|
| 55 | + public function lastInsertId($table) { |
|
| 56 | + return (int) $this->conn->realLastInsertId($table); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * @param string $statement that needs to be changed so the db can handle it |
|
| 61 | - * @return string changed statement |
|
| 62 | - */ |
|
| 63 | - public function fixupStatement($statement) { |
|
| 64 | - return $statement; |
|
| 65 | - } |
|
| 59 | + /** |
|
| 60 | + * @param string $statement that needs to be changed so the db can handle it |
|
| 61 | + * @return string changed statement |
|
| 62 | + */ |
|
| 63 | + public function fixupStatement($statement) { |
|
| 64 | + return $statement; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Create an exclusive read+write lock on a table |
|
| 69 | - * |
|
| 70 | - * @param string $tableName |
|
| 71 | - * @throws Exception |
|
| 72 | - * @since 9.1.0 |
|
| 73 | - */ |
|
| 74 | - public function lockTable($tableName) { |
|
| 75 | - $this->conn->beginTransaction(); |
|
| 76 | - $this->conn->executeUpdate('LOCK TABLE `' .$tableName . '` IN EXCLUSIVE MODE'); |
|
| 77 | - } |
|
| 67 | + /** |
|
| 68 | + * Create an exclusive read+write lock on a table |
|
| 69 | + * |
|
| 70 | + * @param string $tableName |
|
| 71 | + * @throws Exception |
|
| 72 | + * @since 9.1.0 |
|
| 73 | + */ |
|
| 74 | + public function lockTable($tableName) { |
|
| 75 | + $this->conn->beginTransaction(); |
|
| 76 | + $this->conn->executeUpdate('LOCK TABLE `' .$tableName . '` IN EXCLUSIVE MODE'); |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Release a previous acquired lock again |
|
| 81 | - * |
|
| 82 | - * @throws Exception |
|
| 83 | - * @since 9.1.0 |
|
| 84 | - */ |
|
| 85 | - public function unlockTable() { |
|
| 86 | - $this->conn->commit(); |
|
| 87 | - } |
|
| 79 | + /** |
|
| 80 | + * Release a previous acquired lock again |
|
| 81 | + * |
|
| 82 | + * @throws Exception |
|
| 83 | + * @since 9.1.0 |
|
| 84 | + */ |
|
| 85 | + public function unlockTable() { |
|
| 86 | + $this->conn->commit(); |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * Insert a row if the matching row does not exists. To accomplish proper race condition avoidance |
|
| 91 | - * it is needed that there is also a unique constraint on the values. Then this method will |
|
| 92 | - * catch the exception and return 0. |
|
| 93 | - * |
|
| 94 | - * @param string $table The table name (will replace *PREFIX* with the actual prefix) |
|
| 95 | - * @param array $input data that should be inserted into the table (column name => value) |
|
| 96 | - * @param array|null $compare List of values that should be checked for "if not exists" |
|
| 97 | - * If this is null or an empty array, all keys of $input will be compared |
|
| 98 | - * Please note: text fields (clob) must not be used in the compare array |
|
| 99 | - * @return int number of inserted rows |
|
| 100 | - * @throws Exception |
|
| 101 | - * @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 |
|
| 102 | - */ |
|
| 103 | - public function insertIfNotExist($table, $input, array $compare = null) { |
|
| 104 | - if (empty($compare)) { |
|
| 105 | - $compare = array_keys($input); |
|
| 106 | - } |
|
| 107 | - $query = 'INSERT INTO `' .$table . '` (`' |
|
| 108 | - . implode('`,`', array_keys($input)) . '`) SELECT ' |
|
| 109 | - . str_repeat('?,', count($input) - 1).'? ' // Is there a prettier alternative? |
|
| 110 | - . 'FROM `' . $table . '` WHERE '; |
|
| 89 | + /** |
|
| 90 | + * Insert a row if the matching row does not exists. To accomplish proper race condition avoidance |
|
| 91 | + * it is needed that there is also a unique constraint on the values. Then this method will |
|
| 92 | + * catch the exception and return 0. |
|
| 93 | + * |
|
| 94 | + * @param string $table The table name (will replace *PREFIX* with the actual prefix) |
|
| 95 | + * @param array $input data that should be inserted into the table (column name => value) |
|
| 96 | + * @param array|null $compare List of values that should be checked for "if not exists" |
|
| 97 | + * If this is null or an empty array, all keys of $input will be compared |
|
| 98 | + * Please note: text fields (clob) must not be used in the compare array |
|
| 99 | + * @return int number of inserted rows |
|
| 100 | + * @throws Exception |
|
| 101 | + * @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 |
|
| 102 | + */ |
|
| 103 | + public function insertIfNotExist($table, $input, array $compare = null) { |
|
| 104 | + if (empty($compare)) { |
|
| 105 | + $compare = array_keys($input); |
|
| 106 | + } |
|
| 107 | + $query = 'INSERT INTO `' .$table . '` (`' |
|
| 108 | + . implode('`,`', array_keys($input)) . '`) SELECT ' |
|
| 109 | + . str_repeat('?,', count($input) - 1).'? ' // Is there a prettier alternative? |
|
| 110 | + . 'FROM `' . $table . '` WHERE '; |
|
| 111 | 111 | |
| 112 | - $inserts = array_values($input); |
|
| 113 | - foreach ($compare as $key) { |
|
| 114 | - $query .= '`' . $key . '`'; |
|
| 115 | - if (is_null($input[$key])) { |
|
| 116 | - $query .= ' IS NULL AND '; |
|
| 117 | - } else { |
|
| 118 | - $inserts[] = $input[$key]; |
|
| 119 | - $query .= ' = ? AND '; |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - $query = substr($query, 0, -5); |
|
| 123 | - $query .= ' HAVING COUNT(*) = 0'; |
|
| 112 | + $inserts = array_values($input); |
|
| 113 | + foreach ($compare as $key) { |
|
| 114 | + $query .= '`' . $key . '`'; |
|
| 115 | + if (is_null($input[$key])) { |
|
| 116 | + $query .= ' IS NULL AND '; |
|
| 117 | + } else { |
|
| 118 | + $inserts[] = $input[$key]; |
|
| 119 | + $query .= ' = ? AND '; |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + $query = substr($query, 0, -5); |
|
| 123 | + $query .= ' HAVING COUNT(*) = 0'; |
|
| 124 | 124 | |
| 125 | - try { |
|
| 126 | - return $this->conn->executeUpdate($query, $inserts); |
|
| 127 | - } catch (UniqueConstraintViolationException $e) { |
|
| 128 | - // if this is thrown then a concurrent insert happened between the insert and the sub-select in the insert, that should have avoided it |
|
| 129 | - // it's fine to ignore this then |
|
| 130 | - // |
|
| 131 | - // more discussions about this can be found at https://github.com/nextcloud/server/pull/12315 |
|
| 132 | - return 0; |
|
| 133 | - } |
|
| 134 | - } |
|
| 125 | + try { |
|
| 126 | + return $this->conn->executeUpdate($query, $inserts); |
|
| 127 | + } catch (UniqueConstraintViolationException $e) { |
|
| 128 | + // if this is thrown then a concurrent insert happened between the insert and the sub-select in the insert, that should have avoided it |
|
| 129 | + // it's fine to ignore this then |
|
| 130 | + // |
|
| 131 | + // more discussions about this can be found at https://github.com/nextcloud/server/pull/12315 |
|
| 132 | + return 0; |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - /** |
|
| 137 | - * @throws \OCP\DB\Exception |
|
| 138 | - */ |
|
| 139 | - public function insertIgnoreConflict(string $table, array $values) : int { |
|
| 140 | - try { |
|
| 141 | - $builder = $this->conn->getQueryBuilder(); |
|
| 142 | - $builder->insert($table); |
|
| 143 | - foreach ($values as $key => $value) { |
|
| 144 | - $builder->setValue($key, $builder->createNamedParameter($value)); |
|
| 145 | - } |
|
| 146 | - return $builder->execute(); |
|
| 147 | - } catch (UniqueConstraintViolationException $e) { |
|
| 148 | - return 0; |
|
| 149 | - } |
|
| 150 | - } |
|
| 136 | + /** |
|
| 137 | + * @throws \OCP\DB\Exception |
|
| 138 | + */ |
|
| 139 | + public function insertIgnoreConflict(string $table, array $values) : int { |
|
| 140 | + try { |
|
| 141 | + $builder = $this->conn->getQueryBuilder(); |
|
| 142 | + $builder->insert($table); |
|
| 143 | + foreach ($values as $key => $value) { |
|
| 144 | + $builder->setValue($key, $builder->createNamedParameter($value)); |
|
| 145 | + } |
|
| 146 | + return $builder->execute(); |
|
| 147 | + } catch (UniqueConstraintViolationException $e) { |
|
| 148 | + return 0; |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | 151 | } |
@@ -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 | } |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | public function get($key) { |
| 100 | - $result = self::$cache->get($this->getNameSpace() . $key); |
|
| 100 | + $result = self::$cache->get($this->getNameSpace().$key); |
|
| 101 | 101 | if ($result === false and self::$cache->getResultCode() == \Memcached::RES_NOTFOUND) { |
| 102 | 102 | return null; |
| 103 | 103 | } else { |
@@ -107,9 +107,9 @@ discard block |
||
| 107 | 107 | |
| 108 | 108 | public function set($key, $value, $ttl = 0) { |
| 109 | 109 | if ($ttl > 0) { |
| 110 | - $result = self::$cache->set($this->getNameSpace() . $key, $value, $ttl); |
|
| 110 | + $result = self::$cache->set($this->getNameSpace().$key, $value, $ttl); |
|
| 111 | 111 | } else { |
| 112 | - $result = self::$cache->set($this->getNameSpace() . $key, $value); |
|
| 112 | + $result = self::$cache->set($this->getNameSpace().$key, $value); |
|
| 113 | 113 | } |
| 114 | 114 | if ($result !== true) { |
| 115 | 115 | $this->verifyReturnCode(); |
@@ -118,12 +118,12 @@ discard block |
||
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | public function hasKey($key) { |
| 121 | - self::$cache->get($this->getNameSpace() . $key); |
|
| 121 | + self::$cache->get($this->getNameSpace().$key); |
|
| 122 | 122 | return self::$cache->getResultCode() === \Memcached::RES_SUCCESS; |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | public function remove($key) { |
| 126 | - $result = self::$cache->delete($this->getNameSpace() . $key); |
|
| 126 | + $result = self::$cache->delete($this->getNameSpace().$key); |
|
| 127 | 127 | if (self::$cache->getResultCode() !== \Memcached::RES_NOTFOUND) { |
| 128 | 128 | $this->verifyReturnCode(); |
| 129 | 129 | } |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | public function clear($prefix = '') { |
| 134 | - $prefix = $this->getNameSpace() . $prefix; |
|
| 134 | + $prefix = $this->getNameSpace().$prefix; |
|
| 135 | 135 | $allKeys = self::$cache->getAllKeys(); |
| 136 | 136 | if ($allKeys === false) { |
| 137 | 137 | // newer Memcached doesn't like getAllKeys(), flush everything |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | * @throws \Exception |
| 166 | 166 | */ |
| 167 | 167 | public function add($key, $value, $ttl = 0) { |
| 168 | - $result = self::$cache->add($this->getPrefix() . $key, $value, $ttl); |
|
| 168 | + $result = self::$cache->add($this->getPrefix().$key, $value, $ttl); |
|
| 169 | 169 | if (self::$cache->getResultCode() !== \Memcached::RES_NOTSTORED) { |
| 170 | 170 | $this->verifyReturnCode(); |
| 171 | 171 | } |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | */ |
| 182 | 182 | public function inc($key, $step = 1) { |
| 183 | 183 | $this->add($key, 0); |
| 184 | - $result = self::$cache->increment($this->getPrefix() . $key, $step); |
|
| 184 | + $result = self::$cache->increment($this->getPrefix().$key, $step); |
|
| 185 | 185 | |
| 186 | 186 | if (self::$cache->getResultCode() !== \Memcached::RES_SUCCESS) { |
| 187 | 187 | return false; |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | * @return int | bool |
| 199 | 199 | */ |
| 200 | 200 | public function dec($key, $step = 1) { |
| 201 | - $result = self::$cache->decrement($this->getPrefix() . $key, $step); |
|
| 201 | + $result = self::$cache->decrement($this->getPrefix().$key, $step); |
|
| 202 | 202 | |
| 203 | 203 | if (self::$cache->getResultCode() !== \Memcached::RES_SUCCESS) { |
| 204 | 204 | return false; |
@@ -35,194 +35,194 @@ |
||
| 35 | 35 | use OCP\IMemcache; |
| 36 | 36 | |
| 37 | 37 | class Memcached extends Cache implements IMemcache { |
| 38 | - use CASTrait; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var \Memcached $cache |
|
| 42 | - */ |
|
| 43 | - private static $cache = null; |
|
| 44 | - |
|
| 45 | - use CADTrait; |
|
| 46 | - |
|
| 47 | - public function __construct($prefix = '') { |
|
| 48 | - parent::__construct($prefix); |
|
| 49 | - if (is_null(self::$cache)) { |
|
| 50 | - self::$cache = new \Memcached(); |
|
| 51 | - |
|
| 52 | - $defaultOptions = [ |
|
| 53 | - \Memcached::OPT_CONNECT_TIMEOUT => 50, |
|
| 54 | - \Memcached::OPT_RETRY_TIMEOUT => 50, |
|
| 55 | - \Memcached::OPT_SEND_TIMEOUT => 50, |
|
| 56 | - \Memcached::OPT_RECV_TIMEOUT => 50, |
|
| 57 | - \Memcached::OPT_POLL_TIMEOUT => 50, |
|
| 58 | - |
|
| 59 | - // Enable compression |
|
| 60 | - \Memcached::OPT_COMPRESSION => true, |
|
| 61 | - |
|
| 62 | - // Turn on consistent hashing |
|
| 63 | - \Memcached::OPT_LIBKETAMA_COMPATIBLE => true, |
|
| 64 | - |
|
| 65 | - // Enable Binary Protocol |
|
| 66 | - //\Memcached::OPT_BINARY_PROTOCOL => true, |
|
| 67 | - ]; |
|
| 68 | - // by default enable igbinary serializer if available |
|
| 69 | - /** @psalm-suppress RedundantCondition */ |
|
| 70 | - if (\Memcached::HAVE_IGBINARY) { |
|
| 71 | - $defaultOptions[\Memcached::OPT_SERIALIZER] = |
|
| 72 | - \Memcached::SERIALIZER_IGBINARY; |
|
| 73 | - } |
|
| 74 | - $options = \OC::$server->getConfig()->getSystemValue('memcached_options', []); |
|
| 75 | - if (is_array($options)) { |
|
| 76 | - $options = $options + $defaultOptions; |
|
| 77 | - self::$cache->setOptions($options); |
|
| 78 | - } else { |
|
| 79 | - throw new HintException("Expected 'memcached_options' config to be an array, got $options"); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - $servers = \OC::$server->getSystemConfig()->getValue('memcached_servers'); |
|
| 83 | - if (!$servers) { |
|
| 84 | - $server = \OC::$server->getSystemConfig()->getValue('memcached_server'); |
|
| 85 | - if ($server) { |
|
| 86 | - $servers = [$server]; |
|
| 87 | - } else { |
|
| 88 | - $servers = [['localhost', 11211]]; |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - self::$cache->addServers($servers); |
|
| 92 | - } |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * entries in XCache gets namespaced to prevent collisions between owncloud instances and users |
|
| 97 | - */ |
|
| 98 | - protected function getNameSpace() { |
|
| 99 | - return $this->prefix; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - public function get($key) { |
|
| 103 | - $result = self::$cache->get($this->getNameSpace() . $key); |
|
| 104 | - if ($result === false and self::$cache->getResultCode() == \Memcached::RES_NOTFOUND) { |
|
| 105 | - return null; |
|
| 106 | - } else { |
|
| 107 | - return $result; |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - public function set($key, $value, $ttl = 0) { |
|
| 112 | - if ($ttl > 0) { |
|
| 113 | - $result = self::$cache->set($this->getNameSpace() . $key, $value, $ttl); |
|
| 114 | - } else { |
|
| 115 | - $result = self::$cache->set($this->getNameSpace() . $key, $value); |
|
| 116 | - } |
|
| 117 | - if ($result !== true) { |
|
| 118 | - $this->verifyReturnCode(); |
|
| 119 | - } |
|
| 120 | - return $result; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - public function hasKey($key) { |
|
| 124 | - self::$cache->get($this->getNameSpace() . $key); |
|
| 125 | - return self::$cache->getResultCode() === \Memcached::RES_SUCCESS; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - public function remove($key) { |
|
| 129 | - $result = self::$cache->delete($this->getNameSpace() . $key); |
|
| 130 | - if (self::$cache->getResultCode() !== \Memcached::RES_NOTFOUND) { |
|
| 131 | - $this->verifyReturnCode(); |
|
| 132 | - } |
|
| 133 | - return $result; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - public function clear($prefix = '') { |
|
| 137 | - $prefix = $this->getNameSpace() . $prefix; |
|
| 138 | - $allKeys = self::$cache->getAllKeys(); |
|
| 139 | - if ($allKeys === false) { |
|
| 140 | - // newer Memcached doesn't like getAllKeys(), flush everything |
|
| 141 | - self::$cache->flush(); |
|
| 142 | - return true; |
|
| 143 | - } |
|
| 144 | - $keys = []; |
|
| 145 | - $prefixLength = strlen($prefix); |
|
| 146 | - foreach ($allKeys as $key) { |
|
| 147 | - if (substr($key, 0, $prefixLength) === $prefix) { |
|
| 148 | - $keys[] = $key; |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - if (method_exists(self::$cache, 'deleteMulti')) { |
|
| 152 | - self::$cache->deleteMulti($keys); |
|
| 153 | - } else { |
|
| 154 | - foreach ($keys as $key) { |
|
| 155 | - self::$cache->delete($key); |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - return true; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * Set a value in the cache if it's not already stored |
|
| 163 | - * |
|
| 164 | - * @param string $key |
|
| 165 | - * @param mixed $value |
|
| 166 | - * @param int $ttl Time To Live in seconds. Defaults to 60*60*24 |
|
| 167 | - * @return bool |
|
| 168 | - * @throws \Exception |
|
| 169 | - */ |
|
| 170 | - public function add($key, $value, $ttl = 0) { |
|
| 171 | - $result = self::$cache->add($this->getPrefix() . $key, $value, $ttl); |
|
| 172 | - if (self::$cache->getResultCode() !== \Memcached::RES_NOTSTORED) { |
|
| 173 | - $this->verifyReturnCode(); |
|
| 174 | - } |
|
| 175 | - return $result; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * Increase a stored number |
|
| 180 | - * |
|
| 181 | - * @param string $key |
|
| 182 | - * @param int $step |
|
| 183 | - * @return int | bool |
|
| 184 | - */ |
|
| 185 | - public function inc($key, $step = 1) { |
|
| 186 | - $this->add($key, 0); |
|
| 187 | - $result = self::$cache->increment($this->getPrefix() . $key, $step); |
|
| 188 | - |
|
| 189 | - if (self::$cache->getResultCode() !== \Memcached::RES_SUCCESS) { |
|
| 190 | - return false; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - return $result; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * Decrease a stored number |
|
| 198 | - * |
|
| 199 | - * @param string $key |
|
| 200 | - * @param int $step |
|
| 201 | - * @return int | bool |
|
| 202 | - */ |
|
| 203 | - public function dec($key, $step = 1) { |
|
| 204 | - $result = self::$cache->decrement($this->getPrefix() . $key, $step); |
|
| 205 | - |
|
| 206 | - if (self::$cache->getResultCode() !== \Memcached::RES_SUCCESS) { |
|
| 207 | - return false; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - return $result; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - public static function isAvailable() { |
|
| 214 | - return extension_loaded('memcached'); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * @throws \Exception |
|
| 219 | - */ |
|
| 220 | - private function verifyReturnCode() { |
|
| 221 | - $code = self::$cache->getResultCode(); |
|
| 222 | - if ($code === \Memcached::RES_SUCCESS) { |
|
| 223 | - return; |
|
| 224 | - } |
|
| 225 | - $message = self::$cache->getResultMessage(); |
|
| 226 | - throw new \Exception("Error $code interacting with memcached : $message"); |
|
| 227 | - } |
|
| 38 | + use CASTrait; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var \Memcached $cache |
|
| 42 | + */ |
|
| 43 | + private static $cache = null; |
|
| 44 | + |
|
| 45 | + use CADTrait; |
|
| 46 | + |
|
| 47 | + public function __construct($prefix = '') { |
|
| 48 | + parent::__construct($prefix); |
|
| 49 | + if (is_null(self::$cache)) { |
|
| 50 | + self::$cache = new \Memcached(); |
|
| 51 | + |
|
| 52 | + $defaultOptions = [ |
|
| 53 | + \Memcached::OPT_CONNECT_TIMEOUT => 50, |
|
| 54 | + \Memcached::OPT_RETRY_TIMEOUT => 50, |
|
| 55 | + \Memcached::OPT_SEND_TIMEOUT => 50, |
|
| 56 | + \Memcached::OPT_RECV_TIMEOUT => 50, |
|
| 57 | + \Memcached::OPT_POLL_TIMEOUT => 50, |
|
| 58 | + |
|
| 59 | + // Enable compression |
|
| 60 | + \Memcached::OPT_COMPRESSION => true, |
|
| 61 | + |
|
| 62 | + // Turn on consistent hashing |
|
| 63 | + \Memcached::OPT_LIBKETAMA_COMPATIBLE => true, |
|
| 64 | + |
|
| 65 | + // Enable Binary Protocol |
|
| 66 | + //\Memcached::OPT_BINARY_PROTOCOL => true, |
|
| 67 | + ]; |
|
| 68 | + // by default enable igbinary serializer if available |
|
| 69 | + /** @psalm-suppress RedundantCondition */ |
|
| 70 | + if (\Memcached::HAVE_IGBINARY) { |
|
| 71 | + $defaultOptions[\Memcached::OPT_SERIALIZER] = |
|
| 72 | + \Memcached::SERIALIZER_IGBINARY; |
|
| 73 | + } |
|
| 74 | + $options = \OC::$server->getConfig()->getSystemValue('memcached_options', []); |
|
| 75 | + if (is_array($options)) { |
|
| 76 | + $options = $options + $defaultOptions; |
|
| 77 | + self::$cache->setOptions($options); |
|
| 78 | + } else { |
|
| 79 | + throw new HintException("Expected 'memcached_options' config to be an array, got $options"); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + $servers = \OC::$server->getSystemConfig()->getValue('memcached_servers'); |
|
| 83 | + if (!$servers) { |
|
| 84 | + $server = \OC::$server->getSystemConfig()->getValue('memcached_server'); |
|
| 85 | + if ($server) { |
|
| 86 | + $servers = [$server]; |
|
| 87 | + } else { |
|
| 88 | + $servers = [['localhost', 11211]]; |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + self::$cache->addServers($servers); |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * entries in XCache gets namespaced to prevent collisions between owncloud instances and users |
|
| 97 | + */ |
|
| 98 | + protected function getNameSpace() { |
|
| 99 | + return $this->prefix; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + public function get($key) { |
|
| 103 | + $result = self::$cache->get($this->getNameSpace() . $key); |
|
| 104 | + if ($result === false and self::$cache->getResultCode() == \Memcached::RES_NOTFOUND) { |
|
| 105 | + return null; |
|
| 106 | + } else { |
|
| 107 | + return $result; |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + public function set($key, $value, $ttl = 0) { |
|
| 112 | + if ($ttl > 0) { |
|
| 113 | + $result = self::$cache->set($this->getNameSpace() . $key, $value, $ttl); |
|
| 114 | + } else { |
|
| 115 | + $result = self::$cache->set($this->getNameSpace() . $key, $value); |
|
| 116 | + } |
|
| 117 | + if ($result !== true) { |
|
| 118 | + $this->verifyReturnCode(); |
|
| 119 | + } |
|
| 120 | + return $result; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + public function hasKey($key) { |
|
| 124 | + self::$cache->get($this->getNameSpace() . $key); |
|
| 125 | + return self::$cache->getResultCode() === \Memcached::RES_SUCCESS; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + public function remove($key) { |
|
| 129 | + $result = self::$cache->delete($this->getNameSpace() . $key); |
|
| 130 | + if (self::$cache->getResultCode() !== \Memcached::RES_NOTFOUND) { |
|
| 131 | + $this->verifyReturnCode(); |
|
| 132 | + } |
|
| 133 | + return $result; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + public function clear($prefix = '') { |
|
| 137 | + $prefix = $this->getNameSpace() . $prefix; |
|
| 138 | + $allKeys = self::$cache->getAllKeys(); |
|
| 139 | + if ($allKeys === false) { |
|
| 140 | + // newer Memcached doesn't like getAllKeys(), flush everything |
|
| 141 | + self::$cache->flush(); |
|
| 142 | + return true; |
|
| 143 | + } |
|
| 144 | + $keys = []; |
|
| 145 | + $prefixLength = strlen($prefix); |
|
| 146 | + foreach ($allKeys as $key) { |
|
| 147 | + if (substr($key, 0, $prefixLength) === $prefix) { |
|
| 148 | + $keys[] = $key; |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + if (method_exists(self::$cache, 'deleteMulti')) { |
|
| 152 | + self::$cache->deleteMulti($keys); |
|
| 153 | + } else { |
|
| 154 | + foreach ($keys as $key) { |
|
| 155 | + self::$cache->delete($key); |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + return true; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * Set a value in the cache if it's not already stored |
|
| 163 | + * |
|
| 164 | + * @param string $key |
|
| 165 | + * @param mixed $value |
|
| 166 | + * @param int $ttl Time To Live in seconds. Defaults to 60*60*24 |
|
| 167 | + * @return bool |
|
| 168 | + * @throws \Exception |
|
| 169 | + */ |
|
| 170 | + public function add($key, $value, $ttl = 0) { |
|
| 171 | + $result = self::$cache->add($this->getPrefix() . $key, $value, $ttl); |
|
| 172 | + if (self::$cache->getResultCode() !== \Memcached::RES_NOTSTORED) { |
|
| 173 | + $this->verifyReturnCode(); |
|
| 174 | + } |
|
| 175 | + return $result; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * Increase a stored number |
|
| 180 | + * |
|
| 181 | + * @param string $key |
|
| 182 | + * @param int $step |
|
| 183 | + * @return int | bool |
|
| 184 | + */ |
|
| 185 | + public function inc($key, $step = 1) { |
|
| 186 | + $this->add($key, 0); |
|
| 187 | + $result = self::$cache->increment($this->getPrefix() . $key, $step); |
|
| 188 | + |
|
| 189 | + if (self::$cache->getResultCode() !== \Memcached::RES_SUCCESS) { |
|
| 190 | + return false; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + return $result; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * Decrease a stored number |
|
| 198 | + * |
|
| 199 | + * @param string $key |
|
| 200 | + * @param int $step |
|
| 201 | + * @return int | bool |
|
| 202 | + */ |
|
| 203 | + public function dec($key, $step = 1) { |
|
| 204 | + $result = self::$cache->decrement($this->getPrefix() . $key, $step); |
|
| 205 | + |
|
| 206 | + if (self::$cache->getResultCode() !== \Memcached::RES_SUCCESS) { |
|
| 207 | + return false; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + return $result; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + public static function isAvailable() { |
|
| 214 | + return extension_loaded('memcached'); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * @throws \Exception |
|
| 219 | + */ |
|
| 220 | + private function verifyReturnCode() { |
|
| 221 | + $code = self::$cache->getResultCode(); |
|
| 222 | + if ($code === \Memcached::RES_SUCCESS) { |
|
| 223 | + return; |
|
| 224 | + } |
|
| 225 | + $message = self::$cache->getResultMessage(); |
|
| 226 | + throw new \Exception("Error $code interacting with memcached : $message"); |
|
| 227 | + } |
|
| 228 | 228 | } |
@@ -27,47 +27,47 @@ |
||
| 27 | 27 | namespace OC\Memcache; |
| 28 | 28 | |
| 29 | 29 | class NullCache extends Cache implements \OCP\IMemcache { |
| 30 | - public function get($key) { |
|
| 31 | - return null; |
|
| 32 | - } |
|
| 30 | + public function get($key) { |
|
| 31 | + return null; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - public function set($key, $value, $ttl = 0) { |
|
| 35 | - return true; |
|
| 36 | - } |
|
| 34 | + public function set($key, $value, $ttl = 0) { |
|
| 35 | + return true; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - public function hasKey($key) { |
|
| 39 | - return false; |
|
| 40 | - } |
|
| 38 | + public function hasKey($key) { |
|
| 39 | + return false; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - public function remove($key) { |
|
| 43 | - return true; |
|
| 44 | - } |
|
| 42 | + public function remove($key) { |
|
| 43 | + return true; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - public function add($key, $value, $ttl = 0) { |
|
| 47 | - return true; |
|
| 48 | - } |
|
| 46 | + public function add($key, $value, $ttl = 0) { |
|
| 47 | + return true; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - public function inc($key, $step = 1) { |
|
| 51 | - return true; |
|
| 52 | - } |
|
| 50 | + public function inc($key, $step = 1) { |
|
| 51 | + return true; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - public function dec($key, $step = 1) { |
|
| 55 | - return true; |
|
| 56 | - } |
|
| 54 | + public function dec($key, $step = 1) { |
|
| 55 | + return true; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - public function cas($key, $old, $new) { |
|
| 59 | - return true; |
|
| 60 | - } |
|
| 58 | + public function cas($key, $old, $new) { |
|
| 59 | + return true; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - public function cad($key, $old) { |
|
| 63 | - return true; |
|
| 64 | - } |
|
| 62 | + public function cad($key, $old) { |
|
| 63 | + return true; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - public function clear($prefix = '') { |
|
| 67 | - return true; |
|
| 68 | - } |
|
| 66 | + public function clear($prefix = '') { |
|
| 67 | + return true; |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - public static function isAvailable() { |
|
| 71 | - return true; |
|
| 72 | - } |
|
| 70 | + public static function isAvailable() { |
|
| 71 | + return true; |
|
| 72 | + } |
|
| 73 | 73 | } |
@@ -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 | } |
@@ -32,140 +32,140 @@ |
||
| 32 | 32 | use OCP\IMemcache; |
| 33 | 33 | |
| 34 | 34 | class APCu extends Cache implements IMemcache { |
| 35 | - use CASTrait { |
|
| 36 | - cas as casEmulated; |
|
| 37 | - } |
|
| 35 | + use CASTrait { |
|
| 36 | + cas as casEmulated; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - use CADTrait; |
|
| 39 | + use CADTrait; |
|
| 40 | 40 | |
| 41 | - public function get($key) { |
|
| 42 | - $result = apcu_fetch($this->getPrefix() . $key, $success); |
|
| 43 | - if (!$success) { |
|
| 44 | - return null; |
|
| 45 | - } |
|
| 46 | - return $result; |
|
| 47 | - } |
|
| 41 | + public function get($key) { |
|
| 42 | + $result = apcu_fetch($this->getPrefix() . $key, $success); |
|
| 43 | + if (!$success) { |
|
| 44 | + return null; |
|
| 45 | + } |
|
| 46 | + return $result; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - public function set($key, $value, $ttl = 0) { |
|
| 50 | - return apcu_store($this->getPrefix() . $key, $value, $ttl); |
|
| 51 | - } |
|
| 49 | + public function set($key, $value, $ttl = 0) { |
|
| 50 | + return apcu_store($this->getPrefix() . $key, $value, $ttl); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - public function hasKey($key) { |
|
| 54 | - return apcu_exists($this->getPrefix() . $key); |
|
| 55 | - } |
|
| 53 | + public function hasKey($key) { |
|
| 54 | + return apcu_exists($this->getPrefix() . $key); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - public function remove($key) { |
|
| 58 | - return apcu_delete($this->getPrefix() . $key); |
|
| 59 | - } |
|
| 57 | + public function remove($key) { |
|
| 58 | + return apcu_delete($this->getPrefix() . $key); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - public function clear($prefix = '') { |
|
| 62 | - $ns = $this->getPrefix() . $prefix; |
|
| 63 | - $ns = preg_quote($ns, '/'); |
|
| 64 | - if (class_exists('\APCIterator')) { |
|
| 65 | - $iter = new \APCIterator('user', '/^' . $ns . '/', APC_ITER_KEY); |
|
| 66 | - } else { |
|
| 67 | - $iter = new \APCUIterator('/^' . $ns . '/', APC_ITER_KEY); |
|
| 68 | - } |
|
| 69 | - return apcu_delete($iter); |
|
| 70 | - } |
|
| 61 | + public function clear($prefix = '') { |
|
| 62 | + $ns = $this->getPrefix() . $prefix; |
|
| 63 | + $ns = preg_quote($ns, '/'); |
|
| 64 | + if (class_exists('\APCIterator')) { |
|
| 65 | + $iter = new \APCIterator('user', '/^' . $ns . '/', APC_ITER_KEY); |
|
| 66 | + } else { |
|
| 67 | + $iter = new \APCUIterator('/^' . $ns . '/', APC_ITER_KEY); |
|
| 68 | + } |
|
| 69 | + return apcu_delete($iter); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Set a value in the cache if it's not already stored |
|
| 74 | - * |
|
| 75 | - * @param string $key |
|
| 76 | - * @param mixed $value |
|
| 77 | - * @param int $ttl Time To Live in seconds. Defaults to 60*60*24 |
|
| 78 | - * @return bool |
|
| 79 | - */ |
|
| 80 | - public function add($key, $value, $ttl = 0) { |
|
| 81 | - return apcu_add($this->getPrefix() . $key, $value, $ttl); |
|
| 82 | - } |
|
| 72 | + /** |
|
| 73 | + * Set a value in the cache if it's not already stored |
|
| 74 | + * |
|
| 75 | + * @param string $key |
|
| 76 | + * @param mixed $value |
|
| 77 | + * @param int $ttl Time To Live in seconds. Defaults to 60*60*24 |
|
| 78 | + * @return bool |
|
| 79 | + */ |
|
| 80 | + public function add($key, $value, $ttl = 0) { |
|
| 81 | + return apcu_add($this->getPrefix() . $key, $value, $ttl); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Increase a stored number |
|
| 86 | - * |
|
| 87 | - * @param string $key |
|
| 88 | - * @param int $step |
|
| 89 | - * @return int | bool |
|
| 90 | - */ |
|
| 91 | - public function inc($key, $step = 1) { |
|
| 92 | - $this->add($key, 0); |
|
| 93 | - /** |
|
| 94 | - * TODO - hack around a PHP 7 specific issue in APCu |
|
| 95 | - * |
|
| 96 | - * on PHP 7 the apcu_inc method on a non-existing object will increment |
|
| 97 | - * "0" and result in "1" as value - therefore we check for existence |
|
| 98 | - * first |
|
| 99 | - * |
|
| 100 | - * on PHP 5.6 this is not the case |
|
| 101 | - * |
|
| 102 | - * see https://github.com/krakjoe/apcu/issues/183#issuecomment-244038221 |
|
| 103 | - * for details |
|
| 104 | - */ |
|
| 105 | - return apcu_exists($this->getPrefix() . $key) |
|
| 106 | - ? apcu_inc($this->getPrefix() . $key, $step) |
|
| 107 | - : false; |
|
| 108 | - } |
|
| 84 | + /** |
|
| 85 | + * Increase a stored number |
|
| 86 | + * |
|
| 87 | + * @param string $key |
|
| 88 | + * @param int $step |
|
| 89 | + * @return int | bool |
|
| 90 | + */ |
|
| 91 | + public function inc($key, $step = 1) { |
|
| 92 | + $this->add($key, 0); |
|
| 93 | + /** |
|
| 94 | + * TODO - hack around a PHP 7 specific issue in APCu |
|
| 95 | + * |
|
| 96 | + * on PHP 7 the apcu_inc method on a non-existing object will increment |
|
| 97 | + * "0" and result in "1" as value - therefore we check for existence |
|
| 98 | + * first |
|
| 99 | + * |
|
| 100 | + * on PHP 5.6 this is not the case |
|
| 101 | + * |
|
| 102 | + * see https://github.com/krakjoe/apcu/issues/183#issuecomment-244038221 |
|
| 103 | + * for details |
|
| 104 | + */ |
|
| 105 | + return apcu_exists($this->getPrefix() . $key) |
|
| 106 | + ? apcu_inc($this->getPrefix() . $key, $step) |
|
| 107 | + : false; |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * Decrease a stored number |
|
| 112 | - * |
|
| 113 | - * @param string $key |
|
| 114 | - * @param int $step |
|
| 115 | - * @return int | bool |
|
| 116 | - */ |
|
| 117 | - public function dec($key, $step = 1) { |
|
| 118 | - /** |
|
| 119 | - * TODO - hack around a PHP 7 specific issue in APCu |
|
| 120 | - * |
|
| 121 | - * on PHP 7 the apcu_dec method on a non-existing object will decrement |
|
| 122 | - * "0" and result in "-1" as value - therefore we check for existence |
|
| 123 | - * first |
|
| 124 | - * |
|
| 125 | - * on PHP 5.6 this is not the case |
|
| 126 | - * |
|
| 127 | - * see https://github.com/krakjoe/apcu/issues/183#issuecomment-244038221 |
|
| 128 | - * for details |
|
| 129 | - */ |
|
| 130 | - return apcu_exists($this->getPrefix() . $key) |
|
| 131 | - ? apcu_dec($this->getPrefix() . $key, $step) |
|
| 132 | - : false; |
|
| 133 | - } |
|
| 110 | + /** |
|
| 111 | + * Decrease a stored number |
|
| 112 | + * |
|
| 113 | + * @param string $key |
|
| 114 | + * @param int $step |
|
| 115 | + * @return int | bool |
|
| 116 | + */ |
|
| 117 | + public function dec($key, $step = 1) { |
|
| 118 | + /** |
|
| 119 | + * TODO - hack around a PHP 7 specific issue in APCu |
|
| 120 | + * |
|
| 121 | + * on PHP 7 the apcu_dec method on a non-existing object will decrement |
|
| 122 | + * "0" and result in "-1" as value - therefore we check for existence |
|
| 123 | + * first |
|
| 124 | + * |
|
| 125 | + * on PHP 5.6 this is not the case |
|
| 126 | + * |
|
| 127 | + * see https://github.com/krakjoe/apcu/issues/183#issuecomment-244038221 |
|
| 128 | + * for details |
|
| 129 | + */ |
|
| 130 | + return apcu_exists($this->getPrefix() . $key) |
|
| 131 | + ? apcu_dec($this->getPrefix() . $key, $step) |
|
| 132 | + : false; |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - /** |
|
| 136 | - * Compare and set |
|
| 137 | - * |
|
| 138 | - * @param string $key |
|
| 139 | - * @param mixed $old |
|
| 140 | - * @param mixed $new |
|
| 141 | - * @return bool |
|
| 142 | - */ |
|
| 143 | - public function cas($key, $old, $new) { |
|
| 144 | - // apc only does cas for ints |
|
| 145 | - if (is_int($old) and is_int($new)) { |
|
| 146 | - return apcu_cas($this->getPrefix() . $key, $old, $new); |
|
| 147 | - } else { |
|
| 148 | - return $this->casEmulated($key, $old, $new); |
|
| 149 | - } |
|
| 150 | - } |
|
| 135 | + /** |
|
| 136 | + * Compare and set |
|
| 137 | + * |
|
| 138 | + * @param string $key |
|
| 139 | + * @param mixed $old |
|
| 140 | + * @param mixed $new |
|
| 141 | + * @return bool |
|
| 142 | + */ |
|
| 143 | + public function cas($key, $old, $new) { |
|
| 144 | + // apc only does cas for ints |
|
| 145 | + if (is_int($old) and is_int($new)) { |
|
| 146 | + return apcu_cas($this->getPrefix() . $key, $old, $new); |
|
| 147 | + } else { |
|
| 148 | + return $this->casEmulated($key, $old, $new); |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - /** |
|
| 153 | - * @return bool |
|
| 154 | - */ |
|
| 155 | - public static function isAvailable() { |
|
| 156 | - if (!extension_loaded('apcu')) { |
|
| 157 | - return false; |
|
| 158 | - } elseif (!\OC::$server->get(IniGetWrapper::class)->getBool('apc.enabled')) { |
|
| 159 | - return false; |
|
| 160 | - } elseif (!\OC::$server->get(IniGetWrapper::class)->getBool('apc.enable_cli') && \OC::$CLI) { |
|
| 161 | - return false; |
|
| 162 | - } elseif ( |
|
| 163 | - version_compare(phpversion('apc') ?: '0.0.0', '4.0.6') === -1 && |
|
| 164 | - version_compare(phpversion('apcu') ?: '0.0.0', '5.1.0') === -1 |
|
| 165 | - ) { |
|
| 166 | - return false; |
|
| 167 | - } else { |
|
| 168 | - return true; |
|
| 169 | - } |
|
| 170 | - } |
|
| 152 | + /** |
|
| 153 | + * @return bool |
|
| 154 | + */ |
|
| 155 | + public static function isAvailable() { |
|
| 156 | + if (!extension_loaded('apcu')) { |
|
| 157 | + return false; |
|
| 158 | + } elseif (!\OC::$server->get(IniGetWrapper::class)->getBool('apc.enabled')) { |
|
| 159 | + return false; |
|
| 160 | + } elseif (!\OC::$server->get(IniGetWrapper::class)->getBool('apc.enable_cli') && \OC::$CLI) { |
|
| 161 | + return false; |
|
| 162 | + } elseif ( |
|
| 163 | + version_compare(phpversion('apc') ?: '0.0.0', '4.0.6') === -1 && |
|
| 164 | + version_compare(phpversion('apcu') ?: '0.0.0', '5.1.0') === -1 |
|
| 165 | + ) { |
|
| 166 | + return false; |
|
| 167 | + } else { |
|
| 168 | + return true; |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | 171 | } |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | IUserSession $userSession |
| 61 | 61 | ) { |
| 62 | 62 | $this->user = $user; |
| 63 | - $this->isAdmin = (bool)$isAdmin; |
|
| 63 | + $this->isAdmin = (bool) $isAdmin; |
|
| 64 | 64 | $this->groupManager = $groupManager; |
| 65 | 65 | $this->userSession = $userSession; |
| 66 | 66 | } |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | * @return array |
| 77 | 77 | */ |
| 78 | 78 | public function get($groupSearch = '', $userSearch = '') { |
| 79 | - $key = $groupSearch . '::' . $userSearch; |
|
| 79 | + $key = $groupSearch.'::'.$userSearch; |
|
| 80 | 80 | if (isset($this->metaData[$key])) { |
| 81 | 81 | return $this->metaData[$key]; |
| 82 | 82 | } |
@@ -35,175 +35,175 @@ |
||
| 35 | 35 | use OCP\IUserSession; |
| 36 | 36 | |
| 37 | 37 | class MetaData { |
| 38 | - public const SORT_NONE = 0; |
|
| 39 | - public const SORT_USERCOUNT = 1; // May have performance issues on LDAP backends |
|
| 40 | - public const SORT_GROUPNAME = 2; |
|
| 41 | - |
|
| 42 | - /** @var string */ |
|
| 43 | - protected $user; |
|
| 44 | - /** @var bool */ |
|
| 45 | - protected $isAdmin; |
|
| 46 | - /** @var array */ |
|
| 47 | - protected $metaData = []; |
|
| 48 | - /** @var GroupManager */ |
|
| 49 | - protected $groupManager; |
|
| 50 | - /** @var bool */ |
|
| 51 | - protected $sorting = false; |
|
| 52 | - /** @var IUserSession */ |
|
| 53 | - protected $userSession; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @param string $user the uid of the current user |
|
| 57 | - * @param bool $isAdmin whether the current users is an admin |
|
| 58 | - * @param IGroupManager $groupManager |
|
| 59 | - * @param IUserSession $userSession |
|
| 60 | - */ |
|
| 61 | - public function __construct( |
|
| 62 | - $user, |
|
| 63 | - $isAdmin, |
|
| 64 | - IGroupManager $groupManager, |
|
| 65 | - IUserSession $userSession |
|
| 66 | - ) { |
|
| 67 | - $this->user = $user; |
|
| 68 | - $this->isAdmin = (bool)$isAdmin; |
|
| 69 | - $this->groupManager = $groupManager; |
|
| 70 | - $this->userSession = $userSession; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * returns an array with meta data about all available groups |
|
| 75 | - * the array is structured as follows: |
|
| 76 | - * [0] array containing meta data about admin groups |
|
| 77 | - * [1] array containing meta data about unprivileged groups |
|
| 78 | - * @param string $groupSearch only effective when instance was created with |
|
| 79 | - * isAdmin being true |
|
| 80 | - * @param string $userSearch the pattern users are search for |
|
| 81 | - * @return array |
|
| 82 | - */ |
|
| 83 | - public function get($groupSearch = '', $userSearch = '') { |
|
| 84 | - $key = $groupSearch . '::' . $userSearch; |
|
| 85 | - if (isset($this->metaData[$key])) { |
|
| 86 | - return $this->metaData[$key]; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - $adminGroups = []; |
|
| 90 | - $groups = []; |
|
| 91 | - $sortGroupsIndex = 0; |
|
| 92 | - $sortGroupsKeys = []; |
|
| 93 | - $sortAdminGroupsIndex = 0; |
|
| 94 | - $sortAdminGroupsKeys = []; |
|
| 95 | - |
|
| 96 | - foreach ($this->getGroups($groupSearch) as $group) { |
|
| 97 | - $groupMetaData = $this->generateGroupMetaData($group, $userSearch); |
|
| 98 | - if (strtolower($group->getGID()) !== 'admin') { |
|
| 99 | - $this->addEntry( |
|
| 100 | - $groups, |
|
| 101 | - $sortGroupsKeys, |
|
| 102 | - $sortGroupsIndex, |
|
| 103 | - $groupMetaData); |
|
| 104 | - } else { |
|
| 105 | - //admin group is hard coded to 'admin' for now. In future, |
|
| 106 | - //backends may define admin groups too. Then the if statement |
|
| 107 | - //has to be adjusted accordingly. |
|
| 108 | - $this->addEntry( |
|
| 109 | - $adminGroups, |
|
| 110 | - $sortAdminGroupsKeys, |
|
| 111 | - $sortAdminGroupsIndex, |
|
| 112 | - $groupMetaData); |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - //whether sorting is necessary is will be checked in sort() |
|
| 117 | - $this->sort($groups, $sortGroupsKeys); |
|
| 118 | - $this->sort($adminGroups, $sortAdminGroupsKeys); |
|
| 119 | - |
|
| 120 | - $this->metaData[$key] = [$adminGroups, $groups]; |
|
| 121 | - return $this->metaData[$key]; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * sets the sort mode, see SORT_* constants for supported modes |
|
| 126 | - * |
|
| 127 | - * @param int $sortMode |
|
| 128 | - */ |
|
| 129 | - public function setSorting($sortMode) { |
|
| 130 | - switch ($sortMode) { |
|
| 131 | - case self::SORT_USERCOUNT: |
|
| 132 | - case self::SORT_GROUPNAME: |
|
| 133 | - $this->sorting = $sortMode; |
|
| 134 | - break; |
|
| 135 | - |
|
| 136 | - default: |
|
| 137 | - $this->sorting = self::SORT_NONE; |
|
| 138 | - } |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * adds an group entry to the resulting array |
|
| 143 | - * @param array $entries the resulting array, by reference |
|
| 144 | - * @param array $sortKeys the sort key array, by reference |
|
| 145 | - * @param int $sortIndex the sort key index, by reference |
|
| 146 | - * @param array $data the group's meta data as returned by generateGroupMetaData() |
|
| 147 | - */ |
|
| 148 | - private function addEntry(&$entries, &$sortKeys, &$sortIndex, $data) { |
|
| 149 | - $entries[] = $data; |
|
| 150 | - if ($this->sorting === self::SORT_USERCOUNT) { |
|
| 151 | - $sortKeys[$sortIndex] = $data['usercount']; |
|
| 152 | - $sortIndex++; |
|
| 153 | - } elseif ($this->sorting === self::SORT_GROUPNAME) { |
|
| 154 | - $sortKeys[$sortIndex] = $data['name']; |
|
| 155 | - $sortIndex++; |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * creates an array containing the group meta data |
|
| 161 | - * @param \OCP\IGroup $group |
|
| 162 | - * @param string $userSearch |
|
| 163 | - * @return array with the keys 'id', 'name', 'usercount' and 'disabled' |
|
| 164 | - */ |
|
| 165 | - private function generateGroupMetaData(\OCP\IGroup $group, $userSearch) { |
|
| 166 | - return [ |
|
| 167 | - 'id' => $group->getGID(), |
|
| 168 | - 'name' => $group->getDisplayName(), |
|
| 169 | - 'usercount' => $this->sorting === self::SORT_USERCOUNT ? $group->count($userSearch) : 0, |
|
| 170 | - 'disabled' => $group->countDisabled(), |
|
| 171 | - 'canAdd' => $group->canAddUser(), |
|
| 172 | - 'canRemove' => $group->canRemoveUser(), |
|
| 173 | - ]; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * sorts the result array, if applicable |
|
| 178 | - * @param array $entries the result array, by reference |
|
| 179 | - * @param array $sortKeys the array containing the sort keys |
|
| 180 | - * @param return null |
|
| 181 | - */ |
|
| 182 | - private function sort(&$entries, $sortKeys) { |
|
| 183 | - if ($this->sorting === self::SORT_USERCOUNT) { |
|
| 184 | - array_multisort($sortKeys, SORT_DESC, $entries); |
|
| 185 | - } elseif ($this->sorting === self::SORT_GROUPNAME) { |
|
| 186 | - array_multisort($sortKeys, SORT_ASC, $entries); |
|
| 187 | - } |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * returns the available groups |
|
| 192 | - * @param string $search a search string |
|
| 193 | - * @return \OCP\IGroup[] |
|
| 194 | - */ |
|
| 195 | - public function getGroups($search = '') { |
|
| 196 | - if ($this->isAdmin) { |
|
| 197 | - return $this->groupManager->search($search); |
|
| 198 | - } else { |
|
| 199 | - $userObject = $this->userSession->getUser(); |
|
| 200 | - if ($userObject !== null) { |
|
| 201 | - $groups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($userObject); |
|
| 202 | - } else { |
|
| 203 | - $groups = []; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - return $groups; |
|
| 207 | - } |
|
| 208 | - } |
|
| 38 | + public const SORT_NONE = 0; |
|
| 39 | + public const SORT_USERCOUNT = 1; // May have performance issues on LDAP backends |
|
| 40 | + public const SORT_GROUPNAME = 2; |
|
| 41 | + |
|
| 42 | + /** @var string */ |
|
| 43 | + protected $user; |
|
| 44 | + /** @var bool */ |
|
| 45 | + protected $isAdmin; |
|
| 46 | + /** @var array */ |
|
| 47 | + protected $metaData = []; |
|
| 48 | + /** @var GroupManager */ |
|
| 49 | + protected $groupManager; |
|
| 50 | + /** @var bool */ |
|
| 51 | + protected $sorting = false; |
|
| 52 | + /** @var IUserSession */ |
|
| 53 | + protected $userSession; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @param string $user the uid of the current user |
|
| 57 | + * @param bool $isAdmin whether the current users is an admin |
|
| 58 | + * @param IGroupManager $groupManager |
|
| 59 | + * @param IUserSession $userSession |
|
| 60 | + */ |
|
| 61 | + public function __construct( |
|
| 62 | + $user, |
|
| 63 | + $isAdmin, |
|
| 64 | + IGroupManager $groupManager, |
|
| 65 | + IUserSession $userSession |
|
| 66 | + ) { |
|
| 67 | + $this->user = $user; |
|
| 68 | + $this->isAdmin = (bool)$isAdmin; |
|
| 69 | + $this->groupManager = $groupManager; |
|
| 70 | + $this->userSession = $userSession; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * returns an array with meta data about all available groups |
|
| 75 | + * the array is structured as follows: |
|
| 76 | + * [0] array containing meta data about admin groups |
|
| 77 | + * [1] array containing meta data about unprivileged groups |
|
| 78 | + * @param string $groupSearch only effective when instance was created with |
|
| 79 | + * isAdmin being true |
|
| 80 | + * @param string $userSearch the pattern users are search for |
|
| 81 | + * @return array |
|
| 82 | + */ |
|
| 83 | + public function get($groupSearch = '', $userSearch = '') { |
|
| 84 | + $key = $groupSearch . '::' . $userSearch; |
|
| 85 | + if (isset($this->metaData[$key])) { |
|
| 86 | + return $this->metaData[$key]; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + $adminGroups = []; |
|
| 90 | + $groups = []; |
|
| 91 | + $sortGroupsIndex = 0; |
|
| 92 | + $sortGroupsKeys = []; |
|
| 93 | + $sortAdminGroupsIndex = 0; |
|
| 94 | + $sortAdminGroupsKeys = []; |
|
| 95 | + |
|
| 96 | + foreach ($this->getGroups($groupSearch) as $group) { |
|
| 97 | + $groupMetaData = $this->generateGroupMetaData($group, $userSearch); |
|
| 98 | + if (strtolower($group->getGID()) !== 'admin') { |
|
| 99 | + $this->addEntry( |
|
| 100 | + $groups, |
|
| 101 | + $sortGroupsKeys, |
|
| 102 | + $sortGroupsIndex, |
|
| 103 | + $groupMetaData); |
|
| 104 | + } else { |
|
| 105 | + //admin group is hard coded to 'admin' for now. In future, |
|
| 106 | + //backends may define admin groups too. Then the if statement |
|
| 107 | + //has to be adjusted accordingly. |
|
| 108 | + $this->addEntry( |
|
| 109 | + $adminGroups, |
|
| 110 | + $sortAdminGroupsKeys, |
|
| 111 | + $sortAdminGroupsIndex, |
|
| 112 | + $groupMetaData); |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + //whether sorting is necessary is will be checked in sort() |
|
| 117 | + $this->sort($groups, $sortGroupsKeys); |
|
| 118 | + $this->sort($adminGroups, $sortAdminGroupsKeys); |
|
| 119 | + |
|
| 120 | + $this->metaData[$key] = [$adminGroups, $groups]; |
|
| 121 | + return $this->metaData[$key]; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * sets the sort mode, see SORT_* constants for supported modes |
|
| 126 | + * |
|
| 127 | + * @param int $sortMode |
|
| 128 | + */ |
|
| 129 | + public function setSorting($sortMode) { |
|
| 130 | + switch ($sortMode) { |
|
| 131 | + case self::SORT_USERCOUNT: |
|
| 132 | + case self::SORT_GROUPNAME: |
|
| 133 | + $this->sorting = $sortMode; |
|
| 134 | + break; |
|
| 135 | + |
|
| 136 | + default: |
|
| 137 | + $this->sorting = self::SORT_NONE; |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * adds an group entry to the resulting array |
|
| 143 | + * @param array $entries the resulting array, by reference |
|
| 144 | + * @param array $sortKeys the sort key array, by reference |
|
| 145 | + * @param int $sortIndex the sort key index, by reference |
|
| 146 | + * @param array $data the group's meta data as returned by generateGroupMetaData() |
|
| 147 | + */ |
|
| 148 | + private function addEntry(&$entries, &$sortKeys, &$sortIndex, $data) { |
|
| 149 | + $entries[] = $data; |
|
| 150 | + if ($this->sorting === self::SORT_USERCOUNT) { |
|
| 151 | + $sortKeys[$sortIndex] = $data['usercount']; |
|
| 152 | + $sortIndex++; |
|
| 153 | + } elseif ($this->sorting === self::SORT_GROUPNAME) { |
|
| 154 | + $sortKeys[$sortIndex] = $data['name']; |
|
| 155 | + $sortIndex++; |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * creates an array containing the group meta data |
|
| 161 | + * @param \OCP\IGroup $group |
|
| 162 | + * @param string $userSearch |
|
| 163 | + * @return array with the keys 'id', 'name', 'usercount' and 'disabled' |
|
| 164 | + */ |
|
| 165 | + private function generateGroupMetaData(\OCP\IGroup $group, $userSearch) { |
|
| 166 | + return [ |
|
| 167 | + 'id' => $group->getGID(), |
|
| 168 | + 'name' => $group->getDisplayName(), |
|
| 169 | + 'usercount' => $this->sorting === self::SORT_USERCOUNT ? $group->count($userSearch) : 0, |
|
| 170 | + 'disabled' => $group->countDisabled(), |
|
| 171 | + 'canAdd' => $group->canAddUser(), |
|
| 172 | + 'canRemove' => $group->canRemoveUser(), |
|
| 173 | + ]; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * sorts the result array, if applicable |
|
| 178 | + * @param array $entries the result array, by reference |
|
| 179 | + * @param array $sortKeys the array containing the sort keys |
|
| 180 | + * @param return null |
|
| 181 | + */ |
|
| 182 | + private function sort(&$entries, $sortKeys) { |
|
| 183 | + if ($this->sorting === self::SORT_USERCOUNT) { |
|
| 184 | + array_multisort($sortKeys, SORT_DESC, $entries); |
|
| 185 | + } elseif ($this->sorting === self::SORT_GROUPNAME) { |
|
| 186 | + array_multisort($sortKeys, SORT_ASC, $entries); |
|
| 187 | + } |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * returns the available groups |
|
| 192 | + * @param string $search a search string |
|
| 193 | + * @return \OCP\IGroup[] |
|
| 194 | + */ |
|
| 195 | + public function getGroups($search = '') { |
|
| 196 | + if ($this->isAdmin) { |
|
| 197 | + return $this->groupManager->search($search); |
|
| 198 | + } else { |
|
| 199 | + $userObject = $this->userSession->getUser(); |
|
| 200 | + if ($userObject !== null) { |
|
| 201 | + $groups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($userObject); |
|
| 202 | + } else { |
|
| 203 | + $groups = []; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + return $groups; |
|
| 207 | + } |
|
| 208 | + } |
|
| 209 | 209 | } |
@@ -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 | /** |
@@ -29,107 +29,107 @@ |
||
| 29 | 29 | * Abstract base class for user management |
| 30 | 30 | */ |
| 31 | 31 | abstract class Backend implements \OCP\GroupInterface { |
| 32 | - /** |
|
| 33 | - * error code for functions not provided by the group backend |
|
| 34 | - */ |
|
| 35 | - public const NOT_IMPLEMENTED = -501; |
|
| 32 | + /** |
|
| 33 | + * error code for functions not provided by the group backend |
|
| 34 | + */ |
|
| 35 | + public const NOT_IMPLEMENTED = -501; |
|
| 36 | 36 | |
| 37 | - protected $possibleActions = [ |
|
| 38 | - self::CREATE_GROUP => 'createGroup', |
|
| 39 | - self::DELETE_GROUP => 'deleteGroup', |
|
| 40 | - self::ADD_TO_GROUP => 'addToGroup', |
|
| 41 | - self::REMOVE_FROM_GOUP => 'removeFromGroup', |
|
| 42 | - self::COUNT_USERS => 'countUsersInGroup', |
|
| 43 | - self::GROUP_DETAILS => 'getGroupDetails', |
|
| 44 | - self::IS_ADMIN => 'isAdmin', |
|
| 45 | - ]; |
|
| 37 | + protected $possibleActions = [ |
|
| 38 | + self::CREATE_GROUP => 'createGroup', |
|
| 39 | + self::DELETE_GROUP => 'deleteGroup', |
|
| 40 | + self::ADD_TO_GROUP => 'addToGroup', |
|
| 41 | + self::REMOVE_FROM_GOUP => 'removeFromGroup', |
|
| 42 | + self::COUNT_USERS => 'countUsersInGroup', |
|
| 43 | + self::GROUP_DETAILS => 'getGroupDetails', |
|
| 44 | + self::IS_ADMIN => 'isAdmin', |
|
| 45 | + ]; |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Get all supported actions |
|
| 49 | - * @return int bitwise-or'ed actions |
|
| 50 | - * |
|
| 51 | - * Returns the supported actions as int to be |
|
| 52 | - * compared with \OC\Group\Backend::CREATE_GROUP etc. |
|
| 53 | - */ |
|
| 54 | - public function getSupportedActions() { |
|
| 55 | - $actions = 0; |
|
| 56 | - foreach ($this->possibleActions as $action => $methodName) { |
|
| 57 | - if (method_exists($this, $methodName)) { |
|
| 58 | - $actions |= $action; |
|
| 59 | - } |
|
| 60 | - } |
|
| 47 | + /** |
|
| 48 | + * Get all supported actions |
|
| 49 | + * @return int bitwise-or'ed actions |
|
| 50 | + * |
|
| 51 | + * Returns the supported actions as int to be |
|
| 52 | + * compared with \OC\Group\Backend::CREATE_GROUP etc. |
|
| 53 | + */ |
|
| 54 | + public function getSupportedActions() { |
|
| 55 | + $actions = 0; |
|
| 56 | + foreach ($this->possibleActions as $action => $methodName) { |
|
| 57 | + if (method_exists($this, $methodName)) { |
|
| 58 | + $actions |= $action; |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - return $actions; |
|
| 63 | - } |
|
| 62 | + return $actions; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * Check if backend implements actions |
|
| 67 | - * @param int $actions bitwise-or'ed actions |
|
| 68 | - * @return bool |
|
| 69 | - * |
|
| 70 | - * Returns the supported actions as int to be |
|
| 71 | - * compared with \OC\Group\Backend::CREATE_GROUP etc. |
|
| 72 | - */ |
|
| 73 | - public function implementsActions($actions) { |
|
| 74 | - return (bool)($this->getSupportedActions() & $actions); |
|
| 75 | - } |
|
| 65 | + /** |
|
| 66 | + * Check if backend implements actions |
|
| 67 | + * @param int $actions bitwise-or'ed actions |
|
| 68 | + * @return bool |
|
| 69 | + * |
|
| 70 | + * Returns the supported actions as int to be |
|
| 71 | + * compared with \OC\Group\Backend::CREATE_GROUP etc. |
|
| 72 | + */ |
|
| 73 | + public function implementsActions($actions) { |
|
| 74 | + return (bool)($this->getSupportedActions() & $actions); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * is user in group? |
|
| 79 | - * @param string $uid uid of the user |
|
| 80 | - * @param string $gid gid of the group |
|
| 81 | - * @return bool |
|
| 82 | - * |
|
| 83 | - * Checks whether the user is member of a group or not. |
|
| 84 | - */ |
|
| 85 | - public function inGroup($uid, $gid) { |
|
| 86 | - return in_array($gid, $this->getUserGroups($uid)); |
|
| 87 | - } |
|
| 77 | + /** |
|
| 78 | + * is user in group? |
|
| 79 | + * @param string $uid uid of the user |
|
| 80 | + * @param string $gid gid of the group |
|
| 81 | + * @return bool |
|
| 82 | + * |
|
| 83 | + * Checks whether the user is member of a group or not. |
|
| 84 | + */ |
|
| 85 | + public function inGroup($uid, $gid) { |
|
| 86 | + return in_array($gid, $this->getUserGroups($uid)); |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * Get all groups a user belongs to |
|
| 91 | - * @param string $uid Name of the user |
|
| 92 | - * @return array an array of group names |
|
| 93 | - * |
|
| 94 | - * This function fetches all groups a user belongs to. It does not check |
|
| 95 | - * if the user exists at all. |
|
| 96 | - */ |
|
| 97 | - public function getUserGroups($uid) { |
|
| 98 | - return []; |
|
| 99 | - } |
|
| 89 | + /** |
|
| 90 | + * Get all groups a user belongs to |
|
| 91 | + * @param string $uid Name of the user |
|
| 92 | + * @return array an array of group names |
|
| 93 | + * |
|
| 94 | + * This function fetches all groups a user belongs to. It does not check |
|
| 95 | + * if the user exists at all. |
|
| 96 | + */ |
|
| 97 | + public function getUserGroups($uid) { |
|
| 98 | + return []; |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * get a list of all groups |
|
| 103 | - * @param string $search |
|
| 104 | - * @param int $limit |
|
| 105 | - * @param int $offset |
|
| 106 | - * @return array an array of group names |
|
| 107 | - * |
|
| 108 | - * Returns a list with all groups |
|
| 109 | - */ |
|
| 101 | + /** |
|
| 102 | + * get a list of all groups |
|
| 103 | + * @param string $search |
|
| 104 | + * @param int $limit |
|
| 105 | + * @param int $offset |
|
| 106 | + * @return array an array of group names |
|
| 107 | + * |
|
| 108 | + * Returns a list with all groups |
|
| 109 | + */ |
|
| 110 | 110 | |
| 111 | - public function getGroups($search = '', $limit = -1, $offset = 0) { |
|
| 112 | - return []; |
|
| 113 | - } |
|
| 111 | + public function getGroups($search = '', $limit = -1, $offset = 0) { |
|
| 112 | + return []; |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * check if a group exists |
|
| 117 | - * @param string $gid |
|
| 118 | - * @return bool |
|
| 119 | - */ |
|
| 120 | - public function groupExists($gid) { |
|
| 121 | - return in_array($gid, $this->getGroups($gid, 1)); |
|
| 122 | - } |
|
| 115 | + /** |
|
| 116 | + * check if a group exists |
|
| 117 | + * @param string $gid |
|
| 118 | + * @return bool |
|
| 119 | + */ |
|
| 120 | + public function groupExists($gid) { |
|
| 121 | + return in_array($gid, $this->getGroups($gid, 1)); |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - /** |
|
| 125 | - * get a list of all users in a group |
|
| 126 | - * @param string $gid |
|
| 127 | - * @param string $search |
|
| 128 | - * @param int $limit |
|
| 129 | - * @param int $offset |
|
| 130 | - * @return array an array of user ids |
|
| 131 | - */ |
|
| 132 | - public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) { |
|
| 133 | - return []; |
|
| 134 | - } |
|
| 124 | + /** |
|
| 125 | + * get a list of all users in a group |
|
| 126 | + * @param string $gid |
|
| 127 | + * @param string $search |
|
| 128 | + * @param int $limit |
|
| 129 | + * @param int $offset |
|
| 130 | + * @return array an array of user ids |
|
| 131 | + */ |
|
| 132 | + public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) { |
|
| 133 | + return []; |
|
| 134 | + } |
|
| 135 | 135 | } |