From 2fdd11cb24c6152be92b956b32590b5f2b546404 Mon Sep 17 00:00:00 2001 From: addshore Date: Tue, 29 Sep 2026 00:22:41 +0100 Subject: [PATCH] Use query builder for wiki user email checks Bug: T438985 --- app/Services/WikiUserEmailChecker.php | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/app/Services/WikiUserEmailChecker.php b/app/Services/WikiUserEmailChecker.php index 6a6535780..79ddb6082 100644 --- a/app/Services/WikiUserEmailChecker.php +++ b/app/Services/WikiUserEmailChecker.php @@ -17,7 +17,7 @@ public function findEmail(string $email): array { $userTables = $this->getAllMediaWikiUserTables($pdo); foreach ($userTables as $dbName => $userTable) { - if ($this->emailExists($pdo, $dbName, $userTable, $email)) { + if ($this->emailExists($dbName, $userTable, $email)) { $foundIn[] = "{$dbName}.{$userTable}"; } } @@ -42,19 +42,11 @@ private function getAllMediaWikiUserTables(PDO $pdo): array { return $tablesByDb; } - private function emailExists(PDO $pdo, string $dbName, string $table, string $email): bool { - $stmt = $pdo->prepare(" - SELECT 1 - FROM {$dbName}.{$table} - - -- converting from tinyblob data type, see https://github.com/wbstack/api/blob/main/database/mw/new/mw1.43-wbs2.sql#L1006 - WHERE LOWER(CONVERT(user_email USING utf8mb4)) = LOWER(:email) - - LIMIT 1 - "); - - $stmt->execute(['email' => $email]); - - return (bool) $stmt->fetch(); + private function emailExists(string $dbName, string $table, string $email): bool { + return $this->db->connection('mw') + ->table("{$dbName}.{$table}") + // Convert from tinyblob; see https://github.com/wbstack/api/blob/main/database/mw/new/mw1.43-wbs2.sql#L1006. + ->whereRaw('LOWER(CONVERT(user_email USING utf8mb4)) = LOWER(?)', [$email]) + ->exists(); } }