Code will create drafts, but not publish them

Author Message

Gabriel Ambuehl

Sunday 30 January 2005 8:17:38 am

I use the following code to craate a content object:

$class=& eZContentClass::fetch( $classID );
$newObjectInstance=&$class->instantiate(false, $sectionid);

$nodeassignment=$newObjectInstance->createNodeAssignment($class_content['default_placement_node'], true);
$nodeassignment->store();

$newObjectInstance->setAttribute('published',$time);
$newObjectInstance->setAttribute('is_published',true);
$newObjectInstance->setAttribute('modified', $time );
$newObjectInstance->setAttribute('status',1);
$newObjectInstance->store();

After messing with this for several hours, it still only creates Drafts but doesn't publish them (drafts show Not Published Yet for modified, published instead of the time). What am I overlooking?

Visit http://triligon.org

Sven Berg Ryen

Sunday 30 January 2005 10:37:43 am

Hi Gabriel!

I haven't ever tried manually setting the "published" and so attributes, so I can't comment on your code.

I think it would be easier if you, after storing the objectInstance, published it:

    $operationResult = eZOperationHandler::execute( 'content', 'publish', array( 
       'object_id' => $newObjectInstance->attribute( 'id' ), 'version' => 1 ) );

If I were you, I'd take a look at the file /cronjobs/rssimport.php.
In that file, you'll see one of the ways of adding objects to ez by code.

You may also need to create a version 1 of the object:

    $version =& $contentObject->version( 1 );
    $version->setAttribute( 'status', EZ_VERSION_STATUS_DRAFT );
    $version->store();

HTH, and have a nice day! :)

Cheers,

Sven Ryen
sven.ryen at maxus.no

Gabriel Ambuehl

Sunday 30 January 2005 11:41:05 am

Seems like that did the job... Many thanks!

Visit http://triligon.org

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.