1

I got an error while updating user profile data such as name,password and email. I am using entity_metadata_wrapper() for processing update.

exception 'EntityMetadataWrapperException' with message 'Unknown data property original.' in C:\xampp\htdocs\phone_bay\sites\all\modules\entity\includes\entity.wrapper.inc:335\nStack trace:\n#0

This is my code.

require './includes/password.inc';
function commerce_services_user_update($uid, $data, $flatten_fields) {
    $user = user_load($uid);
    $wrapper = entity_metadata_wrapper('user', $user);
    dpm($wrapper->value());

    $name = $data['name'];
    $password = $data['password'];
    $email = $data['email'];

    if ($name != null) {
        $wrapper -> name  = $name;
    }
    if($password != null){
        $wrapper -> pass = user_hash_password($password);
    }
    if ($email != null) {
        $wrapper -> mail = $email;
    }

    try {       
        user_save($wrapper);
        $message = "successessfully update!";
    } catch (Exception $e) {
        $message = "not success! -> ". $e;
    }

    $reply = (array('status' => $status,'message' => $message));
    return $reply;
}
1

Since you are using an entity wrapper, you must use $entity->save to save the updated user object. In your case, use $wrapper->save.

user_save() can be used when the user entity is loaded using user_load().

2
  • Not ok yet after changing code to $wrapper -> save(); exception still occurs. (exception 'EntityMetadataWrapperException' with message 'Invalid data value given. Be sure it matches the required data type and format.' in C:\\xampp\\htdocs\\phone_bay\\sites\\all\\modules\\entity\\includes\\entity.wrapper.inc:737\nStack trace:\n#0) – SAWAUNG Jan 7 '16 at 8:28
  • 1
    Have you given correct values in the user object? Because mail validation also happens here. – Manikandan Jan 7 '16 at 10:25
0

The user entity needs to be also saved. The full code for changing the username and the email address is then the following one.

$wrapper->name->set('Jean louis');
$wrapper->mail->set('mail@mail.com');
$wrapper->save();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.