You are here

function privatemsg_sql_deleted in Privatemsg 6.2

Same name and namespace in other branches
  1. 6 privatemsg.module \privatemsg_sql_deleted()
  2. 7.2 privatemsg.module \privatemsg_sql_deleted()
  3. 7 privatemsg.module \privatemsg_sql_deleted()

Query Builder function to load all messages that should be flushed.

Parameters

$fragments: Query fragments array.

$days: Select messages older than x days.

Related topics

File

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

Code

function privatemsg_sql_deleted(&$fragments, $days) {
  $fragments['primary_table'] = '{pm_message} pm';
  $fragments['select'][] = 'pm.mid';

  // The lowest value is higher than 0 if all recipients have deleted a message.
  $fragments['select'][] = 'MIN(pmi.deleted) as is_deleted';

  // The time the most recent deletion happened.
  $fragments['select'][] = 'MAX(pmi.deleted) as last_deleted';
  $fragments['inner_join'][] = 'INNER JOIN {pm_index} pmi ON (pmi.mid = pm.mid)';
  $fragments['group_by'][] = 'pm.mid';

  // Ignore messages that have not been deleted by all users.
  $fragments['having'][] = 'MIN(pmi.deleted) > 0';

  // Only select messages that have been deleted more than n days ago.
  $fragments['having'][] = 'MAX(pmi.deleted) < %d';
  $fragments['query_args']['having'][] = time() - $days * 86400;
}