You are here

function privatemsg_update_6003 in Privatemsg 6

Same name and namespace in other branches
  1. 6.2 privatemsg.install \privatemsg_update_6003()

Update function to resolve "forever new" messages.

As described in http://drupal.org/node/490650

File

./privatemsg.install, line 424
Install file for privatemsg.module

Code

function privatemsg_update_6003() {

  // Sites which are directly upgrading from Drupal 5 don't have this problem.
  // Skip this update for them, as it can be very slow.
  if (variable_get('privatemsg_update_6000', 0)) {
    variable_del('privatemsg_update_6000');
    return array();
  }
  $ret = array();

  // Find messages that have aformentioned problem
  $sql = "SELECT DISTINCT p1.mid, p1.uid FROM {pm_index} p1 INNER JOIN {pm_index} p2 ON p1.thread_id = p2.thread_id AND p1.mid = p2.mid INNER JOIN {pm_message} pm ON p1.uid = pm.author AND p2.uid = pm.author WHERE p1.is_new <> p2.is_new";
  $result = db_query($sql);
  while ($row = db_fetch_object($result)) {
    privatemsg_message_change_status($row->mid, PRIVATEMSG_READ, $row);
  }
  $ret[] = array(
    'success' => $result !== FALSE,
    'query' => check_plain($sql),
  );
  return $ret;
}