Ejemplo n.º 1
0
        public static ContentItem Publish(this IVersionManager versionManager, IPersister persister, ContentItem previewedItem)
        {
            if (previewedItem.VersionOf.HasValue)
            {
                previewedItem = versionManager.MakeMasterVersion(previewedItem);
                persister.Save(previewedItem);
            }
            if (previewedItem.State != ContentState.Published)
            {
                previewedItem.State = ContentState.Published;
                if (!previewedItem.Published.HasValue)
                {
                    previewedItem.Published = Utility.CurrentTime();
                }

                persister.Save(previewedItem);
            }
            return(previewedItem);
        }
        /// <summary>
        /// Used by PublishScheduledAction and the Publish Button in the Curtain
        /// </summary>
        /// <param name="versionManager"></param>
        /// <param name="persister"></param>
        /// <param name="previewedItem"></param>
        /// <returns></returns>
        public static ContentItem Publish(this IVersionManager versionManager, IPersister persister, ContentItem previewedItem)
        {
            //if (previewedItem.State == ContentState.Published)
            //    return previewedItem; // nothing to do

            if (!previewedItem.IsPage)
            {
                throw new ArgumentException("Publish requires item to be a page");
            }

            if (previewedItem.VersionOf.HasValue)
            {
                // is versioned
                previewedItem = versionManager.MakeMasterVersion(previewedItem);
                persister.Save(previewedItem);
            }

            var stateChanger = Context.Current.Resolve <StateChanger>();

            stateChanger.ChangeTo(previewedItem, ContentState.Published);
            persister.Save(previewedItem);
            return(previewedItem);
        }