Get the new node_id

Author Message

Roy Bøhmer

Tuesday 30 August 2005 9:05:47 am

I finally managed to import data from an excel-file, and publish the content in some new objects/nodes.
But now I need to use these new nodes as parents to a lot more objects/nodes.

The code used to assign the new objects no nodes is pretty much a copy of some code found in the eZ-book:

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

I hoped the $newNodeID would actually contain the node_id, but it don't. It's the id of the eznodeassignment-table. I tried use eZContentObjectTreeNode instead of eZNodeAssignment, but I only endend up emptying the ezcontentobjecttreenode-table :-)

So, how can I get the node_id of a newly created object, just assiged to a node?

Kristof Coomans

Tuesday 30 August 2005 9:46:57 pm

After you've published the content, you can fetch the node and node ID with the following code:

$objectID =& $contentObject->attribute( 'id' );
$parentNodeID =& $parentContentObjectTreeNode->attribute( 'node_id' );

$node =& eZContentObjectTreeNode::fetchNode( $objectID, $parentNodeID );

$nodeID =& $node->attribute( 'node_id' );

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Roy Bøhmer

Wednesday 31 August 2005 1:08:02 pm

Thank you, Kristof!
I hoped there would be a solution where I could avoid another fetch, but your suggestion seems to be the solution.
Since I know the new nodes always will be the main nodes I might use the code

$nodeID=$contentObject->mainNodeID();

I found this function after I did the original post.

Again, thank you!

Roy

Clemens T

Thursday 01 September 2005 2:05:01 am

Thanks, I was looking for this as well!

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 22:31:57
Script start
Timing: Jan 18 2025 22:31:57
Module start 'layout'
Timing: Jan 18 2025 22:31:57
Module start 'content'
Timing: Jan 18 2025 22:31:58
Module end 'content'
Timing: Jan 18 2025 22:31:58
Script end

Main resources:

Total runtime0.7006 sec
Peak memory usage4,096.0000 KB
Database Queries62

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0041 587.8125152.6094
Module start 'layout' 0.00410.0024 740.421939.4141
Module start 'content' 0.00640.6926 779.8359582.2109
Module end 'content' 0.69910.0014 1,362.046912.1875
Script end 0.7005  1,374.2344 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00310.4410160.0002
Check MTime0.00130.1862160.0001
Mysql Total
Database connection0.00070.096910.0007
Mysqli_queries0.653793.3102620.0105
Looping result0.00070.0953600.0000
Template Total0.678696.920.3393
Template load0.00200.285220.0010
Template processing0.676596.573720.3383
Template load and register function0.00040.051310.0004
states
state_id_array0.00060.082710.0006
state_identifier_array0.00070.095020.0003
Override
Cache load0.00170.2414230.0001
Sytem overhead
Fetch class attribute can translate value0.00050.066330.0002
Fetch class attribute name0.00130.190950.0003
XML
Image XML parsing0.00090.131830.0003
class_abstraction
Instantiating content class attribute0.00000.002150.0000
General
dbfile0.00070.0992160.0000
String conversion0.00000.000740.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/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
2content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
6content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
3content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 18
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs