function user_prune_delete in User Prune 7
Deleting the users who matching criteria.
Parameters
array $values: Configuration values used to build out the delete query.
bool $cron: If it is false it will provide page success/failure feedback.
2 calls to user_prune_delete()
- user_prune_cron in ./
user_prune.module - Passing saved variables to user_prune_delete on cron run. Deleting users.
- user_prune_form_submit in ./
user_prune.module - Passing variables from form to user_prune_delete on one time prune.
File
- ./
user_prune.module, line 388 - Module API The main module file. Implementing forms and functions.
Code
function user_prune_delete($values, $cron = FALSE) {
// Fetch the SQL.
$sql = user_prune_build_sql($values);
// Build UID list.
$result = db_query($sql);
$uids = array();
foreach ($result as $row) {
$uids[] = $row->uid;
}
// Check to make sure the number of uids are in the per-run limit
// and if not force it to be.
if (count($uids) > $values['user_prune_prune_per_run']) {
$leftover = count($uids) - $values['user_prune_prune_per_run'];
$chunks = array_chunk($uids, $values['user_prune_prune_per_run']);
$uids = $chunks[0];
}
// Delete user one by one with the Drupal user cancel method.
foreach ($uids as $uid) {
// Get the actual user cancel method.
$method = $values['user_prune_cancel_method'];
// Get the user mail status canceled notify.
$notify = variable_get('user_mail_status_canceled_notify', FALSE);
$edit = array(
'user_cancel_notify' => $notify,
);
// Delete account.
user_cancel($edit, $uid, $method);
$batch =& batch_get();
$batch['progressive'] = FALSE;
batch_process();
}
if (!$cron) {
// If cron didn't kick this off add status message to the page.
$message = t('@count users have been pruned.', array(
'@count' => count($uids),
));
if (isset($leftover)) {
$message .= ' ' . t("@leftover users met your criteria but weren't deleted.", array(
'@leftover' => $leftover,
));
}
drupal_set_message($message);
}
}