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.

eZ debug

Timing: Jan 19 2025 01:14:24
Script start
Timing: Jan 19 2025 01:14:24
Module start 'layout'
Timing: Jan 19 2025 01:14:24
Module start 'content'
Timing: Jan 19 2025 01:14:25
Module end 'content'
Timing: Jan 19 2025 01:14:25
Script end

Main resources:

Total runtime1.0685 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.0094 590.4219152.6406
Module start 'layout' 0.00940.0047 743.062539.4766
Module start 'content' 0.01421.0529 782.5391499.3906
Module end 'content' 1.06700.0014 1,281.929712.1250
Script end 1.0685  1,294.0547 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00400.3759160.0003
Check MTime0.00180.1671160.0001
Mysql Total
Database connection0.00100.090610.0010
Mysqli_queries1.019695.4261570.0179
Looping result0.00070.0658550.0000
Template Total1.023295.820.5116
Template load0.00230.214120.0011
Template processing1.020995.544820.5104
Template load and register function0.00020.015610.0002
states
state_id_array0.00160.152410.0016
state_identifier_array0.00180.167920.0009
Override
Cache load0.00190.1743180.0001
Sytem overhead
Fetch class attribute can translate value0.00060.058320.0003
Fetch class attribute name0.00100.089030.0003
XML
Image XML parsing0.00030.023720.0001
class_abstraction
Instantiating content class attribute0.00000.000830.0000
General
dbfile0.00110.1021100.0001
String conversion0.00000.001240.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
6content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
3content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.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: 15
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs