Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions BlogML/Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,24 @@ namespace BlogML.Helper.BlogML
{
class BlogMLToWRXConverter
{
internal static string GenerateWRXFile(string blogMLFilePath)
private static bool _useIdentitySeed = false;
private static int _identitySeed = 0;

/// <summary>
/// Generate the WRX File
/// </summary>
/// <param name="blogMLFilePath">Path to the BlogML file</param>
/// <param name="identitySeed">If the identitySeed is set the POST ID is overridden with an incremented identitySeed</param>
/// <returns></returns>
internal static string GenerateWRXFile(string blogMLFilePath,int identitySeed=0)
{

if (identitySeed > 0)
{
_useIdentitySeed = true;
_identitySeed = identitySeed;
}

if (string.IsNullOrEmpty(blogMLFilePath))
throw new ArgumentNullException("blogMLFilePath", "BlogMLFilePath is mandatory parameter");

Expand Down Expand Up @@ -208,6 +224,9 @@ private static void WriteWXRDocument(BlogML.blogType blogData, string baseUrl, s
// TODO: Swap code so that all posts are processed, not just first 5.
for (int i = 0; i <= blogData.posts.Length - 1; i++)
{
if (_useIdentitySeed)
_identitySeed = _identitySeed + i;

string postXml=WritePost(blogData.posts[i], blogData, baseUrl);
writer.WriteRaw(postXml);
}
Expand Down Expand Up @@ -276,7 +295,14 @@ private static string WritePost(postType currPost, blogType blogData, string bas
}
writer.WriteCData(content);
writer.WriteEndElement(); // content:encoded
writer.WriteElementString("wp:post_id", currPost.id);

//Replace the orginal identity seed (usually a GUID depending on blog source) with an integer so we don't go over the wordpress limit of 2147483647
var postId = currPost.id;

if (_useIdentitySeed)
postId = _identitySeed.ToString();

writer.WriteElementString("wp:post_id", postId);
writer.WriteElementString("wp:post_date", currPost.datecreated.ToString("yyyy-MM-dd HH:mm:ss"));
writer.WriteElementString("wp:post_date_gmt", currPost.datecreated.ToString("yyyy-MM-dd HH:mm:ss"));
writer.WriteElementString("wp:comment_status", "open");
Expand Down
26 changes: 22 additions & 4 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static void Main(string[] args)
case ToolAction.ExportToWRX:
if (RequiredParametersPrintUsage(ToolAction.ExportToWRX, args))
{
string wrxFileName = BlogMLToWRXConverter.GenerateWRXFile(setting.BlogMLFileName);
string wrxFileName = BlogMLToWRXConverter.GenerateWRXFile(setting.BlogMLFileName, setting.BlogPostIdSeed);
Console.WriteLine("Created WRX format");

//Generate ReDirect, SourceQA and TargetQA File
Expand Down Expand Up @@ -149,7 +149,7 @@ private static void QATarget(string fileName)

private static Setting ParseInput(string[] args)
{
const string validArguments = "/Action: /BlogMLFile: /WRXFile: /QASourceFile: /QATargetFile: /QAReportFile: /SourceUrl: /TargetUrl: /NewWRXWithOnlyFailedPosts:";
const string validArguments = "/Action: /BlogMLFile: /WRXFile: /QASourceFile: /QATargetFile: /QAReportFile: /SourceUrl: /TargetUrl: /NewWRXWithOnlyFailedPosts: /BlogPostIdSeed:";

Setting setting = new Setting();
foreach (string s in args)
Expand Down Expand Up @@ -191,6 +191,17 @@ private static Setting ParseInput(string[] args)

if (argumentKey == "/QAREPORTFILE")
setting.QAReportFileName = argumentValue;

if (argumentKey == "/BLOGPOSTIDSEED")
{
int blogIdSeed = 0;
setting.BlogPostIdSeed = 0;

if (int.TryParse(argumentValue, out blogIdSeed))
{
setting.BlogPostIdSeed = blogIdSeed;
}
}
}

return setting;
Expand Down Expand Up @@ -231,8 +242,8 @@ private static bool RequiredParametersPrintUsage(ToolAction action, string[] arg
}
break;
case ToolAction.ExportToWRX:
validArguments = "/Action: /BlogMLFile: /SourceUrl: /TargetUrl:";
if (args.Length != 4)
validArguments = "/Action: /BlogMLFile: /SourceUrl: /TargetUrl: /BlogPostIdSeed:";
if (args.Length < 4)
{
Console.WriteLine("/BlogMLFile: /SourceUrl: /TargetUrl: are mandatory");
return false;
Expand Down Expand Up @@ -300,5 +311,12 @@ class Setting
public string SourceBaseUrl { get; set; }
public string TargetBaseUrl { get; set; }
public string QAReportFileName { get; set; }

/// <summary>
/// Allows you to change the BlogPost ID Seed
///
/// This helps when importing large amounts of posts into WordPress
/// </summary>
public int BlogPostIdSeed { get; set; }
}
}
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The code in this repository has error handling/logging enhancements and fixed im

For detailed description see the blog post ["Migrating your blog from any BlogML based platform to WordPress"](http://blogs.biztalk360.com/migrating-your-blog-from-any-blogml-based-platform-to-wordpress-2/)

###Extract from the post:
### Extract from the post:

Options available with the tool.
* RemoveComments
Expand All @@ -21,9 +21,16 @@ You simply run the tool with the following command

BlogML.Helper.exe /Action:ExportToWRX /BlogMLFile:BlogML.xml /SourceUrl:geekswithblogs.net/OldBlog /TargetUrl:NewBlog.wordpress.com

###Similar tools :
### Similar tools :
To import blogML format to Wordpress, there are a few tools available.
If your new site is self hosted from Wordpress.org, you can install some of available plugins, e.g. [importing-a-big-honkin-blogml-xml-file-into-wordpress](http://nixmash.com/on-wordpress/importing-a-big-honkin-blogml-xml-file-into-wordpress/)
But custom plugins not supported in Wordpress.com. For Wordpress.com you can use
[Blogmigrator](https://github.com/Dillie-O/blogmigrator ) or this tool(aka BlogML.Helper.exe).
Blogmigrator has less steps to do, but doesn't import comments. If comments are important to you, the only choice that I found is this tool.

## WordPress and high post ID's when using DasBlog as a Source
Depending on which Blog Platform you are migrating from. The postid field is sometimes a GUID, this is usually the case with DasBlog. This can cause issues in the WordPress WRX Importer plugin. It tries to convert the GUIDs to integers but it does this in quite an odd way. If you have quite a few posts in the blog you are migrating it will eventually go past 2147483647 as a postid. This is fine in MySQL but not in WordPress where it attempts to convert postid's when you render posts in WordPress to an int. When PHP encounters a post id higher than 2147483647 when converting to int it just makes the post id 2147483647 and you will end up with what looks like multiple duplicates but what is happening is all blogposts with an id greater than 2147483647 will appear as the post that actually has that id in WordPress.

To get around this use the **BlogPostIdSeed**, first check what the highest postid is in your WordPress if you have existing posts. If you have a new site you should be good with a number around 50. This will replace all the postids in the generated files with an incremented number starting from the seed.

BlogML.Helper.exe /Action:ExportToWRX /BlogMLFile:sourceblogML.xml /SourceUrl:myblog.com /TargetUrl:mynewblog.com /BlogPostIdSeed:50