Importing: Update entry if it already exists

Author Message

Siniša Šehović

Thursday 07 October 2004 1:17:49 am

Hi Paul

Please help:-)

Something strange happend!?
After importing hash into user table there is hash that I have created and I can't login but if I go to user in admin and "change" password with same password(hash import is demo password) "demo" i see that in user table is different hash of demo?!?!
How is that possible?

Best regards,
Sinisa

---
If at first you don't succeed, look in the trash for the instructions.

Siniša Šehović

Thursday 07 October 2004 2:19:32 am

Hi

I have figured out what was wrong!:)-)
Password hash is produced like username\password.
Now everything works great:)

S.

---
If at first you don't succeed, look in the trash for the instructions.

Paul Forsyth

Friday 08 October 2004 12:40:05 am

Glad it works! I was away for most of yesterday.

Paul

Lazaro Ferreira

Wednesday 20 October 2004 1:51:47 am

Paul,

I have read all the thread, and I have picked up this piece of code, that create and publish an user object

$ini =& eZINI::instance();

$userClassID = $ini->variable( "UserSettings", "UserClassID" );
$class =& eZContentClass::fetch( $userClassID );

$userCreatorID = $ini->variable( "UserSettings", "UserCreatorID" );
$defaultSectionID = $ini->variable( "UserSettings", "DefaultSectionID" );
$defaultUserPlacement = $ini->variable( "UserSettings", "DefaultUserPlacement" );

$contentObject =& $class->instantiate( $userCreatorID, $defaultSectionID, false);

$nodeAssignment =& eZNodeAssignment::create( array(
                                                   'contentobject_id' => $contentObject->attribute( 'id' ),
                                                   'contentobject_version' => 1,
                                                   'parent_node' => $defaultUserPlacement,
                                                   'is_main' => 1
                                                  )
                                           );
$nodeAssignment->store();
    
// Set a status for the content object version
$contentObjectVersion =& $contentObject->version($contentObject->attribute( 'current_version' ) );
$contentObjectVersion->setAttribute( 'status', EZ_VERSION_STATUS_DRAFT);
$contentObjectVersion->store();

// Set the members attributes
$contentObjectAttributes =& $contentObject->attribute('data_map');

$firstNameAttribute = $contentObjectAttributes['first_name'];
$lastNameAttribute = $contentObjectAttributes['last_name'];
$userAccountAttribute = $contentObjectAttributes['user_account']->content();

// Now set the details
$firstNameAttribute->setAttribute("data_text", "Enter first name");
$firstNameAttribute->store();
    
$lastNameAttribute->setAttribute("data_text", "Enter second name");
$lastNameAttribute->store();
    
$userAccountAttribute->setAttribute("login", "Choose login");
$userAccountAttribute->setAttribute("email", "Choose email");

// Entered md5 sum of 'publish'. Replace with hash of your own. Make sure the hash type matches.
$userAccountAttribute->setAttribute("password_hash", "9b6d0bb3102b87fae57bc4a39149518e");
    
// Keep the password type as 2. This is the default for eZ publish but look in ezuser.php for more options.
$userAccountAttribute->setAttribute("password_hash_type", 2);
$userAccountAttribute->store();

// Now publish the object.
$operationResult = eZOperationHandler::execute( 'content', 
                                                'publish',
                                                array( 'object_id' => $contentObject->attribute( 'id' ),
                                                       'version' => $contentObject->attribute('current_version' ) ) );

So, my understanding is that here I have all ezp API needed to create and publish my own content objects from my php module extension

Is that right ?

Lazaro
http://www.mzbusiness.com

Paul Forsyth

Wednesday 20 October 2004 2:10:28 am

Some of it, yes. Your own needs may differ of course. The code above is just an example. Search the forums for snippets of this code and you will see it used in other ways.

You could always use the code documentation found at http://pubsvn.ez.no/doxygen/

Btw, can yu reply to the original thread and not this one. Its easier to follow.

paul

First Last

Saturday 30 July 2005 9:45:12 am

Thank you for import script, but could you post format of CSV file to import? I don't know, how to prepare CSV file to be able to import it.

First Last

Monday 08 August 2005 11:05:28 am

Now I know how to import text fields, but could anyone help me how to import images?

Massimiliano Bariola

Saturday 18 March 2006 1:03:24 pm

Hi,

I tried the code provided to change the name of a node, but it does not seem to work. my code does not fail, but the name remains the same.

Please can anyone help me?

thank you!

Massimiliano Bariola

Saturday 18 March 2006 1:48:39 pm

I found it. $contentObject->rename($newname). 4 hours to find it ... sigh.

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 31 2025 06:11:18
Script start
Timing: Jan 31 2025 06:11:18
Module start 'layout'
Timing: Jan 31 2025 06:11:18
Module start 'content'
Timing: Jan 31 2025 06:11:19
Module end 'content'
Timing: Jan 31 2025 06:11:19
Script end

Main resources:

Total runtime1.2412 sec
Peak memory usage4,096.0000 KB
Database Queries80

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0048 588.7891151.2266
Module start 'layout' 0.00480.0025 740.015637.1406
Module start 'content' 0.00731.2330 777.15631,101.6563
Module end 'content' 1.24030.0008 1,878.812521.9453
Script end 1.2411  1,900.7578 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00320.2596160.0002
Check MTime0.00130.1052160.0001
Mysql Total
Database connection0.00060.047610.0006
Mysqli_queries1.167994.0993800.0146
Looping result0.00070.0601780.0000
Template Total1.206397.220.6031
Template load0.00220.176020.0011
Template processing1.204197.012020.6020
Template load and register function0.00120.096710.0012
states
state_id_array0.00210.170710.0021
state_identifier_array0.00280.223020.0014
Override
Cache load0.00200.1577460.0000
Sytem overhead
Fetch class attribute can translate value0.00080.065850.0002
Fetch class attribute name0.00150.1227110.0001
XML
Image XML parsing0.00440.353750.0009
class_abstraction
Instantiating content class attribute0.00000.0019130.0000
General
dbfile0.00550.4409220.0002
String conversion0.00000.000540.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
4content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
9content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
14content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
4content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 34
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs