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

Add pre() and post() hooks for ufgroup entity #18995

Merged

Conversation

lucky091588
Copy link
Contributor

@lucky091588 lucky091588 commented Nov 19, 2020

Overview

This is to add ufgroup support for pre() and post() hooks

Gitlab Issue: https://lab.civicrm.org/dev/core/-/issues/2199

Before

ufgroup was not supported with pre() and post() hooks.

After

ufgroup will be supported with pre() and post() hooks.

@civicrm-builder
Copy link

Can one of the admins verify this patch?

@civibot
Copy link

civibot bot commented Nov 19, 2020

(Standard links)

@civibot civibot bot added the master label Nov 19, 2020
@colemanw
Copy link
Member

add to whitelist

@seamuslee001
Copy link
Contributor

@lucky091588 can you please fix this style issue


UFGroup.php:1456, EndLine, Priority: High
--
Whitespace found at end of line

@demeritcowboy
Copy link
Contributor

@lucky091588 it's failing because it needs rebasing: See https://docs.civicrm.org/dev/en/latest/tools/git/#rebasing

It's a pain but just adding more commits won't fix it. You could also start fresh which might be easier than fighting with git since git usually wins.

If you get stuck try posting at https://chat.civicrm.org (maybe in the dev channel).

@lucky091588
Copy link
Contributor Author

I thank everyone for the helpful comments. This is still WIP, and @twomice is helping me get it ready for review.

eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this pull request Nov 27, 2020
Looking at civicrm#18995 I was struck by the delete hook being non-standard. In general we don't load from the DB just to pass
to the hook as the hook can do that itself. However, when I looked at other hooks
I found that they were passing out nullArray - this is a legacy method that precedes
being on a php version that supported default params when passing by reference.

It's further known to introduce intermittent hard to debug issues. This adds the new hook
and also adds standardisation to the other hooks for pre+delete.

I've left the create one for now but GroupContact is a good example of something
close to what we want to standardise on there
$group = new CRM_Core_DAO_UFGroup();
$group->id = $id;
$group->fetch();
$params = $group->toArray();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't normally load from the db just to pass out to hooks -the db load can be done in the hook if it wants it.

I took a look at the other delete hooks & realised they are a bit of a dogs breakfast so I put up this PR to make the laster parameter optional & clean them up a bit

#19059

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lucky091588 Eileen's commit #19059 means we'll need to rebase this PR and probably resolve some git merge conflicts. Let's talk about that offline.

* Class CRM_Core_BAO_UFGroupTest
* @group headless
*/
class CRM_Core_BAO_UFGroupTest extends CiviUnitTestCase {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loving these tests!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@@ -1451,10 +1458,19 @@ public static function add(&$params, $ids = []) {
if (!empty($params['group_type']) && is_array($params['group_type'])) {
$params['group_type'] = implode(',', $params['group_type']);
}

$ufGroupID = CRM_Utils_Array::value('ufgroup', $ids, CRM_Utils_Array::value('id', $params));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If possible can you squash this down - like we do on GroupContact

 $hook = empty($params['id']) ? 'create' : 'edit';
    CRM_Utils_Hook::pre($hook, 'GroupContact', ($params['id'] ?? NULL) , $params);

Note it's OK not to check the $ids because that param can be deprecated - I'll put up a PR for that

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lucky091588 lucky091588 force-pushed the 2199_ufgroup_pre_post_hook branch 3 times, most recently from bb0f436 to aa72bcb Compare December 7, 2020 21:00
@lucky091588 lucky091588 changed the title WIP: Add pre() and post() hooks for ufgroup entity Add pre() and post() hooks for ufgroup entity Dec 8, 2020
@lucky091588
Copy link
Contributor Author

This PR is ready for review.

$ufGroup = new CRM_Core_DAO_UFGroup();
$ufGroup->copyValues($params);

$ufGroupID = CRM_Utils_Array::value('ufgroup', $ids, CRM_Utils_Array::value('id', $params));
if (!$ufGroupID && empty($params['name'])) {
if (empty($params['name'])) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can drop ufGroupID from this check. I think you removed it in order to use the preferred shorter syntax for the hook - but it looks like the variable is still needed

@eileenmcnaughton
Copy link
Contributor

It's looking very close now

@twomice
Copy link
Contributor

twomice commented Dec 9, 2020

I think this is ready for review and I myself would recommend committing, but Joinery is sponsoring this work so conflict of interest exists. @eileenmcnaughton could you comment/review?

@seamuslee001
Copy link
Contributor

This looks good to me and the code looks nice n clean and can confirm the hook tests are being executed by Jenkins merging

@seamuslee001 seamuslee001 merged commit cbad732 into civicrm:master Dec 9, 2020
@seamuslee001
Copy link
Contributor

@lucky091588 congrats on your first PR being merged can you please create a PR to add in information into here https://github.com/civicrm/civicrm-core/blob/master/contributor-key.yml for yourself please.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants