Forums / Developer / Adding multiple Users

Adding multiple Users

Author Message

Norman Leutner

Monday 16 August 2004 8:20:59 am

Hello,

for your intranet I need to add about 470 Users to our ez 3.1 system.
Because this is too much to add them manual, I`m planning to write a php-script to add them.

I`ve taken a look onto the database while adding a user an found out that the
ezPublish system inserts 15 records into 10 different tables for one Standard User.

Are there any functions within the ezSystem which i can use for my script
or will i have to script each dynamic SQLstatement by myself?

Thanks in advance

Norman Leutner

Mit freundlichen Grüßen
Best regards

Norman Leutner

____________________________________________________________
eZ Publish Platinum Partner - http://www.all2e.com
http://ez.no/partners/worldwide_partners/all2e_gmbh

Ole Morten Halvorsen

Tuesday 17 August 2004 1:33:23 am

Hi Norman,

You do not have to write any SQL statements at all. Have a look at the small user creation example script below:

<?php

include_once( 'kerxnel/classes/ezcontentobject.php' );
include_once( 'lib/ezlocale/classes/ezdatetime.php' );

$firstName = "Average";
$lastName = "Joe";
$email = "average.joe@example.com";

$userClassID = 4;
$class =& eZContentClass::fetch( $userClassID );
$creatorID = 14; // 14 == admin
$groupNodeID = 5;
$contentObject =& $class->instantiate( $creatorID, 1 );

$nodeAssignment =& eZNodeAssignment::create( array(
                                                 'contentobject_id' => $contentObject->attribute( 'id' ),
                                                 'contentobject_version' => $contentObject->attribute( 'current_version' ),
                                                 'parent_node' => $groupNodeID,
                                                 'is_main' => 1
                                                 )
                                             );
$nodeAssignment->store();

$version =& $contentObject->version( 1 );
$version->setAttribute( 'modified', eZDateTime::currentTimeStamp() );
$version->setAttribute( 'status', EZ_VERSION_STATUS_DRAFT );
$version->store();

$contentObjectID = $contentObject->attribute( 'id' );
$contentObjectAttributes =& $version->contentObjectAttributes();

$contentObjectAttributes[0]->setAttribute( 'data_text', $firstName );
$contentObjectAttributes[0]->store();

$contentObjectAttributes[1]->setAttribute( 'data_text', $lastName );
$contentObjectAttributes[1]->store();

$user =& eZUser::create( $contentObjectID );
$password = eZUser::createPassword( 8, $firstName . $lastName . $email );

$hash = $user->createHash( $login, $password, eZUser::site(), eZUser::hashType() );
$user->setAttribute('login', $login );
$user->setAttribute('email', $email);
$user->setAttribute('password_hash', $hash );
$user->setAttribute('password_hash_type', 2 );
$user->store();

include_once( 'lib/ezutils/classes/ezoperationhandler.php' );
$operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $contentObjectID,
                                                                             'version' => 1 ) );
?>

Senior Software Engineer - Vision with Technology

http://www.visionwt.com
http://www.omh.cc
http://www.twitter.com/omh

eZ Certified Developer
http://ez.no/certification/verify/358441
http://ez.no/certification/verify/272578

Norman Leutner

Tuesday 17 August 2004 7:07:08 am

Thanks for the script.

