This project is read-only.

The publish date is always now when importing an old blog to Orchard

Topics: General, Troubleshooting
Mar 4, 2013 at 8:58 AM
Edited Mar 4, 2013 at 9:11 AM
I want to build my own blog, and then import data from other blog platform . The module "BlogML" didn't work for me, so I wrote a Module to extract the data from a xml file and imported it to Orchard, my core code look like this:
var dateStr = xElement.Element("pubDate").Value;
                var date = DateTime.Parse(dateStr);
                var title = xElement.Element("title").Value;
                var body = xElement.Element("description").Value;
                var blogPostContentItem =_orchardServices.ContentManager.New("BlogPost");
                blogPostContentItem.As<ICommonPart>().CreatedUtc = date;
                blogPostContentItem.As<ICommonPart>().VersionCreatedUtc = date;
                blogPostContentItem.As<ICommonPart>().PublishedUtc = date;
                blogPostContentItem.As<ICommonPart>().VersionPublishedUtc = date;
                blogPostContentItem.As<ICommonPart>().ModifiedUtc = date;
                blogPostContentItem.As<ICommonPart>().VersionModifiedUtc = date;
                blogPostContentItem.As<BlogPostPart>().Text = body;
                blogPostContentItem.As<BlogPostPart>().Title = title;
                blogPostContentItem.As<BlogPostPart>().Creator = _orchardServices.WorkContext.CurrentUser;
                blogPostContentItem.As<BlogPostPart>().BlogPart = blog;
But whatever PublishedUtc is, All Posts published date will be changed to now .

And I found the reason, in CommonPartHandler.cs , Publishing event has always reset PublishedUtc now. Is this a bug?
protected void AssignPublishingDates(PublishContentContext context, CommonPart part) {
            var utcNow = _clock.UtcNow;
            part.PublishedUtc = utcNow;
            part.VersionPublishedUtc = utcNow;
Mar 4, 2013 at 9:18 AM
No, that's by design: the last publication date is the date the item was published last. Importing publishes. It's the creation date that should matter anyway.