Forums / Developer / Get the new node_id

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!

eZ debug

Timing: Jan 20 2025 12:47:14
Script start
Timing: Jan 20 2025 12:47:14
Module start 'content'
Timing: Jan 20 2025 12:47:14
Module end 'content'
Timing: Jan 20 2025 12:47:15
Script end

Main resources:

Total runtime0.2262 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.0079 588.8516180.8438
Module start 'content' 0.00790.0121 769.695393.9609
Module end 'content' 0.02010.2061 863.6563522.9844
Script end 0.2262  1,386.6406 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00381.6614200.0002
Check MTime0.00150.6432200.0001
Mysql Total
Database connection0.00070.331110.0007
Mysqli_queries0.170975.54611410.0012
Looping result0.00110.50551390.0000
Template Total0.205790.910.2057
Template load0.00100.439810.0010
Template processing0.204790.477110.2047
Override
Cache load0.00070.306210.0007
Sytem overhead
Fetch class attribute can translate value0.00080.347910.0008
XML
Image XML parsing0.00030.114510.0003
General
dbfile0.00773.4100200.0004
String conversion0.00000.003930.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