Skip to content

Commit 9b5dc1f

Browse files
committed
Fix duplicate entry protection
Fixes #6
1 parent 085fbd8 commit 9b5dc1f

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

file/lib/data/user/otu/blacklist/entry/UserOtuBlacklistEntryAction.class.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,25 @@ class UserOtuBlacklistEntryAction extends \wcf\data\AbstractDatabaseObjectAction
3535
public function bulkCreate() {
3636
\wcf\system\WCF::getDB()->beginTransaction();
3737
// prevent duplicate entries
38-
call_user_func(array($this->className, 'deleteAll'), array_map(function($element) {
38+
$condition = new \wcf\system\database\util\PreparedStatementConditionBuilder();
39+
$condition->add('username IN(?)', array(array_map(function($element) {
3940
return $element['username'];
40-
}, $this->parameters['data']));
41+
}, $this->parameters['data'])));
42+
43+
$sql = "SELECT ".call_user_func(array($this->className, 'getDatabaseTableIndexName'))."
44+
FROM ".call_user_func(array($this->className, 'getDatabaseTableName'))."
45+
".$condition."
46+
FOR UPDATE";
47+
$stmt = \wcf\system\WCF::getDB()->prepareStatement($sql);
48+
$stmt->execute($condition->getParameters());
49+
$entryIDs = array();
50+
while ($entryID = $stmt->fetchColumn()) $entryIDs[] = $entryID;
51+
call_user_func(array($this->className, 'deleteAll'), $entryIDs);
4152

4253
foreach ($this->parameters['data'] as $entry) {
4354
call_user_func(array($this->className, 'create'), $entry);
4455
}
56+
4557
\wcf\system\WCF::getDB()->commitTransaction();
4658
}
4759

@@ -58,10 +70,9 @@ public function prune() {
5870
WHERE time < ?";
5971
$stmt = \wcf\system\WCF::getDB()->prepareStatement($sql);
6072
$stmt->execute(array(TIME_NOW - OTU_BLACKLIST_LIFETIME * 86400));
61-
$usernames = array();
62-
63-
while ($username = $stmt->fetchColumn()) $usernames[] = $username;
73+
$entryIDs = array();
74+
while ($entryID = $stmt->fetchColumn()) $entryIDs[] = $entryID;
6475

65-
return call_user_func(array($this->className, 'deleteAll'), $usernames);
76+
return call_user_func(array($this->className, 'deleteAll'), $entryIDs);
6677
}
6778
}

0 commit comments

Comments
 (0)