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

$event->isValid = false not preventing saveUserPreferences call #3206

Closed
alexmglover opened this issue Aug 15, 2018 · 1 comment
Closed

$event->isValid = false not preventing saveUserPreferences call #3206

alexmglover opened this issue Aug 15, 2018 · 1 comment

Comments

@alexmglover
Copy link

Description

I have an event handler which hooks into User::EVENT_BEFORE_SAVE and is setting $event->isValid to false. I am getting an integrity constraint violation in MySQL because the user doesn't exist when attempting to create the user preferences entry.

This may be intentional behavior but I need to be able to stop the full creation of the user with that event handler. It does seem a bit like if Craft::$app->getElements()->saveElement($user, false) returns false, then an exception should be thrown and the transaction rolled back.

I'm attempting to halt execution and return custom JSON in the event handler, but this does not seem possible. Let me know if I am overlooking something.

Steps to reproduce

  1. Create an event handler with User::EVENT_BEFORE_SAVE hook.
  2. Attempt to stop execution with $event->isValid = false;

Additional info

  • Craft version: 3.0.19
  • PHP version: 7.1.19
  • Database driver & version: MySQL 5.7
  • Plugins & versions:
@brandonkelly
Copy link
Member

Thanks! Fixed for the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants