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.