API: How to refresh frontpage when block content changes?

Author Message

Rainer Krauss

Sunday 02 August 2009 7:42:29 am

Dear all,

I've got an eZ Flow frontpage and within it a block with an article as content.
I'm changing the Article's title and body using the API, and I want this new content to be visible in the frontend.
However, I'm still shown the old version of the content. In the backend, when I edit the frontpage, the block shows me the article under the old title. To get the new content shown in the frontend, I have to remove the article from the block and then add it again - all manually.

Could someone please indicate how I could accomplish this?
I've already tried to publish the frontpage itself again, and have been experimenting with the eZ Flow page block classes.

Looking forward to any hints.

Best wishes,
Rainer

Gaetano Giunta

Sunday 02 August 2009 1:47:55 pm

Hint: look at the code executed by the ezflow cronjob: at the end of ezflowoperations.php:

 eZContentCacheManager::clearContentCache( $contentObject->attribute('id') );

Principal Consultant International Business
Member of the Community Project Board

Rainer Krauss

Monday 03 August 2009 1:59:14 am

Thank you Gaetano.
I'm sorry it's still not working, I'm not getting shown the new content on the site, not when I use the API to refresh the cache and not when I do that manually.

The odd thing is that it does work, but only for one single site out of 15 I've been testing this on. That one is the one I originally programmed it for. Have been searching for anything that would make it specific to that site, but the script seems to be general.

If it's of any help, I'm posting my source code below I'm using to try and refresh the frontpage content.

Best wishes,
Rainer

$node =& eZContentObjectTreeNode::fetch( $homepage_id );
$myContentObjectAttributes =& $node->attribute('data_map');
$title = $myContentObjectAttributes['page'];
$title2 = $title->attribute( 'data_text' );
$new_object = eZPage::createFromXML($title2);

$zones = $new_object->attribute( 'zones' );
$blocks =& $zones[0]->attribute( 'blocks' );
$keys = array_keys($blocks[0]->attribute( 'valid' ));
$block_0 = $blocks[0]->attribute( 'valid' );
$key_1 = $keys[0];

$node_ID = $block_0[$key_1]->attribute( 'object_id' );
$blocks[0]->toBeModified();
$blocks[1]->toBeModified();

$n_o = $new_object->toXML();
$title->setAttribute("data_text", $n_o ); 
$title->store();
print_R($n_o);
$NodeID = $node->NodeID;
$parentContentObject =& $node->attribute( 'object' );
$operationResult = eZOperationHandler::execute( 'content', 'publish',
array(
    'object_id' => $parentContentObject->attribute( 'id' ), 
    'version' => $parentContentObject->attribute('current_version' ) ) );
   print_r($operationResult);
eZContentCacheManager::clearContentCache( $parentContentObject->attribute('id') );

Gaetano Giunta

Monday 03 August 2009 4:14:44 am

I'm a bit at a loss trying to understand your code, sorry.
Otoh I thing you might not be trying to do it the right way - either that or I have not understood your needs...

If the use case is
- article is part of a frontpage as element in a block
- article title is changed via API
- frontpage does not refresh when article is updated

then in your code you will have to expire the cache of the frontpage node, not the cache of the article, as you seem to be doing

Principal Consultant International Business
Member of the Community Project Board

Rainer Krauss

Monday 03 August 2009 5:54:05 am

Thanks for the new hint, Gaetano.

I've now changed my code as per your directions, so that the content cache is cleared for the frontpage object. It still isn't working.

I confirm the use case is correct, plus I'm changing the content of that article as well.

What would you recommend now, please?

Best wishes,
Rainer

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 18 2025 11:22:10
Script start
Timing: Jan 18 2025 11:22:10
Module start 'layout'
Timing: Jan 18 2025 11:22:10
Module start 'content'
Timing: Jan 18 2025 11:22:10
Module end 'content'
Timing: Jan 18 2025 11:22:10
Script end

Main resources:

Total runtime0.7927 sec
Peak memory usage4,096.0000 KB
Database Queries63

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0078 588.1563152.6563
Module start 'layout' 0.00780.0027 740.812539.5078
Module start 'content' 0.01050.7808 780.3203568.9531
Module end 'content' 0.79130.0014 1,349.273416.0938
Script end 0.7927  1,365.3672 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00310.3924160.0002
Check MTime0.00130.1618160.0001
Mysql Total
Database connection0.00070.093710.0007
Mysqli_queries0.732592.4031630.0116
Looping result0.00060.0766610.0000
Template Total0.760295.920.3801
Template load0.00200.253820.0010
Template processing0.758295.642720.3791
Template load and register function0.00020.024110.0002
states
state_id_array0.00120.146610.0012
state_identifier_array0.00170.214620.0009
Override
Cache load0.00170.2187400.0000
Sytem overhead
Fetch class attribute can translate value0.00100.129720.0005
Fetch class attribute name0.00130.162360.0002
XML
Image XML parsing0.00060.076520.0003
class_abstraction
Instantiating content class attribute0.00000.002370.0000
General
dbfile0.00070.0921160.0000
String conversion0.00000.001140.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
5content/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
8content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
2content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.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: 30
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs