Publishing content from template operator

Author Message

Nebojsa Eric

Thursday 01 June 2006 2:51:58 am

I searched over a forum and I cannot find answer for my problem.

I `m writting template operator for a counter. For that purpose I`ve created one class with few integer attributes in it (counter1, counter2...). Passed parameteres are nodeid and attributeid. This operator works, but I can`t acctualy see counter`s incremeted value until I click on clear cache button to refresh content. So, my question is how to publish content from a template operator? Experienced users, please help...

Code follows:

$anode =& eZContentObjectTreeNode::fetch( $nodeid );
if ( !$anode )
{
eZDebugSetting::writeDebug( 'kernel-notification',
'Newsletter module: No node with ID: ' . $nodeid );
return;
}
$anodeObject =& $anode->object();
$attributes =& $anodeObject->contentObjectAttributes();
$atvalue = $attributes[$attributeid]->content();
$atvalue = $atvalue + 1;
$attributes[$attributeid]->setAttribute( "data_int", $atvalue );
$attributes[$attributeid]->store();

/* store object */
$anodeObject->store();

// this should publish the new version ???
$operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $anodeObject->attribute( 'id' ), 'version' => $anodeObject->attribute('current_version') ) );

Kristof Coomans

Thursday 01 June 2006 3:09:44 am

Hi Eric

Where are you displaying the counter? You need to programmatically clear the view cache of the other objects where you display the counter.

include_once( 'kernel/classes/ezcontentcachemanager.php' );
eZContentCacheManager::clearContentCacheIfNeeded( $objectID );

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Nebojsa Eric

Thursday 01 June 2006 4:08:01 am

Cheers.

No. It doest`nt work. Output is the same. If I use admin section to clear content cache it works, from the code it does`nt work. I`ve tried cache-block expiry too, no help. Debug output: everything is OK.

eZContentCacheManager::clearContentCacheIfNeeded( $anodeObject->attribute( 'id' ) );
eZContentCacheManager::clearContentCacheIfNeeded( $ahomenodeObject->attribute( 'id' ) );

For example, I`m calling counter operator from home page for hit counter purpose. It can be any other purpose. $ahomenodeObject is my home page with nodeid 2 and objectid 1.

Maybe someone from eZ Crew can help?

Kristof Coomans

Thursday 01 June 2006 4:46:26 am

Do you display the counter in the module result or in the pagelayout template?

Try to clear the specific related caches one by one and see when your counter get's properly refreshed.

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Nebojsa Eric

Thursday 01 June 2006 5:13:18 am

If I call it from pagelayout.tpl works fine. From {$module_result.content} works only when I clear content cache (all cache of course, content or template & content) in the admin section.

Kristof Coomans

Thursday 01 June 2006 11:02:38 pm

Put this at the beginning of the template where you're calling the counter:

{set-block scope=root variable=cache_ttl}0{/set-block}

Does it work now?

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Nebojsa Eric

Friday 02 June 2006 4:09:47 am

Who`s the man? That`s it.

Tnx Kristof.

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 00:21:52
Script start
Timing: Jan 19 2025 00:21:52
Module start 'layout'
Timing: Jan 19 2025 00:21:52
Module start 'content'
Timing: Jan 19 2025 00:21:54
Module end 'content'
Timing: Jan 19 2025 00:21:54
Script end

Main resources:

Total runtime1.4529 sec
Peak memory usage4,096.0000 KB
Database Queries69

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0060 588.0391152.6406
Module start 'layout' 0.00600.0031 740.679739.4766
Module start 'content' 0.00911.4419 780.1563594.1719
Module end 'content' 1.45100.0018 1,374.328120.1250
Script end 1.4528  1,394.4531 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00320.2231160.0002
Check MTime0.00130.0867160.0001
Mysql Total
Database connection0.00080.052610.0008
Mysqli_queries1.363393.8380690.0198
Looping result0.00070.0490670.0000
Template Total1.420997.820.7104
Template load0.00250.169920.0012
Template processing1.418497.629220.7092
Template load and register function0.00040.027310.0004
states
state_id_array0.00080.055310.0008
state_identifier_array0.00120.082220.0006
Override
Cache load0.00180.1251540.0000
Sytem overhead
Fetch class attribute can translate value0.00100.070820.0005
Fetch class attribute name0.00190.130290.0002
XML
Image XML parsing0.00570.394320.0029
class_abstraction
Instantiating content class attribute0.00010.0040140.0000
General
dbfile0.00600.4140220.0003
String conversion0.00000.000740.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
7content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
7content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
11content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
3content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 32
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs