|
| 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(); |
0 commit comments