Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How pubDate will remain same after opening/editing in WLW #235

Open
LeivoSepp opened this issue Aug 23, 2016 · 2 comments
Open

How pubDate will remain same after opening/editing in WLW #235

LeivoSepp opened this issue Aug 23, 2016 · 2 comments

Comments

@LeivoSepp
Copy link

I have a requirements, that editing post in WLW, the pubDate must stay same as it was initially.
For example I need to edit some post from year 2010 and I need that the published date is staying unchanged. At the moment it is possible only in web-page. In WLW I need to enter each time published date, because it is not loaded into WLW.

I came up with solution to change the code. Can you suggest, is there any better way to do that.

I changed 3 things:

  1. Post.cs:
    public Post()
    {
        ID = Guid.NewGuid().ToString();
        Title = "My new post";
        Author = HttpContext.Current.User.Identity.Name;
        Content = "the content";
        //default datetime only if new posting from web
        if (Blog.IsNewPost)
        {
            PubDate = DateTime.UtcNow;
        }
        LastModified = DateTime.UtcNow;
        Categories = new string[0];
        Comments = new List<Comment>();
        IsPublished = true;
        Latitude = "";
        Longtitude = "";
        Place = "";
    }
  1. MetaWebLogHandler.cs
    string IMetaWeblog.AddPost(string blogid, string username, string password, Post post, bool publish)
    {
        ValidateUser(username, password);
        if (!string.IsNullOrWhiteSpace(post.Slug))
        {
            post.Slug = PostHandler.CreateSlug(post.Slug);
        }
        else
        {
            post.Slug = PostHandler.CreateSlug(post.Title);    
        }
        //in case new post from WLW and pubdate is empty
        if (post.PubDate == DateTime.MinValue)
        {
            post.PubDate = DateTime.UtcNow;
        }
        post.IsPublished = publish;
        Storage.Save(post);
        return post.ID;
    }
  1. MetaWebLogHandler.cs
 bool IMetaWeblog.UpdatePost(string postid, string username, string password, Post post, bool publish)
    {
        ValidateUser(username, password);

        Post match = Storage.GetAllPosts().FirstOrDefault(p => p.ID == postid);

        if (match != null)
        {
            match.Title = post.Title;
            match.Excerpt = post.Excerpt;
            match.Content = post.Content;
            //if posting date is not empty (published date is marked in WLW)  
            if (post.PubDate != DateTime.MinValue)
            {
                match.PubDate = post.PubDate;
            }
            if (!string.Equals(match.Slug, post.Slug, StringComparison.OrdinalIgnoreCase))
                match.Slug = PostHandler.CreateSlug(post.Slug);

            match.Categories = post.Categories;
            match.IsPublished = publish;
            Storage.Save(match);
        }
        return match != null;
    }
@phatcher
Copy link

Not sure your issue and code align...

The changes you've made to IMetaWeblog.UpdatePost allow you to change the publication date, the code as originally stated did not change match,PubDate so it didn't matter what WLW said it would remain the same

@LeivoSepp
Copy link
Author

Interesting. Based on my testing, when you open old post in WLW, the PublishedDate checkbox is not set and the date is empty.
After clicking publish, the post will take current date.
I will make some additional testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants