function drush_paranoia_reset_stale_accounts in Paranoia 7
Drush callback to queue stale accounts to have their passwords reset.
File
- ./
paranoia.drush.inc, line 112 - Drush integration for the paranoia module.
Code
function drush_paranoia_reset_stale_accounts() {
$queue = DrupalQueue::get('paranoia_stale_expirations');
$limit = drush_get_option('limit', FALSE);
// Don't add to the queue if there are remaining items to be processed, to
// avoid duplicate queue items if the cron queue iterator from a previous
// cron run has not gotten through all of its queued items.
if ($queue
->numberOfItems() > 0) {
watchdog('paranoia', 'Skipping adding items to the queue as stale expiration items already exist.');
return;
}
// Check for accounts whose last access time is older than the threshold,
// which defaults to 2 years (365 * 2 = 730 days).
$offset = REQUEST_TIME - variable_get('paranoia_access_threshold', 730) * 60 * 60 * 24;
$query = db_select('users', 'u')
->fields('u', [
'uid',
])
->condition('uid', 0, '>')
->condition('created', $offset, '<')
->condition('access', $offset, '<')
->condition('login', $offset, '<')
->condition('pass', 'ZZZ%', 'NOT LIKE');
if ($limit !== FALSE) {
$query
->range(0, $limit);
}
$result = $query
->execute();
$count = 0;
foreach ($result as $record) {
$count++;
$queue
->createItem($record->uid);
}
drush_log(dt('Queued @count users to have their password reset', array(
'@count' => $count,
)), 'ok');
watchdog('paranoia', 'Queued @count users to have their password reset', array(
'@count' => $count,
));
}