Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to fix <root/> entries that specify a database #98

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions ContentMigrator/ContentMigrationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Guid> GrandChildren = new List<Guid>();
var items = new List<KeyValuePair<Guid, string>>();
if (data.Rev == null || !data.Rev.ContainsKey(item.Id) || data.Rev[item.Id] != localRev[item.Id])
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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));
}
}
}
4 changes: 2 additions & 2 deletions ContentMigrator/Core/ContentItemInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -206,7 +206,7 @@ private void ItemInstaller(PullItemModel args, BlockingCollection<IItemData> ite
CurrentlyProcessing.Add(remoteData.Id);
}

IItemData localData = _sitecore.GetItemData(remoteData.Id);
IItemData localData = _sitecore.GetItemData(remoteData.Id, args.Database);

ProcessItem(args, localData, remoteData);

Expand Down
14 changes: 8 additions & 6 deletions ContentMigrator/Core/ContentItemPuller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public ContentItemPuller(int maxQueue)

public bool Completed { get; private set; }

public void StartGatheringItems(IEnumerable<Guid> rootIds, int threads, bool getChildren, string server, CancellationToken cancellationToken, bool ignoreRevId)
{
public void StartGatheringItems(IEnumerable<Guid> rootIds, string database, int threads, bool getChildren, string server, CancellationToken cancellationToken, bool ignoreRevId)
{
foreach (Guid id in rootIds)
{
ProcessingIds.Add(id);
Expand All @@ -51,12 +51,12 @@ public void StartGatheringItems(IEnumerable<Guid> 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)
Expand All @@ -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)))
Expand All @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions ContentMigrator/Core/ContentMigration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand All @@ -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<ContentMigrationRegistration>()?.RemoteThreads ?? 1, model.Children, model.Server, _cancellation.Token, model.IgnoreRevId);
_puller.StartGatheringItems(model.Ids.Select(Guid.Parse), model.Database, _registration.GetScsRegistration<ContentMigrationRegistration>()?.RemoteThreads ?? 1, model.Children, model.Server, _cancellation.Token, model.IgnoreRevId);
_installer.StartInstallingItems(model, _puller.ItemsToInstall, _registration.GetScsRegistration<ContentMigrationRegistration>()?.WriterThreads ?? 1, _cancellation.Token);
});
}
Expand Down
2 changes: 1 addition & 1 deletion ContentMigrator/Core/Interface/IContentItemPuller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Sidekick.ContentMigrator.Core.Interface
public interface IContentItemPuller
{
bool Completed { get; }
void StartGatheringItems(IEnumerable<Guid> rootIds, int threads, bool getChildren, string server, CancellationToken cancellationToken, bool ignoreRevId);
void StartGatheringItems(IEnumerable<Guid> rootIds, string database, int threads, bool getChildren, string server, CancellationToken cancellationToken, bool ignoreRevId);
BlockingCollection<IItemData> ItemsToInstall { get; }
}
}
6 changes: 3 additions & 3 deletions ContentMigrator/Data/CompareContentTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, List<Tuple<string, string>>>();
IItemData itemData = null;
itemData = Bootstrap.Container.Resolve<IRemoteContentService>().GetRemoteItemData(Guid.Parse(Id), server);
itemData = Bootstrap.Container.Resolve<IRemoteContentService>().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)
{
Expand Down
1 change: 1 addition & 0 deletions ContentMigrator/Models/DiffRequestModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Sidekick.ContentMigrator.Models
public class DiffRequestModel
{
public string Id;
public string Database;
public string Server;
}
}
1 change: 1 addition & 0 deletions ContentMigrator/Models/RevisionModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Sidekick.ContentMigrator.Models
public class RevisionModel
{
public string Id;
public string Database;
public Dictionary<Guid, string> Rev;
}
}
3 changes: 2 additions & 1 deletion ContentMigrator/Resources/cmcontenttreecontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions ContentMigrator/Resources/cmfactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion ContentMigrator/Resources/cmmastercontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}
Expand Down
2 changes: 1 addition & 1 deletion ContentMigrator/Services/ContentMigrationManagerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ContentMigrationManagerService : IContentMigrationManagerService
private readonly Dictionary<string, IContentMigration> _migrations = new Dictionary<string, IContentMigration>();
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;
Expand Down
4 changes: 2 additions & 2 deletions ContentMigrator/Services/Interface/IRemoteContentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Guid, string> rev = null);
IItemData GetRemoteItemData(Guid id, string database, string server);
ChildrenItemDataModel GetRemoteItemDataWithChildren(Guid id, string database, string server, Dictionary<Guid, string> rev = null);
IItemData DeserializeYaml(string yaml, Guid id);
object ChecksumIsGenerating(string server);
bool ChecksumRegenerate(string server);
Expand Down
6 changes: 3 additions & 3 deletions ContentMigrator/Services/RemoteContentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,18 @@ public bool ChecksumRegenerate(string server)
return _jsonSerializationService.DeserializeObject<bool>(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);
string yaml = MakeRequest(url, parameters);
return DeserializeYaml(yaml, id);
}

public ChildrenItemDataModel GetRemoteItemDataWithChildren(Guid id, string server, Dictionary<Guid, string> rev = null)
public ChildrenItemDataModel GetRemoteItemDataWithChildren(Guid id, string database, string server, Dictionary<Guid, string> 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<ChildrenItemDataModel>(json);
}
Expand Down
Loading