private bool ProcessMoved(RemotingPackageManifestEntry action, ILogger logger) { var database = Factory.GetDatabase(action.Database); Assert.IsNotNull(database, "Invalid database " + action.Database); var currentItem = database.GetItem(new ID(action.ItemId)); if (currentItem == null) { logger.Error("Cannot move {0} because it has been deleted.".FormatWith(action.ItemPath)); return false; } var newParentPath = action.ItemPath.Substring(0, action.ItemPath.LastIndexOf('/')); var newParent = database.GetItem(newParentPath); if (newParent == null) { logger.Error("Cannot move {0} because the new parent path {1} is not a valid item.".FormatWith(action.OldItemPath, newParentPath)); return false; } currentItem.MoveTo(newParent); logger.Info("[M] {0} to {1} [remoting]".FormatWith(new SitecoreSourceItem(currentItem).DisplayIdentifier, new SitecoreSourceItem(newParent).DisplayIdentifier)); return true; }
private static void ProcessHistoryEnginePackage(RemotingPackage package, IConfiguration configuration, DateTime ifModifiedSince) { // TODO: need to "coalesce" history so we are not replaying more events than we need to // e.g. create then move in one sync will cause the created item to not be present as a serialized item // in the package because it was moved so the create fails package.Manifest.Strategy = RemotingStrategy.Differential; using (new SecurityDisabler()) { var serializationProvider = package.SerializationProvider; var roots = configuration.Resolve <PredicateRootPathResolver>().GetRootSourceItems(); var historyDatabases = roots.Select(x => x.DatabaseName).Distinct().Select(Factory.GetDatabase).ToArray(); foreach (var historyDatabase in historyDatabases) { var localHistory = GetMergedHistory(ifModifiedSince, historyDatabase); foreach (var historyEntry in localHistory) { if (historyEntry.Action == HistoryAction.Moved) { var item = historyDatabase.GetItem(historyEntry.ItemId); if (item == null) { continue; // invalid history entry - item deleted } var manifestEntry = RemotingPackageManifestEntry.FromEntry(historyEntry, historyDatabase.Name); manifestEntry.OldItemPath = historyEntry.ItemPath; // on a moved entry, the itempath is the pre-move path manifestEntry.ItemPath = item.Paths.Path; // the path from the Item is the post-move path package.Manifest.AddEntry(manifestEntry); } else if (historyEntry.Action == HistoryAction.Deleted) { package.Manifest.AddEntry(RemotingPackageManifestEntry.FromEntry(historyEntry, historyDatabase.Name)); } else { var item = historyDatabase.GetItem(historyEntry.ItemId); if (item == null) { continue; // invalid history entry - item deleted } // serialize updated item to package directory serializationProvider.SerializeItem(new SitecoreSourceItem(item)); package.Manifest.AddEntry(RemotingPackageManifestEntry.FromEntry(historyEntry, historyDatabase.Name)); } } } package.Manifest.LastSynchronized = DateTime.UtcNow; } }
private bool ProcessMoved(RemotingPackageManifestEntry action, ILogger logger) { var database = Factory.GetDatabase(action.Database); Assert.IsNotNull(database, "Invalid database " + action.Database); var currentItem = database.GetItem(new ID(action.ItemId)); if (currentItem == null) { logger.Error("Cannot move {0} because it has been deleted.".FormatWith(action.ItemPath)); return(false); } var newParentPath = action.ItemPath.Substring(0, action.ItemPath.LastIndexOf('/')); var newParent = database.GetItem(newParentPath); if (newParent == null) { logger.Error("Cannot move {0} because the new parent path {1} is not a valid item.".FormatWith(action.OldItemPath, newParentPath)); return(false); } currentItem.MoveTo(newParent); logger.Info("[M] {0} to {1} [remoting]".FormatWith(new SitecoreSourceItem(currentItem).DisplayIdentifier, new SitecoreSourceItem(newParent).DisplayIdentifier)); return(true); }
public static RemotingPackageManifestEntry FromEntry(HistoryEntry entry, string databaseName) { var manifest = new RemotingPackageManifestEntry(); manifest.Action = entry.Action; manifest.ItemId = entry.ItemId.Guid; manifest.ItemPath = entry.ItemPath; manifest.Database = databaseName; return manifest; }
public static RemotingPackageManifestEntry FromEntry(HistoryEntry entry, string databaseName) { var manifest = new RemotingPackageManifestEntry(); manifest.Action = entry.Action; manifest.ItemId = entry.ItemId.Guid; manifest.ItemPath = entry.ItemPath; manifest.Database = databaseName; return(manifest); }
private bool ProcessDeletion(RemotingPackageManifestEntry action, ILogger logger) { var currentItem = Factory.GetDatabase(action.Database).GetItem(new ID(action.ItemId)); if (currentItem == null) { logger.Error("Cannot delete {0} because it had already been deleted.".FormatWith(action.ItemPath)); return false; } currentItem.Delete(); logger.Warn("[D] {0} [remoting]".FormatWith(new SitecoreSourceItem(currentItem).DisplayIdentifier)); return true; }
private bool ProcessDeletion(RemotingPackageManifestEntry action, ILogger logger) { var currentItem = Factory.GetDatabase(action.Database).GetItem(new ID(action.ItemId)); if (currentItem == null) { logger.Error("Cannot delete {0} because it had already been deleted.".FormatWith(action.ItemPath)); return(false); } currentItem.Delete(); logger.Warn("[D] {0} [remoting]".FormatWith(new SitecoreSourceItem(currentItem).DisplayIdentifier)); return(true); }
private bool ProcessUpdate(RemotingPackageManifestEntry action, ILogger logger) { var serializedItem = _package.SerializationProvider.GetItemByPath(action.Database, action.ItemPath); if (serializedItem == null) { logger.Error("Corrupted package: expected serialized item for update {0} did not exist".FormatWith(action.ItemPath)); return(false); } serializedItem.Deserialize(false); var actionTaken = action.Action == HistoryAction.Created ? "[A]" : "[U]"; logger.Info("{0} {1} [remoting]".FormatWith(actionTaken, serializedItem.DisplayIdentifier)); return(true); }
public void AddEntry(RemotingPackageManifestEntry entry) { _entries.Add(entry); }
private bool ProcessUpdate(RemotingPackageManifestEntry action, ILogger logger) { var serializedItem = _package.SerializationProvider.GetItemByPath(action.Database, action.ItemPath); if (serializedItem == null) { logger.Error("Corrupted package: expected serialized item for update {0} did not exist".FormatWith(action.ItemPath)); return false; } serializedItem.Deserialize(false); var actionTaken = action.Action == HistoryAction.Created ? "[A]" : "[U]"; logger.Info("{0} {1} [remoting]".FormatWith(actionTaken, serializedItem.DisplayIdentifier)); return true; }