|
8 | 8 | namespace OC\DB; |
9 | 9 |
|
10 | 10 | use Doctrine\DBAL\Exception; |
11 | | -use Doctrine\DBAL\Exception\UniqueConstraintViolationException; |
12 | 11 | use OC\DB\Exceptions\DbalException; |
13 | 12 |
|
14 | 13 | /** |
@@ -64,54 +63,6 @@ public function unlockTable() { |
64 | 63 | $this->conn->commit(); |
65 | 64 | } |
66 | 65 |
|
67 | | - /** |
68 | | - * Insert a row if the matching row does not exists. To accomplish proper race condition avoidance |
69 | | - * it is needed that there is also a unique constraint on the values. Then this method will |
70 | | - * catch the exception and return 0. |
71 | | - * |
72 | | - * @param string $table The table name (will replace *PREFIX* with the actual prefix) |
73 | | - * @param array $input data that should be inserted into the table (column name => value) |
74 | | - * @param array|null $compare List of values that should be checked for "if not exists" |
75 | | - * If this is null or an empty array, all keys of $input will be compared |
76 | | - * Please note: text fields (clob) must not be used in the compare array |
77 | | - * @return int number of inserted rows |
78 | | - * @throws Exception |
79 | | - * @deprecated 15.0.0 - use unique index and "try { $db->insert() } catch (UniqueConstraintViolationException $e) {}" instead, because it is more reliable and does not have the risk for deadlocks - see https://github.com/nextcloud/server/pull/12371 |
80 | | - */ |
81 | | - public function insertIfNotExist($table, $input, ?array $compare = null) { |
82 | | - $compare = $compare ?: array_keys($input); |
83 | | - |
84 | | - // Prepare column names and generate placeholders |
85 | | - $columns = '`' . implode('`,`', array_keys($input)) . '`'; |
86 | | - $placeholders = implode(', ', array_fill(0, count($input), '?')); |
87 | | - |
88 | | - $query = 'INSERT INTO `' . $table . '` (' . $columns . ') ' |
89 | | - . 'SELECT ' . $placeholders . ' ' |
90 | | - . 'FROM `' . $table . '` WHERE '; |
91 | | - |
92 | | - $inserts = array_values($input); |
93 | | - foreach ($compare as $key) { |
94 | | - $query .= '`' . $key . '`'; |
95 | | - if (is_null($input[$key])) { |
96 | | - $query .= ' IS NULL AND '; |
97 | | - } else { |
98 | | - $inserts[] = $input[$key]; |
99 | | - $query .= ' = ? AND '; |
100 | | - } |
101 | | - } |
102 | | - $query = substr($query, 0, -5); |
103 | | - $query .= ' HAVING COUNT(*) = 0'; |
104 | | - |
105 | | - try { |
106 | | - return $this->conn->executeUpdate($query, $inserts); |
107 | | - } catch (UniqueConstraintViolationException $e) { |
108 | | - // This exception indicates a concurrent insert happened between |
109 | | - // the insert and the sub-select in the insert, which is safe to ignore. |
110 | | - // More details: https://github.com/nextcloud/server/pull/12315 |
111 | | - return 0; |
112 | | - } |
113 | | - } |
114 | | - |
115 | 66 | /** |
116 | 67 | * @throws \OCP\DB\Exception |
117 | 68 | */ |
|
0 commit comments