|
37 | 37 |
|
38 | 38 | namespace OC\Files\Cache; |
39 | 39 |
|
| 40 | +use Doctrine\DBAL\Exception\UniqueConstraintViolationException; |
40 | 41 | use OCP\DB\QueryBuilder\IQueryBuilder; |
41 | 42 | use Doctrine\DBAL\Driver\Statement; |
42 | 43 | use OCP\Files\Cache\ICache; |
@@ -239,6 +240,8 @@ public function put($file, array $data) { |
239 | 240 | * |
240 | 241 | * @return int file id |
241 | 242 | * @throws \RuntimeException |
| 243 | + * |
| 244 | + * @suppress SqlInjectionChecker |
242 | 245 | */ |
243 | 246 | public function insert($file, array $data) { |
244 | 247 | // normalize file |
@@ -269,20 +272,28 @@ public function insert($file, array $data) { |
269 | 272 | return trim($item, "`"); |
270 | 273 | }, $queryParts); |
271 | 274 | $values = array_combine($queryParts, $params); |
272 | | - if (\OC::$server->getDatabaseConnection()->insertIfNotExist('*PREFIX*filecache', $values, [ |
273 | | - 'storage', |
274 | | - 'path_hash', |
275 | | - ]) |
276 | | - ) { |
277 | | - return (int)$this->connection->lastInsertId('*PREFIX*filecache'); |
| 275 | + |
| 276 | + try { |
| 277 | + $builder = $this->connection->getQueryBuilder(); |
| 278 | + $builder->insert('filecache'); |
| 279 | + |
| 280 | + foreach ($values as $column => $value) { |
| 281 | + $builder->setValue($column, $builder->createNamedParameter($value)); |
| 282 | + } |
| 283 | + |
| 284 | + if ($builder->execute()) { |
| 285 | + return (int)$this->connection->lastInsertId('*PREFIX*filecache'); |
| 286 | + } |
| 287 | + } catch(UniqueConstraintViolationException $e) { |
| 288 | + // entry exists already |
278 | 289 | } |
279 | 290 |
|
280 | 291 | // The file was created in the mean time |
281 | 292 | if (($id = $this->getId($file)) > -1) { |
282 | 293 | $this->update($id, $data); |
283 | 294 | return $id; |
284 | 295 | } else { |
285 | | - throw new \RuntimeException('File entry could not be inserted with insertIfNotExist() but could also not be selected with getId() in order to perform an update. Please try again.'); |
| 296 | + throw new \RuntimeException('File entry could not be inserted but could also not be selected with getId() in order to perform an update. Please try again.'); |
286 | 297 | } |
287 | 298 | } |
288 | 299 |
|
|
0 commit comments