[ADDED] Validate all users option

This commit is contained in:
Sebastian Grewe 2014-04-14 10:57:55 +02:00
parent 54a1452d45
commit 1550553a6d

37
scripts/validate_users.php Normal file → Executable file
View File

@ -7,8 +7,10 @@
// Include all settings and classes
require_once('shared.inc.php');
$timeLimitInDays = 90;
$options = getopt("d:a");
isset($options['d']) ? $timeLimitInDays = (int)$options['d'] : $timeLimitInDays = 90;
isset($options['a']) ? $allUsers = true : $allUsers = false;
$notifyStaleUsers = False;
// Fetch all users
@ -19,9 +21,8 @@
$currentTime = time();
$totalSavings = 0;
foreach ($users as $user)
{
foreach ($users as $user) {
$id = $user['id'];
$isAdmin = $user['is_admin'];
$username = $user['username'];
@ -29,32 +30,32 @@
$lastLogin = $user['last_login'];
$coinAddress = $user['coin_address'];
$mailAddress = $user['email'];
$everLoggedIn = !empty($lastLogin);
$timeDelta = $currentTime - $lastLogin;
$lastLoginInDays = round(abs($timeDelta)/60/60/24, 0);
if($lastLoginInDays < $timeLimitInDays)
if(!$allUsers && $lastLoginInDays < $timeLimitInDays)
continue;
// get transactions summary for the user
$summary = $transaction->getTransactionSummary($id);
$summary = $transaction->getTransactionSummary($id);
$transactions_exists = !empty($summary);
// get balances
$balances = $transaction->getBalance($id);
$confirmedBalance = $balances['confirmed'];
$totalSavings += $confirmedBalance;
$totalSavings += $confirmedBalance;
$staleAccount = $everLoggedIn == false && $transactions_exists == false;
if ($notifyStaleUsers) {
$subject = "Account at " . $setting->getValue('website_name') . "!";
$body = "Hi ". $username .",\n\nWe have discovered \
your username as inactive. Your last login is older than 90 days, \
please reactivate your Account if you want to mine again, \
else it will be deleted in 30 days.\n\nBalance left: ". $confirmedBalance . " " . $config['currency'] . "\n\nCheers";
if (mail($mailAddress, $subject, $body)) {
echo("Email successfully sent!");
} else {
@ -62,11 +63,11 @@
}
}
printf($mask, $id, $username, $mailAddress,
printf($mask, $id, $username, $mailAddress,
$loggedIp, strftime("%Y-%m-%d %H:%M:%S", $lastLogin), $lastLoginInDays, $everLoggedIn ? 'yes' : 'no',
$transactions_exists ? 'yes' : 'no', round($confirmedBalance,8),
$staleAccount ? 'yes' : 'no' );
$staleAccount ? 'yes' : 'no' );
}
echo "Total balance of stale accounts: $totalSavings" . PHP_EOL;
?>
?>