This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit

eZ Community » Forums » eZ Publish 5 Platform » Clear symfony single page from legacy

Clear symfony single page from legacy

Clear symfony single page from legacy

Monday 09 September 2013 8:19:24 pm - 10 replies


How to proceed to clear the cache of a Symfony single page from legacy php script ?

are using this code in a legacy mode ? 

$locationIds = array( 123, 456 );$container->get( 'ezpublish.http_cache.purger' )->purge( $locationIds );

Tuesday 10 September 2013 6:12:58 pm

Hi Joël, long time no see happy.gif Emoticon

First, you must run your legacy script through the ezpublish:legacy:script command. Then, in your legacy script you can easily get the service container and clear the cache:

$container = ezpKernel::instance()->getServiceContainer();
$container->get( 'ezpublish.http_cache.purger' )->purge( array( 123, 456 ) ) ;

Please note that you can also use the old API via eZContentCacheManager::clearContentCacheIfNeeded() (but then you need to provide contentIds, not locationIds.

Thursday 12 September 2013 9:35:25 am

Hi Jérôme,

thanks for your reply, I tried without success.

Here is the thing 

In a cronjob script i update a content this way:

$params = array();
$attributesData['pdf_file'] = $fullTmpPath;
$params['attributes'] = $attributesData;
$locationIds[] = $object->attribute('main_node_id');//save node id
//clear the cache
$container = ezpKernel::instance()->getServiceContainer();
$container->get( 'ezpublish.http_cache.purger' )->purge( $locationIds ); 

and in twig template :

 <a href="{{ path( 'ez_legacy', { 'module_uri': 'content/download/' ~ ~ '/' ~ content.getField( 'pdf_file' ).id ~ '/version/' ~ content.contentInfo.currentVersionNo ~ "/file/" ~ content.getField( 'pdf_file' ).value.fileName|escape( 'url' ) }                    ) }}" class="download">Télécharger en PDF</a>

but only the old version of the file is available , the only way to see the last version is to clear the all cache :

 php ezpublish/console cache:clear --env=prod --no-debug

any idea ?

Thursday 12 September 2013 10:09:38 am

mmm Reading your code, you shouldn't even need to manually clear the cache since eZContentFunctions::updateAndPublishObject() should call the old eZContentCacheManager, which triggers HTTP cache clear (you could also use public API in your cronjob blunk.gif Emoticon).


  • Is your cronjob correctly run with:
php ezpublish/console ezpublish:legacy:script cronjobs.php mycronjob
  • Is ViewCache correctly enabled in your legacy configuration ?

Modified on Thursday 12 September 2013 10:10:16 am by Jérôme Vieilledent

Thursday 12 September 2013 10:28:43 am

Yes the cronjob is running as you describe, and for my front siteaccess the ViewCaching is enabled, TemplateCompile is enabled and TemplateCache is enabled.

(Do you think it's a better solution to use the public API in legacy cronjob ?)

Thursday 12 September 2013 10:34:57 am


Quote from Joël LEGER :

(Do you think it's a better solution to use the public API in legacy cronjob ?)


Actually, my advise would be to create a service in your project bundle and call it from your cronjob. Then you can do all the work in a pure Symfony stack environment, use public API and so on. And it will give you forward compatibility (no need to migrate all your work when you upgrade to v6 blunk.gif Emoticon)

Thursday 12 September 2013 12:50:11 pm

thanks Jérôme

Friday 25 October 2013 10:57:14 am

After some test i use the PAPI as Jérôme said but the cache still not cleared (in Prod env).

Here is my command line script : 

$contentDraft = $contentService->createContentDraft( $contentInfo );                
$contentUpdateStruct = $contentService->newContentUpdateStruct();                
$contentUpdateStruct->initialLanguageCode = 'fre-FR';                
$contentUpdateStruct->setField( 'pdf_file', $fullTmpPath );                
$contentDraft = $contentService->updateContent( $contentDraft->versionInfo, $contentUpdateStruct );                
$content = $contentService->publishVersion( $contentDraft->versionInfo );
//clear the cache
$this->getContainer()->get( 'ezpublish.http_cache.purger' )->purge( $locationIds ); 

Friday 25 October 2013 7:47:05 pm



I think you will have to add --env=prod to the conjob command your doing, otherwise it's not able to clear prod cache.

If this is not mention in doc we should definitely fix that.

Modified on Friday 25 October 2013 7:47:24 pm by André R

Sunday 27 October 2013 2:33:37 pm

yes it's working

thanks André

Sunday 27 October 2013 6:49:25 pm

Great, updated doc to reflect this!


You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from