Passed
Push — master ( 8cab1d...e18f97 )
by Julius
40:17 queued 25:44
created
lib/private/Files/Cache/Propagator.php 2 patches
Indentation   +195 added lines, -195 removed lines patch added patch discarded remove patch
@@ -36,199 +36,199 @@
 block discarded – undo
36 36
  * Propagate etags and mtimes within the storage
37 37
  */
38 38
 class Propagator implements IPropagator {
39
-	public const MAX_RETRIES = 3;
40
-	private $inBatch = false;
41
-
42
-	private $batch = [];
43
-
44
-	/**
45
-	 * @var \OC\Files\Storage\Storage
46
-	 */
47
-	protected $storage;
48
-
49
-	/**
50
-	 * @var IDBConnection
51
-	 */
52
-	private $connection;
53
-
54
-	/**
55
-	 * @var array
56
-	 */
57
-	private $ignore = [];
58
-
59
-	public function __construct(\OC\Files\Storage\Storage $storage, IDBConnection $connection, array $ignore = []) {
60
-		$this->storage = $storage;
61
-		$this->connection = $connection;
62
-		$this->ignore = $ignore;
63
-	}
64
-
65
-
66
-	/**
67
-	 * @param string $internalPath
68
-	 * @param int $time
69
-	 * @param int $sizeDifference number of bytes the file has grown
70
-	 */
71
-	public function propagateChange($internalPath, $time, $sizeDifference = 0) {
72
-		// Do not propagate changes in ignored paths
73
-		foreach ($this->ignore as $ignore) {
74
-			if (strpos($internalPath, $ignore) === 0) {
75
-				return;
76
-			}
77
-		}
78
-
79
-		$storageId = (int)$this->storage->getStorageCache()->getNumericId();
80
-
81
-		$parents = $this->getParents($internalPath);
82
-
83
-		if ($this->inBatch) {
84
-			foreach ($parents as $parent) {
85
-				$this->addToBatch($parent, $time, $sizeDifference);
86
-			}
87
-			return;
88
-		}
89
-
90
-		$parentHashes = array_map('md5', $parents);
91
-		$etag = uniqid(); // since we give all folders the same etag we don't ask the storage for the etag
92
-
93
-		$builder = $this->connection->getQueryBuilder();
94
-		$hashParams = array_map(function ($hash) use ($builder) {
95
-			return $builder->expr()->literal($hash);
96
-		}, $parentHashes);
97
-
98
-		$builder->update('filecache')
99
-			->set('mtime', $builder->func()->greatest('mtime', $builder->createNamedParameter((int)$time, IQueryBuilder::PARAM_INT)))
100
-			->where($builder->expr()->eq('storage', $builder->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
101
-			->andWhere($builder->expr()->in('path_hash', $hashParams));
102
-		if (!$this->storage->instanceOfStorage(IReliableEtagStorage::class)) {
103
-			$builder->set('etag', $builder->createNamedParameter($etag, IQueryBuilder::PARAM_STR));
104
-		}
105
-
106
-		if ($sizeDifference !== 0) {
107
-			$hasCalculatedSize = $builder->expr()->gt('size', $builder->expr()->literal(-1, IQUeryBuilder::PARAM_INT));
108
-			$sizeColumn = $builder->getColumnName('size');
109
-			$newSize = $builder->func()->greatest(
110
-				$builder->func()->add('size', $builder->createNamedParameter($sizeDifference)),
111
-				$builder->createNamedParameter(-1, IQueryBuilder::PARAM_INT)
112
-			);
113
-
114
-			// Only update if row had a previously calculated size
115
-			$builder->set('size', $builder->createFunction("CASE WHEN $hasCalculatedSize THEN $newSize ELSE $sizeColumn END"));
116
-
117
-			if ($this->storage->instanceOfStorage(Encryption::class)) {
118
-				// in case of encryption being enabled after some files are already uploaded, some entries will have an unencrypted_size of 0 and a non-zero size
119
-				$hasUnencryptedSize = $builder->expr()->neq('unencrypted_size', $builder->expr()->literal(0, IQueryBuilder::PARAM_INT));
120
-				$sizeColumn = $builder->getColumnName('size');
121
-				$unencryptedSizeColumn = $builder->getColumnName('unencrypted_size');
122
-				$newUnencryptedSize = $builder->func()->greatest(
123
-					$builder->func()->add(
124
-						$builder->createFunction("CASE WHEN $hasUnencryptedSize THEN $unencryptedSizeColumn ELSE $sizeColumn END"),
125
-						$builder->createNamedParameter($sizeDifference)
126
-					),
127
-					$builder->createNamedParameter(-1, IQueryBuilder::PARAM_INT)
128
-				);
129
-
130
-				// Only update if row had a previously calculated size
131
-				$builder->set('unencrypted_size', $builder->createFunction("CASE WHEN $hasCalculatedSize THEN $newUnencryptedSize ELSE $unencryptedSizeColumn END"));
132
-			}
133
-		}
134
-
135
-		for ($i = 0; $i < self::MAX_RETRIES; $i++) {
136
-			try {
137
-				$builder->executeStatement();
138
-				break;
139
-			} catch (DbalException $e) {
140
-				if (!$e->isRetryable()) {
141
-					throw $e;
142
-				}
143
-
144
-				/** @var LoggerInterface $loggerInterface */
145
-				$loggerInterface = \OCP\Server::get(LoggerInterface::class);
146
-				$loggerInterface->warning('Retrying propagation query after retryable exception.', [ 'exception' => $e ]);
147
-			}
148
-		}
149
-	}
150
-
151
-	protected function getParents($path) {
152
-		$parts = explode('/', $path);
153
-		$parent = '';
154
-		$parents = [];
155
-		foreach ($parts as $part) {
156
-			$parents[] = $parent;
157
-			$parent = trim($parent . '/' . $part, '/');
158
-		}
159
-		return $parents;
160
-	}
161
-
162
-	/**
163
-	 * Mark the beginning of a propagation batch
164
-	 *
165
-	 * Note that not all cache setups support propagation in which case this will be a noop
166
-	 *
167
-	 * Batching for cache setups that do support it has to be explicit since the cache state is not fully consistent
168
-	 * before the batch is committed.
169
-	 */
170
-	public function beginBatch() {
171
-		$this->inBatch = true;
172
-	}
173
-
174
-	private function addToBatch($internalPath, $time, $sizeDifference) {
175
-		if (!isset($this->batch[$internalPath])) {
176
-			$this->batch[$internalPath] = [
177
-				'hash' => md5($internalPath),
178
-				'time' => $time,
179
-				'size' => $sizeDifference,
180
-			];
181
-		} else {
182
-			$this->batch[$internalPath]['size'] += $sizeDifference;
183
-			if ($time > $this->batch[$internalPath]['time']) {
184
-				$this->batch[$internalPath]['time'] = $time;
185
-			}
186
-		}
187
-	}
188
-
189
-	/**
190
-	 * Commit the active propagation batch
191
-	 */
192
-	public function commitBatch() {
193
-		if (!$this->inBatch) {
194
-			throw new \BadMethodCallException('Not in batch');
195
-		}
196
-		$this->inBatch = false;
197
-
198
-		$this->connection->beginTransaction();
199
-
200
-		$query = $this->connection->getQueryBuilder();
201
-		$storageId = (int)$this->storage->getStorageCache()->getNumericId();
202
-
203
-		$query->update('filecache')
204
-			->set('mtime', $query->func()->greatest('mtime', $query->createParameter('time')))
205
-			->set('etag', $query->expr()->literal(uniqid()))
206
-			->where($query->expr()->eq('storage', $query->expr()->literal($storageId, IQueryBuilder::PARAM_INT)))
207
-			->andWhere($query->expr()->eq('path_hash', $query->createParameter('hash')));
208
-
209
-		$sizeQuery = $this->connection->getQueryBuilder();
210
-		$sizeQuery->update('filecache')
211
-			->set('size', $sizeQuery->func()->add('size', $sizeQuery->createParameter('size')))
212
-			->where($query->expr()->eq('storage', $query->expr()->literal($storageId, IQueryBuilder::PARAM_INT)))
213
-			->andWhere($query->expr()->eq('path_hash', $query->createParameter('hash')))
214
-			->andWhere($sizeQuery->expr()->gt('size', $sizeQuery->expr()->literal(-1, IQueryBuilder::PARAM_INT)));
215
-
216
-		foreach ($this->batch as $item) {
217
-			$query->setParameter('time', $item['time'], IQueryBuilder::PARAM_INT);
218
-			$query->setParameter('hash', $item['hash']);
219
-
220
-			$query->execute();
221
-
222
-			if ($item['size']) {
223
-				$sizeQuery->setParameter('size', $item['size'], IQueryBuilder::PARAM_INT);
224
-				$sizeQuery->setParameter('hash', $item['hash']);
225
-
226
-				$sizeQuery->execute();
227
-			}
228
-		}
229
-
230
-		$this->batch = [];
231
-
232
-		$this->connection->commit();
233
-	}
39
+    public const MAX_RETRIES = 3;
40
+    private $inBatch = false;
41
+
42
+    private $batch = [];
43
+
44
+    /**
45
+     * @var \OC\Files\Storage\Storage
46
+     */
47
+    protected $storage;
48
+
49
+    /**
50
+     * @var IDBConnection
51
+     */
52
+    private $connection;
53
+
54
+    /**
55
+     * @var array
56
+     */
57
+    private $ignore = [];
58
+
59
+    public function __construct(\OC\Files\Storage\Storage $storage, IDBConnection $connection, array $ignore = []) {
60
+        $this->storage = $storage;
61
+        $this->connection = $connection;
62
+        $this->ignore = $ignore;
63
+    }
64
+
65
+
66
+    /**
67
+     * @param string $internalPath
68
+     * @param int $time
69
+     * @param int $sizeDifference number of bytes the file has grown
70
+     */
71
+    public function propagateChange($internalPath, $time, $sizeDifference = 0) {
72
+        // Do not propagate changes in ignored paths
73
+        foreach ($this->ignore as $ignore) {
74
+            if (strpos($internalPath, $ignore) === 0) {
75
+                return;
76
+            }
77
+        }
78
+
79
+        $storageId = (int)$this->storage->getStorageCache()->getNumericId();
80
+
81
+        $parents = $this->getParents($internalPath);
82
+
83
+        if ($this->inBatch) {
84
+            foreach ($parents as $parent) {
85
+                $this->addToBatch($parent, $time, $sizeDifference);
86
+            }
87
+            return;
88
+        }
89
+
90
+        $parentHashes = array_map('md5', $parents);
91
+        $etag = uniqid(); // since we give all folders the same etag we don't ask the storage for the etag
92
+
93
+        $builder = $this->connection->getQueryBuilder();
94
+        $hashParams = array_map(function ($hash) use ($builder) {
95
+            return $builder->expr()->literal($hash);
96
+        }, $parentHashes);
97
+
98
+        $builder->update('filecache')
99
+            ->set('mtime', $builder->func()->greatest('mtime', $builder->createNamedParameter((int)$time, IQueryBuilder::PARAM_INT)))
100
+            ->where($builder->expr()->eq('storage', $builder->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
101
+            ->andWhere($builder->expr()->in('path_hash', $hashParams));
102
+        if (!$this->storage->instanceOfStorage(IReliableEtagStorage::class)) {
103
+            $builder->set('etag', $builder->createNamedParameter($etag, IQueryBuilder::PARAM_STR));
104
+        }
105
+
106
+        if ($sizeDifference !== 0) {
107
+            $hasCalculatedSize = $builder->expr()->gt('size', $builder->expr()->literal(-1, IQUeryBuilder::PARAM_INT));
108
+            $sizeColumn = $builder->getColumnName('size');
109
+            $newSize = $builder->func()->greatest(
110
+                $builder->func()->add('size', $builder->createNamedParameter($sizeDifference)),
111
+                $builder->createNamedParameter(-1, IQueryBuilder::PARAM_INT)
112
+            );
113
+
114
+            // Only update if row had a previously calculated size
115
+            $builder->set('size', $builder->createFunction("CASE WHEN $hasCalculatedSize THEN $newSize ELSE $sizeColumn END"));
116
+
117
+            if ($this->storage->instanceOfStorage(Encryption::class)) {
118
+                // in case of encryption being enabled after some files are already uploaded, some entries will have an unencrypted_size of 0 and a non-zero size
119
+                $hasUnencryptedSize = $builder->expr()->neq('unencrypted_size', $builder->expr()->literal(0, IQueryBuilder::PARAM_INT));
120
+                $sizeColumn = $builder->getColumnName('size');
121
+                $unencryptedSizeColumn = $builder->getColumnName('unencrypted_size');
122
+                $newUnencryptedSize = $builder->func()->greatest(
123
+                    $builder->func()->add(
124
+                        $builder->createFunction("CASE WHEN $hasUnencryptedSize THEN $unencryptedSizeColumn ELSE $sizeColumn END"),
125
+                        $builder->createNamedParameter($sizeDifference)
126
+                    ),
127
+                    $builder->createNamedParameter(-1, IQueryBuilder::PARAM_INT)
128
+                );
129
+
130
+                // Only update if row had a previously calculated size
131
+                $builder->set('unencrypted_size', $builder->createFunction("CASE WHEN $hasCalculatedSize THEN $newUnencryptedSize ELSE $unencryptedSizeColumn END"));
132
+            }
133
+        }
134
+
135
+        for ($i = 0; $i < self::MAX_RETRIES; $i++) {
136
+            try {
137
+                $builder->executeStatement();
138
+                break;
139
+            } catch (DbalException $e) {
140
+                if (!$e->isRetryable()) {
141
+                    throw $e;
142
+                }
143
+
144
+                /** @var LoggerInterface $loggerInterface */
145
+                $loggerInterface = \OCP\Server::get(LoggerInterface::class);
146
+                $loggerInterface->warning('Retrying propagation query after retryable exception.', [ 'exception' => $e ]);
147
+            }
148
+        }
149
+    }
150
+
151
+    protected function getParents($path) {
152
+        $parts = explode('/', $path);
153
+        $parent = '';
154
+        $parents = [];
155
+        foreach ($parts as $part) {
156
+            $parents[] = $parent;
157
+            $parent = trim($parent . '/' . $part, '/');
158
+        }
159
+        return $parents;
160
+    }
161
+
162
+    /**
163
+     * Mark the beginning of a propagation batch
164
+     *
165
+     * Note that not all cache setups support propagation in which case this will be a noop
166
+     *
167
+     * Batching for cache setups that do support it has to be explicit since the cache state is not fully consistent
168
+     * before the batch is committed.
169
+     */
170
+    public function beginBatch() {
171
+        $this->inBatch = true;
172
+    }
173
+
174
+    private function addToBatch($internalPath, $time, $sizeDifference) {
175
+        if (!isset($this->batch[$internalPath])) {
176
+            $this->batch[$internalPath] = [
177
+                'hash' => md5($internalPath),
178
+                'time' => $time,
179
+                'size' => $sizeDifference,
180
+            ];
181
+        } else {
182
+            $this->batch[$internalPath]['size'] += $sizeDifference;
183
+            if ($time > $this->batch[$internalPath]['time']) {
184
+                $this->batch[$internalPath]['time'] = $time;
185
+            }
186
+        }
187
+    }
188
+
189
+    /**
190
+     * Commit the active propagation batch
191
+     */
192
+    public function commitBatch() {
193
+        if (!$this->inBatch) {
194
+            throw new \BadMethodCallException('Not in batch');
195
+        }
196
+        $this->inBatch = false;
197
+
198
+        $this->connection->beginTransaction();
199
+
200
+        $query = $this->connection->getQueryBuilder();
201
+        $storageId = (int)$this->storage->getStorageCache()->getNumericId();
202
+
203
+        $query->update('filecache')
204
+            ->set('mtime', $query->func()->greatest('mtime', $query->createParameter('time')))
205
+            ->set('etag', $query->expr()->literal(uniqid()))
206
+            ->where($query->expr()->eq('storage', $query->expr()->literal($storageId, IQueryBuilder::PARAM_INT)))
207
+            ->andWhere($query->expr()->eq('path_hash', $query->createParameter('hash')));
208
+
209
+        $sizeQuery = $this->connection->getQueryBuilder();
210
+        $sizeQuery->update('filecache')
211
+            ->set('size', $sizeQuery->func()->add('size', $sizeQuery->createParameter('size')))
212
+            ->where($query->expr()->eq('storage', $query->expr()->literal($storageId, IQueryBuilder::PARAM_INT)))
213
+            ->andWhere($query->expr()->eq('path_hash', $query->createParameter('hash')))
214
+            ->andWhere($sizeQuery->expr()->gt('size', $sizeQuery->expr()->literal(-1, IQueryBuilder::PARAM_INT)));
215
+
216
+        foreach ($this->batch as $item) {
217
+            $query->setParameter('time', $item['time'], IQueryBuilder::PARAM_INT);
218
+            $query->setParameter('hash', $item['hash']);
219
+
220
+            $query->execute();
221
+
222
+            if ($item['size']) {
223
+                $sizeQuery->setParameter('size', $item['size'], IQueryBuilder::PARAM_INT);
224
+                $sizeQuery->setParameter('hash', $item['hash']);
225
+
226
+                $sizeQuery->execute();
227
+            }
228
+        }
229
+
230
+        $this->batch = [];
231
+
232
+        $this->connection->commit();
233
+    }
234 234
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 			}
77 77
 		}
78 78
 
79
-		$storageId = (int)$this->storage->getStorageCache()->getNumericId();
79
+		$storageId = (int) $this->storage->getStorageCache()->getNumericId();
80 80
 
81 81
 		$parents = $this->getParents($internalPath);
82 82
 
@@ -91,12 +91,12 @@  discard block
 block discarded – undo
91 91
 		$etag = uniqid(); // since we give all folders the same etag we don't ask the storage for the etag
92 92
 
93 93
 		$builder = $this->connection->getQueryBuilder();
94
-		$hashParams = array_map(function ($hash) use ($builder) {
94
+		$hashParams = array_map(function($hash) use ($builder) {
95 95
 			return $builder->expr()->literal($hash);
96 96
 		}, $parentHashes);
97 97
 
98 98
 		$builder->update('filecache')
99
-			->set('mtime', $builder->func()->greatest('mtime', $builder->createNamedParameter((int)$time, IQueryBuilder::PARAM_INT)))
99
+			->set('mtime', $builder->func()->greatest('mtime', $builder->createNamedParameter((int) $time, IQueryBuilder::PARAM_INT)))
100 100
 			->where($builder->expr()->eq('storage', $builder->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
101 101
 			->andWhere($builder->expr()->in('path_hash', $hashParams));
102 102
 		if (!$this->storage->instanceOfStorage(IReliableEtagStorage::class)) {
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 
144 144
 				/** @var LoggerInterface $loggerInterface */
145 145
 				$loggerInterface = \OCP\Server::get(LoggerInterface::class);
146
-				$loggerInterface->warning('Retrying propagation query after retryable exception.', [ 'exception' => $e ]);
146
+				$loggerInterface->warning('Retrying propagation query after retryable exception.', ['exception' => $e]);
147 147
 			}
148 148
 		}
149 149
 	}
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 		$parents = [];
155 155
 		foreach ($parts as $part) {
156 156
 			$parents[] = $parent;
157
-			$parent = trim($parent . '/' . $part, '/');
157
+			$parent = trim($parent.'/'.$part, '/');
158 158
 		}
159 159
 		return $parents;
160 160
 	}
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
 		$this->connection->beginTransaction();
199 199
 
200 200
 		$query = $this->connection->getQueryBuilder();
201
-		$storageId = (int)$this->storage->getStorageCache()->getNumericId();
201
+		$storageId = (int) $this->storage->getStorageCache()->getNumericId();
202 202
 
203 203
 		$query->update('filecache')
204 204
 			->set('mtime', $query->func()->greatest('mtime', $query->createParameter('time')))
Please login to merge, or discard this patch.
lib/private/DB/Exceptions/DbalException.php 1 patch
Indentation   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -50,92 +50,92 @@
 block discarded – undo
50 50
  * @psalm-immutable
51 51
  */
52 52
 class DbalException extends Exception {
53
-	/** @var \Doctrine\DBAL\Exception */
54
-	private $original;
53
+    /** @var \Doctrine\DBAL\Exception */
54
+    private $original;
55 55
 
56
-	/**
57
-	 * @param \Doctrine\DBAL\Exception $original
58
-	 * @param int $code
59
-	 * @param string $message
60
-	 */
61
-	private function __construct(\Doctrine\DBAL\Exception $original, int $code, string $message) {
62
-		parent::__construct(
63
-			$message,
64
-			$code,
65
-			$original
66
-		);
67
-		$this->original = $original;
68
-	}
56
+    /**
57
+     * @param \Doctrine\DBAL\Exception $original
58
+     * @param int $code
59
+     * @param string $message
60
+     */
61
+    private function __construct(\Doctrine\DBAL\Exception $original, int $code, string $message) {
62
+        parent::__construct(
63
+            $message,
64
+            $code,
65
+            $original
66
+        );
67
+        $this->original = $original;
68
+    }
69 69
 
70
-	public static function wrap(\Doctrine\DBAL\Exception $original, string $message = ''): self {
71
-		return new self(
72
-			$original,
73
-			is_int($original->getCode()) ? $original->getCode() : 0,
74
-			empty($message) ? $original->getMessage() : $message
75
-		);
76
-	}
70
+    public static function wrap(\Doctrine\DBAL\Exception $original, string $message = ''): self {
71
+        return new self(
72
+            $original,
73
+            is_int($original->getCode()) ? $original->getCode() : 0,
74
+            empty($message) ? $original->getMessage() : $message
75
+        );
76
+    }
77 77
 
78
-	public function isRetryable(): bool {
79
-		return $this->original instanceof RetryableException;
80
-	}
78
+    public function isRetryable(): bool {
79
+        return $this->original instanceof RetryableException;
80
+    }
81 81
 
82
-	public function getReason(): ?int {
83
-		/**
84
-		 * Constraint errors
85
-		 */
86
-		if ($this->original instanceof ForeignKeyConstraintViolationException) {
87
-			return parent::REASON_FOREIGN_KEY_VIOLATION;
88
-		}
89
-		if ($this->original instanceof NotNullConstraintViolationException) {
90
-			return parent::REASON_NOT_NULL_CONSTRAINT_VIOLATION;
91
-		}
92
-		if ($this->original instanceof UniqueConstraintViolationException) {
93
-			return parent::REASON_UNIQUE_CONSTRAINT_VIOLATION;
94
-		}
95
-		// The base exception comes last
96
-		if ($this->original instanceof ConstraintViolationException) {
97
-			return parent::REASON_CONSTRAINT_VIOLATION;
98
-		}
82
+    public function getReason(): ?int {
83
+        /**
84
+         * Constraint errors
85
+         */
86
+        if ($this->original instanceof ForeignKeyConstraintViolationException) {
87
+            return parent::REASON_FOREIGN_KEY_VIOLATION;
88
+        }
89
+        if ($this->original instanceof NotNullConstraintViolationException) {
90
+            return parent::REASON_NOT_NULL_CONSTRAINT_VIOLATION;
91
+        }
92
+        if ($this->original instanceof UniqueConstraintViolationException) {
93
+            return parent::REASON_UNIQUE_CONSTRAINT_VIOLATION;
94
+        }
95
+        // The base exception comes last
96
+        if ($this->original instanceof ConstraintViolationException) {
97
+            return parent::REASON_CONSTRAINT_VIOLATION;
98
+        }
99 99
 
100
-		/**
101
-		 * Other server errors
102
-		 */
103
-		if ($this->original instanceof DatabaseObjectExistsException) {
104
-			return parent::REASON_DATABASE_OBJECT_EXISTS;
105
-		}
106
-		if ($this->original instanceof DatabaseObjectNotFoundException) {
107
-			return parent::REASON_DATABASE_OBJECT_NOT_FOUND;
108
-		}
109
-		if ($this->original instanceof DeadlockException) {
110
-			return parent::REASON_DEADLOCK;
111
-		}
112
-		if ($this->original instanceof InvalidFieldNameException) {
113
-			return parent::REASON_INVALID_FIELD_NAME;
114
-		}
115
-		if ($this->original instanceof NonUniqueFieldNameException) {
116
-			return parent::REASON_NON_UNIQUE_FIELD_NAME;
117
-		}
118
-		if ($this->original instanceof SyntaxErrorException) {
119
-			return parent::REASON_SYNTAX_ERROR;
120
-		}
121
-		// The base server exception class comes last
122
-		if ($this->original instanceof ServerException) {
123
-			return parent::REASON_SERVER;
124
-		}
100
+        /**
101
+         * Other server errors
102
+         */
103
+        if ($this->original instanceof DatabaseObjectExistsException) {
104
+            return parent::REASON_DATABASE_OBJECT_EXISTS;
105
+        }
106
+        if ($this->original instanceof DatabaseObjectNotFoundException) {
107
+            return parent::REASON_DATABASE_OBJECT_NOT_FOUND;
108
+        }
109
+        if ($this->original instanceof DeadlockException) {
110
+            return parent::REASON_DEADLOCK;
111
+        }
112
+        if ($this->original instanceof InvalidFieldNameException) {
113
+            return parent::REASON_INVALID_FIELD_NAME;
114
+        }
115
+        if ($this->original instanceof NonUniqueFieldNameException) {
116
+            return parent::REASON_NON_UNIQUE_FIELD_NAME;
117
+        }
118
+        if ($this->original instanceof SyntaxErrorException) {
119
+            return parent::REASON_SYNTAX_ERROR;
120
+        }
121
+        // The base server exception class comes last
122
+        if ($this->original instanceof ServerException) {
123
+            return parent::REASON_SERVER;
124
+        }
125 125
 
126
-		/**
127
-		 * Generic errors
128
-		 */
129
-		if ($this->original instanceof ConnectionException) {
130
-			return parent::REASON_CONNECTION_LOST;
131
-		}
132
-		if ($this->original instanceof InvalidArgumentException) {
133
-			return parent::REASON_INVALID_ARGUMENT;
134
-		}
135
-		if ($this->original instanceof DriverException) {
136
-			return parent::REASON_DRIVER;
137
-		}
126
+        /**
127
+         * Generic errors
128
+         */
129
+        if ($this->original instanceof ConnectionException) {
130
+            return parent::REASON_CONNECTION_LOST;
131
+        }
132
+        if ($this->original instanceof InvalidArgumentException) {
133
+            return parent::REASON_INVALID_ARGUMENT;
134
+        }
135
+        if ($this->original instanceof DriverException) {
136
+            return parent::REASON_DRIVER;
137
+        }
138 138
 
139
-		return null;
140
-	}
139
+        return null;
140
+    }
141 141
 }
Please login to merge, or discard this patch.