eZ Community » Forums » Developer » Updating EZ User object in PHP
expandshrink

Updating EZ User object in PHP

Updating EZ User object in PHP

Tuesday 06 November 2012 5:49:38 pm - 2 replies

I am updating the the current user like so:

        $currentUser = eZUser::currentUser();       

        $dataMap = $currentUser->contentObject()->dataMap();

        $userAttribute = $dataMap['address_1'];           

        $userAttribute->setAttribute('data_text', $_POST['AddressLine1']);           

        $userAttribute->store();

 

Which works fine, but I need to clear the cache after to update in the backend after as the content cache needs clearing

I was going to use eZCache::clearByID( 'user_info_cache' );

But I feel this is wrong. Is there a better way? 

Wednesday 07 November 2012 10:19:36 am

Hello Jon,

Maybe you can update your user by using the eZContentFunction::updateAndPublishObject()

You can find documentation here : http://pubsvn.ez.no/doxygen/2012.5/html/classeZContentFunctions.html#a2607b8b2ebde4f590cf5f2996ebc4458

In your case :

$currentUser = eZUser::currentUser();
$currentUserObject = $currentUser->contentObject();
$attributeList = array( 'address_1', $_POST['AddressLine1'] );
$params = array();
$params['attributes'] = $attributeList;
$result = eZContentFunctions::updateAndPublishObject( $currentUserObject, $params );
if ( $result ) {
  echo 'OK';
}

Hope it helps blunk.gif Emoticon

Paul

Modified on Wednesday 07 November 2012 10:20:09 am by Paul FROMAGE

Wednesday 07 November 2012 10:29:12 am

I do not think you need to clear the user_info cache, which relates to the roles and policies, but rather the view cache for the user node - since all you update is the user "profile" data.

Using the publication function above as suggested by Paul is one good way to do it - but you will get a new version of your user object. If you prefer to keep the version history "clean", just clearing the cache would be fine

Modified on Wednesday 07 November 2012 10:30:47 am by Gaetano Giunta

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from