From 0d778fcc4e489f541271fa25087777a9253d129e Mon Sep 17 00:00:00 2001 From: Ole Ostergaard Date: Tue, 26 Feb 2019 14:08:55 +0100 Subject: [PATCH] Code cleanup. Signed-off-by: Ole Ostergaard --- lib/private/DB/Adapter.php | 4 ++-- lib/private/DB/AdapterPgSql.php | 10 ++++------ lib/private/DB/Connection.php | 4 ++-- lib/private/Lock/DBLockingProvider.php | 7 +++++-- lib/public/IDBConnection.php | 6 +++--- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/private/DB/Adapter.php b/lib/private/DB/Adapter.php index a9c20c735e0..0df2e0769f7 100644 --- a/lib/private/DB/Adapter.php +++ b/lib/private/DB/Adapter.php @@ -130,11 +130,11 @@ class Adapter { /* * @suppress SqlInjectionChecker */ - public function insertIgnoreConflict($table, $input) : int { + public function insertIgnoreConflict(string $table,array $values) : int { try { $builder = $this->conn->getQueryBuilder(); $builder->insert($table); - foreach($input as $key => $value) { + foreach($values as $key => $value) { $builder->setValue($key, $builder->createNamedParameter($value)); } return $builder->execute(); diff --git a/lib/private/DB/AdapterPgSql.php b/lib/private/DB/AdapterPgSql.php index de4fca3ebf4..b7b473f37c2 100644 --- a/lib/private/DB/AdapterPgSql.php +++ b/lib/private/DB/AdapterPgSql.php @@ -39,15 +39,13 @@ class AdapterPgSql extends Adapter { /* * @suppress SqlInjectionChecker */ - public function insertIgnoreConflict($table, $input) : int { + public function insertIgnoreConflict(string $table,array $values) : int { $builder = $this->conn->getQueryBuilder(); - $builder->insert($table) - ->values($input); - foreach($input as $key => $value) { + $builder->insert($table); + foreach($values as $key => $value) { $builder->setValue($key, $builder->createNamedParameter($value)); } $queryString = $builder->getSQL() . ' ON CONFLICT DO NOTHING'; - $inserts = array_values($input); - return $this->conn->executeUpdate($queryString, $inserts); + return $this->conn->executeUpdate($queryString, $builder->getParameters(), $builder->getParameterTypes()); } } diff --git a/lib/private/DB/Connection.php b/lib/private/DB/Connection.php index 12a0af6121e..506f4bcd4c9 100644 --- a/lib/private/DB/Connection.php +++ b/lib/private/DB/Connection.php @@ -257,8 +257,8 @@ class Connection extends ReconnectWrapper implements IDBConnection { return $this->adapter->insertIfNotExist($table, $input, $compare); } - public function insertIgnoreConflict($table, $input) : int { - return $this->adapter->insertIgnoreConflict($table, $input); + public function insertIgnoreConflict(string $table, array $values) : int { + return $this->adapter->insertIgnoreConflict($table, $values); } private function getType($value) { diff --git a/lib/private/Lock/DBLockingProvider.php b/lib/private/Lock/DBLockingProvider.php index a1859047fe6..bd76385d85d 100644 --- a/lib/private/Lock/DBLockingProvider.php +++ b/lib/private/Lock/DBLockingProvider.php @@ -131,10 +131,13 @@ class DBLockingProvider extends AbstractLockingProvider { * @param int $lock * @return int number of inserted rows */ - protected function initLockField(string $path, int $lock = 0): int { $expire = $this->getExpireTime(); - return $this->connection->insertIgnoreConflict('file_locks', ['key' => $path, 'lock' => $lock, 'ttl' => $expire]); + return $this->connection->insertIgnoreConflict('file_locks', [ + 'key' => $path, + 'lock' => $lock, + 'ttl' => $expire + ]); } /** diff --git a/lib/public/IDBConnection.php b/lib/public/IDBConnection.php index f640ec126f0..4c66896a2fe 100644 --- a/lib/public/IDBConnection.php +++ b/lib/public/IDBConnection.php @@ -128,11 +128,11 @@ interface IDBConnection { * Implementation is not fully finished and should not be used! * * @param string $table The table name (will replace *PREFIX* with the actual prefix) - * @param array $input data that should be inserted into the table (column name => value) + * @param array $values data that should be inserted into the table (column name => value) * @return int number of inserted rows - * @since 17.0.0 + * @since 16.0.0 */ - public function insertIgnoreConflict($table, $input) : int; + public function insertIgnoreConflict(string $table,array $values) : int; /** * Insert or update a row value -- 2.39.5