Friday, March 28, 2025

Setup Sitecore Serialization SCS

Are you looking to setup SCS on Sitecore 10.4 version in 5-10 minutes on your local Sitecore CM instance? then you have come to the right place. I promise I will keep the setup & configuration, quick, simple & straight forward to the point. 

 STEPS 
  • Install Sitecore Management Service package on Sitecore 10.4 CM instance
  • Open Visual Studio 2022 with Admin privileges and install Sitecore.CLI package via package console terminal
    • Execute: install sitecore.CLI
    • Execute: dotnet sitecore init
  • The above command will add few JSON files to your project solution under “.sitecore” folder
    • RootConfigurationFile.schema.json
    • UserConfiguration.schema.json
    • ModuleFile.schema.json
  • It also adds sitecore.json file to the project solution which needs to be updated
    • [Optional] Disable TelemetryEnable in sitecore.json file (set the flag to false) 
    • Update the path of Modules section in sitecore.json as shown below (I wanted to have all my serialization in single project so i went with current project folder path "./*.module.json")


  • You must create a module.json file under the project solution and configure the item structure as shown below (if you prefer to create the module.json in different location then you can do so but make sure to update the path in the sitecore.json)
    • E.g. MedicalOneProject.module.json
  • Add the item structure in the module.json file as shown below 


  • Execute the command to connect the CLI to an existing Sitecore CM instance
    • sitecore login --authority https://<Identity Server Hostname> --cm https://<CM Hostname> --allow-write true --client-credentials true --client-id Device
  • This will open a Sitecore CM instance in the browser to login
    • Execute: sitecore ser pull -v (This command will pull the item(s) into project solution)


  • Properties for JSON file:
    • name : Unique name for serialization
    • path : Path of the item to serialize
    • scope : Define what content to serialize
      • SingleItem: Only the item specified from the Path
      • ItemAndChildren: Item specified in path with immediate children
      • ItemAndDescendants: Item specified in path including all the descendant items
      • DescendantsOnly: Only the descendent items specified form the path
      • Ignored: All children and descendants will be ignored, unless in previously matched.
      • database : Selected database to sync. 
        • This can be “master” or “core”
      • maxRelativePathLength : Specify how long the path may be, 
        • by default this is 130 characters
        • If the length has been reached it will create a new hashed folder in the root of the directory
      • allowedPushOperations : Define how content can be serialized
        • CreateOnly: This will only create the item, if it already exists it will be ignored.
        • CreateAndUpdate: Creating and updating items. If it already exists but is modified, it will update the item. This setting will not remove items.
        • CreateUpdateAndDelete: Items will be created, updated and removed
 
Serialization Commands: 
    • sitecore ser pull (pull items from sitecore) 
    • sitecore ser push (push all the items into sitecore) 
    • sitecore ser push -w (What if mode is active. No changes will be made.)



Note: Following error is thrown when you do not install Sitecore Management Service on Sitecore CM

Instance. [CheckGraphQLAvailabilityException] Make sure the GraphQL service is installed and available. [GraphQLHttpException] Unexpected HttpResponseMessage with code: Redirect

Other reference:

Configuration to include, exclude items refer Sitecore Documentation

Command to Create a Sitecore package: sitecore ser pkg create -o “package name” 

Those who wants to leverage the TDS license and looking for GUI serialization solution then they can install Sitecore for Visual Studio and configure it. Sitecore documentation

“What do you think about Sitecore CLI? Let me know in the comments below!”


Friday, March 26, 2021

Un-Clone Sitecore Items

Other day I got a request to un-clone 100+ Sitecore items. Doing it manually through Content Editor is not a feasible option. so I thought of putting together a PowerShell script which can un-clone Sitecore items.


[Reflection.Assembly]::LoadFile("< wwwroot Directory>\Sitecore.Kernel.dll")
$root = Get-Item -Path "master:/sitecore/content/Home"
$props = @{
Parameters = @(@{Name="root"; Title="Choose the root"; Tooltip="Only items from this root will be returned."; } )
    Title = "Clone Item Comparison Report"
    Description = "Choose the root node."
    Width = 550
    Height = 300
    ShowHints = $true
Icon=[regex]::Replace($PSScript.Appearance.Icon,"Office","OfficeWhite", [System.Text.RegularExpressions.RegexOptions]::IgnoreCase)
}
$result = Read-Variable @props
if($result -eq "cancel") {
    exit
}
$clonedItems=Get-ChildItem -Path $root.FullPath -Recurse
$CloneCollection = New-Object System.Collections.ArrayList
write-host 'start un-cloning the items...'
foreach($clonedItem in $clonedItems){  
    if($clonedItem.IsClone){ 
        $ClonedProperties = [PSCustomObject] @{
ItemId = $clonedItem.ID;
ClonedItemName=$clonedItem.Name;
FullPath = $clonedItem.FullPath;
Source = $clonedItem."__Source";
SourceItem = $clonedItem."__Source Item";
}
        $CloneCollection.Add($ClonedProperties) 
$clonedItem.Editing.BeginEdit()
        $itemUnClone = New-Object Sitecore.Data.Items.CloneItem($clonedItem)
        $itemUnClone.Unclone()
$clonedItem.Editing.EndEdit()
    }
}
write-host 'Generate clone comparison report'
if($CloneCollection.Count -ne 0){
$CloneCollection | Show-ListView -Property ItemId, ClonedItemName, FullPath, Source, SourceItem
}
write-host ' done!'



