Skip to main content

Posts

Solr Service in Paused State during Sitecore installation

 The Problem I was working on Sitecore installation on a new machine. Everything was running smooth but the SOLR service always ended up in PAUSED state.  The Research I tried stopping the service and then starting it using NSSM multiple times but it did not help. Then I thought of removing and recreating the service but again no help. And then it was followed by a machine restart and the service still ended up in PAUSED state.  I started googling about this issue and found answers suggesting that may be JAVA_HOME environment variable is not set or may be JAVA is not installed. I opened my command prompt to execute  echo %java_home% to get value for JAVA_HOME environment variable and it returned a blank value. This proved there is definitely an issue with JAVA setup on my new machine. Next,  I executed  java -version in cmd prompt and I found that the new machine is using Microsoft build of openJDK   instead of JRE (snapshot below) It was found that new machine is using openJDK because

Sitecore PowerShell script to update Allowed Controls field in placeholder settings

The Problem We created a new module (or component or rendering) in Sitecore and we needed to add this rendering to Allowed Controls field in the placeholder settings in Sitecore. It is also required to allow this rendering on all the placeholders in Sitecore so that content authors have the ability to add this rendering on pages in experience editor. Below is a snapshot of the field that is used for this- If the placeholders were in limited number, it would have been an easy manual job. But we had more than 20 placeholders for different page types. And we were in a process of introducing several new modules which meant this task is going to be repetitive and time consuming. So, to save time and for accuracy, we decided that we should develop a simple PowerShell script to make this process simple. The Solution We developed below script -  $placeholders = Get-ChildItem "/sitecore/layout/Placeholder Settings/<path where your placeholders are present>" -recurse Foreach($pla

Sitecore Content Serialization error - The container is defined twice

The Problem If you use Sitecore Content Serialization to serialize your Sitecore items into yml files (and if you use Leprechaun to generate/update item models automatically in our solution), there are chances you may stumble upon the error as in the snapshot below -  The Solution If you have used Sitecore Content Serialization, then you will know that it makes use of a module.json file in which you specify details about what items to serialize. It usually looks something like this -  {   "namespace": "Feature.Sample",   "items": {     "includes": [       {         "name": "templates",         "path": "/sitecore/templates/Feature/Sample"       },       {         "name": "renderings",         "path": "/sitecore/layout/Renderings/Feature/Sample"       },       {         "name": "buttons",         "database": "core",         "

Publishing Service Failed: Could not resolve stores 'web' of type source

Problem While trying to publish an item using Sitecore Publishing Service, the publish job shows status as Failed (check snapshot below) and when user clicks on it to get more details, it says -  Could not resolve stores 'web' of type source Solution We checked the logs and it said -  2023-10-09 09:31:32.560 -04:00 [Error] Error during publish of 443f1620-188b-4f39-a9c8-ef284d9a6c6b - Error: "Could not resolve stores web of type source" System.Exception: Could not resolve stores web of type source at Sitecore.Framework.Publishing.Data.DefaultStoreFactory.CreateSources(DataAccessContextType dataAccessContext, String[] names) at Sitecore.Framework.Publishing.PublishContext..ctor(IStoreFactory storeFactory, PublishOptions publishOptions, Guid jobId, DateTime started) at Sitecore.Framework.Publishing.PublishContextFactory.Create(IStoreFactory storeFactory, PublishOptions publishOptions, Guid jobId, DateTime started) at Sitecore.Framework.Publishing.Tasks.Publi

String Interning in Sitecore

I am always looking at different ways of optimizing application resources in Sitecore. After all, low resources means low cost!! I came across the concept of String Interning and I got interested into it. Next, I was thinking how can I make use of it in my Sitecore instances. I started digging little bit and I found Sitecore is smart enough to already make use of it. I will share some of the findings in this post. What is String Interning?  In computer science, string interning is a method of storing only one copy of each distinct string value, which must be immutable.  What this means is if you have a string object str1 with value "Hello" and then if your code initializes another string object str2 with same value "Hello", string interning will prevent creation of second object for str2 as String Constants Pool already has a string object with same value. It will assign the reference of str1 to str2 and str2 will reuse the object that was created for str1. This obv

Sitecore CD servers triggering index update jobs?

The Problem Recently, I was checking my CD server logs for an issue that was reported and stumbled across some log entries which mentioned about index update jobs getting triggered as in snapshot below- This made me think that should these jobs actually get triggered from CDs?? The answer is NO!  Why?? Because web indexes already get updated from CM servers during item publish events etc. (if the indexes are already maintained by the CM instance). Doing the same from CD servers is redundant and increasing unwanted load of index update jobs on CD servers. Also, CD servers are only supposed to READ from indexes and not WRITE to them (in most cases) Then why are these jobs getting created? I started looking into my index configurations on CD servers and from what I could see, all the web indexes in our case on the CD instances are configured with  "onPublishEndAsync", "remoteRebuild" or "rebuildAfterFullPublish" strategies. As per Sitecore best practice, if

Script to read contents of media files attached to Sitecore media library items

Ever wondered how can we read contents of files uploaded to media library without rendering them? Recently, we needed a PowerShell script to read the content of our SVGs and create a list of SVGs which contained a pattern in them. After a little research, I came up with this script -  $item =Get-Item -Path "/sitecore/media library/<filepath here>" $mediaItem = New-Object 'Sitecore.Data.Items.MediaItem' $item; $blobField = $mediaItem.InnerItem.Fields["blob"] if($blobField){         $blobStream = $blobField.GetBlobStream()         if($blobStream){             try                 {                 $contents = New-Object byte[] $blobStream.Length                 $blobStream.Read($contents, 0, $blobStream.Length) | Out-Null             }              finally              {                     $blobStream.Close()                 }             $fileText = ([System.Text.Encoding]::Default.GetString($contents))         } } In the above script, $fileText will co