function privatemsg_thread_change_delete

1 privatemsg.module privatemsg_thread_change_delete($threads, $delete, $account = NULL)
7-1 privatemsg.module privatemsg_thread_change_delete($threads, $delete, $account = NULL)
7-2 privatemsg.module privatemsg_thread_change_delete($threads, $delete, $account = NULL)
6-2 privatemsg.module privatemsg_thread_change_delete($threads, $delete, $account = NULL)

Delete or restore one or multiple threads.

Parameters

$threads: Array with thread id's or a single thread id.

$delete: Indicates if the threads should be deleted or restored. 1 => delete, 0 => restore.

$account: User account for which the delete action should be carried out - Set to NULL to delete for all users.

1 string reference to 'privatemsg_thread_change_delete'

File

./privatemsg.module, line 2278
Allows users to send private messages to other users.

Code

function privatemsg_thread_change_delete($threads, $delete, $account = NULL) {
  if (!is_array($threads)) {
    $threads = array($threads);
  }
  if (empty($account)) {
    global $user;
    $account = clone $user;
  }

  // Record which messages will be deleted.
  $changed = db_select('pm_index', 'pmi')->fields('pmi', array('mid'))->condition('deleted', 0, $delete ? '=' : '>')->condition('recipient', $account->uid)->condition('type', array('user', 'hidden'))->condition('thread_id', $threads)->execute()->fetchCol();

  // Merge status and uid with the threads list. array_merge() will not overwrite/ignore thread_id 1.
  $delete_value = 0;
  if ($delete == TRUE) {
    $delete_value = REQUEST_TIME;
  }
  // Update the status of the threads.
  db_update('pm_index')->fields(array('deleted' => $delete_value))->condition('recipient', $account->uid)->condition('type', array('user', 'hidden'))->condition('thread_id', $threads)->execute();

  // Allow modules to respond to the deleted changes.
  foreach ($changed as $mid) {
    module_invoke_all('privatemsg_message_status_deleted', $mid, $delete, $account);
  }

  if ($delete) {
    drupal_set_message(format_plural(count($threads), 'Deleted 1 thread.', 'Deleted @count threads.'));
  }
  else {
    drupal_set_message(format_plural(count($threads), 'Restored 1 thread.', 'Restored @count threads.'));
  }
}