Example #1
0
 /// <summary>
 /// Constructor for creating a Content object
 /// </summary>
 /// <param name="name">Name of the content</param>
 /// <param name="parentId">Id of the Parent content</param>
 /// <param name="contentType">ContentType for the current Content object</param>
 /// <param name="properties">Collection of properties</param>
 /// <param name="culture">An optional culture.</param>
 public Content(string name, int parentId, IContentType contentType, PropertyCollection properties, string culture = null)
     : base(name, parentId, contentType, properties, culture)
 {
     _contentType       = contentType ?? throw new ArgumentNullException(nameof(contentType));
     _publishedState    = PublishedState.Unpublished;
     PublishedVersionId = 0;
 }
        public void SetEventState(Guid id, PublishedState state)
        {
            var @event = DbSet.Find(id);

            @event.EventState = state;

            Update(@event);
        }
        public async Task SetEventStateAsync(Guid id, PublishedState state)
        {
            var @event = await DbSet.FindAsync(id);

            @event.EventState = state;

            await UpdateAsync(@event);
        }
        /// <summary>
        /// Determines if the item should be persisted at all
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="publishedState"></param>
        /// <returns></returns>
        /// <remarks>
        /// In one particular case, a content item shouldn't be persisted:
        /// * The item exists and is published
        /// * A call to ContentService.Save is made
        /// * The item has not been modified whatsoever apart from changing it's published status from published to saved
        ///
        /// In this case, there is no reason to make any database changes at all
        /// </remarks>
        internal static bool RequiresSaving(this IContent entity, PublishedState publishedState)
        {
            var publishedChanged = entity.IsPropertyDirty("Published") && publishedState != PublishedState.Unpublished;
            //check if any user prop has changed
            var propertyValueChanged = entity.IsAnyUserPropertyDirty();

            //We need to know if any other property apart from Published was changed here
            //don't create a new version if the published state has changed to 'Save' but no data has actually been changed
            if (publishedChanged && entity.Published == false && propertyValueChanged == false)
            {
                //at this point we need to check if any non property value has changed that wasn't the published state
                var changedProps = ((TracksChangesEntityBase)entity).GetDirtyProperties();
                if (changedProps.Any(x => x != "Published") == false)
                {
                    return(false);
                }
            }

            return(true);
        }
        /// <summary>
        /// Determines if a new version should be created
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="publishedState"></param>
        /// <returns></returns>
        /// <remarks>
        /// A new version needs to be created when:
        /// * The publish status is changed
        /// * The language is changed
        /// * The item is already published and is being published again and any property value is changed (to enable a rollback)
        /// </remarks>
        internal static bool ShouldCreateNewVersion(this IContent entity, PublishedState publishedState)
        {
            //check if the published state has changed or the language
            var publishedChanged = entity.IsPropertyDirty("Published") && publishedState != PublishedState.Unpublished;
            var langChanged      = entity.IsPropertyDirty("Language");
            var contentChanged   = publishedChanged || langChanged;

            //check if any user prop has changed
            var propertyValueChanged = entity.IsAnyUserPropertyDirty();

            //return true if published or language has changed
            if (contentChanged)
            {
                return(true);
            }

            //check if any content prop has changed
            var contentDataChanged = ((Content)entity).IsEntityDirty();

            //return true if the item is published and a property has changed or if any content property has changed
            return((propertyValueChanged && publishedState == PublishedState.Published) || contentDataChanged);
        }
        /// <summary>
        /// Determines if a new version should be created
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="publishedState"></param>
        /// <returns></returns>
        /// <remarks>
        /// A new version needs to be created when:
        /// * The publish status is changed
        /// * The language is changed
        /// * The item is already published and is being published again and any property value is changed (to enable a rollback)
        /// </remarks>
        internal static bool ShouldCreateNewVersion(this IContent entity, PublishedState publishedState)
        {
            var dirtyEntity = (ICanBeDirty)entity;
            
            //check if the published state has changed or the language
            var contentChanged =
                (dirtyEntity.IsPropertyDirty("Published") && publishedState != PublishedState.Unpublished)
                || dirtyEntity.IsPropertyDirty("Language");

            //return true if published or language has changed
            if (contentChanged)
            {
                return true;
            }

            //check if any user prop has changed
            var propertyValueChanged = ((Content) entity).IsAnyUserPropertyDirty();
            //check if any content prop has changed
            var contentDataChanged = ((Content) entity).IsEntityDirty();

            //return true if the item is published and a property has changed or if any content property has changed
            return (propertyValueChanged && publishedState == PublishedState.Published) || contentDataChanged;
        }
        /// <summary>
        /// Determines if the published db flag should be set to true for the current entity version and all other db
        /// versions should have their flag set to false.
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="publishedState"></param>
        /// <param name="isCreatingNewVersion"></param>
        /// <returns></returns>
        /// <remarks>
        /// This is determined by:
        /// * If a new version is being created and the entity is published
        /// * If the published state has changed and the entity is published OR the entity has been un-published.
        /// </remarks>
        internal static bool ShouldClearPublishedFlagForPreviousVersions(this IContent entity, PublishedState publishedState, bool isCreatingNewVersion)
        {
            if (isCreatingNewVersion && entity.Published)
            {
                return(true);
            }

            //If Published state has changed then previous versions should have their publish state reset.
            //If state has been changed to unpublished the previous versions publish state should also be reset.
            if (entity.IsPropertyDirty("Published") && (entity.Published || publishedState == PublishedState.Unpublished))
            {
                return(true);
            }

            return(false);
        }
Example #8
0
 /// <summary>
 /// Changes the Published state of the content object
 /// </summary>
 public void ChangePublishedState(PublishedState state)
 {
     Published      = state == PublishedState.Published;
     PublishedState = state;
 }
Example #9
0
 /// <summary>
 /// Changes the Published state of the content object
 /// </summary>
 public void ChangePublishedState(PublishedState state)
 {
     Published = state == PublishedState.Published;
     PublishedState = state;
 }
        /// <summary>
        /// Determines if the published db flag should be set to true for the current entity version and all other db
        /// versions should have their flag set to false.
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="publishedState"></param>
        /// <param name="isCreatingNewVersion"></param>
        /// <returns></returns>
        /// <remarks>
        /// This is determined by:
        /// * If a new version is being created and the entity is published
        /// * If the published state has changed and the entity is published OR the entity has been un-published.
        /// </remarks>
        internal static bool ShouldClearPublishedFlagForPreviousVersions(this IContent entity, PublishedState publishedState, bool isCreatingNewVersion)
        {
            if (isCreatingNewVersion && entity.Published)
            {
                return true;
            }

            //If Published state has changed then previous versions should have their publish state reset.
            //If state has been changed to unpublished the previous versions publish state should also be reset.
            if (((ICanBeDirty)entity).IsPropertyDirty("Published") && (entity.Published || publishedState == PublishedState.Unpublished))
            {
                return true;
            }

            return false;
        }