Make use of the `SearchFailed` exception in MysqlSearchEngine
authorTim Düsterhus <duesterhus@woltlab.com>
Fri, 27 Aug 2021 10:03:15 +0000 (12:03 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Fri, 27 Aug 2021 10:03:15 +0000 (12:03 +0200)
wcfsetup/install/files/lib/system/search/mysql/MysqlSearchEngine.class.php

index 0c292b5b185942926018515e0698bcaecf9cfbca..9ddbe94a12ac2123be9c454eeadabe95dea7326e 100644 (file)
@@ -2,10 +2,12 @@
 
 namespace wcf\system\search\mysql;
 
-use wcf\system\database\DatabaseException;
+use wcf\system\database\DatabaseException as LegacyDatabaseException;
+use wcf\system\database\exception\DatabaseException;
 use wcf\system\database\util\PreparedStatementConditionBuilder;
 use wcf\system\exception\SystemException;
 use wcf\system\search\AbstractSearchEngine;
+use wcf\system\search\exception\SearchFailed;
 use wcf\system\search\SearchEngine;
 use wcf\system\search\SearchIndexManager;
 use wcf\system\WCF;
@@ -103,15 +105,18 @@ class MysqlSearchEngine extends AbstractSearchEngine
             $sql .= " ORDER BY " . $orderBy;
         }
 
-        // send search query
-        $messages = [];
-        $statement = WCF::getDB()->prepareStatement($sql, $limit);
-        $statement->execute($parameters);
-        while ($row = $statement->fetchArray()) {
-            $messages[] = [
-                'objectID' => $row['objectID'],
-                'objectType' => $row['objectType'],
-            ];
+        try {
+            $messages = [];
+            $statement = WCF::getDB()->prepareStatement($sql, $limit);
+            $statement->execute($parameters);
+            while ($row = $statement->fetchArray()) {
+                $messages[] = [
+                    'objectID' => $row['objectID'],
+                    'objectType' => $row['objectType'],
+                ];
+            }
+        } catch (DatabaseException $e) {
+            throw new SearchFailed('MySQL search query failed.', $e);
         }
 
         return $messages;
@@ -467,7 +472,7 @@ class MysqlSearchEngine extends AbstractSearchEngine
                 $statement = WCF::getDB()->prepareStatement($sql);
                 $statement->execute();
                 $row = $statement->fetchArray();
-            } catch (DatabaseException $e) {
+            } catch (LegacyDatabaseException $e) {
                 // fallback if user is disallowed to issue 'SHOW VARIABLES'
                 $row = ['Value' => 3];
             }