Skip to content

Commit 9ce632e

Browse files
committed
Reformat SQL statements and add "order by" to selects
1 parent 17f94ac commit 9ce632e

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

file/acp/be.bastelstu.max.wcf.otu.install.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@
1515
if (!defined('OTU_BLACKLIST_LIFETIME')) define('OTU_BLACKLIST_LIFETIME', 182);
1616

1717
// We don't check for "lastUsernameChange > 0", if this isn't set (how ever this may happen) TIME_NOW will be used.
18-
$sql = "SELECT
19-
oldUsername, lastUsernameChange
20-
FROM
21-
wcf".WCF_N."_user
22-
WHERE
23-
oldUsername <> ?";
18+
$sql = "SELECT oldUsername, lastUsernameChange
19+
FROM wcf".WCF_N."_user
20+
WHERE oldUsername <> ?
21+
ORDER BY oldUsername ASC";
2422
$stmt = \wcf\system\WCF::getDB()->prepareStatement($sql);
2523
$stmt->execute(array(''));
2624
$usernames = array();
@@ -30,9 +28,9 @@
3028

3129
// blacklist the usernames that have been used before
3230
\wcf\system\WCF::getDB()->beginTransaction();
33-
$sql = "INSERT INTO
34-
wcf".WCF_N."_otu_blacklist (username, time)
35-
VALUES (?, ?)";
31+
$sql = "INSERT INTO wcf".WCF_N."_otu_blacklist
32+
(username, time)
33+
VALUES (?, ?)";
3634
$stmt = \wcf\system\WCF::getDB()->prepareStatement($sql);
3735
foreach ($usernames as $user) {
3836
$stmt->execute(array($user['username'], ($user['time'] > 0) ? $user['time'] : TIME_NOW));

file/lib/system/user/OTUHandler.class.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,16 @@ public function blacklistUsernames(array $usernames) {
3232
\wcf\system\WCF::getDB()->beginTransaction();
3333
$condition = new \wcf\system\database\util\PreparedStatementConditionBuilder();
3434
$condition->add('username IN (?)', array($usernames));
35-
$sql = "DELETE FROM
36-
wcf".WCF_N."_otu_blacklist
35+
$sql = "DELETE FROM wcf".WCF_N."_otu_blacklist
3736
".$condition;
3837

3938
// save username on One-Time Username blacklist
4039
$stmt = \wcf\system\WCF::getDB()->prepareStatement($sql);
4140
$stmt->execute($condition->getParameters());
4241

43-
$sql = "INSERT INTO
44-
wcf".WCF_N."_otu_blacklist (username, time)
45-
VALUES (?, ?)";
42+
$sql = "INSERT INTO wcf".WCF_N."_otu_blacklist
43+
(username, time)
44+
VALUES (?, ?)";
4645
$stmt = \wcf\system\WCF::getDB()->prepareStatement($sql);
4746
foreach ($usernames as $username) {
4847
$stmt->execute(array($username, TIME_NOW));
@@ -59,9 +58,8 @@ public function blacklistUsernames(array $usernames) {
5958
public function prune() {
6059
if (OTU_BLACKLIST_LIFETIME == -1) return;
6160

62-
$sql = "DELETE FROM
63-
wcf".WCF_N."_otu_blacklist
64-
WHERE time < ?";
61+
$sql = "DELETE FROM wcf".WCF_N."_otu_blacklist
62+
WHERE time < ?";
6563
$stmt = \wcf\system\WCF::getDB()->prepareStatement($sql);
6664
$stmt->execute(array(TIME_NOW - OTU_BLACKLIST_LIFETIME * 86400));
6765

@@ -87,11 +85,10 @@ public function rebuildOption() {
8785
if (OTU_BLACKLIST_LIFETIME > -1) $condition->add('time > ?', array(TIME_NOW - OTU_BLACKLIST_LIFETIME * 86400));
8886
else $condition->add('1 = 1');
8987

90-
$sql = "SELECT
91-
username
92-
FROM
93-
wcf".WCF_N."_otu_blacklist
94-
".$condition;
88+
$sql = "SELECT username
89+
FROM wcf".WCF_N."_otu_blacklist
90+
".$condition."
91+
ORDER BY username ASC";
9592
$stmt = \wcf\system\WCF::getDB()->prepareStatement($sql);
9693
$stmt->execute($condition->getParameters());
9794

0 commit comments

Comments
 (0)