]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1453681 - Phabricator project.search when searching for a specific project name...
authordklawren <dklawren@users.noreply.github.com>
Thu, 12 Apr 2018 17:21:21 +0000 (13:21 -0400)
committerDylan William Hardison <dylan@hardison.net>
Thu, 12 Apr 2018 17:21:21 +0000 (13:21 -0400)
extensions/PhabBugz/lib/Project.pm
extensions/PhabBugz/lib/Util.pm

index b0babc58b8ff1758b00b05ba5cc3d5d4dc0b212b..0fb9ecaa5213236badfa5527c627849c5d9308b1 100644 (file)
@@ -47,7 +47,18 @@ sub new_from_query {
 
     my $result = request( 'project.search', $data );
     if ( exists $result->{result}{data} && @{ $result->{result}{data} } ) {
-        return $class->new( $result->{result}{data}[0] );
+        # If name is used as a query param, we need to loop through and look
+        # for exact match as Conduit will tokenize the name instead of doing
+        # exact string match :( If name is not used, then return first one.
+        if ( exists $params->{name} ) {
+            foreach my $item ( @{ $result->{result}{data} } ) {
+                next if $item->{fields}{name} ne $params->{name};
+                return $class->new($item);
+            }
+        }
+        else {
+            return $class->new( $result->{result}{data}[0] );
+        }
     }
 }
 
index 52ea9c0d5821b87d0a454c90a47ef1d809e8bc5a..cd396602e0bd7aa55facc5758b84b0577e7a2ade 100644 (file)
@@ -297,7 +297,14 @@ sub get_project_phid {
         return undef
             unless (exists $result->{result}{data} && @{ $result->{result}{data} });
 
-        $project_phid = $result->{result}{data}[0]{phid};
+        # If name is used as a query param, we need to loop through and look
+        # for exact match as Conduit will tokenize the name instead of doing
+        # exact string match :(
+        foreach my $item ( @{ $result->{result}{data} } ) {
+            next if $item->{fields}{name} ne $project;
+            $project_phid = $item->{phid};
+        }
+
         $memcache->set_config({ key => "phab_project_phid_" . $project, data => $project_phid });
     }
     return $project_phid;