From 1167d28cf2df57fcb5e02f8e290b0582b44d9aa5 Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Thu, 16 Aug 2018 08:32:07 -0700 Subject: [PATCH] Fixed #3206 --- CHANGELOG-v3.md | 3 +++ src/controllers/UsersController.php | 9 +++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG-v3.md b/CHANGELOG-v3.md index 2c969d95956..57683c49f01 100644 --- a/CHANGELOG-v3.md +++ b/CHANGELOG-v3.md @@ -2,6 +2,9 @@ ## Unreleased +### Fixed +- Fixed a SQL error that occurred when saving a user if a `craft\elements\User::EVENT_BEFORE_SAVE` event listener was setting `$event->isValid = false`. ([#3206](https://github.com/craftcms/cms/issues/3206)) + ### Security - External links in the Control Panel now set `rel="noopener"`. ([#3201](https://github.com/craftcms/cms/issues/3201)) diff --git a/src/controllers/UsersController.php b/src/controllers/UsersController.php index f6aef8d86d3..bbc1f3fb76e 100644 --- a/src/controllers/UsersController.php +++ b/src/controllers/UsersController.php @@ -1034,7 +1034,11 @@ public function actionSaveUser() $user->setScenario(Element::SCENARIO_LIVE); } - if (!$user->validate(null, false)) { + // Manually validate the user so we can pass $clearErrors=false + if ( + !$user->validate(null, false) || + !Craft::$app->getElements()->saveElement($user, false) + ) { Craft::info('User not saved due to validation error.', __METHOD__); if ($thisIsPublicRegistration) { @@ -1059,9 +1063,6 @@ public function actionSaveUser() return null; } - // Save the user (but no need to re-validate) - Craft::$app->getElements()->saveElement($user, false); - // Save their preferences too $preferences = [ 'language' => $request->getBodyParam('preferredLanguage', $user->getPreference('language')),