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.