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-20625 Don't crash if we can't find the payment processor class. #11631

Conversation

mattwire
Copy link
Contributor

@mattwire mattwire commented Feb 5, 2018

Overview

If the payment processor doesn't exist CiviCRM crashes horribly and you can't do anything (via the UI). This can happen for a couple of reasons:

  1. Extension path is changed (so enabled payment processor is now missing).
  2. Payment processor extension is disabled.

Before

CiviCRM crashes and you can't restore the extension (except via CLI wizardry).

After

CiviCRM does not crash.
Any payment processor with missing class is not loaded (the same as if it had an invalid config).
If you edit payment processors you get a warning message if the payment processor no longer exists and you can change it to another type if desired.

Technical Details

CiviCRM was not checking for payment processor classes before trying to use them.
Also identified a bug where the first time you save after changing a payment processor, the values of the previous payment processor are still saved - we need to reload the payment processor object before saving if the type has changed.


throw new \CRM_Core_Exception('no class provided');
}
require_once str_replace('_', DIRECTORY_SEPARATOR, $paymentClass) . '.php';
if (class_exists($paymentClass)) {
require_once str_replace('_', DIRECTORY_SEPARATOR, $paymentClass) . '.php';
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we still need this?

Copy link
Contributor

Choose a reason for hiding this comment

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

actually by definition we don't - ie. class_exists will fail if not already included

/**
* @var int $_ppType Payment processor Type ID
*/
protected $_ppType;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we keep away from vars that are not readable - ie. ppType would be more readable as paymentProcessorType or processorType

@@ -332,9 +342,13 @@ public function setDefaultValues() {

CRM_Core_DAO::storeValues($dao, $defaults);
// When user changes payment processor type, it is passed in via $this->_ppType so update defaults array.
if ($this->_ppType) {
if ($this->_ppType && array_key_exists($this->_ppType, $this->_ppTypes)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

putting ppTypes in a static var is not actually gaining any efficiency over calling CRM_Core_PseudoConstant::paymentProcessorType() since it is already cached

@eileenmcnaughton
Copy link
Contributor

@mattwire this makes a lot of sense - I made a few trivial comments but the thing I'm thinking is whether
CRM_Core_PseudoConstant::paymentProcessorType() should do a class_exists filter. It's cached so it should only happen once

@mattwire
Copy link
Contributor Author

mattwire commented Feb 7, 2018

@eileenmcnaughton Thanks for the review. I agree with your proposed changes and have made them in a separate commit as they would obscure the original fixes and be difficult to review.

@eileenmcnaughton
Copy link
Contributor

@mattwire that looks fine but can we squash them before merging. The commit history outlives the review substantially so I'd rather not introduce a parameter & then rename it in a separate commit.

FWIW my feeling is that commits should be logical & discrete & not show the 'workings' of getting to the final patch for the sake of people who come later. But I think multiple commits in a PR are fine as long as they are logical & discrete & not reworkings

… when editing a payment processor that doesn't exist.
@mattwire mattwire force-pushed the CRM-20625_payproc_extension_dont_kill_civi branch from 2e03c7b to 8461467 Compare February 7, 2018 21:24
@mattwire
Copy link
Contributor Author

mattwire commented Feb 7, 2018

@eileenmcnaughton Squashed :-)

@eileenmcnaughton
Copy link
Contributor

Great let's get this into the rc since someone is hurting for it on chat I believe - merge on pass

@eileenmcnaughton eileenmcnaughton merged commit f4743a1 into civicrm:master Feb 7, 2018
@mlutfy mlutfy added this to the 4.7.31 milestone Feb 9, 2018
@mattwire mattwire deleted the CRM-20625_payproc_extension_dont_kill_civi branch September 25, 2018 11:06
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.

4 participants