From 826e1d4647060b30ed6af1be5dff3233ced17840 Mon Sep 17 00:00:00 2001 From: Philipp Kamps Date: Sun, 5 Jan 2020 09:18:04 +0000 Subject: [PATCH] Forcing a unique login per user row, making sure code can handle it --- kernel/classes/datatypes/ezuser/ezusertype.php | 6 +++++- update/database/mysql/lovestack/4.sql | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 update/database/mysql/lovestack/4.sql diff --git a/kernel/classes/datatypes/ezuser/ezusertype.php b/kernel/classes/datatypes/ezuser/ezusertype.php index 485c32d404a..9fa13d31da6 100644 --- a/kernel/classes/datatypes/ezuser/ezusertype.php +++ b/kernel/classes/datatypes/ezuser/ezusertype.php @@ -251,7 +251,10 @@ function storeObjectAttribute( $contentObjectAttribute ) else { // No "draft" for version 1 to avoid regression for existing code creating new users. - if ( $contentObjectAttribute->attribute( 'version' ) == '1' ) + if ( + $contentObjectAttribute->attribute( 'version' ) == '1' && + ! $contentObjectAttribute->hasValidationError() + ) { $user->store(); $contentObjectAttribute->setContent( $user ); @@ -386,6 +389,7 @@ function objectAttributeContent( $contentObjectAttribute ) if ( !empty( $serializedDraft ) ) { + if( !$user ) $user = new eZUser(); $user = $this->updateUserDraft( $user, $serializedDraft ); } diff --git a/update/database/mysql/lovestack/4.sql b/update/database/mysql/lovestack/4.sql new file mode 100644 index 00000000000..e886c0276b1 --- /dev/null +++ b/update/database/mysql/lovestack/4.sql @@ -0,0 +1,7 @@ +# You may already have non-unique values in your ezuser database table. +# Use following SQL statement to test and identify those instances: +# SELECT login, COUNT(*) AS instances FROM ezuser GROUP BY login HAVING instances > 1; +# You would need to manually resolve those duplicate rows - for example by editing the login values +# Otherwise the following SQL statements will fail. +DROP INDEX ezuser_login on ezuser; +CREATE UNIQUE INDEX ezuser_login ON ezuser (login);