@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Custom integer fields: fix search by array of possible values

Summary:
This minimal changes seems the natural expansion of this search function,
that "seems" designed to only search with a single value, but the backend
is designed to receive an array of possible values.

Look at the same method in PhabricatorStandardCustomFieldLink that already
works also for array inputs.

To get extra confidence look at the method withApplicationSearchContainsConstraint()
that works perfectly with arrays (to be honest it only works with arrays in mind...)

This feature allows to avoid crashes when extension developers tries to run "IN" queries
because for example they try to follow our performance guidelines:

https://we.phorge.it/book/contrib/article/n_plus_one/

Closes T15752

Test Plan:
Have a nice custom integer field, like this one for Maniphest:

{
"mycompany.estimated-hours": {
"name": "Estimated Hours",
"type": "int",
"caption": "Estimated number of hours this will take.",
"search": true
}
}

You can reproduce T15752 before the change. It just works after the change.

Or, just trust your instincts by looking at the same method in PhabricatorStandardCustomFieldLink.

Also, use the "normal" frontend search page. Still works as usual.

Reviewers: O1 Blessed Committers, 20after4

Reviewed By: O1 Blessed Committers, 20after4

Subscribers: tobiaswiese, Matthew, Cigaryno

Maniphest Tasks: T15752

Differential Revision: https://we.phorge.it/D25554

+17 -4
+17 -4
src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldInt.php
··· 48 48 return $request->getStr($this->getFieldKey()); 49 49 } 50 50 51 + /** 52 + * Apply an application search constraint to a query. 53 + * If you have a field of type integer, and a value (or an array of values), 54 + * the result set will be limited to the rows with these values. 55 + * @param PhabricatorApplicationSearchEngine $engine 56 + * @param PhabricatorCursorPagedPolicyAwareQuery $query 57 + * @param mixed $value Single value or array of values (IN query). 58 + */ 51 59 public function applyApplicationSearchConstraintToQuery( 52 60 PhabricatorApplicationSearchEngine $engine, 53 61 PhabricatorCursorPagedPolicyAwareQuery $query, 54 62 $value) { 55 63 56 - if (phutil_nonempty_scalar($value)) { 57 - $query->withApplicationSearchContainsConstraint( 58 - $this->newNumericIndex(null), 59 - $value); 64 + // The basic use case is with a single value. 65 + // The backend really works with an array. So also array allowed. 66 + if (is_array($value) || phutil_nonempty_scalar($value)) { 67 + $value = (array)$value; 68 + if ($value) { 69 + $query->withApplicationSearchContainsConstraint( 70 + $this->newNumericIndex(null), 71 + $value); 72 + } 60 73 } 61 74 } 62 75