From 3872a0383dc77ec47d965a2e8770c016904abeda Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Fri, 27 Aug 2021 12:03:15 +0200 Subject: [PATCH] Make use of the `SearchFailed` exception in MysqlSearchEngine --- .../search/mysql/MysqlSearchEngine.class.php | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/wcfsetup/install/files/lib/system/search/mysql/MysqlSearchEngine.class.php b/wcfsetup/install/files/lib/system/search/mysql/MysqlSearchEngine.class.php index 0c292b5b18..9ddbe94a12 100644 --- a/wcfsetup/install/files/lib/system/search/mysql/MysqlSearchEngine.class.php +++ b/wcfsetup/install/files/lib/system/search/mysql/MysqlSearchEngine.class.php @@ -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]; } -- 2.20.1