You are here

function _privatemsg_prune in Privatemsg 5

Same name and namespace in other branches
  1. 5.3 privatemsg.module \_privatemsg_prune()
1 call to _privatemsg_prune()
privatemsg_cron in ./privatemsg.module
Implementation of hook_cron().

File

./privatemsg.module, line 2437

Code

function _privatemsg_prune() {

  // move deleted message older than 1 month to archive table, and optimize table
  $result = db_query('SELECT * FROM {privatemsg} WHERE author_del = 1 AND recipient_del = 1 AND timestamp < %d', time() - 3600 * 24 * 30);
  while ($message = db_fetch_object($result)) {
    db_query("INSERT INTO {privatemsg_archive} (id, author, recipient, subject, message, timestamp, hostname, format, folder, thread, type) VALUES (%d, %d, %d, '%s', '%s', %d, '%s', %d, %d, %d, '%s')", $message->id, $message->author, $message->recipient, $message->subject, $message->message, $message->timestamp, $message->hostname, $message->format, $message->folder, $message->thread, $message->type);
    db_query('DELETE FROM {privatemsg} WHERE id = %d', $message->id);

    // Notify other modules that a message is pruned.
    privatemsg_invoke_privatemsg($message, 'prune');
  }

  // this is MySQL-specific
  if (!strncmp($GLOBALS['db_type'], 'mysql', 5)) {
    db_query('OPTIMIZE TABLE {privatemsg}');
  }
}