Forums / General / Publishing content from template operator

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.

eZ debug

Timing: Jan 18 2025 21:01:34
Script start
Timing: Jan 18 2025 21:01:34
Module start 'content'
Timing: Jan 18 2025 21:01:34
Module end 'content'
Timing: Jan 18 2025 21:01:34
Script end

Main resources:

Total runtime0.1821 sec
Peak memory usage2,048.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0062 587.8359180.8203
Module start 'content' 0.00620.0067 768.6563102.0234
Module end 'content' 0.01290.1691 870.6797533.3750
Script end 0.1820  1,404.0547 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00382.0955200.0002
Check MTime0.00150.8456200.0001
Mysql Total
Database connection0.00070.387710.0007
Mysqli_queries0.133673.36031410.0009
Looping result0.00140.74791390.0000
Template Total0.168892.710.1688
Template load0.00090.511810.0009
Template processing0.167892.171010.1678
Override
Cache load0.00070.365810.0007
Sytem overhead
Fetch class attribute can translate value0.00060.314110.0006
XML
Image XML parsing0.00020.119710.0002
General
dbfile0.00512.8004200.0003
String conversion0.00000.002630.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs