From 0d5d1a2b913b7f4154324cbc04218092c33d5393 Mon Sep 17 00:00:00 2001 From: Byron Jones Date: Wed, 8 May 2013 21:43:39 +0800 Subject: Bug 863686: "Congratulations" email received for first approval+ instead of first review+ (schema only) --- extensions/ContributorEngagement/Extension.pm | 28 +++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'extensions') diff --git a/extensions/ContributorEngagement/Extension.pm b/extensions/ContributorEngagement/Extension.pm index 7e7031b33..13956c3e8 100644 --- a/extensions/ContributorEngagement/Extension.pm +++ b/extensions/ContributorEngagement/Extension.pm @@ -36,6 +36,34 @@ sub install_update_db { { TYPE => 'INT3' }); _migrate_first_approved_ids(); } + if (!$dbh->bz_column_info('profiles', 'first_patch_reviewed_id')) { + $dbh->bz_add_column('profiles', 'first_patch_reviewed_id', { TYPE => 'INT3' }); + _populate_first_reviewed_ids(); + } +} +sub _populate_first_reviewed_ids { + my $dbh = Bugzilla->dbh; + + my $sth = $dbh->prepare('UPDATE profiles SET first_patch_reviewed_id = ? WHERE userid = ?'); + my $ra = $dbh->selectall_arrayref("SELECT attachments.submitter_id, + attachments.attach_id + FROM attachments + INNER JOIN flags ON attachments.attach_id = flags.attach_id + INNER JOIN flagtypes ON flags.type_id = flagtypes.id + WHERE flagtypes.name LIKE 'review%' AND flags.status = '+' + ORDER BY flags.modification_date"); + my $count = 1; + my $total = scalar @$ra; + my %user_seen; + foreach my $ra_row (@$ra) { + my ($user_id, $attach_id) = @$ra_row; + indicate_progress({ current => $count++, total => $total, every => 25 }); + next if $user_seen{$user_id}; + $sth->execute($attach_id, $user_id); + $user_seen{$user_id} = 1; + } + + print "done\n"; } sub _migrate_first_approved_ids { -- cgit v1.2.3-24-g4f1b