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

[4.x][5.x]: Tidy up UserException thrown during pending user purge? #3686

Closed
samhibberd opened this issue Sep 20, 2024 · 11 comments
Closed

[4.x][5.x]: Tidy up UserException thrown during pending user purge? #3686

samhibberd opened this issue Sep 20, 2024 · 11 comments
Assignees
Labels
bug commerce4 Issues related to Commerce v4 Craft Commerce

Comments

@samhibberd
Copy link

What happened?

Could the UserException thrown during the pending user purge be reworked, we use sentry to monitor exceptions and this has added ~100k issues to our usage:

public function beforeDeleteUserHandler(ModelEvent $event): void
{
/** @var User $user */
$user = $event->sender;
// If there are any orders, make sure that this is not allowed.
if (Order::find()->customerId($user->id)->status(null)->exists()) {
// TODO revise this stop-gap measure when Craft CMS gets a way to hook into the user delete process.
throw new UserException(Craft::t('commerce', 'Unable to delete user {user}: the user has a Craft Commerce order.', [
'user' => $user->id,
]));
}
}

As the user is correctly not being deleted as the user (customer) has an order, could this not be handled - the activation code / state be removed, or event added to the user purge logic so commerce could hook into that and exclude users that have an order?

Also is there a reason you don't return theisValid = false and intead throw the excpetion?

You may set [[\yii\base\ModelEvent::$isValid]] to false to prevent the element from getting deleted.

Impacts both 4.x and 5.x

Craft CMS version

4.10.8

Craft Commerce version

4.6.7

PHP version

No response

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

@samhibberd samhibberd added bug commerce4 Issues related to Commerce v4 Craft Commerce labels Sep 20, 2024
Copy link

linear bot commented Sep 20, 2024

PT-2161 [4.x][5.x]:

@samhibberd samhibberd changed the title [4.x][5.x]: [4.x][5.x]: Tidy up UserException thrown during pending user purge? Sep 20, 2024
@lukeholder lukeholder self-assigned this Sep 23, 2024
@samhibberd
Copy link
Author

Thanks @nfourtythree @lukeholder

@nfourtythree
Copy link
Contributor

Hi @samhibberd

Commerce versions 4.6.13 and 5.1.3 have now been released with this fix included.

Thanks!

@samhibberd
Copy link
Author

samhibberd commented Oct 2, 2024

Actually @lukeholder @nfourtythree thinking about it, this doesn't change much for us (as in we still push craft errors to Sentry).

Would it be fair to argue in this case that this is not actually an error, or a warning, it's doing exactly what it should, prevent the deleting of an user that has an order. Should the logging level not be set to info?

@peteeveleigh
Copy link
Contributor

Agree with @samhibberd. This shouldn't be logged as an Error. It's Info or, at worst, a Warning.

@lukeholder
Copy link
Member

@lukeholder
Copy link
Member

Sorry just realised you were referring to our logging in Commerce.

I have gone ahead and fixed that for the next release in 5.3.x

To get the fix early, change your craftcms/commerce requirement in composer.json to:

"require": {
  "craftcms/commerce": "5.x-dev#5a31da5714f7442f5fd864274ebaccbf51a95db3 as 5.3.0.2",
  "...": "..."
}

Then run composer update.

We will update this ticket once the release is out.

@nfourtythree
Copy link
Contributor

Commerce version 5.3.1 has now been released with this fix included.

Thanks!

@samhibberd
Copy link
Author

Will this make it into the 4.x branch @nfourtythree ?

@nfourtythree
Copy link
Contributor

HI @samhibberd

Yes this is in the 4.x branch with this commit: fee301f

It will be included in the next release of Commerce 4.

To get this early, change your craftcms/commerce requirement in your project's composer.json to:

"require": {
  "craftcms/commerce": "4.x-dev as 4.8.0.1",
  "...": "..."
}

Then run composer update.

Thanks!

@nfourtythree
Copy link
Contributor

Hi

This update has now been back ported to Commerce 4 in version 4.8.1 which has just been released.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug commerce4 Issues related to Commerce v4 Craft Commerce
Projects
None yet
Development

No branches or pull requests

4 participants