Пример #1
0
        protected override void AfterRemove(bool isDestroy)
        {
            Post.UpdateCommentCount(PostId);

            ZCache.RemoveCache("Comments-" + PostId);
            ZCache.RemoveByPattern("Comments-Recent");
        }
Пример #2
0
        protected override void AfterCommit()
        {
            base.AfterCommit();

            Post.UpdateCommentCount(PostId);

            if (!DontSendEmail)
            {
                try
                {
                    EmailTemplateToolboxContext etc = new EmailTemplateToolboxContext();
                    etc.Put("comment", this);
                    EmailTemplate ef = new EmailTemplate();
                    ef.Context      = etc;
                    ef.Subject      = "New Comment: " + Post.Title;
                    ef.To           = Post.User.Email;
                    ef.TemplateName = "comment.view";
                    ef.ReplyTo      = ((this.Email == "") ? Post.User.Email : this.Email);
                    Emailer.Send(ef);
                    Log.Info("Comment Sent", "Email sent to {0} ({1}) from the post \"{2}\" ({3}).", Post.User.ProperName, Post.User.Email, Post.Title, Post.Id);
                }
                catch (Exception ex)
                {
                    Log.Error("Email Failure", ex.Message);
                }
            }

            ZCache.RemoveCache("Comments-" + PostId);
            ZCache.RemoveByPattern("Comments-Recent");
        }
Пример #3
0
        private static void DeleteByColumn(Column column, bool state)
        {
            var idsToDelete    = new List <string>();
            var postIdsChanged = new List <int>();

            Query q = CreateQuery();

            q.AndWhere(column, state);
            q.AndWhere(Columns.Published,
                       DateTime.Now.AddDays(-1 *
                                            Int32.Parse(ConfigurationManager.AppSettings["Graffiti::Comments::DaysToDelete"] ??
                                                        "7")), Comparison.LessOrEquals);
            q.Top = "25";
            q.OrderByAsc(Columns.Published);
            CommentCollection cc = CommentCollection.FetchByQuery(q);

            foreach (Comment c in cc)
            {
                idsToDelete.Add(c.Id.ToString());
                if (!postIdsChanged.Contains(c.PostId))
                {
                    postIdsChanged.Add(c.PostId);
                }
            }

            if (idsToDelete.Count > 0)
            {
                QueryCommand deleteCommand =
                    new QueryCommand("DELETE FROM graffiti_Comments where Id in (" + string.Join(",", idsToDelete.ToArray()) + ")");

                DataService.ExecuteNonQuery(deleteCommand);

                foreach (int pid in postIdsChanged)
                {
                    Post.UpdateCommentCount(pid);
                }

                Log.Info("Deleted Comments",
                         idsToDelete.Count + " comment(s) were removed from the database since they were older than " +
                         (ConfigurationManager.AppSettings["Graffiti::Comments::DaysToDelete"] ?? "7") + " days and marked as " +
                         ((column.Name == "IsDeleted") ? " deleted" : " unpublished"));
            }
        }