diff --git a/project_issue.install b/project_issue.install index 36e9e6b..3147f96 100644 --- a/project_issue.install +++ b/project_issue.install @@ -747,13 +747,52 @@ function project_issue_update_6009() { } /** + * Migrate users with notifications for >= 50 projects to a global setting. + * + * Since there never used to be a way to say "Send me e-mail notifications + * for my own issues for all projects" many users have had to select this + * option individually on a large number of projects. If a user is subscribed + * to 50 or more projects at this notification level, remove all of those + * per-project settings and just set their per-user global default. + */ +function project_issue_update_6010() { + $ret = array(); + + // Find all the users with 50 or more projects configured to send e-mail for + // "own issues". + $uids = array(); + $result = db_query("SELECT uid, COUNT(nid) AS project_count FROM {project_issue_notification_project} WHERE level = %d GROUP BY uid HAVING project_count >= 50", PROJECT_ISSUE_NOTIFICATION_OWN); + while ($uid = db_result($result)) { + $uids[] = $uid; + } + + if (!empty($uids)) { + // Define a per-user default for all of them. + foreach ($uids as $uid) { + $query = db_query("INSERT INTO {project_issue_notification_global} (uid, level) VALUES (%d, %d)", $uid, PROJECT_ISSUE_NOTIFICATION_OWN); + } + + // Remove all the per-project settings for them. + $placeholders = db_placeholders($uids); + $query = db_query("DELETE FROM {project_issue_notification_project} WHERE level = " . PROJECT_ISSUE_NOTIFICATION_OWN . " AND uid IN (" . $placeholders . ")", $uids); + + $ret[] = array( + 'success' => TRUE, + 'query' => format_plural(count($uids), 'Converted per-project notification settings for @count users to per-user global defaults.', 'Converted per-project notification settings for 1 user a per-user global default.'), + ); + } + + return $ret; +} + +/** * Add primary key to {project_issue_notification_project}. * * 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 three hours on reasonable hardware. */ -function project_issue_update_6010() { +function project_issue_update_6011() { $ret = array(); db_add_primary_key($ret, 'project_issue_notification_project', array('uid', 'nid')); return $ret; @@ -765,7 +804,7 @@ function project_issue_update_6010() { * WARNING: This update can take a *very* long time (potentially hours) if * there are a high number of rows in the table. */ -function project_issue_update_6011() { +function project_issue_update_6012() { $ret = array(); db_add_index($ret, 'project_issue_notification_project', 'nid_level', array('nid', 'level')); return $ret; @@ -774,7 +813,7 @@ function project_issue_update_6011() { /** * Drop unneccessary indexes from {project_issue_notification_project}. */ -function project_issue_update_6012() { +function project_issue_update_6013() { $ret = array(); db_drop_index($ret, 'project_issue_notification_project', 'project_subscriptions_nid_uid_level'); return $ret;