Create User

Author Message

Brijesh Tekrawala

Thursday 17 February 2011 11:50:11 pm

I am creating user from PHP code but it is not working

function createUser($parentNodeId, $userClassId, $sectionId, $login, $email, $password, $dataTextAttributeList){ $class = eZContentClass::fetch( $userClassId ); $contentObject = $class->instantiate( 1, 1 ); $contentObjectId = $contentObject->attribute( 'id' ); //$contentObject->setAttribute( 'name', $login); $dataMap = $contentObject->dataMap(); foreach($dataTextAttributeList as $identifier=>$value) { $attribute = $dataMap[$identifier]; $attribute->setAttribute( 'data_text', $value); $attribute->sync(); } $nodeAssignment = eZNodeAssignment::create( array( 'contentobject_id' => $contentObjectId, 'contentobject_version' => $contentObject->attribute( 'current_version' ), 'parent_node' => $parentNodeId, 'sort_field' => 2, 'sort_order' => 0, 'is_main' => 1)); $nodeAssignment->store(); $version = $contentObject->version( 1 ); $version->setAttribute( 'status', 'EZ_VERSION_STATUS_DRAFT' ); $version->store(); $user = new eZUser( $contentObject->attribute( 'id' ) ); $user->setAttribute('login', $login ); $user->setAttribute('email', $email ); $hashType = eZUser::hashType() . ""; $newHash = $user->createHash( $login, $password, eZUser::site(), $hashType ); $user->setAttribute( "password_hash_type", $hashType ); $user->setAttribute( "password_hash", $newHash ); $user->store(); $operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $contentObjectId, 'version' => 1 ) ); //assign section ... maybe there is a shorter way $object = eZContentObject::fetch( $contentObjectId, true); eZContentObjectTreeNode::assignSectionToSubTree( $contentObject->attribute( 'main_node_id' ), $sectionId ); return $user;}
//eg: create a new user under user group "Users" (node_id=5)$dataTextAttributeList = array('first_name'=>'Toto', 'last_name'=>'De La Motte');$oUser = createUser( 5, 4, 2, "toto", "toto@nospam.com", 'pass', $dataTextAttributeList );function createUser($parentNodeId, $userClassId, $sectionId, $login, $email, $password, $dataTextAttributeList){ $class = eZContentClass::fetch( $userClassId ); $contentObject = $class->instantiate( 1, 1 ); $contentObjectId = $contentObject->attribute( 'id' ); //$contentObject->setAttribute( 'name', $login); $dataMap = $contentObject->dataMap(); foreach($dataTextAttributeList as $identifier=>$value) { $attribute = $dataMap[$identifier]; $attribute->setAttribute( 'data_text', $value); $attribute->sync(); } $nodeAssignment = eZNodeAssignment::create( array( 'contentobject_id' => $contentObjectId, 'contentobject_version' => $contentObject->attribute( 'current_version' ), 'parent_node' => $parentNodeId, 'sort_field' => 2, 'sort_order' => 0, 'is_main' => 1)); $nodeAssignment->store(); $version = $contentObject->version( 1 ); $version->setAttribute( 'status', 'EZ_VERSION_STATUS_DRAFT' ); $version->store(); $user = new eZUser( $contentObject->attribute( 'id' ) ); $user->setAttribute('login', $login ); $user->setAttribute('email', $email ); $hashType = eZUser::hashType() . ""; $newHash = $user->createHash( $login, $password, eZUser::site(), $hashType ); $user->setAttribute( "password_hash_type", $hashType ); $user->setAttribute( "password_hash", $newHash ); $user->store(); $operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $contentObjectId, 'version' => 1 ) ); //assign section ... maybe there is a shorter way $object = eZContentObject::fetch( $contentObjectId, true); eZContentObjectTreeNode::assignSectionToSubTree( $contentObject->attribute( 'main_node_id' ), $sectionId ); return $user;}
//eg: create a new user under user group "Users" (node_id=5)$dataTextAttributeList = array('first_name'=>'Toto', 'last_name'=>'De La Motte');$oUser = createUser( 5, 4, 2, "toto", "toto@nospam.com", 'pass', $dataTextAttributeList );

can someone help ?

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 02:17:55
Script start
Timing: Jan 18 2025 02:17:55
Module start 'layout'
Timing: Jan 18 2025 02:17:55
Module start 'content'
Timing: Jan 18 2025 02:17:56
Module end 'content'
Timing: Jan 18 2025 02:17:56
Script end

Main resources:

Total runtime0.9839 sec
Peak memory usage4,096.0000 KB
Database Queries46

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0083 587.7891152.6094
Module start 'layout' 0.00840.0049 740.398439.4063
Module start 'content' 0.01330.9693 779.8047418.0156
Module end 'content' 0.98260.0013 1,197.820312.2031
Script end 0.9839  1,210.0234 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00360.3674160.0002
Check MTime0.00140.1418160.0001
Mysql Total
Database connection0.00120.118010.0012
Mysqli_queries0.936495.1752460.0204
Looping result0.00050.0549440.0000
Template Total0.938795.420.4694
Template load0.00250.252520.0012
Template processing0.936295.157920.4681
Template load and register function0.00020.019610.0002
states
state_id_array0.00120.123310.0012
state_identifier_array0.00110.110620.0005
Override
Cache load0.00190.193080.0002
Sytem overhead
Fetch class attribute can translate value0.00060.064010.0006
Fetch class attribute name0.00080.078010.0008
XML
Image XML parsing0.00010.011610.0001
class_abstraction
Instantiating content class attribute0.00000.000510.0000
General
dbfile0.00740.7488100.0007
String conversion0.00000.001540.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
1content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
2content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
1content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 6
 Number of unique templates used: 5

Time used to render debug report: 0.0001 secs