Creating content objects programmatically

Author Message

Brian Gerspacher

Friday 18 November 2005 1:29:22 pm

Hi,

I'm having some trouble adding a new content object/node programmatically. For simplicity, let's just say that I have a user group (although I think this discussion will be the same for any class)...

$userGroup =& eZContentObject::fetch($myContentObjectId);

...and that I want to add a new user group as a child of that object. Here's my code to add a new group.

$contentClass =& eZContentClass::fetchByIdentifier($userGroup->className());
$newGroup =& eZContentObject::create('A new child group', $contentClass->attribute('id'));

This seems to work fine and I can retrieve the group by calling eZContentObject::fetchList() with the group's name ('A new child group') as a parameter. At this point, the group does not appear in the tree of user groups when I click on 'User accounts' in the admin site. So I have tried a few things to add the group as a child of the desired node. Something like this seems to deal with data in the eznodeassignment table...

$parameters = array(
  'contentobject_id' => $newGroup->attribute('id'),
  'contentobject_version' => $newGroup->attribute('current_version'),
  'parent_node' => $userGroup->attribute('main_node_id'),
  'is_main' => 1);
$nodeAssignment =& eZNodeAssignment::create($parameters);

And this seems to deal with the ezcontentobject_tree table...

$treeNode =& eZContentObjectTreeNode::create(
  $contentobject->attribute('main_node_id'),
  $newObject->attribute('id'));

By examining the DB (and changing values as an experiment), it seems that the path_string field of the ezcontentobject_tree table is very important in deciding how the tree is displayed in the admin site. Can someone describe how the ezcontentobject, ezcontentobject_tree, and eznodeassignment tables are related and what code should be used to manipulate them appropriately?

Thanks in advance,

Brian.

Kristof Coomans

Saturday 19 November 2005 12:59:06 am

Maybe this can help you:
http://ez.no/community/forum/developer/creating_a_simple_content_object_via_php

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

Brian Gerspacher

Monday 21 November 2005 7:29:11 am

Yes, thanks, that got me going. I can create and publish new content items. However my overall understanding of content items/versions/nodes remains blurry. I'll just take things one step at a time. (My next task is to add a location for a content item but I'll start a new thread for that.)

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 19 2025 01:07:23
Script start
Timing: Jan 19 2025 01:07:23
Module start 'layout'
Timing: Jan 19 2025 01:07:23
Module start 'content'
Timing: Jan 19 2025 01:07:24
Module end 'content'
Timing: Jan 19 2025 01:07:24
Script end

Main resources:

Total runtime0.9569 sec
Peak memory usage4,096.0000 KB
Database Queries57

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0065 589.2891152.6406
Module start 'layout' 0.00650.0033 741.929739.4766
Module start 'content' 0.00980.9455 781.4063539.3047
Module end 'content' 0.95530.0015 1,320.710912.1250
Script end 0.9568  1,332.8359 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00330.3464160.0002
Check MTime0.00130.1325160.0001
Mysql Total
Database connection0.00090.090010.0009
Mysqli_queries0.910295.1215570.0160
Looping result0.00050.0567550.0000
Template Total0.925696.720.4628
Template load0.00220.227620.0011
Template processing0.923496.498820.4617
Template load and register function0.00020.020510.0002
states
state_id_array0.00120.123410.0012
state_identifier_array0.00100.109220.0005
Override
Cache load0.00170.1816210.0001
Sytem overhead
Fetch class attribute can translate value0.00100.108320.0005
Fetch class attribute name0.00120.122240.0003
XML
Image XML parsing0.00040.037820.0002
class_abstraction
Instantiating content class attribute0.00000.000940.0000
General
dbfile0.00080.0823160.0000
String conversion0.00000.001140.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
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
7content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
4content/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
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: 18
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs