Upgrading from commerce_paypal 8.x-1.0-beta4 to 8.x-1.0-beta8 we are seeing the following in the status report:

```
Mismatched entity and/or field definitions
The following changes were detected in the entity type and field definitions.
Payment method
The Card type field needs to be installed.
The Card number field needs to be installed.
The Card expiration month field needs to be installed.
The Card expiration year field needs to be installed.
```

It would appear that `drush entity-updates` has been removed by drupal. Other than installing devel do we have any other options?

I tried uninstalling commerce_paypal which resulted in the error:
```
Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'drupal.commerce_payment_method__card_type' doesn't exist: UPDATE {commerce_payment_method__card_type} SET deleted=:db_update_placeholder_0 WHERE bundle = :db_condition_placeholder_0; Array ( [:db_update_placeholder_0] => 1 [:db_condition_placeholder_0] => paypal_checkout ) in Drupal\Core\Entity\Sql\SqlContentEntityStorage->onFieldDefinitionDelete() (line 1636 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).
```

CommentFileSizeAuthor
#13 3157704-13.patch807 bytesjsacksick

Comments

sittard created an issue. See original summary.

jsacksick’s picture

Have you tried running the updates?

sittard’s picture

Sorry yes should have mentioned, we ran the DB updates. No errors to report.

jsacksick’s picture

I'm not sure why your update failed... But basically this is what you need:

$entity_type = \Drupal::entityTypeManager()->getDefinition('commerce_payment_method');
  \Drupal::service('entity.bundle_plugin_installer')->installBundles($entity_type, ['commerce_paypal']);

You could try running that again using drush php-eval.

sittard’s picture

Thanks should I run that before or after the drupal db updates?

jsacksick’s picture

You said you ran the drupal updates already?

sittard’s picture

Yes I did but only in my testing environment so I can roll back the database if needed.

jsacksick’s picture

That is the code that is supposed to install the payment method type (which is already present in the update hook).

sittard’s picture

I think I might have spotted a typo in:
https://git.drupalcode.org/project/commerce_paypal/-/blob/8.x-1.0-beta8/...

function commerce_paypal_post_update_3() {
  $entity_type = \Drupal::entityTypeManager()->getDefinition('commerce_payment_method');
  \Drupal::service('entity.bundle_plugin_installer')->uninstallBundles($entity_type, ['commerce_paypal']);
}

Around line 112 currently reads `uninstallBundles` I think this should be `installBundles` as per your example above. Would also explain why the update failed for me.

jsacksick’s picture

It's not a typo, it might be affecting you because you're upgrading from beta4 to beta8, and a lot has changed since.

We used to use the payment method type that was then uninstalled, we're using it again now. I should probably have created a post update function instead of an update hook to install the bundle so it runs last.

sittard’s picture

Thank you, I've now managed to install the payment method type but have hit a further error. The steps that I've followed are:

Drupal 8.8.8 / Drupal Commerce 8.x-2.20

1) Update drupal/commerce_paypal (1.0.0-beta4 => 1.0.0-beta8)
2) drush cr
3) run db update via gui (update.php) this updates as follows:

commerce_paypal module
- 8102 - Install the PayPal Checkout payment method type.
- Delete the PayPal Checkout payment methods.
- Uninstall the PayPal Checkout payment method type.
- Uninstall the flow field.
- Set the "payment_method_types" to "paypal_checkout".

> completes without error but reports mismatched entity (payment method) in status report
> database no longer has the commerce_payment_method__card tables

4) drush php-eval '$entity_type = \Drupal::entityTypeManager()->getDefinition("commerce_payment_method"); \Drupal::service("entity.bundle_plugin_installer")->installBundles($entity_type, ["commerce_paypal"]);'

> creates payment method type and resolves missing entity issue
> database now has commerce_payment_method__card tables (but they contain null data)

All looks good but now when I navigate to admin/commerce/orders we get the following error:

The website encountered an unexpected error. Please try again later.
TypeError: Argument 1 passed to Drupal\commerce_payment\CreditCard::getType() must be of the type string, null given, called in /web/modules/contrib/commerce/modules/payment/src/Plugin/Commerce/PaymentMethodType/CreditCard.php on line 23 in Drupal\commerce_payment\CreditCard::getType() (line 28 of modules/contrib/commerce/modules/payment/src/CreditCard.php).
Drupal\commerce_payment\CreditCard::getType(NULL) (Line: 23)
Drupal\commerce_payment\Plugin\Commerce\PaymentMethodType\CreditCard->buildLabel(Object) (Line: 76)
Drupal\commerce_payment\Entity\PaymentMethod->label() (Line: 63)

It would appear that I can view historical PayPal orders via admin/commerce/orders/123 but if the payment method for the order is Credit or Debit Card (Braintree) then we get the above error message. Which I'm guessing is a result of the commerce_payment_method__card tables being purged.

Thanks.

jsacksick’s picture

Priority: Normal » Major

Thanks for this detailed report... One of the mistakes that was probably made was to reuse the same payment method type we previously had and was uninstalled.

The payment method type initially uninstalled defined different fields that are no longer needed.

Because the payment method type now extends CreditCard, running the post update functions actually uninstalls fields defined by the CreditCard plugin (not the previous fields that we intended to remove in the first place)....

I'm wondering if we should simply empty the post update function that contains payment method type uninstallation. That should fix it, and prevent issues with people upgrading from earlier versions.

jsacksick’s picture

Component: PayPal EC » PayPal Checkout
Status: Active » Needs review
StatusFileSize
new807 bytes

Could you try rerunning everything after applying the attached patch?

jsacksick’s picture

I'm pretty sure the patch would fix the issue, and I'm tempted to tag a new beta right after committing it so that people upgrading from "old" beta versions don't experience the same error.

sittard’s picture

Thanks - I should be able to test the patch later today if that helps.

  • jsacksick committed 46295da on 8.x-1.x
    Issue #3157704 by sittard, jsacksick: Fix issues occurring when...
jsacksick’s picture

Ok, I actually went ahead and tagged a new release that includes this fix since I consider this a "major" issue that can result in data loss.

sittard’s picture

Just confirming the update from 1.0.0-beta4 => 1.0.0-beta9 works without error or issue.

Many Thanks

jsacksick’s picture

Status: Needs review » Fixed

Awesome! Thanks for confirming.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.