science-ation/db/db.update.87.php

51 lines
1.2 KiB
PHP
Raw Normal View History

<?
function db_update_87_post()
{
global $config, $pdo;
$q = $pdo->prepare('SELECT id,types,passwordset FROM users');
while ($i = $q->fetch(PDO::FETCH_OBJ)) {
$id = $i->id;
$types = explode(',', $i->types);
$expiry = $i->passwordset;
if ($expiry == NULL) {
$newval = 'created';
} else if ($expiry == '0000-00-00') {
$newval = false;
} else {
/* Find the expiry based on the type */
$longest_expiry = 0;
foreach ($types as $t) {
$e = $config["{$t}_password_expiry_days"];
if ($e == 0) {
/* Catch a never expire case. */
$longest_expiry = 0;
break;
} else if ($e > $longest_expiry) {
$longest_expiry = $e;
}
}
if ($longest_expiry == 0) {
/*
* Password never expires, set the password
* set time to the creation time
*/
$newval = 'created';
} else {
/* Compute when the password was set */
$newval = date('Y-m-d',
strtotime("$expiry -$longest_expiry days"));
$newval = "'$newval'";
}
}
if ($newval != false) {
2025-02-09 17:24:37 +00:00
$query = "UPDATE users SET passwordset=? WHERE id=?";
echo "$query\n";
$stmt = $pdo->prepare($query);
2025-02-09 17:24:37 +00:00
$stmt->execute([$newval,$id]);
}
}
}
?>