Monday, September 13, 2021

Sitecore 10 - Fix for deleted child items remain in the web database.

While working on the current project (Sitecore 10) with SXA, We have noticed that when we deleted a child item of the composite component ( like an accordion).

We also raised the Sitecore ticket and came to know a few suggestions like 

Option 1 

You can modify the RemoveUnknownChildren processor in publishItem pipeline to always check for deleted item by removing this line:

if (!ShouldProcess(context))

{

return;

}

Note that this might incur higher overhead for the publishing process.

Option 2

If editing the code is not feasible, you can first publish the pages with "publish related items" and "publish subitems" settings to publish the media items and data source items. Next, you need to publish the page and the Data item under the Site with "publish subitems" setting only to remove the deleted item from target database.

Please try these workaround and let me know if you need further assistance. Thank you.

As this is a critical functionality, here is the fix for this issue.



Create a patch file -


<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">

    <sitecore>

        <pipelines>

            <publishItem help="Processors should derive from Sitecore.Publishing.Pipelines.PublishItem.PublishItemProcessor">

                    <processor type= "CustomSolution.Project.SitecoreFix_Sitecore.Publishing.Pipelines.PublishItem.RemoveUnknownChildren, CustomSolution.Project.SitecoreFix_Sitecore" patch:instead="processor[@type='Sitecore.Publishing.Pipelines.PublishItem.RemoveUnknownChildren, Sitecore.Kernel']"/>

                </publishItem>

        </pipelines>

    </sitecore>

</configuration>

 and add a class 

using Sitecore.Data;

using Sitecore.Data.Items;

using Sitecore.Diagnostics;

using Sitecore.Publishing;

using Sitecore.Publishing.Pipelines.Publish;

using Sitecore.Publishing.Pipelines.PublishItem;


namespace CustomSolution.Project.SitecoreFix_Sitecore.Publishing.Pipelines.PublishItem

{

    public class RemoveUnknownChildren : PublishItemProcessor

    {

        public override void Process(PublishItemContext context)

        {

            Assert.ArgumentNotNull(context, nameof(context));

            Assert.IsNotNull(context.PublishContext, "context.PublishContext");

            foreach (ID unknownChildId in context.PublishHelper.GetUnknownChildIds(context.ItemId))

            {

                PublishingCandidate publishingCandidate = new PublishingCandidate(unknownChildId, context.PublishOptions)

                {

                    PublishAction = PublishAction.DeleteTargetItem

                };

                Item obj = context.PublishOptions.TargetDatabase.GetItem(unknownChildId);

                if (obj != null)

                {

                    publishingCandidate.ItemName = obj.Name;

                    publishingCandidate.ItemUri = obj.Uri;

                }

                context.PublishContext.DeleteCandidates.Enqueue(publishingCandidate);

            }

        }

    }

}

that will fix the issue and will not see any pending deleted items in the web DB.

No comments:

Post a Comment