Forums / Setup & design / nodeassignment and treenode
andre müller
Monday 20 March 2006 8:32:31 am
i'm trying to assign a new node to my contentobjects with a script. whenever i use the following code:
$nodeAssignment =& eZNodeAssignment::create( array( 'contentobject_id' => $cobj->attribute( 'id' ), 'contentobject_version' => $cobj->attribute( 'current_version' ), 'parent_node' => $parentNodeID, 'sort_field' => 2, 'sort_order' => 0, 'is_main' => 0 ) ); $nodeAssignment->store();
now my node assignment is created in the table eznode_assignment table. but no new treenode is created and therefore the the new node isn't really added. can anybody tell me what i'm missing?thanks!
Betsy Gamrat
Monday 20 March 2006 9:45:51 am
'is_main' => 0
Try changing this to 'is_main'=>1.
Kristof Coomans
Monday 20 March 2006 11:53:11 am
You'll have to call the publish operation of the content module. See http://ez.no/community/forum/developer/insert_objects_from_module_clear_cache_problem/.
independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org
Tuesday 21 March 2006 1:03:49 am
thanks for the replies. i did publish the object - without success. it may be a problem that i do not create a new version when i edit my objects. i just get the current version and the contentobjectattributes of that version. then i set new values for some attributes and try to add a node assignment before i call the publish operation..
Tuesday 21 March 2006 3:28:09 am
If I remember well, the operation result is stored for each content object version. If you try to publish a specific version for a second time then the operation won't do anything.
Try to create a new version, add a node assignment for the new version and run the publish operation on that version.
Tuesday 21 March 2006 7:48:53 am
that sounds like a good advice. i'll give it a try. thanks!
Wednesday 22 March 2006 9:44:02 am
well - still doesn't work..version is created fine. attributes of that version are created fine. but the version status is still 0 even after publishing.
could it be a permission problem? i used the code:
$user =& eZUser::instance(14);$user->loginCurrent();
which i'm sure is wrong..but worked for the version creation..hm..
Wednesday 22 March 2006 10:26:49 am
I have had good luck with this approach.
//Where to place the object // inital values $user_id = 14; $GroupID = 13; $parentNodeID=2; //Get the user node and node_id include_once( 'kernel/classes/datatypes/ezuser/ezuser.php' ); $user =& eZUser::fetch($user_id); $user_id = $user->attribute( 'contentobject_id' ); $userObject =& eZContentObject::fetch($user_id); $user_node =& $userObject->attribute('main_node');
<b>Code adapted from: // Copyright (C) 1999-2004 Björn. All rights reserved. /*run this script from the shell
php -C create.php
*/</b>
Thursday 23 March 2006 6:48:00 am
ok, my problem was that i used:
$script =& eZScript::instance( array( 'description' => ( "pieps" ), 'use-session' => false, 'use-modules' => true, 'use-extensions' => true ) );
without 'use-modules' => true, so the publish operation for rhe content module wasn't able to run properly.
Thursday 23 March 2006 1:48:35 pm
Good job!