November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
Hi Greg, check what is the language of the returned block when you use the item.GetContent(). When you say that you get only one block in Swedish language branch - are you sure that the returned block is actually the Swedish version and not the English version (as only one item exists in both Swedish and English).
Hi Greg, seems something happened in the forum - my previous post disappeared :D
So I wrote that previously that check the language of the returned block(s), it might be that you are getting the english version blocks only when using the item.GetContent() (its actually using the language from the context and in scheduled jobs the *-host is used and if that is defined as english version, then that is used)
So I assumme that when you are iteraring the Swedish language branch blocks you are actually getting back the English version as master language fallback and in the Swedish version there is only the one block that is in Swedish and English. But have a look at the returned blocks language in debugger.
Thanks Antti good comment.
So actually it is so that item.GetContent() is able to return only items in English (so when called on Swedish it returns only blocks having both EN and SV, but the block returned is still English)
With IContentLoader it is also not solved fully at the end, when called on Swedish it returns correctly blocks having only Swedish version, but when block has both it is returned ... but still English
Pass the language branches language also to the GetItemsWithContentLoader method and use that language in that method to create the language loaderoption - I think that should fix the issue.
Uncle Valdis will soon come here and comment that the extension method should be done against the IContentLoader so that you don't need to use that injected ContentLoader property in the extension method ;-) (besides you already have the IContentLoader in the scheduled job AND scheduled jobs support nowadays constructor injection so you don't even need to use the injected property in the scheduled job either.
Updated the original code, changed the extension so it runs against the ContentLoader and also added language parameter (otherwise it still was loading English for blocks being with more language versions)
Hi Grzegorz, Thanks for letting us know about the changes you made. Has that fixed the original problem?
Hi Bob,
Well we workaround the problem with replacing the calls for extension method with ContentLoader (with language parameter version). But still how about the extension method for ContentAreaItem which is calling the method from DefaultContentAreaLoader? Shouldn't it still allow to load blocks also in other languages than default when called from scheduled job?
In one of the projects we took over recently there is a scheduled job which is indexing all the pages for search engine (not Find).
One of new features requested by customer was to have a page type strongly built with wide range of content blocks, so to be able to use values from blocks we had to pull some of the data from blocks inserted into content areas when indexing.
After initial release we noticed that sometimes the content is not loaded properly, then I started look into the extension method used there and it seems that DefaultContentAreaLoader have issues load blocks when called from scheduled job.
Steps to reproduce with Alloy site:
Simply we can see that when we call from scheduled job the way to load blocks with IContent GetContent(this ContentAreaItem item) extension blocks missing English language version are not loaded (only 1 block loaded for Swedish).
When instead of that we use the IContentLoader then it works correctly
I started looking at the extension and internally Episerver calls inside the GetContent() method IContent Get(ContentAreaItem contentAreaItem) from DefaultContentAreaLoader which internally uses language from IContentLanguageAccessor _languageAccessor and that seems to be always English when called from scheduled job.
Note: it works just fine when called e.g. when publishing page from publish content event.
As an effect in our solution every time we run the scheduled job blocks data was incomplete, but when called manual publish from CMS it was fixing problem (until next run from scheduled job).
It seems that calling ContentLoader.Service.Get<ContentData>(item.ContentLink) fixed all issues, but seems that implementation of the IContent GetContent(this ContentAreaItem item) have some bug?