Friday 12 March 2010 3:41:37 am
Hi, I have a few questions about the right way to create an ez object, using PHP. I was not able to find a place where there are clear guidelines on the subject. So from different places I checked (forum, eZpedia, API code) I figured out the following steps : 1/ getting an instance of the class of the object
2/ creating an object from the class (adding records in tables ezcontentobject and ezcontentobject_attribute ) $object = $class->instantiate( $userID, $sectionID, $version, $languageCode, eZContentObjectVersion::STATUS_INTERNAL_DRAFT );
3/ setting internal object attributes using
$object->setAttribute( <attribute_name>, <attribute_value> );
(...); $object->store();
4/ setting other attributes using }
$dataMap = $object->attribute( 'data_map' );
$attribute = $dataMap[ <attribute_name> ];
$attribute->setAttribute( <attribute_type>, <attribute_value> ); $attribute->sync();
5/ creating a node assignement (adding record a record in table eznode_assignment)
$nodeAssignment = $object->createNodeAssignment( $parentNodeID,
$isMain, $remoteID,
$class->attribute( 'sort_field' ), $class->attribute( 'sort_order' ) ); What is the purpose of this step - is it mandatory ? What the assignment is used for in ez Publish ?It is not clear to understand this assignment of a node that does not yet exist (there are no ezcontentobject_tree object created at this step) 6/ publishing the object, which is doing a lot of things and along them:
- create a node (main node)
- update the publishing date of the object
- update the op_code of the nodeAsssignment
- call custom edit handler and workflow scripts
- ...
$operationResult = eZOperationHandler::execute( 'content',
'publish',
array( 'object_id' => $object->ID,
'version' => $object->CurrentVersion ) ); We need to fetch again the object, for the $object to hold of the changes made during the publish process. Is there a way to directly pass the $object to a publish process so that we do not need to refetch the current object ? Is this process correct ? Are there any "more efficient way" to do it ? And a last question about object updating. Is there a way to update a published object without having to republish it ? When I only "store" my changes, they are not directely available, unless I republish the object - which is a problem when updating an object in a workflow or a custom edit handler (because it makes a loop) Thanks for all your feedback, and once I get the answers I will post the global method I wrote to handle object creation and hide the complexity.
Hakim Bouras PRISMALOG - Creation de site Internet
|