diff options
author | Morris Jobke <hey@morrisjobke.de> | 2018-11-12 15:44:53 +0100 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2018-11-14 15:24:03 +0100 |
commit | 6bace99aa1da9849f850ea1f84dee54b7cfbcc25 (patch) | |
tree | 18e8dbe973406504cfbde13811dca8a9674f95d6 /apps/files_external | |
parent | 859dd1e742c4c71b3fbd7035a866c230b80142c2 (diff) | |
download | nextcloud-server-6bace99aa1da9849f850ea1f84dee54b7cfbcc25.tar.gz nextcloud-server-6bace99aa1da9849f850ea1f84dee54b7cfbcc25.zip |
Fix UniqueConstraintViolationException while insert into files_external config tables
* followup to #12371
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Diffstat (limited to 'apps/files_external')
-rw-r--r-- | apps/files_external/lib/Service/DBConfigService.php | 46 |
1 files changed, 28 insertions, 18 deletions
diff --git a/apps/files_external/lib/Service/DBConfigService.php b/apps/files_external/lib/Service/DBConfigService.php index c986acbaa5d..65995b21cc4 100644 --- a/apps/files_external/lib/Service/DBConfigService.php +++ b/apps/files_external/lib/Service/DBConfigService.php @@ -25,6 +25,7 @@ namespace OCA\Files_External\Service; +use Doctrine\DBAL\Exception\UniqueConstraintViolationException; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; use OCP\Security\ICrypto; @@ -300,12 +301,15 @@ class DBConfigService { if ($key === 'password') { $value = $this->encryptValue($value); } - $count = $this->connection->insertIfNotExist('*PREFIX*external_config', [ - 'mount_id' => $mountId, - 'key' => $key, - 'value' => $value - ], ['mount_id', 'key']); - if ($count === 0) { + + try { + $builder = $this->connection->getQueryBuilder(); + $builder->insert('external_config') + ->setValue('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)) + ->setValue('key', $builder->createNamedParameter($key, IQueryBuilder::PARAM_STR)) + ->setValue('value', $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR)) + ->execute(); + } catch(UniqueConstraintViolationException $e) { $builder = $this->connection->getQueryBuilder(); $query = $builder->update('external_config') ->set('value', $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR)) @@ -321,13 +325,14 @@ class DBConfigService { * @param string $value */ public function setOption($mountId, $key, $value) { - - $count = $this->connection->insertIfNotExist('*PREFIX*external_options', [ - 'mount_id' => $mountId, - 'key' => $key, - 'value' => json_encode($value) - ], ['mount_id', 'key']); - if ($count === 0) { + try { + $builder = $this->connection->getQueryBuilder(); + $builder->insert('external_options') + ->setValue('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)) + ->setValue('key', $builder->createNamedParameter($key, IQueryBuilder::PARAM_STR)) + ->setValue('value', $builder->createNamedParameter(json_encode($value), IQueryBuilder::PARAM_STR)) + ->execute(); + } catch(UniqueConstraintViolationException $e) { $builder = $this->connection->getQueryBuilder(); $query = $builder->update('external_options') ->set('value', $builder->createNamedParameter(json_encode($value), IQueryBuilder::PARAM_STR)) @@ -338,11 +343,16 @@ class DBConfigService { } public function addApplicable($mountId, $type, $value) { - $this->connection->insertIfNotExist('*PREFIX*external_applicable', [ - 'mount_id' => $mountId, - 'type' => $type, - 'value' => $value - ], ['mount_id', 'type', 'value']); + try { + $builder = $this->connection->getQueryBuilder(); + $builder->insert('external_applicable') + ->setValue('mount_id', $builder->createNamedParameter($mountId)) + ->setValue('type', $builder->createNamedParameter($type)) + ->setValue('value', $builder->createNamedParameter($value)) + ->execute(); + } catch(UniqueConstraintViolationException $e) { + // applicable exists already + } } public function removeApplicable($mountId, $type, $value) { |