Exemplo n.º 1
0
        public static MessageResult RemoveInternal(int contentId, int[] ids, bool fromArchive, bool?boundToExternal, bool disableNotifications)
        {
            if (ContentRepository.IsAnyAggregatedFields(contentId))
            {
                return(MessageResult.Error(ArticleStrings.OperationIsNotAllowedForAggregated));
            }

            if (ids == null)
            {
                throw new ArgumentNullException(nameof(ids));
            }

            var content = ContentRepository.GetById(contentId);

            if (!content.IsArticleChangingActionsAllowed(boundToExternal))
            {
                return(MessageResult.Error(ContentStrings.ArticleChangingIsProhibited));
            }

            if (content == null)
            {
                throw new Exception(string.Format(ContentStrings.ContentNotFound, contentId));
            }

            if (!content.AllowItemsPermission && !SecurityRepository.IsEntityAccessible(EntityTypeCode.Content, contentId, ActionTypeCode.Remove))
            {
                return(MessageResult.Error(ArticleStrings.CannotRemoveBecauseOfSecurity));
            }

            var disableSecurityCheck = !content.AllowItemsPermission;
            var result = CheckIdResult <Article> .CreateForRemove(contentId, ids, disableSecurityCheck);

            var idsToProceed = result.ValidItems.Cast <Article>().SelectMany(a => a.SelfAndChildIds).ToArray();
            var idsToNotify  = result.ValidItems.Select(n => n.Id).ToArray();

            var isUpdate = content.AutoArchive && !fromArchive;
            var code     = isUpdate ? NotificationCode.Update : NotificationCode.Delete;
            var repo     = new NotificationPushRepository();

            repo.PrepareNotifications(contentId, idsToNotify, code, disableNotifications);

            if (content.AutoArchive && !fromArchive)
            {
                ArticleRepository.SetArchiveFlag(idsToProceed, true);
                repo.SendNotifications();
            }
            else
            {
                repo.SendNonServiceNotifications(true);
                foreach (var entry in result.ValidItems)
                {
                    var article = (Article)entry;
                    article.RemoveAllVersionFolders();
                }

                ArticleRepository.MultipleDelete(idsToProceed);
                repo.SendServiceNotifications();
            }

            return(result.GetServiceResult());
        }
Exemplo n.º 2
0
        public static MessageResult Remove(int contentId, Article articleToRemove, bool fromArchive, bool?boundToExternal, bool disableNotifications)
        {
            if (ContentRepository.IsAnyAggregatedFields(contentId))
            {
                return(MessageResult.Error(ArticleStrings.OperationIsNotAllowedForAggregated));
            }

            if (articleToRemove == null)
            {
                throw new Exception(string.Format(ArticleStrings.ArticleNotFound, articleToRemove.Id));
            }

            if (!articleToRemove.IsArticleChangingActionsAllowed(boundToExternal))
            {
                return(MessageResult.Error(ContentStrings.ArticleChangingIsProhibited));
            }

            var content = ContentRepository.GetById(contentId);

            if (content == null)
            {
                throw new Exception(string.Format(ContentStrings.ContentNotFound, articleToRemove.Id));
            }

            if (articleToRemove.LockedByAnyoneElse)
            {
                return(MessageResult.Error(string.Format(ArticleStrings.LockedByAnyoneElse, articleToRemove.LockedByDisplayName)));
            }

            if (!articleToRemove.IsAccessible(ActionTypeCode.Remove))
            {
                return(MessageResult.Error(ArticleStrings.CannotRemoveBecauseOfSecurity));
            }

            if (!articleToRemove.IsRemovableWithWorkflow)
            {
                return(MessageResult.Error(ArticleStrings.CannotRemoveBecauseOfWorkflow));
            }

            if (!articleToRemove.IsRemovableWithRelationSecurity)
            {
                return(MessageResult.Error(ArticleStrings.CannotRemoveBecauseOfRelationSecurity));
            }

            var idsToProceed = articleToRemove.SelfAndChildIds;

            var isUpdate = content.AutoArchive && !fromArchive;
            var code     = isUpdate ? NotificationCode.Update : NotificationCode.Delete;
            var repo     = new NotificationPushRepository();

            repo.PrepareNotifications(articleToRemove, new[] { code }, disableNotifications);
            if (isUpdate)
            {
                ArticleRepository.SetArchiveFlag(idsToProceed, true);
                repo.SendNotifications();
            }
            else
            {
                articleToRemove.RemoveAllVersionFolders();
                repo.SendNonServiceNotifications(true);
                ArticleRepository.MultipleDelete(idsToProceed);
                repo.SendServiceNotifications();
            }

            return(null);
        }