You are here

function invite_update_3 in Invite 5.2

Same name and namespace in other branches
  1. 5 invite.install \invite_update_3()

Clean up invites originating from deleted users.

File

./invite.install, line 159
Installation file for invite module.

Code

function invite_update_3() {
  $ret = array();
  $result = db_query("SELECT DISTINCT i.uid FROM {invite} i LEFT JOIN {users} u ON i.uid = u.uid WHERE u.uid IS NULL");
  $count = db_num_rows($result);
  $sql = "DELETE FROM {invite} WHERE uid = %d";
  if (!variable_get('invite_allow_join_delete', 0)) {
    $sql .= " AND timestamp != 0";
  }
  while ($inviter = db_fetch_object($result)) {
    db_query($sql, $inviter->uid);
  }
  $ret[] = array(
    'query' => strtr('%count orphaned invites have been deleted.', array(
      '%count' => $count,
    )),
    'success' => TRUE,
  );
  return $ret;
}