diff --git a/ContentMigrator/ContentMigrationController.cs b/ContentMigrator/ContentMigrationController.cs index 531084b..a677a9a 100644 --- a/ContentMigrator/ContentMigrationController.cs +++ b/ContentMigrator/ContentMigrationController.cs @@ -84,8 +84,8 @@ public ActionResult GetItemYamlWithChildren(RevisionModel data) using (new SecurityDisabler()) { - IItemData item = _sitecore.GetItemData(guid); - var localRev = _sitecore.GetItemAndChildrenRevision(guid); + IItemData item = _sitecore.GetItemData(guid, data.Database); + var localRev = _sitecore.GetItemAndChildrenRevision(guid, data.Database); List GrandChildren = new List(); var items = new List>(); if (data.Rev == null || !data.Rev.ContainsKey(item.Id) || data.Rev[item.Id] != localRev[item.Id]) @@ -229,8 +229,8 @@ public ActionResult BuildDiff(DiffRequestModel model) { using (new SecurityDisabler()) { - CompareContentTreeNode ret = new CompareContentTreeNode(_sitecore.GetItemData(model.Id), false); - ret.BuildDiff(model.Server); + CompareContentTreeNode ret = new CompareContentTreeNode(_sitecore.GetItemData(model.Id, model.Database), false); + ret.BuildDiff(model.Database, model.Server); return ScsJson(ret); } } @@ -386,7 +386,7 @@ private CompareContentTreeNode GetContentTree(ContentTreeModel data) return null; } - return data.Id == "" ? ContentMigrationRegistration.Root : new CompareContentTreeNode(_sitecore.GetItemData(data.Id)); + return data.Id == "" ? ContentMigrationRegistration.Root : new CompareContentTreeNode(_sitecore.GetItemData(data.Id, data.Database)); } } } diff --git a/ContentMigrator/Core/ContentItemInstaller.cs b/ContentMigrator/Core/ContentItemInstaller.cs index f450694..16fddb0 100644 --- a/ContentMigrator/Core/ContentItemInstaller.cs +++ b/ContentMigrator/Core/ContentItemInstaller.cs @@ -161,7 +161,7 @@ private void ItemCreator(PullItemModel args, CancellationToken cancellationToken try { - var context = bulkLoader.NewBulkLoadContext("master"); + var context = bulkLoader.NewBulkLoadContext(args.Database); bulkLoader.LoadItems(context, GetAllItemsToCreate(context, cancellationToken)); _checksumManager.RegenerateChecksum(); } @@ -206,7 +206,7 @@ private void ItemInstaller(PullItemModel args, BlockingCollection ite CurrentlyProcessing.Add(remoteData.Id); } - IItemData localData = _sitecore.GetItemData(remoteData.Id); + IItemData localData = _sitecore.GetItemData(remoteData.Id, args.Database); ProcessItem(args, localData, remoteData); diff --git a/ContentMigrator/Core/ContentItemPuller.cs b/ContentMigrator/Core/ContentItemPuller.cs index 856c73d..710c8db 100644 --- a/ContentMigrator/Core/ContentItemPuller.cs +++ b/ContentMigrator/Core/ContentItemPuller.cs @@ -41,8 +41,8 @@ public ContentItemPuller(int maxQueue) public bool Completed { get; private set; } - public void StartGatheringItems(IEnumerable rootIds, int threads, bool getChildren, string server, CancellationToken cancellationToken, bool ignoreRevId) - { + public void StartGatheringItems(IEnumerable rootIds, string database, int threads, bool getChildren, string server, CancellationToken cancellationToken, bool ignoreRevId) + { foreach (Guid id in rootIds) { ProcessingIds.Add(id); @@ -51,12 +51,12 @@ public void StartGatheringItems(IEnumerable rootIds, int threads, bool get { Task.Run(async () => { - await GatherItems(getChildren, server, cancellationToken, ignoreRevId); + await GatherItems(getChildren, database, server, cancellationToken, ignoreRevId); }); } } - internal async Task GatherItems(bool getChildren, string server, CancellationToken cancellationToken, bool ignoreRevId) + internal async Task GatherItems(bool getChildren, string database, string server, CancellationToken cancellationToken, bool ignoreRevId) { ChildrenItemDataModel buffer = null; while (!Completed) @@ -73,10 +73,12 @@ internal async Task GatherItems(bool getChildren, string server, CancellationTok break; } lock (_locker) + { _processing++; + } if (buffer == null) { - buffer = _remoteContent.GetRemoteItemDataWithChildren(id, server, ignoreRevId ? null : _sitecore.GetItemAndChildrenRevision(id)); + buffer = _remoteContent.GetRemoteItemDataWithChildren(id, database, server, ignoreRevId ? null : _sitecore.GetItemAndChildrenRevision(id, database)); } foreach (var item in (getChildren ? buffer.Items : buffer.Items.Where(x => x.Key == id))) @@ -88,7 +90,7 @@ internal async Task GatherItems(bool getChildren, string server, CancellationTok } else { - GatheredRemoteItems.Add(_sitecore.GetItemData(item.Key), cancellationToken); + GatheredRemoteItems.Add(_sitecore.GetItemData(item.Key, database), cancellationToken); } } if (getChildren && buffer.GrandChildren != null) diff --git a/ContentMigrator/Core/ContentMigration.cs b/ContentMigrator/Core/ContentMigration.cs index a4d5eef..a83a92f 100644 --- a/ContentMigrator/Core/ContentMigration.cs +++ b/ContentMigrator/Core/ContentMigration.cs @@ -35,15 +35,15 @@ public void StartContentMigration(PullItemModel model) _model = model; if (model.PullParent) { - foreach (var id in model.Ids.Select(Guid.Parse).Where(x => _sitecoreAccess.GetItemData(x) == null)) + foreach (var id in model.Ids.Select(Guid.Parse).Where(x => _sitecoreAccess.GetItemData(x, model.Database) == null)) { - var item = _remoteContent.GetRemoteItemData(id, model.Server); - var parent = _sitecoreAccess.GetItemData(item.ParentId); + var item = _remoteContent.GetRemoteItemData(id, model.Database, model.Server); + var parent = _sitecoreAccess.GetItemData(item.ParentId, model.Database); while (parent == null) { - item = _remoteContent.GetRemoteItemData(item.ParentId, model.Server); + item = _remoteContent.GetRemoteItemData(item.ParentId, model.Database, model.Server); _puller.ItemsToInstall.Add(item); - parent = _sitecoreAccess.GetItemData(item.ParentId); + parent = _sitecoreAccess.GetItemData(item.ParentId, model.Database); } } } @@ -53,7 +53,7 @@ public void StartContentMigration(PullItemModel model) { _installer.SetupTrackerForUnwantedLocalItems(model.Ids.Select(Guid.Parse)); } - _puller.StartGatheringItems(model.Ids.Select(Guid.Parse), _registration.GetScsRegistration()?.RemoteThreads ?? 1, model.Children, model.Server, _cancellation.Token, model.IgnoreRevId); + _puller.StartGatheringItems(model.Ids.Select(Guid.Parse), model.Database, _registration.GetScsRegistration()?.RemoteThreads ?? 1, model.Children, model.Server, _cancellation.Token, model.IgnoreRevId); _installer.StartInstallingItems(model, _puller.ItemsToInstall, _registration.GetScsRegistration()?.WriterThreads ?? 1, _cancellation.Token); }); } diff --git a/ContentMigrator/Core/Interface/IContentItemPuller.cs b/ContentMigrator/Core/Interface/IContentItemPuller.cs index a37df3b..b664816 100644 --- a/ContentMigrator/Core/Interface/IContentItemPuller.cs +++ b/ContentMigrator/Core/Interface/IContentItemPuller.cs @@ -9,7 +9,7 @@ namespace Sidekick.ContentMigrator.Core.Interface public interface IContentItemPuller { bool Completed { get; } - void StartGatheringItems(IEnumerable rootIds, int threads, bool getChildren, string server, CancellationToken cancellationToken, bool ignoreRevId); + void StartGatheringItems(IEnumerable rootIds, string database, int threads, bool getChildren, string server, CancellationToken cancellationToken, bool ignoreRevId); BlockingCollection ItemsToInstall { get; } } } diff --git a/ContentMigrator/Data/CompareContentTreeNode.cs b/ContentMigrator/Data/CompareContentTreeNode.cs index 1cd2658..8f3400b 100644 --- a/ContentMigrator/Data/CompareContentTreeNode.cs +++ b/ContentMigrator/Data/CompareContentTreeNode.cs @@ -70,14 +70,14 @@ private bool AreFieldsEqual(Field local, IItemFieldValue remote) return false; } - public void BuildDiff(string server) + public void BuildDiff(string server, string database) { Compare = new Dictionary>>(); IItemData itemData = null; - itemData = Bootstrap.Container.Resolve().GetRemoteItemData(Guid.Parse(Id), server); + itemData = Bootstrap.Container.Resolve().GetRemoteItemData(Guid.Parse(Id), database, server); using (new SecurityDisabler()) { - var localItem = Factory.GetDatabase("master", true).DataManager.DataEngine.GetItem(new ID(Id), LanguageManager.DefaultLanguage, Sitecore.Data.Version.Latest); + var localItem = Factory.GetDatabase(database, true).DataManager.DataEngine.GetItem(new ID(Id), LanguageManager.DefaultLanguage, Sitecore.Data.Version.Latest); localItem.Fields.ReadAll(); foreach (var chk in itemData.SharedFields) { diff --git a/ContentMigrator/Models/DiffRequestModel.cs b/ContentMigrator/Models/DiffRequestModel.cs index ca109a5..5a63906 100644 --- a/ContentMigrator/Models/DiffRequestModel.cs +++ b/ContentMigrator/Models/DiffRequestModel.cs @@ -9,6 +9,7 @@ namespace Sidekick.ContentMigrator.Models public class DiffRequestModel { public string Id; + public string Database; public string Server; } } diff --git a/ContentMigrator/Models/RevisionModel.cs b/ContentMigrator/Models/RevisionModel.cs index cfbf61c..16ca7b0 100644 --- a/ContentMigrator/Models/RevisionModel.cs +++ b/ContentMigrator/Models/RevisionModel.cs @@ -9,6 +9,7 @@ namespace Sidekick.ContentMigrator.Models public class RevisionModel { public string Id; + public string Database; public Dictionary Rev; } } diff --git a/ContentMigrator/Resources/cmcontenttreecontroller.js b/ContentMigrator/Resources/cmcontenttreecontroller.js index 8216469..6c82b66 100644 --- a/ContentMigrator/Resources/cmcontenttreecontroller.js +++ b/ContentMigrator/Resources/cmcontenttreecontroller.js @@ -15,7 +15,7 @@ vm.buildDiff = function(status, id, events) { if (status !== "cmfieldchanged") return; - CMfactory.getDiff(id, vm.server).then(function(response) { + CMfactory.getDiff(id, vm.db, vm.server).then(function(response) { events.lastClicked = response.data; events.diff = id; vm.setupCompare(events.lastClicked.Compare, events.showAll, events); @@ -42,6 +42,7 @@ $scope.init = function (nodeId, selectedId, events, server, database) { vm.events = events; vm.data = nodeId; + vm.db = database; vm.loading = true; if (typeof(nodeId) === "object") vm.data.loading = true; diff --git a/ContentMigrator/Resources/cmfactory.js b/ContentMigrator/Resources/cmfactory.js index 75b1138..18c4263 100644 --- a/ContentMigrator/Resources/cmfactory.js +++ b/ContentMigrator/Resources/cmfactory.js @@ -45,8 +45,8 @@ queuedItems: function (operationId) { return $http.post("/scs/cm/cmqueuelength.scsvc", "'" + operationId + "'"); }, - getDiff: function (id, server) { - var data = { "id": id, "server": server }; + getDiff: function (id, database, server) { + var data = { "id": id, "server": server, "database": database }; return $http.post("/scs/cm/cmbuilddiff.scsvc", data); }, getPresets: function (server) { diff --git a/ContentMigrator/Resources/cmmastercontroller.js b/ContentMigrator/Resources/cmmastercontroller.js index ef12060..8ab2c63 100644 --- a/ContentMigrator/Resources/cmmastercontroller.js +++ b/ContentMigrator/Resources/cmmastercontroller.js @@ -63,7 +63,7 @@ vm.events.selected.splice(index, 1); vm.events.selectedIds.splice(index, 1); } - ScsFactory.contentTreeSelectedRelated(vm.events.selectedIds, vm.server).then(function (response) { + ScsFactory.contentTreeSelectedRelated(vm.events.selectedIds, vm.server, val.DatabaseName).then(function (response) { vm.events.relatedIds = response.data; }); } diff --git a/ContentMigrator/Services/ContentMigrationManagerService.cs b/ContentMigrator/Services/ContentMigrationManagerService.cs index 4075320..08e7e23 100644 --- a/ContentMigrator/Services/ContentMigrationManagerService.cs +++ b/ContentMigrator/Services/ContentMigrationManagerService.cs @@ -20,7 +20,7 @@ public class ContentMigrationManagerService : IContentMigrationManagerService private readonly Dictionary _migrations = new Dictionary(); public ContentMigration StartContentMigration(PullItemModel model) { - Log.Info($"Starting Content Migration...\n{model.Server}\n{string.Join(", ", model.Ids)}", this); + Log.Info($"Starting Content Migration...\n{model.Server}\n{string.Join(", ", model.Ids)}\n{model.Database}", this); string id = Guid.NewGuid().ToString(); ContentMigration newMigration = new ContentMigration(); newMigration.Status.OperationId = id; diff --git a/ContentMigrator/Services/Interface/IRemoteContentService.cs b/ContentMigrator/Services/Interface/IRemoteContentService.cs index 4d53047..94838fb 100644 --- a/ContentMigrator/Services/Interface/IRemoteContentService.cs +++ b/ContentMigrator/Services/Interface/IRemoteContentService.cs @@ -13,8 +13,8 @@ namespace Sidekick.ContentMigrator.Services.Interface { public interface IRemoteContentService { - IItemData GetRemoteItemData(Guid id, string server); - ChildrenItemDataModel GetRemoteItemDataWithChildren(Guid id, string server, Dictionary rev = null); + IItemData GetRemoteItemData(Guid id, string database, string server); + ChildrenItemDataModel GetRemoteItemDataWithChildren(Guid id, string database, string server, Dictionary rev = null); IItemData DeserializeYaml(string yaml, Guid id); object ChecksumIsGenerating(string server); bool ChecksumRegenerate(string server); diff --git a/ContentMigrator/Services/RemoteContentService.cs b/ContentMigrator/Services/RemoteContentService.cs index 43d8a27..23140bd 100644 --- a/ContentMigrator/Services/RemoteContentService.cs +++ b/ContentMigrator/Services/RemoteContentService.cs @@ -61,7 +61,7 @@ public bool ChecksumRegenerate(string server) return _jsonSerializationService.DeserializeObject(json); } - public IItemData GetRemoteItemData(Guid id, string server) + public IItemData GetRemoteItemData(Guid id, string database, string server) { string url = $"{server}/scs/cm/cmgetitemyaml.scsvc"; string parameters = _jsonSerializationService.SerializeObject(id); @@ -69,10 +69,10 @@ public IItemData GetRemoteItemData(Guid id, string server) return DeserializeYaml(yaml, id); } - public ChildrenItemDataModel GetRemoteItemDataWithChildren(Guid id, string server, Dictionary rev = null) + public ChildrenItemDataModel GetRemoteItemDataWithChildren(Guid id, string database, string server, Dictionary rev = null) { string url = $"{server}/scs/cm/cmgetitemyamlwithchildren.scsvc"; - string parameters = _jsonSerializationService.SerializeObject(new {id, rev}); + string parameters = _jsonSerializationService.SerializeObject(new {id, rev, database}); string json = MakeRequest(url, parameters); return _jsonSerializationService.DeserializeObject(json); } diff --git a/ScsContentMigrator.UnitTests/Core/ContentItemPullerTests.cs b/ScsContentMigrator.UnitTests/Core/ContentItemPullerTests.cs index 7344d01..b19955c 100644 --- a/ScsContentMigrator.UnitTests/Core/ContentItemPullerTests.cs +++ b/ScsContentMigrator.UnitTests/Core/ContentItemPullerTests.cs @@ -25,7 +25,7 @@ public void StartGatheringItems_AddsRootIdsToProcessingCollection() List expectedGuids = new List {Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()}; - contentItemPuller.StartGatheringItems(expectedGuids, 0, false, "", CancellationToken.None, false); + contentItemPuller.StartGatheringItems(expectedGuids, "master", 0, false, "", CancellationToken.None, false); contentItemPuller.ProcessingIds.Count.Should().Be(expectedGuids.Count); } @@ -34,10 +34,10 @@ public void StartGatheringItems_AddsRootIdsToProcessingCollection() public void GatherItems_TakesFromProcessingList() { ContentItemPuller contentItemPuller = CreateInstance(); - GetSubstitute().GetRemoteItemDataWithChildren(Arg.Any(), Arg.Any()).Returns(new ChildrenItemDataModel()); + GetSubstitute().GetRemoteItemDataWithChildren(Arg.Any(), Arg.Any(), Arg.Any()).Returns(new ChildrenItemDataModel()); contentItemPuller.ProcessingIds.Add(Guid.NewGuid()); - contentItemPuller.GatherItems(false, "", CancellationToken.None, false); + contentItemPuller.GatherItems(false, "master", "", CancellationToken.None, false); contentItemPuller.ProcessingIds.Should().BeEmpty(); } @@ -46,22 +46,22 @@ public void GatherItems_TakesFromProcessingList() public void GatherItems_FetchesRemoteContent() { ContentItemPuller contentItemPuller = CreateInstance(); - GetSubstitute().GetRemoteItemDataWithChildren(Arg.Any(), Arg.Any()).Returns(new ChildrenItemDataModel()); + GetSubstitute().GetRemoteItemDataWithChildren(Arg.Any(), Arg.Any(), Arg.Any()).Returns(new ChildrenItemDataModel()); contentItemPuller.ProcessingIds.Add(Guid.NewGuid()); - contentItemPuller.GatherItems(false, "", CancellationToken.None, false); + contentItemPuller.GatherItems(false, "master", "", CancellationToken.None, false); - GetSubstitute().Received(1).GetRemoteItemDataWithChildren(Arg.Any(), Arg.Any()); + GetSubstitute().Received(1).GetRemoteItemDataWithChildren(Arg.Any(), Arg.Any(), Arg.Any()); } [Fact] public void GatherItems_DeserializesRemoteContentItem() { ContentItemPuller contentItemPuller = CreateInstance(); - GetSubstitute().GetRemoteItemDataWithChildren(Arg.Any(), Arg.Any()).Returns(new ChildrenItemDataModel()); + GetSubstitute().GetRemoteItemDataWithChildren(Arg.Any(), Arg.Any(), Arg.Any()).Returns(new ChildrenItemDataModel()); contentItemPuller.ProcessingIds.Add(Guid.NewGuid()); - contentItemPuller.GatherItems(false, "", CancellationToken.None, false); + contentItemPuller.GatherItems(false, "master", "", CancellationToken.None, false); GetSubstitute().Received(1).DeserializeYaml(Arg.Any(), Arg.Any()); } @@ -72,11 +72,11 @@ public void GatherItems_AddsDeserializedValueToGatheredRemoteItems() IItemData expectedItemData = Substitute.For(); expectedItemData.Name.Returns("ExpectedName"); ContentItemPuller contentItemPuller = CreateInstance(); - GetSubstitute().GetRemoteItemDataWithChildren(Arg.Any(), Arg.Any()).Returns(new ChildrenItemDataModel()); + GetSubstitute().GetRemoteItemDataWithChildren(Arg.Any(), Arg.Any(), Arg.Any()).Returns(new ChildrenItemDataModel()); GetSubstitute().DeserializeYaml(Arg.Any(), Arg.Any()).Returns(expectedItemData); contentItemPuller.ProcessingIds.Add(Guid.NewGuid()); - contentItemPuller.GatherItems(false, "", CancellationToken.None, false); + contentItemPuller.GatherItems(false, "master", "", CancellationToken.None, false); contentItemPuller.GatheredRemoteItems.Should().NotBeEmpty(); contentItemPuller.GatheredRemoteItems.Should().Contain(expectedItemData); @@ -90,11 +90,11 @@ public void GatherItems_DoNotGetChildren_DoesNotGetChildren() expectedItemData.GetChildren().Returns(new List {Substitute.For()}); ContentItemPuller contentItemPuller = CreateInstance(); - GetSubstitute().GetRemoteItemDataWithChildren(Arg.Any(), Arg.Any()).Returns(new ChildrenItemDataModel()); + GetSubstitute().GetRemoteItemDataWithChildren(Arg.Any(), Arg.Any(), Arg.Any()).Returns(new ChildrenItemDataModel()); GetSubstitute().DeserializeYaml(Arg.Any(), Arg.Any()).Returns(expectedItemData); contentItemPuller.ProcessingIds.Add(Guid.NewGuid()); - contentItemPuller.GatherItems(false, "", CancellationToken.None, false); + contentItemPuller.GatherItems(false, "master", "", CancellationToken.None, false); contentItemPuller.GatheredRemoteItems.Count.Should().Be(1); } @@ -109,12 +109,12 @@ public void GatherItems_GetsChildren_ProcessesChildren() expectedItemData.GetChildren().Returns(new List { Substitute.For() }); ContentItemPuller contentItemPuller = CreateInstance(); - GetSubstitute().GetRemoteItemDataWithChildren(parentGuid, Arg.Any()).Returns(new ChildrenItemDataModel {GrandChildren = new List {childGuid}}); - GetSubstitute().GetRemoteItemDataWithChildren(childGuid, Arg.Any()).Returns(new ChildrenItemDataModel()); + GetSubstitute().GetRemoteItemDataWithChildren(parentGuid, Arg.Any(), Arg.Any()).Returns(new ChildrenItemDataModel {GrandChildren = new List {childGuid}}); + GetSubstitute().GetRemoteItemDataWithChildren(childGuid, Arg.Any(), Arg.Any()).Returns(new ChildrenItemDataModel()); GetSubstitute().DeserializeYaml(Arg.Any(), Arg.Any()).Returns(expectedItemData); contentItemPuller.ProcessingIds.Add(parentGuid); - contentItemPuller.GatherItems(true, "", CancellationToken.None, false); + contentItemPuller.GatherItems(true, "master", "", CancellationToken.None, false); contentItemPuller.GatheredRemoteItems.Count.Should().Be(2); } @@ -123,7 +123,7 @@ public void GatherItems_GetsChildren_ProcessesChildren() public void GatherItems_MultipleItems_CanceledDuringFirstItem_OnlyGathersOneItem() { ContentItemPuller contentItemPuller = CreateInstance(); - GetSubstitute().GetRemoteItemDataWithChildren(Arg.Any(), Arg.Any()).Returns(ci => + GetSubstitute().GetRemoteItemDataWithChildren(Arg.Any(), Arg.Any(), Arg.Any()).Returns(ci => { // Introduce a delay Thread.Sleep(10); @@ -135,7 +135,7 @@ public void GatherItems_MultipleItems_CanceledDuringFirstItem_OnlyGathersOneItem contentItemPuller.ProcessingIds.Add(Guid.NewGuid()); CancellationTokenSource cts = new CancellationTokenSource(10); - contentItemPuller.GatherItems(false, "", cts.Token, false); + contentItemPuller.GatherItems(false, "master", "", cts.Token, false); contentItemPuller.GatheredRemoteItems.Count.Should().BeLessThan(3); } @@ -148,13 +148,13 @@ public void GatherItems_MultipleItems_ProcessesEachItem() expectedItemData.GetChildren().Returns(new List { Substitute.For() }); ContentItemPuller contentItemPuller = CreateInstance(); - GetSubstitute().GetRemoteItemDataWithChildren(Arg.Any(), Arg.Any()).Returns(new ChildrenItemDataModel()); + GetSubstitute().GetRemoteItemDataWithChildren(Arg.Any(), Arg.Any(), Arg.Any()).Returns(new ChildrenItemDataModel()); GetSubstitute().DeserializeYaml(Arg.Any(), Arg.Any()).Returns(expectedItemData); contentItemPuller.ProcessingIds.Add(Guid.NewGuid()); contentItemPuller.ProcessingIds.Add(Guid.NewGuid()); contentItemPuller.ProcessingIds.Add(Guid.NewGuid()); - contentItemPuller.GatherItems(false, "", CancellationToken.None, false); + contentItemPuller.GatherItems(false, "master", "", CancellationToken.None, false); contentItemPuller.GatheredRemoteItems.Count.Should().Be(3); } @@ -168,7 +168,7 @@ public async Task GatherItems_MultipleThreads_AllCompleteWhenFinished() expectedItemData.GetChildren().Returns(new List { Substitute.For() }); ContentItemPuller contentItemPuller = CreateInstance(); - GetSubstitute().GetRemoteItemDataWithChildren(Arg.Any(), Arg.Any()).Returns(new ChildrenItemDataModel()); + GetSubstitute().GetRemoteItemDataWithChildren(Arg.Any(), Arg.Any(), Arg.Any()).Returns(new ChildrenItemDataModel()); GetSubstitute().DeserializeYaml(Arg.Any(), Arg.Any()).Returns(expectedItemData); for (int i = 0; i < expectedCount; i++) contentItemPuller.ProcessingIds.Add(Guid.NewGuid()); @@ -179,15 +179,15 @@ public async Task GatherItems_MultipleThreads_AllCompleteWhenFinished() { Task.Run(() => { - contentItemPuller.GatherItems(false, "", cancellationTokenSource.Token, false); + contentItemPuller.GatherItems(false, "master", "", cancellationTokenSource.Token, false); }), Task.Run(() => { - contentItemPuller.GatherItems(false, "", cancellationTokenSource.Token, false); + contentItemPuller.GatherItems(false, "master", "", cancellationTokenSource.Token, false); }), Task.Run(() => { - contentItemPuller.GatherItems(false, "", cancellationTokenSource.Token, false); + contentItemPuller.GatherItems(false, "master", "", cancellationTokenSource.Token, false); }) }; diff --git a/ScsContentMigrator.UnitTests/Core/ContentMigratorTests.cs b/ScsContentMigrator.UnitTests/Core/ContentMigratorTests.cs index a0d29e5..59de452 100644 --- a/ScsContentMigrator.UnitTests/Core/ContentMigratorTests.cs +++ b/ScsContentMigrator.UnitTests/Core/ContentMigratorTests.cs @@ -28,7 +28,7 @@ public void StartContentMigration_PullParent_AttemptsToGetFromSitecore() var item = Substitute.For(); item.ParentId.Returns(parent); ContentMigration contentMigration = CreateInstance(); - GetSubstitute().GetRemoteItemData(Arg.Any(), Arg.Any()).Returns(Substitute.For()); + GetSubstitute().GetRemoteItemData(Arg.Any(), Arg.Any(), Arg.Any()).Returns(Substitute.For()); GetSubstitute().ItemsToInstall.Returns(new BlockingCollection()); GetSubstitute().GetItemData(parent).Returns(Substitute.For()); @@ -48,9 +48,9 @@ public void StartContentMigration_PullParent_PullsFromSitecoreUntilParentNodeIsF var parentItem = Substitute.For(); parentItem.ParentId.Returns(secondParent); ContentMigration contentMigration = CreateInstance(); - GetSubstitute().GetRemoteItemData(initialTarget, Arg.Any()).Returns(item); - GetSubstitute().GetRemoteItemData(firstParent, Arg.Any()).Returns(parentItem); - GetSubstitute().GetRemoteItemData(secondParent, Arg.Any()).Returns(Substitute.For()); + GetSubstitute().GetRemoteItemData(initialTarget, Arg.Any(), Arg.Any()).Returns(item); + GetSubstitute().GetRemoteItemData(firstParent, Arg.Any(), Arg.Any()).Returns(parentItem); + GetSubstitute().GetRemoteItemData(secondParent, Arg.Any(), Arg.Any()).Returns(Substitute.For()); GetSubstitute().ItemsToInstall.Returns(new BlockingCollection()); GetSubstitute().GetItemData(initialTarget).Returns((IItemData)null); GetSubstitute().GetItemData(firstParent).Returns((IItemData)null); @@ -71,7 +71,7 @@ public void StartContentMigration_NotPullingParent_DoesNotPullFromSitecoreOrRemo contentMigration.StartContentMigration(new PullItemModel {PullParent = false, Ids = new List{Guid.NewGuid().ToString()}}); - GetSubstitute().Received(0).GetRemoteItemData(Arg.Any(), Arg.Any()); + GetSubstitute().Received(0).GetRemoteItemData(Arg.Any(), Arg.Any(), Arg.Any()); GetSubstitute().Received(0).GetItemData(Arg.Any()); } @@ -94,7 +94,7 @@ public void StartContentMigration_PullerStartsGatheringItems() contentMigration.StartContentMigration(new PullItemModel { PullParent = false, Ids = new List { Guid.NewGuid().ToString() } }); - GetSubstitute().Received(1).StartGatheringItems(Arg.Any>(), Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any()); + GetSubstitute().Received(1).StartGatheringItems(Arg.Any>(), Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any()); } [Fact] diff --git a/Source/SitecoreSidekick/Handlers/ScsMainController.cs b/Source/SitecoreSidekick/Handlers/ScsMainController.cs index 34d8c79..6af7f92 100644 --- a/Source/SitecoreSidekick/Handlers/ScsMainController.cs +++ b/Source/SitecoreSidekick/Handlers/ScsMainController.cs @@ -107,7 +107,7 @@ private async Task> GetContentSelectedRelated(Content { var node = _jsonSerializationService.DeserializeObject>( await _httpClientService.Post($"{data.Server}/scs/platform/contenttreeselectedrelated.scsvc", - $@"{{ ""selectedIds"": {_jsonSerializationService.SerializeObject(data.SelectedIds)}, ""server"": null}}").ConfigureAwait(false)); + $@"{{ ""selectedIds"": {_jsonSerializationService.SerializeObject(data.SelectedIds)}, ""server"": null, ""database"": ""{data.Database}"" }}").ConfigureAwait(false)); return node; } } @@ -118,16 +118,16 @@ await _httpClientService.Post($"{data.Server}/scs/platform/contenttreeselectedre Dictionary ret = new Dictionary(); foreach (string selectedId in data.SelectedIds) { - BuildRelatedTree(ret, selectedId); + BuildRelatedTree(ret, selectedId, data.Database); } return ret; } - private void BuildRelatedTree(Dictionary ret, string selectedId) + private void BuildRelatedTree(Dictionary ret, string selectedId, string database) { using (new SecurityDisabler()) { - ScsSitecoreItem i = _sitecoreDataAccessService.GetScsSitecoreItem(selectedId).Parent; + ScsSitecoreItem i = _sitecoreDataAccessService.GetScsSitecoreItem(selectedId, database).Parent; while (i != null) { if (!ret.ContainsKey(i.Id)) diff --git a/Source/SitecoreSidekick/Models/ContentSelectedRelatedModel.cs b/Source/SitecoreSidekick/Models/ContentSelectedRelatedModel.cs index 70d7e23..3208d0e 100644 --- a/Source/SitecoreSidekick/Models/ContentSelectedRelatedModel.cs +++ b/Source/SitecoreSidekick/Models/ContentSelectedRelatedModel.cs @@ -8,7 +8,8 @@ namespace Sidekick.Core.Models { public class ContentSelectedRelatedModel { - public string Server { get; set; } + public string Server { get; set; } + public string Database { get; set; } public List SelectedIds { get; set; } } } diff --git a/Source/SitecoreSidekick/Resources/scsfactory.js b/Source/SitecoreSidekick/Resources/scsfactory.js index 7610969..5344fd4 100644 --- a/Source/SitecoreSidekick/Resources/scsfactory.js +++ b/Source/SitecoreSidekick/Resources/scsfactory.js @@ -13,8 +13,8 @@ var data = { "id": id, "database": database, "server": server }; return $http.post("/scs/platform/contenttree.scsvc", data); }, - contentTreeSelectedRelated: function(selectedIds, server) { - var data = { "selectedIds": selectedIds, "server": server }; + contentTreeSelectedRelated: function(selectedIds, server, database) { + var data = { "selectedIds": selectedIds, "server": server, "database": database }; return $http.post("/scs/platform/contenttreeselectedrelated.scsvc", data); }, valid: function() { diff --git a/Source/SitecoreSidekick/Services/Interface/ISitecoreDataAccessService.cs b/Source/SitecoreSidekick/Services/Interface/ISitecoreDataAccessService.cs index 567ef75..69932d4 100644 --- a/Source/SitecoreSidekick/Services/Interface/ISitecoreDataAccessService.cs +++ b/Source/SitecoreSidekick/Services/Interface/ISitecoreDataAccessService.cs @@ -13,6 +13,7 @@ namespace Sidekick.Core.Services.Interface public interface ISitecoreDataAccessService { ScsSitecoreItem GetScsSitecoreItem(string id); + ScsSitecoreItem GetScsSitecoreItem(string id, string database); IItemData GetLatestItemData(string idataId, string database = null); IItemData GetLatestItemData(Guid idataId, string database = null); IItemData GetItemData(string idataId, string database = null); diff --git a/Source/SitecoreSidekick/Services/SitecoreDataAccessService.cs b/Source/SitecoreSidekick/Services/SitecoreDataAccessService.cs index b4033d2..fdf4b2b 100644 --- a/Source/SitecoreSidekick/Services/SitecoreDataAccessService.cs +++ b/Source/SitecoreSidekick/Services/SitecoreDataAccessService.cs @@ -22,6 +22,15 @@ public class SitecoreDataAccessService : ISitecoreDataAccessService { private readonly Database _db = Factory.GetDatabase("master", false); + public ScsSitecoreItem GetScsSitecoreItem(string id, string database) + { + var db = string.IsNullOrWhiteSpace(database) ? _db : Factory.GetDatabase(database,false); + + Item item = db.GetItem(id); + + return new ScsSitecoreItem(item); + } + public ScsSitecoreItem GetScsSitecoreItem(string id) { Item item = _db.GetItem(id); @@ -92,7 +101,7 @@ public List GetChildrenIds(Guid guid) public IEnumerable GetVersions(IItemData itemData) { - Item item = GetItem(itemData.Id); + Item item = GetItem(itemData.Id, itemData.DatabaseName); return item.Versions.GetVersions(true).Select(v => v[FieldIDs.Revision]); } @@ -155,7 +164,7 @@ public string GetItemYaml(string idataId, Func serializationFunc } private string GetItemRevision(Item item) { - var ret = item.Languages.Aggregate(new StringBuilder(), (sb, lang) => sb.Append(GetItem(item.ID.Guid, null, lang, Version.Latest).Versions.GetVersions().Aggregate(new StringBuilder(), (sb2, version) => sb2.Append(version[FieldIDs.Revision])).ToString())).ToString().GetHashCode().ToString(); + var ret = item.Languages.Aggregate(new StringBuilder(), (sb, lang) => sb.Append(GetItem(item.ID.Guid, item.Database.Name, lang, Version.Latest).Versions.GetVersions().Aggregate(new StringBuilder(), (sb2, version) => sb2.Append(version[FieldIDs.Revision])).ToString())).ToString().GetHashCode().ToString(); return ret; }