I`ve got the problem left that the publish function does not work and returns:
<b>Cannot execute operation 'publish' in module 'content', no valid dataeZOperationHandler::execute</b>

The script only creates only a draft at the moment.

Here is the script again:

<?php 

include_once( 'kernel/classes/ezcontentobject.php' ); 
include_once( 'lib/ezlocale/classes/ezdatetime.php' ); 
  
// Testuser definition 
$firstName = "Hugo"; 
$lastName = "Heise"; 
$email = "hugo.heise@hoppecke.com"; 
$login= "h-waldmann"; 



echo "creating Account: ".$login." - ".$firstName." ".$lastName." / ".$email."<br>"; 

$userClassID = 4; 
$class =& eZContentClass::fetch( $userClassID ); 

$creatorID = 426; // 426 = N.Leutner 
$groupNodeID = 140; 

$contentObject =& $class->instantiate( $creatorID, 1 ); 
  
// Insert into Table eznode_assignment 
$nodeAssignment =& eZNodeAssignment::create( array( 
                                                 'contentobject_id' => $contentObject->attribute( 'id' ), 
                                                 'contentobject_version' => $contentObject->attribute( 'current_version' ),

                                                 'parent_node' => $groupNodeID, 
                                                 'sort_field' => 9, 
                                                 'is_main' => 1 
                                                 ) 
                                             ); 
$nodeAssignment->store(); 
  

// Insert into Table ezcontentobject_version  
$version =& $contentObject->version( 1 ); 
$version->setAttribute( 'modified', eZDateTime::currentTimeStamp() ); 
$version->setAttribute( 'status', EZ_VERSION_STATUS_DRAFT ); 
$version->store(); 



// Inserts into Table ezcontentobject_attribute 

    // Attribute1 = parent attribute 
    $contentObjectID = $contentObject->attribute( 'id' ); 
    $contentObjectAttributes =& $version->contentObjectAttributes(); 

    // Attribute2 = firstname 
    $contentObjectAttributes[0]->setAttribute( 'data_text', $firstName ); 
    $contentObjectAttributes[0]->store(); 

    // Attribute3 = lastname 
    $contentObjectAttributes[1]->setAttribute( 'data_text', $lastName ); 
    $contentObjectAttributes[1]->store(); 



// Inserts into Table ezuser 

    // Create user by parent attribute ID 
    $user =& eZUser::create( $contentObjectID ); 

    // Create password with 8 Charakters 
    $password = eZUser::createPassword( 8, $firstName . $lastName . $email ); 
    echo "Password lautet: ".$password."<br>"; 
    
    // Create passwordhash 
    $hash = $user->createHash( $login, $password, eZUser::site(), eZUser::hashType() ); 

    // Set attributes 
    $user->setAttribute('login', $login ); 
    $user->setAttribute('email', $email); 
    $user->setAttribute('password_hash', $hash ); 
    $user->setAttribute('password_hash_type', 2 ); 
    $user->store(); 

// Publish user 
// This function returns the error: Cannot execute operation 'publish' in module 'content', 
// no valid dataeZOperationHandler::execute

include_once( 'lib/ezutils/classes/ezoperationhandler.php' ); 
$operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $contentObjectID, 
                                                                             'version' => 1 ) ); 

?> 

Mit freundlichen Grüßen
Best regards

Norman Leutner

____________________________________________________________
eZ Publish Platinum Partner - http://www.all2e.com
http://ez.no/partners/worldwide_partners/all2e_gmbh

Joanie Chembars

Friday 22 April 2005 6:34:38 am

Hi Norman --
Did you get this script to work for you? I need to do the same thing and thought I would check with you before I tried the script.......
Thanks,
Joanie

eZ debug

Timing: Jan 19 2025 15:23:57
Script start
Timing: Jan 19 2025 15:23:57
Module start 'content'
Timing: Jan 19 2025 15:23:57
Module end 'content'
Timing: Jan 19 2025 15:23:57
Script end

Main resources:

Total runtime0.1487 sec
Peak memory usage2,048.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0077 588.8516180.8438
Module start 'content' 0.00770.0064 769.6953101.9609
Module end 'content' 0.01410.1345 871.6563530.7344
Script end 0.1486  1,402.3906 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00362.3891200.0002
Check MTime0.00120.8376200.0001
Mysql Total
Database connection0.00110.757910.0011
Mysqli_queries0.105671.00381410.0007
Looping result0.00120.81131390.0000
Template Total0.134090.110.1340
Template load0.00090.603810.0009
Template processing0.133189.536210.1331
Override
Cache load0.00060.413010.0006
Sytem overhead
Fetch class attribute can translate value0.00070.474710.0007
XML
Image XML parsing0.00040.293710.0004
General
dbfile0.00402.6969200.0002
String conversion0.00000.005030.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs