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

Open
samhibberd opened this issue Sep 20, 2024 · 1 comment
Open
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
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

1 participant