uc_payment_install() adds 'payment_received' order status on install and quite rightly does not remove it when uninstalled. If uc_payment is installed again it causes a database insert error as the order status already exists.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tinker’s picture

Status: Active » Needs review
FileSize
1.25 KB

Attached patch adds check to uc_payment_install() to see if 'payment_received' status already exists.

TR’s picture

Can you use db_merge() instead? See uc_paypal.install in hook_install() for how we did this with the paypal_pending order status.

tinker’s picture

Revised patch using db_merge().

  • longwave committed 438fb30 on 7.x-3.x authored by tinker
    Issue #2533192 by tinker: Duplicate key payment_received when...
longwave’s picture

Status: Needs review » Fixed

Committed, thanks for the patch!

TR’s picture

Version: 7.x-3.x-dev » 8.x-4.x-dev
Status: Fixed » Patch (to be ported)

Let's make sure we take care of this in 8.x-4.x too - we actually have more problems like this because of the config system. Configs for other modules, like uc_order.status.payment_received.yml in this case, aren't removed upon uninstall and you can't reinstall without taking care of that.

longwave’s picture

True, though I'm not sure what the correct method to handle this is in Drupal 8. For reference when you install uc_payment, uninstall it, and reinstall it again, a PreExistingConfigException is thrown with message 'Configuration objects (uc_order.status.payment_received) provided by uc_payment already exist in active configuration'.

TR’s picture

For reference, this is a problem with configs for:

  • images styles in uc_cart, uc_catalog, and uc_product
  • date format in uc_store
  • order status in uc_cart and uc_payment

And of course with fields ...

longwave’s picture

I reproduced this in core alone with Forum module via its dependency on Comment, so I reported it as a bug over there to see what the right solution is: #2534532: Cannot reinstall Forum after it was previously installed

longwave’s picture

Status: Patch (to be ported) » Needs review
FileSize
6.4 KB

A start on this following what I learned from #2534532: Cannot reinstall Forum after it was previously installed

TR’s picture

For some of the configs that seems to be the right way to go. For others, not so much.

Take for example the order status 'abandoned', which is defined by uc_cart. I would argue that the way we handle it now is pretty good. When uc_cart is uninstalled, a message is shown that says the 'abandoned' status has not been deleted and gives a link to delete it. uc_cart_uninstall() unlocks the status so it can be deleted, but it does not delete it because there may be data in the database that depends on this. (Now of course if uc_order gets uninstalled, it DOES make sense to remove any module-provided statuses at that time). Deleting in this case should be a conscious choice of the administrator, not something that is done automatically. Perhaps we can follow in the footsteps of the image module where, when you delete an image style, if someone is using it you are given the choice to replace current uses with a different style. That would be nice for other order statuses too.

The big problem we have that could be fixed with enforced dependencies is re-installing content types like Product Kits - that is directly analogous to the Forum situation. In that case, it makes perfect sense to remove the node type configuration from the database.