summaryrefslogtreecommitdiffstats
path: root/extensions/PhabBugz/lib/Util.pm
diff options
context:
space:
mode:
authorDylan William Hardison <dylan@hardison.net>2018-05-09 16:28:26 +0200
committerGitHub <noreply@github.com>2018-05-09 16:28:26 +0200
commit2c2b5a5644c17e2a9cc2d56fdbea76a25a24280f (patch)
tree85fd62c2ec982c67128de472ac1cc3d3904578d9 /extensions/PhabBugz/lib/Util.pm
parent739676cf4b122cdec12981c2bc3a79c3f54aa7e4 (diff)
downloadbugzilla-2c2b5a5644c17e2a9cc2d56fdbea76a25a24280f.tar.gz
bugzilla-2c2b5a5644c17e2a9cc2d56fdbea76a25a24280f.tar.xz
Revert "Bug 1440086 - Refactor PhabBugz extension code to use new User.pm module for better type checking"
Diffstat (limited to 'extensions/PhabBugz/lib/Util.pm')
-rw-r--r--extensions/PhabBugz/lib/Util.pm103
1 files changed, 87 insertions, 16 deletions
diff --git a/extensions/PhabBugz/lib/Util.pm b/extensions/PhabBugz/lib/Util.pm
index 916455e24..42da79c39 100644
--- a/extensions/PhabBugz/lib/Util.pm
+++ b/extensions/PhabBugz/lib/Util.pm
@@ -34,7 +34,10 @@ our @EXPORT_OK = qw(
edit_revision_policy
get_attachment_revisions
get_bug_role_phids
+ get_members_by_bmo_id
+ get_members_by_phid
get_needs_review
+ get_phab_bmo_ids
get_project_phid
get_revisions_by_ids
get_revisions_by_phids
@@ -131,13 +134,7 @@ sub get_bug_role_phids {
push(@bug_users, $bug->qa_contact) if $bug->qa_contact;
push(@bug_users, @{ $bug->cc_users }) if @{ $bug->cc_users };
- my $phab_users = Bugzilla::Extension::PhabBugz::User->match(
- {
- ids => [ map { $_->id } @bug_users ]
- }
- );
-
- return [ map { $_->phid } @$phab_users ];
+ return get_members_by_bmo_id(\@bug_users);
}
sub create_private_revision_policy {
@@ -357,6 +354,84 @@ sub set_project_members {
return $result->{result}{object}{phid};
}
+sub get_members_by_bmo_id {
+ my $users = shift;
+
+ my $result = get_phab_bmo_ids({ ids => [ map { $_->id } @$users ] });
+
+ my @phab_ids;
+ foreach my $user (@$result) {
+ push(@phab_ids, $user->{phid})
+ if ($user->{phid} && $user->{phid} =~ /^PHID-USER/);
+ }
+
+ return \@phab_ids;
+}
+
+sub get_members_by_phid {
+ my $phids = shift;
+
+ my $result = get_phab_bmo_ids({ phids => $phids });
+
+ my @bmo_ids;
+ foreach my $user (@$result) {
+ push(@bmo_ids, $user->{id})
+ if ($user->{phid} && $user->{phid} =~ /^PHID-USER/);
+ }
+
+ return \@bmo_ids;
+}
+
+sub get_phab_bmo_ids {
+ my ($params) = @_;
+ my $memcache = Bugzilla->memcached;
+
+ # Try to find the values in memcache first
+ my @results;
+ if ($params->{ids}) {
+ my @bmo_ids = @{ $params->{ids} };
+ for (my $i = 0; $i < @bmo_ids; $i++) {
+ my $phid = $memcache->get({ key => "phab_user_bmo_id_" . $bmo_ids[$i] });
+ if ($phid) {
+ push(@results, {
+ id => $bmo_ids[$i],
+ phid => $phid
+ });
+ splice(@bmo_ids, $i, 1);
+ }
+ }
+ $params->{ids} = \@bmo_ids;
+ }
+
+ if ($params->{phids}) {
+ my @phids = @{ $params->{phids} };
+ for (my $i = 0; $i < @phids; $i++) {
+ my $bmo_id = $memcache->get({ key => "phab_user_phid_" . $phids[$i] });
+ if ($bmo_id) {
+ push(@results, {
+ id => $bmo_id,
+ phid => $phids[$i]
+ });
+ splice(@phids, $i, 1);
+ }
+ }
+ $params->{phids} = \@phids;
+ }
+
+ my $result = request('bugzilla.account.search', $params);
+
+ # Store new values in memcache for later retrieval
+ foreach my $user (@{ $result->{result} }) {
+ $memcache->set({ key => "phab_user_bmo_id_" . $user->{id},
+ value => $user->{phid} });
+ $memcache->set({ key => "phab_user_phid_" . $user->{phid},
+ value => $user->{id} });
+ push(@results, $user);
+ }
+
+ return \@results;
+}
+
sub is_attachment_phab_revision {
my ($attachment) = @_;
return ($attachment->contenttype eq PHAB_CONTENT_TYPE
@@ -484,13 +559,9 @@ sub get_needs_review {
$user //= Bugzilla->user;
return unless $user->id;
- my $phab_user = Bugzilla::Extension::PhabBugz::User->new_from_query(
- {
- ids => [ $user->id ]
- }
- );
-
- return [] unless $phab_user;
+ my $ids = get_members_by_bmo_id([$user]);
+ return [] unless @$ids;
+ my $phid_user = $ids->[0];
my $diffs = request(
'differential.revision.search',
@@ -499,7 +570,7 @@ sub get_needs_review {
reviewers => 1,
},
constraints => {
- reviewerPHIDs => [$phab_user->phid],
+ reviewerPHIDs => [$phid_user],
statuses => [qw( needs-review )],
},
order => 'newest',
@@ -513,7 +584,7 @@ sub get_needs_review {
foreach my $diff (@{ $diffs->{result}{data} }) {
my $attachments = delete $diff->{attachments};
my $reviewers = $attachments->{reviewers}{reviewers};
- my $review = first { $_->{reviewerPHID} eq $phab_user->phid } @$reviewers;
+ my $review = first { $_->{reviewerPHID} eq $phid_user } @$reviewers;
$diff->{fields}{review_status} = $review->{status};
push @result, $diff;
}