public static void DestroyDeletedPosts() { DateTime dt = DateTime.Now.AddDays(-1 * SiteSettings.DestroyDeletedPostsOlderThanDays); Query q = CreateQuery(); q.AndWhere(Columns.IsDeleted, true); q.AndWhere(Columns.ModifiedOn, dt, Comparison.LessOrEquals); PostCollection pc = PostCollection.FetchByQuery(q); if (pc.Count > 0) { Log.Info("Deleting Posts", "Deleting {0} post(s) since they were deleted before {1}", pc.Count, dt); foreach (Post p in pc) { try { DestroyDeletedPost(p.Id); Log.Info("Post Deleted", "The post \"{0}\" ({3}) and related content was deleted. It had been marked to be deleted on {1} by {2}", p.Title, p.ModifiedOn, p.ModifiedBy, p.Id); } catch (Exception ex) { Log.Error("Post Delete", "The post \"{0}\" was not successfully deleted. Reason: {1}", p.Title, ex.Message); } } } }
public static void DestroyDeletedPostCascadingForCategory(int categoryId) { Query q = CreateQuery(); q.AndWhere(Columns.IsDeleted, true); q.AndWhere(Columns.CategoryId, categoryId); PostCollection pc = PostCollection.FetchByQuery(q); if (pc.Count > 0) { foreach (Post p in pc) { DestroyDeletedPost(p.Id); } } }
/// <summary> /// Gets x amount of popular posts from the specified category Id /// </summary> /// <param name="numberOfPosts"></param> /// <param name="categoryId"></param> /// <returns></returns> public PostCollection PopularPosts(int numberOfPosts, int categoryId) { PostCollection pc = ZCache.Get <PostCollection>("Posts-Popular-" + numberOfPosts + "c:" + categoryId); if (pc == null) { Query q = PostCollection.DefaultQuery(); if (categoryId > 0) { Category category = new CategoryController().GetCachedCategory(categoryId, true); if (category != null) { if (category.ParentId > 0) { q.AndWhere(Post.Columns.CategoryId, categoryId); } else { List <int> ids = new List <int>(category.Children.Count + 1); foreach (Category child in category.Children) { ids.Add(child.Id); } ids.Add(category.Id); q.AndInWhere(Post.Columns.CategoryId, ids.ToArray()); } } else { //this should result in no data, but it will signal to //the end user to edit/remove this widget q.AndWhere(Post.Columns.CategoryId, categoryId); } } q.Orders.Clear(); q.OrderByDesc(Post.Columns.Views); q.Top = numberOfPosts.ToString(); pc = PostCollection.FetchByQuery(q); ZCache.InsertCache("Posts-Popular-" + numberOfPosts + "c:" + categoryId, pc, 60); } return(pc); }