Exemple #1
0
        private void ChangeStateToExpiredItems()
        {
            var implicitExpire = persister.Repository
                                 .Find(Parameter.LessOrEqual("Expires", Utility.CurrentTime())
                                       & Parameter.Equal("State", ContentState.Published))
                                 .ToList();

            for (int i = 0; i < implicitExpire.Count; i++)
            {
                try
                {
                    // reset status on expired items
                    var item = implicitExpire[i];
                    changer.ChangeTo(item, ContentState.Unpublished);
                    persister.Save(item);
                }
                catch (Exception ex)
                {
                    while (ex.InnerException != null)
                    {
                        ex = ex.InnerException;
                    }
                    logger.Error(ex);
                }
            }
        }
Exemple #2
0
        public static ContentItem CloneForVersioningRecursive(this ContentItem item, StateChanger stateChanger = null, bool asPreviousVersion = true)
        {
            ContentItem clone = item.Clone(false);

            if (stateChanger != null)
            {
                if (item.State == ContentState.Published && asPreviousVersion)
                {
                    stateChanger.ChangeTo(clone, ContentState.Unpublished);
                }
                else if (item.State != ContentState.Unpublished || asPreviousVersion == false)
                {
                    stateChanger.ChangeTo(clone, ContentState.Draft);
                }
            }
            clone.Updated        = Utility.CurrentTime().AddSeconds(-1);
            clone.Parent         = null;
            clone.AncestralTrail = "/";
            clone.VersionOf      = item.VersionOf.Value ?? item;

            CopyAutoImplementedProperties(item, clone);

            foreach (var child in item.Children.Where(c => !c.IsPage))
            {
                var childClone = child.CloneForVersioningRecursive(stateChanger, asPreviousVersion);
                childClone.AddTo(clone);
            }

            return(clone);
        }
Exemple #3
0
 private void ExpireTrashedItemsRecursive(ContentItem item)
 {
     if (item.State == ContentState.Published)
     {
         stateChanger.ChangeTo(item, ContentState.Deleted);
     }
     foreach (ContentItem child in item.Children)
     {
         ExpireTrashedItemsRecursive(child);
     }
 }
 public virtual void MarkForFuturePublishing(ContentItem item, DateTime futureDate)
 {
     if (!item.VersionOf.HasValue)
     {
         item.Published = futureDate;
     }
     else
     {
         item["FuturePublishDate"] = futureDate;
     }
     changer.ChangeTo(item, ContentState.Waiting);
 }
Exemple #5
0
        public override void Process(CommandContext state)
        {
            changer.ChangeTo(state.Content, toState);
            foreach (ContentItem item in state.GetItemsToSave().Distinct())
            {
                if (item == state.Content)
                {
                    continue;
                }

                changer.ChangeTo(item, toState);
            }
        }
        private void ChangeStateToExpiredItems()
        {
            var implicitExpire = persister.Repository
                                 .Find(Parameter.LessOrEqual("Expires", Utility.CurrentTime())
                                       & Parameter.Equal("State", ContentState.Published))
                                 .ToList();

            for (int i = 0; i < implicitExpire.Count; i++)
            {
                // reset status on expired items
                var item = implicitExpire[i];
                changer.ChangeTo(item, ContentState.Unpublished);
                persister.Save(item);
            }
        }
Exemple #7
0
        /// <summary>Expires an item that has been thrown so that it's not accessible to external users.</summary>
        /// <param name="item">The item to restore.</param>
        public virtual void ExpireTrashedItem(ContentItem item)
        {
            item[FormerName]    = item.Name;
            item[FormerParent]  = item.Parent;
            item[FormerExpires] = item.Expires;
            item[FormerState]   = (int)item.State;
            item[DeletedDate]   = DateTime.Now;
            item.Expires        = DateTime.Now;
            item.Name           = item.ID.ToString();
            stateChanger.ChangeTo(item, ContentState.Deleted);

            foreach (ContentItem child in item.Children)
            {
                ExpireTrashedItem(child);
            }
        }
        public override void Process(CommandContext state)
        {
            // items with a future publish date should have a 'waiting' state
            var toState = state.Content.Published.HasValue && state.Content.Published > N2.Utility.CurrentTime() ? ContentState.Waiting : ContentState.Published;

            changer.ChangeTo(state.Content, toState);
            foreach (ContentItem item in state.GetItemsToSave().Distinct())
            {
                if (item == state.Content)
                {
                    continue;
                }

                changer.ChangeTo(item, toState);
            }
        }
