public void ItemMarkedForFuturePublishing_IsPublished_WhenPublishingTimeIsReached() { var item = new ExternalItem { Title = "Original", State = ContentState.Published, Published = DateTime.Now.AddSeconds(-10) }; using (engine.SecurityManager.Disable()) { engine.Persister.Save(item); var version = versionManager.AddVersion(item, asPreviousVersion: false); version.Title = "ToBePublished"; action.MarkForFuturePublishing(version, DateTime.Now.AddSeconds(-5)); versionManager.UpdateVersion(version); } action.Execute(); var published = engine.Persister.Get(item.ID); var allVersions = versionManager.GetVersionsOf(published); var unpublished = allVersions.Single(v => v.State == ContentState.Unpublished); allVersions.Count.ShouldBe(2); published.Title.ShouldBe("ToBePublished"); unpublished.Title.ShouldBe("Original"); }
public override void Process(CommandContext state) { var item = state.Content; var page = Find.ClosestPage(item); var pageVersion = page.VersionOf.HasValue ? page : versionMaker.AddVersion(page, asPreviousVersion: false); if (!item.IsPage) { var parentVersion = pageVersion.FindPartVersion(item.Parent); if (state.Parameters.ContainsKey("MoveBeforeVersionKey") && !string.IsNullOrEmpty(state.Parameters["MoveBeforeVersionKey"] as string)) { var beforeKey = (string)state.Parameters["MoveBeforeVersionKey"]; var beforeItem = pageVersion.FindDescendantByVersionKey(beforeKey); beforeItem.Parent.InsertChildBefore(item, beforeItem.SortOrder); } else if (state.Parameters.ContainsKey("MoveBeforeSortOrder") && !string.IsNullOrEmpty(state.Parameters["MoveBeforeSortOrder"] as string)) { int beforeSortOrder = Convert.ToInt32(state.Parameters["MoveBeforeSortOrder"]); parentVersion.InsertChildBefore(item, beforeSortOrder); } else { item.AddTo(parentVersion); Utility.UpdateSortOrder(parentVersion.Children); } } versionMaker.UpdateVersion(pageVersion); }
private void UpdateSortOrderAndSave(ContentItem parent) { IEnumerable <ContentItem> siblings = parent.Children; var changes = 0; using (var tx = persister.Repository.BeginTransaction()) { foreach (ContentItem updatedItem in Utility.UpdateSortOrder(siblings)) { if (updatedItem.ID > 0) { persister.Repository.SaveOrUpdate(updatedItem); changes++; } else { Logger.ErrorFormat("skip save for {0}", updatedItem); // TODO } } if (changes == 0 && versionMaker != null) { var page = Find.ClosestPage(parent); if (page.State == ContentState.Draft) { var pageVersion = page.VersionOf.HasValue ? page : versionMaker.AddVersion(page, asPreviousVersion: false); // TODO //if (pageVersion != null && pageVersion.SavedBy != state.User.Identity.Name) // pageVersion.SavedBy = state.User.Identity.Name; versionMaker.UpdateVersion(pageVersion); Logger.ErrorFormat("save draft of {0}", page); // TODO //persister.Repository.SaveOrUpdate(page); } } tx.Commit(); } }