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

dev/core#2823 Restructure determination of required actions. #21401

Merged
merged 3 commits into from
Sep 13, 2021

Conversation

eileenmcnaughton
Copy link
Contributor

Overview

dev/core#2823 Restructure determination of required actions.
This builds on top of the 2 cleanups in the other open PRs #21399 & #21440 to build an array of actions for the reconcile enable in the constructor & adds functions to retreive those. It is a part-way refactor

Before

The determination of actions to take & the doing of the actions is interwoven

After

The determination happens in the constructor. The doing happens in 'reconcile'

Technical Details

The code that calls the action-actions
is still pretty cludgey - but the intent is that
we would stop passing the dao object into those
action-action functions in the near future.

Comments

@civibot
Copy link

civibot bot commented Sep 8, 2021

(Standard links)

@civibot civibot bot added the master label Sep 8, 2021
}
public function reconcileEnabledModule(string $module): void {
foreach ($this->getManagedEntitiesToUpdate(['module' => $module]) as $todo) {
$dao = new CRM_Core_DAO_Managed();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This $dao building is fugly but I wanted to leave the signatures of the action functions unchanged for this commit & follow up in a later change. Given that I was happy with what looks like a bit of duplication for now

@eileenmcnaughton
Copy link
Contributor Author

CRM_Core_ManagedEntitiesTest.testModifyDeclaration_UpdateNever
CRM_Core_ManagedEntitiesTest.testRemoveDeclaration_CleanupNever
CRM_Core_ManagedEntitiesTest.testRemoveDeclaration_CleanupUnused
api_v4_AfformTest.testGetUpdateRevert with data set #0

@eileenmcnaughton eileenmcnaughton force-pushed the mgd2 branch 4 times, most recently from fff2cbc to 9d8ffde Compare September 9, 2021 06:57
@colemanw
Copy link
Member

colemanw commented Sep 10, 2021

@eileenmcnaughton it looks to me like the big functional change in this PR which may be affecting tests is that loading declarations is no longer done "on demand" but now it's done as part of the class constructor, which may mean it's running earlier than it was before, possibly before all extensions have been loaded into the container?

I was able to reproduce the test failures locally, running tests inside PhpStorm.

@eileenmcnaughton
Copy link
Contributor Author

@colemanw

Yeah the 2 commits before that one are passing just fine #21400

There isn't a gap between when the constructor is called and the reconcile from the calling functions point of view...

I feel like maybe I should fix the main tests on the ManagedEntities class to use hooks rather than pass in 'decls' so it's working the same way as 'real' code. Maybe if the first 2 are merged I should make that change before trying to change the constructor

image

@eileenmcnaughton
Copy link
Contributor Author

OK - I think I understand what is happening here - when the ManagedEntities class is constructed using the singleton it uses a copy of it cached in the static. Almost all the places that call this singleton force a flush - but the afform places that are resulting in test fails are a notable exception.

I've tried fixing it to use \Civi::statics but I think the right answer is likely not to cache it - given that any interaction with ManagedEntities is, by it's nature, expensive I feel like any effort to cache it in a singleton is adding edge case risk without that much benefit

@eileenmcnaughton
Copy link
Contributor Author

I should note - we don't have to load these things in the constructor - we could load them later - which is what is happening. But what are we actually caching at that point? Probably only a copy of CRM_Core_Module::getAll() which is itself cached.

To wit - why would you want to interact with ManagedEntities with anything other than a fresh copy of what is to be managed?

@eileenmcnaughton
Copy link
Contributor Author

Hmm - ok - a recursive in there to figure out

@colemanw
Copy link
Member

Retest this please

@eileenmcnaughton
Copy link
Contributor Author

@colemanw putting the declaration calculation in the constructor seems to be a battle!

I've switched tack for now and have ensuring they are calculated in the reconcile function and to offset that have made most of the other functions protected. The reason I didn't do that before is that one of them is called from outside core - but I put up a PR to address that - veda-consulting-company/uk.co.vedaconsulting.gdpr#294

Only these functions are now public - the 'get' one is used in tests & also pretty hard to grep for so not digging too much into it for now but I made it deprecated as it's silly

image

The expected actions are now calculated at the start of reconcile.
and retrievable by function.

The code that calls the action-actions
is still pretty cludgey - but the intent is that
we would stop passing the dao object into those
action-action functions in the near future.

This PR punts any decisions about how outputs might look
(eg. making the array retrievable from outside of the function.

Note that there is pretty comprehensive
test cover in CRM_Core_ManagedEntitiesTest
The only affected universe place I found was
veda-consulting-company/uk.co.vedaconsulting.gdpr#294

Since putting the 'information gathering & storing' function on
the constructor is tricky due to the singleton
caching this means we are always working with a consistent entry point
@eileenmcnaughton
Copy link
Contributor Author

@colemanw this is passing now AND there is a regression in master without it now....

@colemanw colemanw merged commit 24ae4af into civicrm:master Sep 13, 2021
@colemanw
Copy link
Member

Then let's merge it!

@colemanw colemanw deleted the mgd2 branch September 13, 2021 00:38
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.

2 participants