Exemple #1
0
 public CsvReader(int siteId, int contentId, ImportSettings settings)
 {
     _siteId                 = siteId;
     _contentId              = contentId;
     _importSettings         = settings;
     _reader                 = new FileReader(settings);
     _notificationRepository = new NotificationPushRepository {
         IgnoreInternal = true
     };
 }
Exemple #2
0
 // Добавление значений m2m и o2m полей
 public void PostUpdateM2MRelationAndO2MRelationFields()
 {
     if (_importSettings.ContainsO2MRelationOrM2MRelationFields)
     {
         //get all relations between old and new article ids
         var values = GetNewValues();
         if (values.Any())
         {
             var repo = new NotificationPushRepository();
             repo.PrepareNotifications(_contentId, values.Select(n => n.NewId).Distinct().ToArray(), NotificationCode.Update);
             PostUpdateM2MValues(values);
             PostUpdateO2MValues(values);
             repo.SendNotifications();
         }
     }
 }
Exemple #3
0
        public static MessageResult MoveToArchive(Article articleToArchive, bool?boundToExternal, bool disableNotifications)
        {
            if (articleToArchive == null)
            {
                throw new Exception(string.Format(ArticleStrings.ArticleNotFound, articleToArchive.Id));
            }

            if (articleToArchive.IsAggregated)
            {
                return(MessageResult.Error(ArticleStrings.OperationIsNotAllowedForAggregated));
            }

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

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

            if (!articleToArchive.IsAccessible(ActionTypeCode.Archive))
            {
                return(MessageResult.Error(ArticleStrings.CannotUpdateBecauseOfSecurity));
            }

            if (!articleToArchive.IsUpdatableWithWorkflow)
            {
                return(MessageResult.Error(ArticleStrings.CannotRemoveBecauseOfWorkflow));
            }

            if (!articleToArchive.IsUpdatableWithRelationSecurity)
            {
                return(MessageResult.Error(ArticleStrings.CannotUpdateBecauseOfRelationSecurity));
            }

            var idsToProceed = articleToArchive.SelfAndChildIds;
            var repo         = new NotificationPushRepository();

            repo.PrepareNotifications(articleToArchive, new[] { NotificationCode.Update }, disableNotifications);

            ArticleRepository.SetArchiveFlag(idsToProceed, true);
            repo.SendNotifications();

            return(null);
        }
Exemple #4
0
        public Article HideArticle(int articleId)
        {
            using (new QPConnectionScope(_connectionString))
            {
                var article = ArticleRepository.GetById(articleId);
                if (article != null && article.Visible)
                {
                    article.LoadFieldValues();
                    var repo = new NotificationPushRepository();
                    repo.PrepareNotifications(article, new[] { NotificationCode.Update });
                    QPContext.EFContext.SetContentItemVisible(articleId, false, article.LastModifiedBy);
                    repo.SendNotifications();
                }

                return(article);
            }
        }
Exemple #5
0
        public Article HideArticle(int articleId)
        {
            QPContext.CurrentDbConnectionInfo = new QpConnectionInfo(_connectionString, _dbType);
            using (var scope = new QPConnectionScope())
            {
                var article = ArticleRepository.GetById(articleId);
                if (article != null && article.Visible)
                {
                    article.LoadFieldValues();
                    var repo = new NotificationPushRepository();
                    repo.PrepareNotifications(article, new[] { NotificationCode.Update });
                    Common.SetContentItemVisible(scope.DbConnection, articleId, false, article.LastModifiedBy);
                    repo.SendNotifications();
                }

                return(article);
            }
        }
