diff options
author | Morris Jobke <hey@morrisjobke.de> | 2018-11-14 21:05:32 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-14 21:05:32 +0100 |
commit | 08bd8373f66a3697835f3b35cfa9e10bf759bae6 (patch) | |
tree | 1c7779ad9c4a32c2d1779b7b8aad1832a0f77c70 /apps/files_external | |
parent | c965d2921dfea06ec2af2edb63c419875f396acc (diff) | |
parent | 6bace99aa1da9849f850ea1f84dee54b7cfbcc25 (diff) | |
download | nextcloud-server-08bd8373f66a3697835f3b35cfa9e10bf759bae6.tar.gz nextcloud-server-08bd8373f66a3697835f3b35cfa9e10bf759bae6.zip |
Merge pull request #12417 from nextcloud/bugfix/noid/app-files_external-replace-insertIfNotExist
Fix UniqueConstraintViolationException while insert into files_external config tables
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) { |