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-18515 - Allow Payment Processor with same name when using multi-d… #8344

Merged
merged 2 commits into from
Oct 10, 2016

Conversation

darrick
Copy link
Contributor

@darrick darrick commented May 10, 2016

@civicrm-builder
Copy link

Can one of the admins verify this patch?

@eileenmcnaughton
Copy link
Contributor

ok to test

@eileenmcnaughton
Copy link
Contributor

@PalanteJon what is the status here? I recall seeing you saying this had been recently fixed - is this the fix you mentioned, or a duplicate, or?

@MegaphoneJon
Copy link
Contributor

This was the fix I was thinking of - I hadn't realized it hadn't merged yet! My apologies if that was misleading.

@eileenmcnaughton
Copy link
Contributor

Have you qa'd it @PalanteJon ? It's not in a group this month but you could still do it

@MegaphoneJon
Copy link
Contributor

I haven't - but I'm quite behind on my work. I opted not to do QA this
month, but I ended up doing some anyhow! I can do this next month if
it's still here.

@JoeMurray
Copy link
Contributor

Heh @darrick as Release Manager this month, I'm trying to recruit people to help pare down the backlog of almost 100 PRs, some going back to last summer. I'm wondering if you would be able to help QA another PR if I got someone to QA this PR?

@darrick
Copy link
Contributor Author

darrick commented Jun 13, 2016

@JoeMurray Not sure what all is involved in that, but I'll give it my best shot.

@eileenmcnaughton
Copy link
Contributor

test this please

*/
public static function paymentProcessorNameExists($value, $options) {
$fieldName = 'name';
$daoName = CRM_Utils_Array::value(0, $options);
Copy link
Contributor

@eileenmcnaughton eileenmcnaughton Jun 23, 2016

Choose a reason for hiding this comment

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

I think the patch makes sense but stylistically

  1. it seems odd to pass in $daoName when there is no reason for it to be anything other than 'CRM_Financial_DAO_PaymentProcessor'
  2. there is no reason to instantiate $config - that happens in lots of places randomly but for no reason that is still valid.

I think you could simplify the whole thing to

return civicrm_api3('PaymentProcessor', 'getcount' array(
  'id' => array('<>' => $id), 
  'domain_id' => CRM_Core_Config::domainID(), 
  'name' => $value,
));

(or is that the opposite ie.)

$count =  civicrm_api3('PaymentProcessor', 'getcount' array(
  'id' => array('<>' => $id), 
  'domain_id' => CRM_Core_Config::domainID(), 
  'name' => $value,
));

return !$count;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay. I just copied and pasted the objectExists rule and added the domain_id to it.

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah there is lots of bad code in the code base :-)

Copy link
Member

@omarabuhussein omarabuhussein Jun 25, 2016

Choose a reason for hiding this comment

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

While I agree to what you said above , I am just no convinced that using the API way is better ( even if it look simpler ) .... The API is meant to be used for extensions and other systems that want to interact with civicrm and not to be used inside the core system files .. also I think its kinda slower than using DAO object directly... and also when API v3 in this case get deperacted ( and later on removed ) then you have to update the core everywhere the API get used.

I know the API is already used in a lot of places in the core files ... but I believe it just wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree with that. Also regarding passing in $daoName. I believe my idea was to keep open the possibility of a generic NameExistsForDomainID rule which could possibly be used by other classes.

Another idea is to modify the current objectExists rule to optionally filter by domain id if it's passed in as an option.

Copy link
Member

Choose a reason for hiding this comment

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

How does that compare to just having a name-exists function? I mean it should be appropriately domain sensitive but the calling code maybe doesn't need to know that

Yes I agree . so to sum up what changes are needed for now :
1- change the method name to nameExists.
2- move the method to CRM_Utils_Rule.
3- use the API instead of DAO inside the method.
4- using the API will require you to pass the entity name instead of DAO name .

@eileenmcnaughton does all of that make sense ? ^

Copy link
Member

Choose a reason for hiding this comment

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

also i believe unit tests should written for this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I kept this rule local, although with the idea it could maybe be used by something, just to fix the issue at hand. The nameExists rule already exists and is used quite a bit. I'm not sure if limiting it by domain by default would effect other uses of it. As domain id is not included in every entity. Personally I like the idea of passing in the domain id for now and modifying the current nameExists rule to handle that.

As for use of the API by core. I think someone needs to decide the rules about that. I'd imagine you may want to look ahead at a sort headless civicrm. I.e. only have UI code use the api not Core. Granted this is UI code so maybe it works. But absent guidelines rather then try to start that here I think it's best to stick with how all the other rules are written and follow that format. Then when you come to a decision someone can do a PR which modifies all the rules to use the API.

Copy link
Contributor

Choose a reason for hiding this comment

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

Altering nameExists makes sense.

Copy link
Member

Choose a reason for hiding this comment

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

@darrick
An interesting discussing happened between my colleague ( davi ) and (Tim otten) on dev channel regarding using API in core ... it may worth to check it out :

https://chat.civicrm.org/civicrm/pl/8tisabi96pysid8j7ugo6xnrxa

@eileenmcnaughton
Copy link
Contributor

Re deprecation - I think there is at least as much chance of the DAO being deprecated before apiv3 as the reverse so it's probably not a good consideration

@colemanw
Copy link
Member

@PalanteJon I did a quick review of the code and it looks fine. Can you give it a quick test and we'll get it merged?

@jaapjansma
Copy link
Contributor

I have just reviewed this PR and it looks good. I have tested it locally and it seems to work.
@michaelmcandrew could you merge this PR?

@michaelmcandrew michaelmcandrew merged commit 463f73b into civicrm:master Oct 10, 2016
@michaelmcandrew
Copy link
Contributor

@jaapjansma - done!

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.

10 participants