|
7 | 7 | */ |
8 | 8 | namespace OC\Files\Cache; |
9 | 9 |
|
10 | | -use Doctrine\DBAL\Exception\UniqueConstraintViolationException; |
11 | 10 | use OC\DB\Exceptions\DbalException; |
12 | 11 | use OC\DB\QueryBuilder\Sharded\ShardDefinition; |
13 | 12 | use OC\Files\Cache\Wrapper\CacheJail; |
|
16 | 15 | use OC\Files\Search\SearchQuery; |
17 | 16 | use OC\Files\Storage\Wrapper\Encryption; |
18 | 17 | use OC\SystemConfig; |
| 18 | +use OCP\DB\Exception; |
19 | 19 | use OCP\DB\QueryBuilder\IQueryBuilder; |
20 | 20 | use OCP\EventDispatcher\IEventDispatcher; |
21 | 21 | use OCP\Files\Cache\CacheEntryInsertedEvent; |
@@ -249,7 +249,7 @@ public function put($file, array $data) { |
249 | 249 | * @param array $data |
250 | 250 | * |
251 | 251 | * @return int file id |
252 | | - * @throws \RuntimeException |
| 252 | + * @throws \RuntimeException|Exception |
253 | 253 | */ |
254 | 254 | public function insert($file, array $data) { |
255 | 255 | // normalize file |
@@ -309,15 +309,19 @@ public function insert($file, array $data) { |
309 | 309 | $this->eventDispatcher->dispatchTyped($event); |
310 | 310 | return $fileId; |
311 | 311 | } |
312 | | - } catch (UniqueConstraintViolationException $e) { |
313 | | - // entry exists already |
314 | | - if ($this->connection->inTransaction()) { |
315 | | - $this->connection->commit(); |
316 | | - $this->connection->beginTransaction(); |
| 312 | + } catch (Exception $e) { |
| 313 | + if ($e->getReason() === Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION) { |
| 314 | + // entry exists already |
| 315 | + if ($this->connection->inTransaction()) { |
| 316 | + $this->connection->commit(); |
| 317 | + $this->connection->beginTransaction(); |
| 318 | + } |
| 319 | + } else { |
| 320 | + throw $e; |
317 | 321 | } |
318 | 322 | } |
319 | 323 |
|
320 | | - // The file was created in the mean time |
| 324 | + // The file was created in the meantime |
321 | 325 | if (($id = $this->getId($file)) > -1) { |
322 | 326 | $this->update($id, $data); |
323 | 327 | return $id; |
@@ -377,7 +381,10 @@ public function update($id, array $data) { |
377 | 381 | } |
378 | 382 |
|
379 | 383 | $query->executeStatement(); |
380 | | - } catch (UniqueConstraintViolationException $e) { |
| 384 | + } catch (Exception $e) { |
| 385 | + if ($e->getReason() !== Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION) { |
| 386 | + throw $e; |
| 387 | + } |
381 | 388 | $query = $this->getQueryBuilder(); |
382 | 389 | $query->update('filecache_extended') |
383 | 390 | ->whereFileId($id) |
|
0 commit comments