public void Relation_InDetailCollection_OfVersion_IsRemoved()
        {
            var item1_1 = CreateOneItem <ThrowableItem>(0, "child", item);

            engine.Persister.Save(item1_1);

            var collection = item2.GetDetailCollection("Links", true);

            collection.Add(item);
            collection.Add(item1_1);
            engine.Persister.Save(item2);

            var version = versions.AddVersion(item2);

            persister.Dispose();
            item = persister.Get <ThrowableItem>(item.ID);

            trash.Throw(item);
            trash.PurgeAll();

            persister.Dispose();
            item2 = persister.Get <ThrowableItem>(item2.ID);
            var repository = engine.Resolve <ContentVersionRepository>();

            version = repository.DeserializeVersion(repository.GetVersion(item2, version.VersionIndex));
            // persister.Get<ThrowableItem>(version.ID);

            item2.GetDetailCollection("Links", false).Count.ShouldBe(0);
            version.GetDetailCollection("Links", false).Count.ShouldBe(0);
        }
Beispiel #2
0
        public void SaveOnly_OnVersion_SetsItemStateTo_Draft()
        {
            var item = activator.CreateInstance <StatefulPage>(null);

            persister.Save(item);
            var version = versionManager.AddVersion(item);

            var result = editManager.Save(version, editors, ItemEditorVersioningMode.SaveOnly, admin);

            Assert.That(result.State, Is.EqualTo(ContentState.Draft));
        }
 public override void Process(CommandContext state)
 {
     if (versionMaker.IsVersionable(state.Content))
     {
         versionMaker.AddVersion(state.Content, asPreviousVersion: true);
     }
 }
Beispiel #4
0
        private string CreateItem(TemplateDefinition template, NameValueCollection request)
        {
            var path = new PathData(navigator.Navigate(request["below"]));

            if (!versionRepository.TryParseVersion(request[PathData.VersionIndexQueryKey], request[PathData.VersionKeyQueryKey], path))
            {
                path.CurrentItem = versions.AddVersion(path.CurrentItem, asPreviousVersion: false);
            }
            var parent = path.CurrentItem;

            ContentItem item = activator.CreateInstance(template.Definition.ItemType, parent);

            item.ZoneName    = request["zone"];
            item.TemplateKey = template.Name;

            string beforeVersionKey = request["beforeVersionKey"];
            string beforeSortOrder  = request["beforeSortOrder"];
            string before           = request["before"];

            if (string.IsNullOrEmpty(beforeSortOrder))
            {
                item.AddTo(parent);
            }
            else
            {
                int index = int.Parse(beforeSortOrder);
                parent.InsertChildBefore(item, index);
            }

            versionRepository.Save(parent);
            return(request["returnUrl"].ToUrl().SetQueryParameter(PathData.VersionIndexQueryKey, parent.VersionIndex));
        }
        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");
        }
Beispiel #6
0
        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);
        }
Beispiel #7
0
 public override void Process(CommandContext state)
 {
     if (versionMaker.IsVersionable(state.Content) && (state.Content.State == ContentState.Published || state.Content.State == ContentState.Unpublished))
     {
         state.Content = versionMaker.AddVersion(state.Content, asPreviousVersion: false);
     }
 }
Beispiel #8
0
        private ContentItem SaveVersion(ContentItem current)
        {
            ContentItem savedVersion  = null;
            var         savingHandler = Events[savingVersionKey] as EventHandler <CancellableItemEventArgs>;
            var         savedHandler  = Events[savedVersionKey] as EventHandler <ItemEventArgs>;

            Utility.InvokeEvent(savingHandler, current, this, delegate(ContentItem item)
            {
                savedVersion = versioner.AddVersion(item);
                versioner.TrimVersionCountTo(item, MaximumNumberOfVersions);
            }, savedHandler);
            return(savedVersion);
        }
Beispiel #9
0
        public static PathData EnsureDraft(IVersionManager versions, ContentVersionRepository versionRepository, Edit.Navigator navigator, NameValueCollection request)
        {
            var item = navigator.Navigate(request["item"]);

            item = versionRepository.ParseVersion(request[PathData.VersionIndexQueryKey], request["versionKey"], item)
                   ?? item;

            var page = Find.ClosestPage(item);

            if (!page.VersionOf.HasValue)
            {
                page = versions.AddVersion(page, asPreviousVersion: false);
                item = page.FindPartVersion(item);
            }

            return(new PathData(page, item));
        }
Beispiel #10
0
        // see also UseDraftCommand.cs (should use it here?)
        public static PathData EnsureDraft(ContentItem item, IVersionManager versions, ContentVersionRepository versionRepository, out bool isNew)
        {
            isNew = false;

            // find containing page
            var page = Find.ClosestPage(item);

            if (versions.IsVersionable(page) && page.State != ContentState.Draft)
            {
                // current version is not draft, see if there are any drafts
                // page is not versioned, add a new version
                page = versions.AddVersion(page, asPreviousVersion: false);

                // find part to be modified on new page version
                item  = page.FindPartVersion(item);
                isNew = true;
            }

            return(new PathData(page, item));
        }
        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();
            }
        }