Sitecore upgrade from 8.1 XP to 10.4 XM Scaled -Part 3
Continuation from Part 2 of upgrading from Sitecore 8.1 to 10.4, in this article we will see the issues faced during the upgrading of the 8.1 code to 10.4
- Upgrade the solution projects to the .net 4.8 framework
- Upgrade the Sitecore Nuget packages to 10.4
- We have received this below error while doing an upgrade to 10.4
- The solution to this error: upgrade the SolrNet.dll nuget package from 0.4.0.2002 to 1.0.19.0
- Upgrade Glass mapper Nuget packages to 10.4
- In V5 the Glassmapper configuration is modified from the V4 version, In this new version we have different types of services to get the content from Sitecore.
In 8.1 we will be using SitecoreContext to grab the content from Sitecore but in V5 we will be using the following to grab the content from Sitecore - RequestContext
- MvcContext
- WebFormsContext
- We will be using MvcContext in the Asp.net MVC application, for other like Class libraries we will use RequestContext
- GlassController is now not available in V5 Glass Mapper, so we will be using SitecoreController
- Update the Glass mapper model:
- Update the Glass mapper model proper which defined the attribute [SitecoreChildren(IsLazy = false)] in the previous Glass mapper version to the following in the Glass mapper V5 version to [SitecoreChildren]
Here, there is no need to explicitly mention that the model property is isLazy=false, it is by default in the V5 version of Glass Mapper.
We can even disable Lazy loading on the model while loading from the Glass mapper by the following configuration LazyDisabled() - We can have Infer Type in the attributes in V5 similar to V4 Glassmapper like [SitecoreChildren(InferType = true)]
Code way: - To set dependency injection for MvcContext in the Servicecollection for injecting into the constructor or other place
If we need to access the MvcContext in any method without constructor injection, like the one below,
_mvcContext = ServiceLocator.ServiceProvider.GetService(typeof(IMvcContext)) as IMvcContext;
- To Cast the object received from the Glass mapper to a particular model type will be done like below.
- In Sitecore 8.1 V4 Glassmapper
- SitecoreContext.Cast<CommonTextModel>(p.GetItem(), false, false)).ToList()
- In Sitecore 10.4 V5 Glass Mapper
- _mvcContext.SitecoreService.GetItem<CommonTextModel>(p.ItemId.Guid)
- Sometimes we will get the below error while casting the glass mapper model
Unable to cast object of type 'Castle.Proxies.ISitecoreItemProxy' to type
A solution to this error is to use the above way of casting in V5. - Or without a Glass mapper then use this below snippet
- Database db = Sitecore.Context.Database; var homeitem = Sitecore.Context.Item.GetHomeItem();
- From the below Fast Query:
- var query = string.Format("fast:{0}//*", homeitem.Paths.FullPath);
- To this Query:
- var query = string.Format("{0}//*",homeitem.Paths.FullPath); var detailList = new List<Item>(db.SelectItems(query));
- Link Manager: in Sitecore 8.1 we can form the Item URL link using UrlOptions but in Sitecore 10.4 we will be using ItemUrlBuilderOptions, This implementation did not come in Sitecore 10.4 it is available in the older version, for reference
- https://doc.sitecore.com/xp/en/developers/93/sitecore-experience-manager/build-item-and-media-urls.html#idp55744
Snippet for ItemUrlBuilderOptions - Media Manager: in Sitecore 8.1 we can form the Media item URL using MediaUrlOptions but in Sitecore 10.4 we will be using MediaUrlBuilderOptions, This implementation did not come in Sitecore 10.4 it is available in the older version, for reference
- https://doc.sitecore.com/xp/en/developers/93/sitecore-experience-manager/build-item-and-media-urls.html#idp55744
- Snippet for MediaUrlBuilderOptions
- Server Error page configuration (500) in Sitecore 8.1 will be done using the pipeline code below.
- <setting name="RequestErrors.UseServerSideRedirect">
- <patch:attribute name="value">true</patch:attribute>
- </setting>
- In Sitecore 10.4, we can use the errorPage property in the Sites node (image provided below) which will automatically take the page defined to the ErrorPage property and load the error page by getting the respective language content from Sitecore.
- The Page Not Found (400) page is loaded in Sitecore 8.1 through the pipeline, using the following class Sitecore.Pipelines.HttpRequest.ExecuteRequest but the same class will not work in Sitecore 10.4, This class is available in Sitecore.Kernel.dll
8.1 sample pipeline code - If we try to re-use the same function in Sitecore 10.4 then we will have the following error
- But in Sitecore 10.4, we can easily make the Page Not Found using the itemNotFoundUrl property in the sites node. The item path assigned to this property will automatically be loaded in the respective context language and the page will be loaded in UI if the user navigates to any page which is not available in Sitecore.
- Publishing Targets: if there is any extra publishing target added in Sitecore 8.1, we can use the below patch file in Sitecore 10.4 for the publishing target "preview"
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<eventing defaultprovider="sitecore">
<eventqueueprovider>
<eventqueue name="preview" patch:after="eventQueue[@name='web']" type="Sitecore.Data.Eventing.$(database)EventQueue, Sitecore.Kernel">
<param param1="$(name)" ref="dataApis/dataApi[@name='$(database)']" />
<param hint="" ref="PropertyStoreProvider/store[@name='$(name)']" />
</eventqueue>
</eventqueueprovider>
</eventing>
<propertystoreprovider>
<store getvaluewithoutprefix="true" name="preview" patch:after="store[@name='web']" prefix="web_secondary" singleinstance="true" type="Sitecore.Data.Properties.$(database)PropertyStore, Sitecore.Kernel">
<param param1="$(name)" ref="dataApis/dataApi[@name='$(database)']" />
<param resolve="true" type="Sitecore.Abstractions.BaseEventManager, Sitecore.Kernel" />
<param resolve="true" type="Sitecore.Abstractions.BaseCacheManager, Sitecore.Kernel" />
</store>
</propertystoreprovider>
<databases>
<!--preview-->
<database id="preview" patch:after="database[@id='web']" singleinstance="true" type="Sitecore.Data.DefaultDatabase, Sitecore.Kernel">
<param desc="name" />$(id)
<icon>Images/database_web.png</icon>
<securityenabled>true</securityenabled>
<dataproviders hint="list:AddDataProvider">
<dataprovider type="Sitecore.Data.DataProviders.CompositeDataProvider, Sitecore.Kernel">
<param desc="readOnlyDataProviders" hint="list" />
<protobufitems type="Sitecore.Data.DataProviders.ReadOnly.Protobuf.ProtobufDataProvider, Sitecore.Kernel">
<filepaths hint="list">
<filepath>$(dataFolder)/items/$(id)</filepath>
<modulesfilepath>/sitecore modules/items/$(id)</modulesfilepath>
</filepaths>
</protobufitems>
<param desc="headProvider" />
<dataprovider param1="$(id)" ref="dataProviders/main">
<disablegroup>publishing</disablegroup>
<prefetch hint="raw:AddPrefetch">
<sc .include="" file="/App_Config/Prefetch/Common.config">
<sc .include="" file="/App_Config/Prefetch/Webdb.config">
</sc></sc></prefetch>
</dataprovider>
</dataprovider>
</dataproviders>
<propertystore ref="PropertyStoreProvider/store[@name='$(id)']">
<remoteevents .eventqueue="">
<obj ref="eventing/eventQueueProvider/eventQueue[@name='$(id)']">
</obj></remoteevents>
<archives hint="raw:AddArchive">
<archive name="archive">
<archive name="recyclebin">
</archive></archive></archives>
<cachesizes hint="setting">
<data>100MB</data>
<items>50MB</items>
<paths>2500KB</paths>
<itempaths>50MB</itempaths>
<standardvalues>2500KB</standardvalues>
</cachesizes>
<blobstorage hint="raw:AddBlobStorage">
<providers default="classic">
<provider name="classic" type="Sitecore.Data.Blobs.ClassicSqlBlobProvider, Sitecore.Kernel">
<param desc="databaseName" />$(id)
</provider>
</providers>
</blobstorage>
</propertystore></database>
</databases>
</sitecore>
</configuration>
Comments
Post a Comment