From fe145a220b7d5e2002fa6667c67805d4789f7a71 Mon Sep 17 00:00:00 2001 From: Calvin Williams <40271790+sc-CalvinWilliams@users.noreply.github.com> Date: Mon, 7 Dec 2020 13:00:08 -0500 Subject: [PATCH] created patch --- .editorconfig | 5 + src/Sitecore.Support.409554.sln | 22 +++ .../zzz/Sitecore.Support.409554.config | 9 + .../Properties/AssemblyInfo.cs | 6 + .../PushCloneService.cs | 184 ++++++++++++++++++ .../Sitecore.Support.409554.csproj | 99 ++++++++++ src/Sitecore.Support.409554/packages.config | 6 + src/Sitecore.Support.409554/web.config | 4 + 8 files changed, 335 insertions(+) create mode 100644 .editorconfig create mode 100644 src/Sitecore.Support.409554.sln create mode 100644 src/Sitecore.Support.409554/App_Config/Include/zzz/Sitecore.Support.409554.config create mode 100644 src/Sitecore.Support.409554/Properties/AssemblyInfo.cs create mode 100644 src/Sitecore.Support.409554/PushCloneService.cs create mode 100644 src/Sitecore.Support.409554/Sitecore.Support.409554.csproj create mode 100644 src/Sitecore.Support.409554/packages.config create mode 100644 src/Sitecore.Support.409554/web.config diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..20f59eb --- /dev/null +++ b/.editorconfig @@ -0,0 +1,5 @@ +root = true + +[*.{cs,sln,csproj,config,xml}] +indent_size = 4 +indent_style = space diff --git a/src/Sitecore.Support.409554.sln b/src/Sitecore.Support.409554.sln new file mode 100644 index 0000000..930083f --- /dev/null +++ b/src/Sitecore.Support.409554.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25123.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{3C37EC03-5AB1-4191-8F87-CD4F923F90D6}") = "Sitecore.Support.409554", "Sitecore.Support.409554\Sitecore.Support.409554.csproj", "{584D9292-FD6F-4399-A116-0EF143823224}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {584D9292-FD6F-4399-A116-0EF143823224}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {584D9292-FD6F-4399-A116-0EF143823224}.Debug|Any CPU.Build.0 = Debug|Any CPU + {584D9292-FD6F-4399-A116-0EF143823224}.Release|Any CPU.ActiveCfg = Release|Any CPU + {584D9292-FD6F-4399-A116-0EF143823224}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/src/Sitecore.Support.409554/App_Config/Include/zzz/Sitecore.Support.409554.config b/src/Sitecore.Support.409554/App_Config/Include/zzz/Sitecore.Support.409554.config new file mode 100644 index 0000000..9d69552 --- /dev/null +++ b/src/Sitecore.Support.409554/App_Config/Include/zzz/Sitecore.Support.409554.config @@ -0,0 +1,9 @@ + + + + + Sitecore.Support.XA.Foundation.Multisite.Services.PushCloneService, Sitecore.Support.409554 + + + + \ No newline at end of file diff --git a/src/Sitecore.Support.409554/Properties/AssemblyInfo.cs b/src/Sitecore.Support.409554/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..f6657be --- /dev/null +++ b/src/Sitecore.Support.409554/Properties/AssemblyInfo.cs @@ -0,0 +1,6 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("Sitecore.Support.409554")] +[assembly: AssemblyProduct("Sitecore.Support.409554")] +[assembly: ComVisible(false)] diff --git a/src/Sitecore.Support.409554/PushCloneService.cs b/src/Sitecore.Support.409554/PushCloneService.cs new file mode 100644 index 0000000..3054a25 --- /dev/null +++ b/src/Sitecore.Support.409554/PushCloneService.cs @@ -0,0 +1,184 @@ +using System.Collections.Generic; +using System.Linq; +using Sitecore.Data.Comparers; +using Sitecore.Data.Items; +using Sitecore.Pipelines; +using Sitecore.XA.Foundation.Multisite.Pipelines.PushCloneChanges; +using Sitecore.XA.Foundation.Multisite.Services; + +namespace Sitecore.Support.XA.Foundation.Multisite.Services +{ + public class PushCloneService : IPushCloneService + { + private readonly IPushCloneCoordinatorService _coordinatorService; + + public PushCloneService(IPushCloneCoordinatorService pushCloneCoordinatorService) + { + _coordinatorService = pushCloneCoordinatorService; + } + + public void AddChild(Item item) + { + var parent = item.Parent; + + #region Support Fix 409554 + if (parent == null) + { + return; + } + #endregion + var clones = parent.GetClones(); + + foreach (var clone in clones) + { + if (!_coordinatorService.ShouldProcess(clone)) + { + continue; + } + + if (item.Versions.GetVersionNumbers().Length > 0) + { + var cloneItem = item.CloneTo(clone); + ProtectItem(cloneItem); + } + } + } + + public void Move(Item item) + { + if (item.Parent.HasClones) + { + var parentClones = GetCloneItem(item.Parent); + foreach (var parentClone in parentClones.ToList()) + { + if (!_coordinatorService.ShouldProcess(parentClone)) + { + return; + } + + var clones = GetCloneItem(item); + foreach (var clone in clones) + { + if (parentClone.Paths.FullPath.Contains(clone.Paths.FullPath) || clone.Paths.FullPath.Contains(parentClone.Paths.FullPath)) + { + clone.MoveTo(parentClone); + } + } + } + } + } + + public void Remove(Item item) + { + var clones = item.GetClones(); + foreach (var clone in clones) + { + if (_coordinatorService.ShouldProcess(clone)) + { + clone.Delete(); + } + } + } + + public void SaveClone(Item item, ItemChanges changes) + { + var clones = GetCloneItem(item); + foreach (var clone in clones) + { + if (!_coordinatorService.ShouldProcess(clone)) + { + return; + } + + var args = new PushCloneChangesArgs() + { + Item = item, + Changes = changes, + Clone = clone + }; + + CorePipeline.Run("pushCloneChanges", args); + } + } + + public void AddVersion(Item item) + { + var parent = item.Parent; + #region Support Fix 409554 + + if (parent == null) + { + return; + } + if (item.Versions.Count == 0) + { + return; + } + #endregion + var latest = item.Versions.GetLatestVersion(); + var versionUri = latest.Uri; + var clones = GetCloneItem(latest); + var enumerable = clones as IList ?? clones.ToList(); + if (!enumerable.Any() && parent.HasClones) + { + var parentClones = GetCloneItem(parent); + foreach (var parentClone in parentClones) + { + if (!_coordinatorService.ShouldProcess(parentClone)) + { + continue; + } + + var cloneItem = item.CloneTo(parentClone); + CopyWorkflow(item, cloneItem); + ProtectItem(cloneItem); + } + } + else + { + foreach (var clone in enumerable) + { + if (!_coordinatorService.ShouldProcess(clone)) + { + continue; + } + + var versionedClone = clone.Database.GetItem(clone.ID, latest.Language); + using (new SecurityModel.SecurityDisabler()) + { + var newVersion = versionedClone.Versions.AddVersion(); + newVersion.Editing.BeginEdit(); + newVersion[FieldIDs.Source] = versionUri.ToString(); + newVersion[FieldIDs.SourceItem] = versionUri.ToString(false); + newVersion.Editing.EndEdit(); + } + } + } + } + + protected virtual void CopyWorkflow(Item source, Item target) + { + var item = source.Database.GetItem(source.ID); + target.Editing.BeginEdit(); + target[FieldIDs.Workflow] = item[FieldIDs.Workflow]; + target[FieldIDs.WorkflowState] = item[FieldIDs.WorkflowState]; + target.Editing.EndEdit(); + } + + protected virtual void ProtectItem(Item item) + { + item.Editing.BeginEdit(); + item.Appearance.ReadOnly = true; + item.Editing.EndEdit(); + } + + protected virtual IEnumerable GetCloneItem(Item item) + { + return item.GetClones().Distinct(new ItemIdComparer()); + } + + public void RemoveVersion(Item commandItem) + { + } + } +} \ No newline at end of file diff --git a/src/Sitecore.Support.409554/Sitecore.Support.409554.csproj b/src/Sitecore.Support.409554/Sitecore.Support.409554.csproj new file mode 100644 index 0000000..c860e22 --- /dev/null +++ b/src/Sitecore.Support.409554/Sitecore.Support.409554.csproj @@ -0,0 +1,99 @@ + + + + + Debug + AnyCPU + + + 2.0 + {584D9292-FD6F-4399-A116-0EF143823224} + {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} + Library + Properties + Sitecore.Support + Sitecore.Support.409554 + v4.6.2 + true + + + + + + + 6 + + + + false + none + false + bin\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\ + TRACE + prompt + 4 + + + + ..\packages\SC.Sitecore.Kernel.9.0.2\lib\Sitecore.Kernel.dll + False + + + ..\packages\SXA90.Sitecore.XA.Foundation.Common.1.8.0\lib\Sitecore.XA.Foundation.Common.dll + False + + + ..\packages\SXA90.Sitecore.XA.Foundation.Multisite.1.8.0\lib\Sitecore.XA.Foundation.Multisite.dll + False + + + + + + + + + + + + + + + + + + + + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + + + + + + True + True + 0 + / + http://localhost:50707/ + False + False + + + False + + + + + \ No newline at end of file diff --git a/src/Sitecore.Support.409554/packages.config b/src/Sitecore.Support.409554/packages.config new file mode 100644 index 0000000..3e61e79 --- /dev/null +++ b/src/Sitecore.Support.409554/packages.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/Sitecore.Support.409554/web.config b/src/Sitecore.Support.409554/web.config new file mode 100644 index 0000000..7e1d425 --- /dev/null +++ b/src/Sitecore.Support.409554/web.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file