Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions app/Services/WikiUserEmailChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}";
}
}
Expand All @@ -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();
}
}
Loading