Skip to content

Commit a2fcbed

Browse files
committed
Add install script
1 parent a4a6cf4 commit a2fcbed

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
namespace be\bastelstu\max\wcf\otu;
3+
4+
/**
5+
* Handles installation of One-Time Username.
6+
*
7+
* @author Maximilian Mader
8+
* @copyright 2013 Maximilian Mader
9+
* @license BSD 3-Clause License <http://opensource.org/licenses/BSD-3-Clause>
10+
* @package be.bastelstu.max.wcf.otu
11+
*/
12+
// @codingStandardsIgnoreFile
13+
14+
// little workaround, options have already been loaded and the constant won't be defined
15+
if (!defined('OTU_BLACKLIST_LIFETIME')) define('OTU_BLACKLIST_LIFETIME', 182);
16+
17+
// 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 <> ?";
24+
$stmt = \wcf\system\WCF::getDB()->prepareStatement($sql);
25+
$stmt->execute(array(''));
26+
$usernames = array();
27+
while ($row = $stmt->fetchArray()) {
28+
$usernames[] = array('username' => $row['oldUsername'], 'time' => $row['lastUsernameChange']);
29+
}
30+
31+
// blacklist the usernames that have been used before
32+
\wcf\system\WCF::getDB()->beginTransaction();
33+
$sql = "INSERT INTO
34+
wcf".WCF_N."_otu_blacklist (username, time)
35+
VALUES (?, ?)";
36+
$stmt = \wcf\system\WCF::getDB()->prepareStatement($sql);
37+
foreach ($usernames as $user) {
38+
$stmt->execute(array($user['username'], ($user['time'] > 0) ? $user['time'] : TIME_NOW));
39+
}
40+
\wcf\system\WCF::getDB()->commitTransaction();
41+
42+
// rebuild the corresponding option
43+
\wcf\system\user\OTUHandler::getInstance()->rebuildOption();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function blacklistUsernames(array $usernames) {
4444
wcf".WCF_N."_otu_blacklist (username, time)
4545
VALUES (?, ?)";
4646
$stmt = \wcf\system\WCF::getDB()->prepareStatement($sql);
47-
foreach($usernames as $username) {
47+
foreach ($usernames as $username) {
4848
$stmt->execute(array($username, TIME_NOW));
4949
}
5050
\wcf\system\WCF::getDB()->commitTransaction();

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@
2525
<instruction type="eventListener">eventListener.xml</instruction>
2626
<instruction type="option">option.xml</instruction>
2727
<instruction type="language">language/*.xml</instruction>
28+
<instruction type="script" run="standalone">acp/be.bastelstu.max.wcf.otu.install.php</instruction>
2829
</instructions>
2930
</package>

0 commit comments

Comments
 (0)