Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-21792 Extension.get API - Fix regression (4.7.13) in result filtering #11709

Merged
merged 3 commits into from
Feb 22, 2018

Conversation

totten
Copy link
Member

@totten totten commented Feb 22, 2018

Overview

When one calls the Extension.get API, it should support filtering. For
example, these commands would return only installed extensions or only
uninstalled extensions (respectively):

cv api Extension.get status=installed
cv api Extension.get status=uninstalled

Before

The implementation of Extension.get passes a list of all extensions down to
_civicrm_api3_basic_array_get() which is supposed to interpret any APIv3
options (such as filter-values/offsets/limits). However, it confuses the
return list (i.e. the names of any columns that the user wants to see) with the
filterable list (i.e. the names of any columns for which filtering is
permitted
).

After

The implementation of Extension.get passes a list of all extensions down to
_civicrm_api3_basic_array_get(). It also passes a fixed list of columns
which one might reasonably want to filter.

It might be nice to support filtering on all fields, but (a) several fields
wouldn't be sensible (because they're nested arrays) and (b) this provides a
smaller surface-area to maintain.

Comments

The doc-block for _civicrm_api3_basic_array_get() describes the purpose of this field:

https://github.com/civicrm/civicrm-core/blob/4.7.0/api/v3/utils.php#L2390-L2391

Since ~v4.7.13, this line of code appears to have gone through several revisions, e.g.

CC @lucianov88 @twomice @tschuettler @seamuslee001 for review


Overview
--------

When one calls the `Extension.get` API, it should support filtering.  For
example, these commands would return only installed extensions or only
uninstalled extensions (respectively):

```
cv api Extension.get status=installed
cv api Extension.get status=uninstalled
```

Before
------

The implementation of `Extension.get` passes a list of all extensions down to
`_civicrm_api3_basic_array_get()` which is supposed to interpret any APIv3
options (such as filter-values/offsets/limits).  However, it confuses the
`return` list (i.e.  the names of any columns *that the user wants to see*) with the
*filterable* list (i.e.  the names of any columns *for which filtering is
permitted*).

After
-----

The implementation of `Extension.get` passes a list of all extensions down to
`_civicrm_api3_basic_array_get()`.  It also passes a fixed list of columns
which one might reasonably want to filter.

It might be nice to support filtering on all fields, but (a) several fields
wouldn't be sensible (because they're nested arrays) and (b) this provides a
smaller surface-area to maintain.

Comments
--------

The doc-block for `_civicrm_api3_basic_array_get()` describes the purpose of this field:

https://github.com/civicrm/civicrm-core/blob/4.7.0/api/v3/utils.php#L2390-L2391

Since ~v4.7.13, this line of code appears to have gone through several revisions, e.g.

 * The regression was originally introduced by 517dfba
 * Subsequent partial-fixes were d4c44c7, 9776f41, 34239e8, 525ccb6

CC @lucianov88  @twomice @tschuettler @seamuslee001 for review
Filtering extensions by key is a good idea -- so good we have three ways to do it! ;)

All of these fields accept a `string|array<string>` input, which is different from
the typical filtering supported by `_civicrm_api3_basic_array_get()` (which only
matches on values)...  If you happen to choose a basic filter that passes both
filters (i.e.  a simple string-match), then it works.  But if you choose a filter
where they behave differnetly (i.e.  an array), then you get weird results.
The test has a magic number which seems to be based on the number of
extensions in the `drupal-clean` build profile -- which is basically the
smallest number anyone might have.  However, it gives false-negatives if you
have any other extensions around.  Make it a little less flaky.
@totten
Copy link
Member Author

totten commented Feb 22, 2018

Updated to (a) include unit-test for filtering by status and (b) fix double-filtering for key/keys/full_name and (c) make api_v3_ExtensionTest a little less flaky.

@seamuslee001 seamuslee001 changed the title Extension.get API - Fix regression (4.7.13) in result filtering CRM-21792 Extension.get API - Fix regression (4.7.13) in result filtering Feb 22, 2018
@seamuslee001
Copy link
Contributor

(CiviCRM Review Template WORD-1.0)

  • (r-jira) Pass
  • (r-test) Pass - Tests look good and
  • (r-code) Pass - Code is very readable and makes sens
  • (r-doc) Pass no extra documentation needed
  • (r-maint) Pass has a unit test to verify the fix
  • (r-run)Pass before i applied this i was able to verify i could only filter on the extension key not status as well after applying i could filter on key status and id also was able to verify that the filtering of return was still able to be done
  • (r-user) Pass
  • (r-tech) Pass - has a unit test to lock in behavior

@seamuslee001 seamuslee001 merged commit 6e2ceb8 into civicrm:master Feb 22, 2018
@totten totten deleted the master-extget branch February 22, 2018 22:12
@mlutfy mlutfy added this to the 4.7.32 milestone Mar 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants