diff -u b/includes/subscribe.inc b/includes/subscribe.inc --- b/includes/subscribe.inc +++ b/includes/subscribe.inc @@ -61,7 +61,7 @@ $result = db_query(db_rewrite_sql("SELECT pisp.nid, n.title, pisp.level FROM {project_issue_subscriptions_project} pisp INNER JOIN {node} n ON n.nid = pisp.nid - WHERE n.type = 'project_project' AND n.status = 1 AND pisp.uid = %d ORDER BY n.title + WHERE n.status = 1 AND pisp.uid = %d ORDER BY n.title ", 'n'), $account->uid); while ($project = db_fetch_object($result)) { $form['project_issue_subscriptions']['projects'][$project->nid]['title'] = array( diff -u b/project_issue.install b/project_issue.install --- b/project_issue.install +++ b/project_issue.install @@ -660,7 +660,7 @@ $ret = array(); if (!isset($sandbox['total'])) { - // Pull counts of all duplicate entries. + // Pull counts of all duplicate entries. $result = db_query("SELECT COUNT(*) AS count FROM {project_subscriptions} GROUP BY nid, uid HAVING COUNT(*) > 1"); $sandbox['count'] = 0; $sandbox['total'] = 0; @@ -675,16 +675,16 @@ $result = db_query("SELECT nid, uid FROM {project_subscriptions} GROUP BY nid, uid HAVING COUNT(*) > 1 LIMIT %d", $limit); while ($row = db_fetch_object($result)) { - $sandbox['count']++; - $nid = intval($row->nid); - $uid = intval($row->uid); - // Only delete one row at a time. - $ret[] = update_sql("DELETE FROM {project_subscriptions} WHERE nid = $nid AND uid = $uid LIMIT 1"); + $sandbox['count']++; + $nid = intval($row->nid); + $uid = intval($row->uid); + // Only delete one row at a time. + $ret[] = update_sql("DELETE FROM {project_subscriptions} WHERE nid = $nid AND uid = $uid LIMIT 1"); } // Check to see if finished, report progress if not. if ($sandbox['count'] >= $sandbox['total']) { - $ret['#finished'] = 1; + $ret['#finished'] = 1; } else { $ret['#finished'] = $sandbox['count'] / $sandbox['total']; @@ -747,7 +747,7 @@ * * WARNING: This update can take a *very* long time (potentially hours) if * there are a high number of rows in the table. The test table had 2.34 - * million rows, and the query took over two hours on reasonable hardware. + * million rows, and the query took over three hours on reasonable hardware. */ function project_issue_update_6010() { $ret = array(); diff -u b/project_issue.module b/project_issue.module --- b/project_issue.module +++ b/project_issue.module @@ -907,7 +907,7 @@ } /** - * Loads user account settings for project issue subscriptions. + * Loads per-user account settings for project issue subscriptions. * * @param $account * A user account object to attach project issue subscription settings to. @@ -939,25 +939,38 @@ } /** - * Saves user account settings for project issue subscriptions. + * Saves per-user account settings for project issue subscriptions. * * @param $account * A user account object containing at least the properties: * - uid: The ID of the user account. * - project_issue_subscriptions: An associative array containing: * - level: An integer denoting the user's global issue subscription level. + * - PROJECT_ISSUE_SUBSCRIPTIONS_NONE + * - PROJECT_ISSUE_SUBSCRIPTIONS_FLAGGED + * - PROJECT_ISSUE_SUBSCRIPTIONS_ALL + * When passing PROJECT_ISSUE_SUBSCRIPTIONS_NONE the user's per-user + * subscription setting is deleted. * * @see project_issue_subscriptions_user_settings_load() */ function project_issue_subscriptions_user_settings_save($account) { - db_query("UPDATE {project_issue_subscriptions_user} SET level = %d WHERE uid = %d", array( - $account->project_issue_subscriptions['level'], - $account->uid, - )); - if (!db_affected_rows()) { - db_query("INSERT INTO {project_issue_subscriptions_user} (uid, level) VALUES (%d, %d)", array( + $level = $account->project_issue_subscriptions['level']; + if ($level > PROJECT_ISSUE_SUBSCRIPTIONS_NONE) { + db_query("UPDATE {project_issue_subscriptions_user} SET level = %d WHERE uid = %d", array( + $level, + $account->uid, + )); + if (!db_affected_rows()) { + db_query("INSERT INTO {project_issue_subscriptions_user} (uid, level) VALUES (%d, %d)", array( + $account->uid, + $level, + )); + } + } + else { + db_query("DELETE FROM {project_issue_subscriptions_user} WHERE uid = %d", array( $account->uid, - $account->project_issue_subscriptions['level'], )); } } @@ -1032,7 +1045,7 @@ function project_issue_user($op, $edit, $account) { // Delete project maintainer assignments and all e-mail notification settings // in case a user account is deleted or disabled/banned. - if ($op == 'delete' || ($op == 'after_update' && empty($account->status))) { + if ($op == 'delete') { db_query("DELETE FROM {project_issue_subscriptions_user} WHERE uid = %d", $account->uid); db_query("DELETE FROM {project_issue_subscriptions_project} WHERE uid = %d", $account->uid); db_query("DELETE FROM {project_issue_project_maintainer} WHERE uid = %d", $account->uid);