Disclaimer : Don't run this script on Production without validating it on Dev/Test.

Happy coding.

Thursday, November 21, 2019

Optimize Sitecore Performance


Sitecore Optimization

Let's separate out optimization into two categories 
Content Management (CM)
Content Delivery  (CD)

Alright let's talk about CM optimization that being said there are different ways to optimize content management server first let's talk about a setting called disable cache size limits in Sitecore

File Path : <Sitecore Web root>/App_Config/Sitecore.config

<setting name="Caching.DisableCacheSizeLimits" value="true"/>

If true, Sitecore does not limit cache size growth and ignores any maximum cache sizes specified in the web.config file. Enabling this setting can improve the application's performance in 64-bit environments by allowing Sitecore to take full advantage of the available memory. After setting this value to true, monitor the system at regular intervals, as this configuration can cause Sitecore to consume too much memory and cause Out Of Memory errors.

Note: It is only recommended to set the setting to true in 64-bit environments.
You can keep track of live cache statistics https://your.sitecore.website/sitecore/admin/cache.aspx

Enable IIS HTTP keep-alive

Enabling the HTTP keep-alive reduces the number of connections required to be opened. If the HTTP keep-alive is disabled, a new connection is made for every requested object on a web page.
To enable the HTTP keep-alive:
  1. Launch IIS Manager.
  2. Navigate to the site that you wish to enable the HTTP keep-alive.
  3. Double click the HTTP Response Headers (located in the IIS grouping).
  4. In the Actions panel, click Set common headers...
  5. Select Enable HTTP keep-alive.
  6. Click OK


Memory monitor & Health monitor

Sitecore recommends disabling the Memory Monitor in production environments, and only enabling it for troubleshooting memory related issues.
<hook type="Sitecore.Diagnostics.HealthMonitorHook, Sitecore.Kernel"/>
<hook type="Sitecore.Diagnostics.MemoryMonitorHook, Sitecore.Kernel">
<param desc="Threshold">6GB</param>
<param desc="Check interval">00:00:05</param>
<param desc="Minimum time between log entries">00:01:00</param>
<ClearCaches>false</ClearCaches>
<GarbageCollect>false</GarbageCollect>
<AdjustLoadFactor>false</AdjustLoadFactor>
</hook>

Note: Disabling Item Caching has a significant negative impact on performance

<setting name=”Caching.ItemCachingEnabled” value=”true”/> (enabled by default)

Optimize Sitecore Tree

Administrators should take into account that performance degrades as the number of items under any item increases. Usability is also affected. As a general precaution, no item should be the parent of more than 100 other items. Make use of bucketed items.

If a company has a thousand users who access the site or more, architects should group users such as by location, by office, by department, by team, by first letter(s) of login name or other criteria to support a limited number of users under each folder in user manager.

Optimize Sitecore Cache

     Client Data Store cache
          Security caches
     Viewstate cache (not sure how this goes with MVC)
          Registry cache
          XSL caches
          Prefetch caches (Sitecore loads Prefetch caches during application initialization)
o   First caching layer between the application & database
o   Prefetch contains data from single provider
o   Loading too much data into Prefetch can adversely affect
Note: recycling of IIS clears all the Sitecore cache except media cache (media uses file system)


----- Stay tune for rest of the content -----

Wednesday, November 15, 2017

Create Custom Commands

Custom Command in 4 simple steps


  1. Create a class by inheriting (Sitecore.Shell.Framework.Commands.Command)
    • Implement Execute method --> Public override void Execute(CommandContext context) { SheerResponse.Alert("Hello from Custom Command"); }
    • Implement QueryState method (this method is optional based on the need) -->Public override CommandState QueryState(CommandContext context) { return context.Items[0].Children.Count == 0 ? CommandState.Hidden : base.QueryState(context); }
  2. Adding Following config tag in Commands.config located under (Sitecore/website/App_Config)
    • <command name=”item:[class name in all lower case letters]” type=”[fully qualified namesspace.classname, namespace]”/>
  3. Go to Sitecore Desktop and switch to “CORE” database
    • Select “Sitecore/Content/Applications/Content Editor/Context Menus/Default”
    • Create a new menu item
    • fill in the item fields --> Display name, Icon, Message = item:classname(id=$Target)
    • Save the changes and switch to “MASTER” database
  4. Right Click on any Sitecore item to notice newly added menu item

Setup Sitecore Serialization SCS

Are you looking to setup SCS on Sitecore 10.4 version in 5-10 minutes on your local Sitecore CM instance? then you have come to the right pl...