Exemple #9
0
        private ContentItem SaveAsMaster(ContentItem item, IDictionary <string, Control> addedEditors, IPrincipal user)
        {
            using (ITransaction tx = persister.Repository.BeginTransaction())
            {
                ContentItem itemToUpdate = item.VersionOf;
                if (itemToUpdate == null)
                {
                    throw new ArgumentException("Expected the current item to be a version of another item.", "item");
                }

                if (ShouldCreateVersionOf(item))
                {
                    SaveVersion(itemToUpdate);
                }

                DateTime?published  = itemToUpdate.Published;
                bool     wasUpdated = UpdateItem(definitions.GetDefinition(itemToUpdate.GetContentType()), itemToUpdate, addedEditors, user).Length > 0;
                if (wasUpdated || IsNew(itemToUpdate))
                {
                    itemToUpdate.Published = published ?? Utility.CurrentTime();
                    stateChanger.ChangeTo(itemToUpdate, ContentState.Published);
                    persister.Save(itemToUpdate);
                }

                tx.Commit();

                OnItemSaved(new ItemEventArgs(itemToUpdate));
                return(item.VersionOf);
            }
        }
Exemple #10
0
 protected virtual void OnItemCreating(ContentItem item, ContentItem parentItem)
 {
     stateChanger.ChangeTo(item, ContentState.New);
     item.Parent = parentItem;
     notifier.NotifiyCreated(item);
     if (ItemCreated != null)
     {
         ItemCreated.Invoke(this, new ItemEventArgs(item));
     }
 }
Exemple #11
0
        /// <summary>Creates an instance of a certain type of item. It's good practice to create new items through this method so the item's dependencies can be injected by the engine.</summary>
        /// <returns>A new instance of an item.</returns>
        public virtual ContentItem CreateInstance(Type itemType, ContentItem parentItem)
        {
            object      intercepted = interceptor.Create(itemType.FullName, 0);
            ContentItem item        = (intercepted ?? Activator.CreateInstance(itemType, true))
                                      as ContentItem;

            stateChanger.ChangeTo(item, ContentState.New);
            OnItemCreating(item, parentItem);
            return(item);
        }
Exemple #12
0
        /// <summary>Creates a version of the item. This must be called before the item item is modified to save a version before modifications.</summary>
        /// <param name="item">The item to create a old version of.</param>
        /// <returns>The old version.</returns>
        public virtual ContentItem SaveVersion(ContentItem item)
        {
            CancellableItemEventArgs args = new CancellableItemEventArgs(item);

            if (ItemSavingVersion != null)
            {
                ItemSavingVersion.Invoke(this, args);
            }
            if (!args.Cancel)
            {
                item = args.AffectedItem;

                ContentItem oldVersion = item.Clone(false);
                if (item.State == ContentState.Published)
                {
                    stateChanger.ChangeTo(oldVersion, ContentState.Unpublished);
                }
                else
                {
                    stateChanger.ChangeTo(oldVersion, ContentState.Draft);
                }
                oldVersion.Expires   = Utility.CurrentTime().AddSeconds(-1);
                oldVersion.Updated   = Utility.CurrentTime().AddSeconds(-1);
                oldVersion.Parent    = null;
                oldVersion.VersionOf = item;
                if (item.Parent != null)
                {
                    oldVersion["ParentID"] = item.Parent.ID;
                }
                itemRepository.SaveOrUpdate(oldVersion);

                if (ItemSavedVersion != null)
                {
                    ItemSavedVersion.Invoke(this, new ItemEventArgs(oldVersion));
                }

                TrimVersionCountTo(item, maximumVersionsPerItem);

                return(oldVersion);
            }
            return(null);
        }
Exemple #13
0
 public override void Process(CommandContext state)
 {
     changer.ChangeTo(state.Content, toState);
 }
Exemple #14
0
 protected virtual void OnItemCreating(ContentItem item, ContentItem parentItem)
 {
     stateChanger.ChangeTo(item, ContentState.New);
     item.Parent = parentItem;
     NotifyCreated(item);
 }