Exemple #6
0
        public MultistepActionStepResult Step(int step)
        {
            var context = (RecreateDynamicImagesContext)HttpContext.Current.Session[HttpContextSession.RecreateDynamicImagesServiceProcessingContext];
            IEnumerable <Tuple <int, string> > dataForStep = context.ArticleData.Skip(step * ItemsPerStep).Take(ItemsPerStep).ToArray();

            var flds = GetFields(context.FieldId);
            var dimg = flds.Item1.DynamicImage;
            var baseImagePathInfo = flds.Item2.PathInfo;

            if (dataForStep.Any())
            {
                var ids = dataForStep.Select(d => d.Item1).ToArray();
                var notificationRepository = new NotificationPushRepository {
                    IgnoreInternal = true
                };
                notificationRepository.PrepareNotifications(context.ContentId, ids, NotificationCode.Update);

                foreach (var dfs in dataForStep)
                {
                    using (var transaction = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions {
                        IsolationLevel = IsolationLevel.ReadCommitted
                    }))
                    {
                        var newValue = dimg.GetValue(dimg.GetDesiredFileName(dfs.Item2));
                        RecreateDynamicImagesRepository.UpdateDynamicFieldValue(dimg.Field.Id, dfs.Item1, newValue);

                        if (!context.ProcessedImages.Contains(dfs.Item2))
                        {
                            dimg.CreateDynamicImage(baseImagePathInfo.GetPath(dfs.Item2), dfs.Item2);
                            context.ProcessedImages.Add(dfs.Item2);
                        }
                        transaction.Complete();
                    }
                }

                notificationRepository.SendNotifications();
            }

            return(new MultistepActionStepResult {
                ProcessedItemsCount = dataForStep.Count()
            });
        }
Exemple #7
0
        public Article PublishAndCloseSchedule(int scheduleId)
        {
            Article article = null;

            using (var transaction = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions {
                IsolationLevel = IsolationLevel.ReadCommitted
            }))
            {
                QPContext.CurrentDbConnectionInfo = new QpConnectionInfo(_connectionString, _dbType);
                using (var scope = new QPConnectionScope())
                {
                    var schedule = ScheduleRepository.GetScheduleById(scheduleId);
                    if (schedule != null)
                    {
                        article          = ArticleRepository.GetById(schedule.ArticleId);
                        schedule.Article = article;
                        if (article != null && article.Delayed)
                        {
                            QPContext.IsLive = true;
                            article.LoadFieldValues();
                            QPContext.IsLive = false;

                            var repo = new NotificationPushRepository();
                            repo.PrepareNotifications(article, new[] { NotificationCode.DelayedPublication });
                            Common.MergeArticle(scope.DbConnection, schedule.ArticleId, article.LastModifiedBy);
                            repo.SendNotifications();
                        }
                        else
                        {
                            ScheduleRepository.Delete(schedule);
                        }
                    }
                }

                transaction.Complete();
            }

            return(article);
        }
Exemple #8
0
        public MultistepActionStepResult Step(int step)
        {
            var context    = (FieldDefaultValueContext)HttpContext.Current.Session[HttpContextSession.FieldDefaultValueServiceProcessingContext];
            var idsForStep = context.ProcessedContentItemIds
                             .Skip(step * ItemsPerStep)
                             .Take(ItemsPerStep)
                             .ToList();

            if (idsForStep.Any())
            {
                var notificationRepository = new NotificationPushRepository {
                    IgnoreInternal = true
                };
                notificationRepository.PrepareNotifications(context.ContentId, idsForStep.ToArray(), NotificationCode.Update);
                FieldDefaultValueRepository.SetDefaultValue(context.ContentId, context.FieldId, context.IsBlob, context.IsM2M, idsForStep, context.Symmetric);
                notificationRepository.SendNotifications();
            }

            return(new MultistepActionStepResult {
                ProcessedItemsCount = idsForStep.Count
            });
        }
Exemple #9
0
        private static MessageResult RestoreFromArchiveInternal(int contentId, int[] ids, bool?boundToExternal, bool disableNotifications)
        {
            if (ids == null)
            {
                throw new ArgumentNullException(nameof(ids));
            }

            if (ContentRepository.IsAnyAggregatedFields(contentId))
            {
                return(MessageResult.Error(ArticleStrings.OperationIsNotAllowedForAggregated));
            }

            var content = ContentRepository.GetById(contentId);

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

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

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

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

            var repo = new NotificationPushRepository();

            repo.PrepareNotifications(contentId, idsToNotify, new[] { NotificationCode.Update }, disableNotifications);
            ArticleRepository.SetArchiveFlag(idsToProceed, false);
            repo.SendNotifications();

            return(result.GetServiceResult());
        }
