public function do_delete_users(FormUI $form)
{
$success = true;
// Get the user to assign deleted users' posts to
$assign = intval($form->reassign->value);
if (in_array($assign, $form->deletion_queue->value)) {
Session::error(_t('You may not assign posts from deleted users to a user that is being deleted'));
return false;
}
$count = 0;
if (count($form->deletion_queue->value) == 0) {
Session::notice(_t('No users deleted.'));
return false;
}
foreach ($form->deletion_queue->value as $id) {
$user = User::get_by_id($id);
$posts = Posts::get(array('user_id' => $user->id, 'nolimit' => 1));
$one_success = $user->delete();
if ($one_success && count($posts)) {
if (0 == $assign) {
/** @var Post $post */
foreach ($posts as $post) {
$post->delete();
}
} else {
Posts::reassign($assign, $posts);
}
}
$success = $success && $one_success;
$count++;
}
if ($success) {
$msg_status = sprintf(_n('Deleted one user.', 'Deleted %s users.', $count), $count);
Session::notice($msg_status);
return true;
} else {
$msg_status = _t('There was a problem deleting users.');
Session::error($msg_status);
return false;
}
}