I'm trying to create a plugin to create/update users' profile data. I figured out how to create a user but updating... not so much.
Here is the code I'm using:
$user = craft()->userSession->getUser();
$user->setContent(array('middleName' => "Dave"));
craft()->users->saveUser($user);
From what I understand the "saveUser" method is used for both creating and updating user data. Whenever I run the code I get the following error:
CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1-en_us' for key 'craft_content_elementId_locale_unq_idx'
If "saveUser" is truly used for creating and updating what am I doing wrong?