Exemple #10
0
        public static MessageResult RestoreFromArchive(Article articleToRestore, bool?boundToExternal, bool disableNotifications)
        {
            if (articleToRestore == null)
            {
                throw new Exception(string.Format(ArticleStrings.ArticleNotFound, articleToRestore.Id));
            }

            if (articleToRestore.IsAggregated)
            {
                return(MessageResult.Error(ArticleStrings.OperationIsNotAllowedForAggregated));
            }

            if (!articleToRestore.IsUpdatableWithRelationSecurity)
            {
                return(MessageResult.Error(ArticleStrings.CannotUpdateBecauseOfRelationSecurity));
            }

            if (!SecurityRepository.IsEntityAccessible(EntityTypeCode.Article, articleToRestore.Id, ActionTypeCode.Restore))
            {
                return(MessageResult.Error(ArticleStrings.CannotUpdateBecauseOfSecurity));
            }

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

            var idsToProceed = articleToRestore.SelfAndChildIds;
            var repo         = new NotificationPushRepository();

            repo.PrepareNotifications(articleToRestore, new[] { NotificationCode.Update }, disableNotifications);

            ArticleRepository.SetArchiveFlag(idsToProceed, false);
            repo.SendNotifications();

            return(null);
        }
Exemple #11
0
 public ExternalNotificationService()
 {
     _notificationPushRepository = new NotificationPushRepository();
 }
Exemple #12
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());
        }
Exemple #13
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);
        }
Exemple #14
0
        public static CopyResult Copy(Article article, bool?boundToExternal, bool disableNotifications, Guid?guidForSubstitution)
        {
            var result = new CopyResult();

            Ensure.NotNull(article, string.Format(ArticleStrings.ArticleNotFound, article.Id));

            if (article.IsAggregated)
            {
                return(new CopyResult {
                    Message = MessageResult.Error(ArticleStrings.OperationIsNotAllowedForAggregated)
                });
            }

            if (!article.IsArticleChangingActionsAllowed(boundToExternal))
            {
                return(new CopyResult {
                    Message = MessageResult.Error(ContentStrings.ArticleChangingIsProhibited)
                });
            }

            article.LoadFieldValues();
            if (!article.Content.IsUpdatable || !article.IsAccessible(ActionTypeCode.Read))
            {
                return(new CopyResult {
                    Message = MessageResult.Error(ArticleStrings.CannotCopyBecauseOfSecurity)
                });
            }

            if (!article.IsUpdatableWithWorkflow)
            {
                return(new CopyResult {
                    Message = MessageResult.Error(ArticleStrings.CannotAddBecauseOfWorkflow)
                });
            }

            if (!article.IsUpdatableWithRelationSecurity)
            {
                return(new CopyResult {
                    Message = MessageResult.Error(ArticleStrings.CannotAddBecauseOfRelationSecurity)
                });
            }

            article.UniqueId = guidForSubstitution ?? Guid.NewGuid();
            result.UniqueId  = article.UniqueId.Value;

            var previousAggregatedArticles = article.AggregatedArticles;

            article.ReplaceAllUrlsToPlaceHolders();

            try
            {
                article   = ArticleRepository.Copy(article);
                result.Id = article.Id;
                article.CopyAggregates(previousAggregatedArticles);

                var repo = new NotificationPushRepository();
                repo.PrepareNotifications(article, new[] { NotificationCode.Create }, disableNotifications);
                repo.SendNotifications();
            }
            catch (UnsupportedConstraintException)
            {
                result.Message = MessageResult.Error(ArticleStrings.UnsupportedConstraint);
            }

            return(result);
        }