Monday 06 June 2005 10:01:08 am
Hi Kristian, Thanks for the heads up. I was thinking that maybe the object method looped through the attributes and stored them as well, but I guess that's not the case. I must say, I find it confusing to create, or in this case modify, ezp objects in PHP, making me think that I might be using uneccessary code. Here's a short hand version of what I do. Are there any commands that could be dropped?
// fetch object
$object = eZContentObject::fetch($objectID);
// not sure if this fetches the current version or creates a new version
$version =& $object->version( $object->attribute('current_version') );
// set version status to draft
$version->setAttribute( 'status', EZ_VERSION_STATUS_DRAFT );
$version->store();
// update object name
$object->setAttribute( 'name', $name);
// fetch object attributes
$objectAttributes =& $version->contentObjectAttributes();
// update and store attribute
$objectAttributes[0]->setAttribute( 'data_int', $data_int );
$objectAttributes[0]->store();
// store object
$object->store();
// publish the new/current/whatever version
$operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $object->attribute( 'id' ), 'version' => $object->attribute('current_version') ) );
Running this code takes about 0.2 seconds (I update a few more attributes) and when the objects are in the hundreds, the execution time really starts to drag out. I would have no problem modifying the existing current version instead of creating a new one if it would save me some time.
Sincerely,
Eirik Alfstad Johansen
http://www.netmaking.no/
|