private void ReduceBlogArchive(BlogPostPart blogPostPart) {
            _blogArchiveRepository.Flush();

            // don't reduce archive count if the content item is not published
            if (!_previousCreatedUtc.ContainsKey(blogPostPart.Id)) {
                return;
            }

            var commonPart = blogPostPart.As<ICommonPart>();
            if (commonPart == null || !commonPart.CreatedUtc.HasValue)
                return;

            var timeZone = _workContextAccessor.GetContext().CurrentTimeZone;
            var datetime = TimeZoneInfo.ConvertTimeFromUtc(commonPart.CreatedUtc.Value, timeZone);

            var previousArchiveRecord = _blogArchiveRepository.Table
                .FirstOrDefault(x => x.BlogPart.Id == blogPostPart.BlogPart.Id
                                    && x.Month == datetime.Month
                                    && x.Year == datetime.Year);

            if(previousArchiveRecord == null)
                return;

            if (previousArchiveRecord.PostCount > 1)
                previousArchiveRecord.PostCount--;
            else
                _blogArchiveRepository.Delete(previousArchiveRecord);
        }
        private void ProcessBlogPostsCount(BlogPostPart blogPostPart) {
            CommonPart commonPart = blogPostPart.As<CommonPart>();
            if (commonPart != null &&
                commonPart.Record.Container != null) {

                _blogService.ProcessBlogPostsCount(commonPart.Container.Id);
            }
        }
        private void RecalculateBlogArchive(IRepository<BlogPartArchiveRecord> blogArchiveRepository, BlogPostPart blogPostPart) {
            blogArchiveRepository.Flush();
            
            var commonPart = blogPostPart.As<CommonPart>();
                if(commonPart == null || !commonPart.CreatedUtc.HasValue)
                    return;

            // get the time zone for the current request
            var timeZone = _workContextAccessor.GetContext().CurrentTimeZone;

            var previousCreatedUtc = _previousCreatedUtc.ContainsKey(blogPostPart) ? _previousCreatedUtc[blogPostPart] : DateTime.MinValue;
            previousCreatedUtc = TimeZoneInfo.ConvertTimeFromUtc(previousCreatedUtc, timeZone);

            var previousMonth = previousCreatedUtc.Month;
            var previousYear = previousCreatedUtc.Year;

            var newCreatedUtc = commonPart.CreatedUtc;
            newCreatedUtc = newCreatedUtc.HasValue ? TimeZoneInfo.ConvertTimeFromUtc(newCreatedUtc.Value, timeZone) : newCreatedUtc;

            var newMonth = newCreatedUtc.HasValue ? newCreatedUtc.Value.Month : 0;
            var newYear = newCreatedUtc.HasValue ? newCreatedUtc.Value.Year : 0;

            // if archives are the same there is nothing to do
            if (previousMonth == newMonth && previousYear == newYear) {
                return;
            }
            
            // decrement previous archive record
            var previousArchiveRecord = blogArchiveRepository.Table
                .Where(x => x.BlogPart == blogPostPart.BlogPart.Record
                    && x.Month == previousMonth
                    && x.Year == previousYear)
                .FirstOrDefault();

            if (previousArchiveRecord != null && previousArchiveRecord.PostCount > 0) {
                previousArchiveRecord.PostCount--;
            }

            // if previous count is now zero, delete the record
            if (previousArchiveRecord != null && previousArchiveRecord.PostCount == 0) {
                blogArchiveRepository.Delete(previousArchiveRecord);
            }
            
            // increment new archive record
            var newArchiveRecord = blogArchiveRepository.Table
                .Where(x => x.BlogPart == blogPostPart.BlogPart.Record
                    && x.Month == newMonth
                    && x.Year == newYear)
                .FirstOrDefault();

            // if record can't be found create it
            if (newArchiveRecord == null) {
                newArchiveRecord = new BlogPartArchiveRecord { BlogPart = blogPostPart.BlogPart.Record, Year = newYear, Month = newMonth, PostCount = 0 };
                blogArchiveRepository.Create(newArchiveRecord);
            }

            newArchiveRecord.PostCount++;            
        }
Esempio n. 4
0
        private void UpdateBlogPostCount(BlogPostPart blogPostPart) {
            CommonPart commonPart = blogPostPart.As<CommonPart>();
            if (commonPart != null &&
                commonPart.Record.Container != null) {

                BlogPart blogPart = blogPostPart.BlogPart ?? 
                    _blogService.Get(commonPart.Record.Container.Id, VersionOptions.Published).As<BlogPart>();

                // Ensure the "right" set of published posts for the blog is obtained
                blogPart.PostCount = _blogPostService.PostCount(blogPart);
            }
        }
        private void ReduceBlogArchive(IRepository<BlogPartArchiveRecord> blogArchiveRepository, BlogPostPart blogPostPart) {
            blogArchiveRepository.Flush();

            var commonPart = blogPostPart.As<CommonPart>();
            if (commonPart == null || !commonPart.CreatedUtc.HasValue)
                return;

            var timeZone = _workContextAccessor.GetContext().CurrentTimeZone;
            var datetime = TimeZoneInfo.ConvertTimeFromUtc(commonPart.CreatedUtc.Value, timeZone);

            var previousArchiveRecord = blogArchiveRepository.Table
                .FirstOrDefault(x => x.BlogPart == blogPostPart.BlogPart.Record
                                    && x.Month == datetime.Month
                                    && x.Year == datetime.Year);

            if(previousArchiveRecord == null)
                return;

            if (previousArchiveRecord.PostCount > 0)
                previousArchiveRecord.PostCount--;
            else
                blogArchiveRepository.Delete(previousArchiveRecord);
        }
 public static string BlogPost(this UrlHelper urlHelper, BlogPostPart blogPostPart) {
     return urlHelper.Action("Item", "BlogPost", new { blogPath = blogPostPart.BlogPart.As<IRoutableAspect>().Path, postSlug = blogPostPart.As<IRoutableAspect>().GetEffectiveSlug(), area = "Orchard.Blogs" });
 }
Esempio n. 7
0
        private static XRpcStruct CreateBlogStruct(
            BlogPostPart blogPostPart,
            UrlHelper urlHelper)
        {
            var url = urlHelper.AbsoluteAction(() => urlHelper.ItemDisplayUrl(blogPostPart));

            if (blogPostPart.HasDraft()) {
                url = urlHelper.AbsoluteAction("Preview", "Item", new { area = "Contents", id = blogPostPart.ContentItem.Id });
            }

            var blogStruct = new XRpcStruct()
                .Set("postid", blogPostPart.Id)
                .Set("title", HttpUtility.HtmlEncode(blogPostPart.Title))

                .Set("description", blogPostPart.Text)
                .Set("link", url)
                .Set("permaLink", url);

            blogStruct.Set("wp_slug", blogPostPart.As<IAliasAspect>().Path);

            if (blogPostPart.PublishedUtc != null) {
                blogStruct.Set("dateCreated", blogPostPart.PublishedUtc);
                blogStruct.Set("date_created_gmt", blogPostPart.PublishedUtc);
            }

            return blogStruct;
        }