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")); } }
private void BuildPage() { if (Request.QueryString["id"] == null) { //CommentCollection cc = new CommentCollection(); Query q = Comment.CreateQuery(); if (!(Request.QueryString["a"] == "d")) { q.AndWhere(Comment.Columns.IsPublished, !(Request.QueryString["a"] == "f")); } q.AndWhere(Comment.Columns.IsDeleted, (Request.QueryString["a"] == "d")); if (!String.IsNullOrEmpty(Request.QueryString["pid"])) { q.AndWhere(Comment.Columns.PostId, Request.QueryString["pid"]); } q.OrderByDesc(Comment.Columns.Id); CommentCollection tempCC = CommentCollection.FetchByQuery(q); CommentCollection permissionsFilteredCount = new CommentCollection(); permissionsFilteredCount.AddRange(tempCC); foreach (Comment c in tempCC) { if (!RolePermissionManager.GetPermissions(c.Post.CategoryId, GraffitiUsers.Current).Read) { permissionsFilteredCount.Remove(c); } } q.PageIndex = Int32.Parse(Request.QueryString["p"] ?? "1"); q.PageSize = 25; CommentCollection cc = CommentCollection.FetchByQuery(q); CommentCollection permissionsFiltered = new CommentCollection(); permissionsFiltered.AddRange(cc); foreach (Comment c in cc) { if (!RolePermissionManager.GetPermissions(c.Post.CategoryId, GraffitiUsers.Current).Read) { permissionsFiltered.Remove(c); } } CommentList.DataSource = permissionsFiltered; CommentList.DataBind(); string qs = Request.QueryString["a"] != null ? "?a=" + Request.QueryString["a"] : "?a=t"; Pager.Text = Util.Pager(q.PageIndex, q.PageSize, permissionsFilteredCount.Count, "navigation", qs); if (Request.QueryString["a"] == "f") { CommentLinks.SetActiveView(PendingComments); } else if (Request.QueryString["a"] == "d") { CommentLinks.SetActiveView(DeletedComments); } } else { the_Views.SetActiveView(Comment_Form); Comment comment = new Comment(Request.QueryString["id"]); if (comment.IsNew) { throw new Exception("Invalid Comment Id"); } txtName.Text = Server.HtmlDecode(comment.Name); txtSite.Text = comment.WebSite; txtEmail.Text = comment.Email; CommentEditor.Text = comment.Body; } #region build the page title StringBuilder sb = new StringBuilder(); string page = Request.QueryString["a"] ?? "t"; switch (page) { case "t": sb.Append("Published "); break; case "f": sb.Append("Pending "); break; case "d": sb.Append("Deleted "); break; } sb.Append(" Comments"); lblPageTitle.Text = sb.ToString(); string post = Request.QueryString["pid"]; if (!String.IsNullOrEmpty(post)) { Post p = new Post(Convert.ToInt32(post)); lblPageTitle.Text += " for \"" + p.Name + "\""; } #endregion }