Friday, July 29, 2011

SubText Comments to Disqus

Currently I have a Blog migration task that needs to transfer articles from SubText to Blogger. One of the requirements is using Disqus to handle comment moderation.

Disqus allows importing of comments using WordPress eXtended RSS (WXR) XML file. This is in contrast with SubText because it uses BlogML in exporting blog contents. So the nearest possible way to do is to convert BlogML to WXR.

I find it hard to search for a converter tool until such time I luckily found Dillie-O's Blog Migrator tool. You can download the source code here. It is it capable of converting BlogML XML file to a reliable WXR file.
Since we are importing to Disqus we need to follow its importing format. You can see it here. Do note that all fields are required even they contain no content.

After my first try, I noticed that Blog Migrator tool is lacking of the following tags:

<dsq:thread_identifier></dsq:thread_identifier>
<wp:comment_id></wp:comment_id>
<wp:comment_author_ip></wp:comment_author_ip>

These tags should be present to the WXR file. Since I don't want to waste time to manually add them, I made my hands dirty to Blog Migrator's source code. Here is what I did:

Open the source code and go to Solution Explorer tab.

Open Generator.cs file under the objects folder.

Inside the WriteWXRDocument() function:

Replace the attribute
writer.WriteAttributeString("xmlns", "wfw", null, "http://wellformedweb.org/CommentAPI/");
with
writer.WriteAttributeString("xmlns", "dsq", null, "http://www.disqus.com/");
Insert the code
writer.WriteStartElement("dsq:thread_identifier");
writer.WriteEndElement(); // dsq:thread_identifier
under
writer.WriteCData(currPost.content.Value);
writer.WriteEndElement();
Insert the code
writer.WriteElementString("wp:comment_id", currComment.id);
under
writer.WriteStartElement("wp:comment");
And insert the code
writer.WriteElementString("wp:comment_author_IP", "");
under
writer.WriteElementString("wp:comment_type", " ");
Save the solution and then start debugging (F5).

On the Blog Migrator window, configure the source blog. Make sure to select BlogML as the Blog Service and browse the BlogML XML file.


Configure the Destination Blog. Just select WXR File from Blog Service and browse the destination WXR file.


Click the Get Posts from Source button. The articles will then be listed. Click the Select All button.

Now click the Migrate Selected Posts button. Voila! the WXR is created.

Another important thing to note is to set the <dsq:thread_identifier></dsq:thread_identifier> tag. Usually it is the internal identifier of the article but I just leaved it blank so the URL inside the <link></link> tag will be used. If you leave it blank, make sure the url is correctly set so the comments will be properly linked to its articles.

Once you finalize the WXR, you can now log on to Disqus and import the comments using the Generic (WXR) category.

Thanks again Dillie-O for the tool. You saved my day!

Wednesday, July 13, 2011

How to Reset root's Password of MySQL

We've got a problem accessing the MySQL database when someone changes the password of 'root' user and we cannot retrieve it. So, I decided to reset it's password.


This is my setup:
  1. Using Windows Server 2008
  2. MySQL Server 5.1 installed in the default directory, inside the Program Files folder.

If your installation directory is different, just make the necessary adjustments to the steps below.

Before doing the next step, create first the init file. This will reset the password of the user 'root'.
  1. Go to C:\ drive.
  2. Create the mysql-init.txt file and open it.
  3. Copy and paste the following to the file and save it.

UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
FLUSH PRIVILEGES;

Note: Replace MyNewPass with your password.



A. If MySQL is running as a Windows Service:

Stop the service:
  1. Log in as Administrator in the server.
  2. Go to Control Panel > Administrative Tools > Services.
  3. Find the MySQL service and stop it.

Start the service:
  1. Go the Services window again and find MySQL service.
  2. Right click it and select Properties.
  3. Put the following in the Start parameters text box.
    --init-file=C:\\mysql-init.txt
  4. Now, click the Start button. Click OK once the service has started.


B. If MySQL was executed as a process:

Stop mysqld.exe:
  1. Log in as Administrator in the server.
  2. Open the Task Manager.
  3. Go to Processes tab.
  4. Select mysqld.exe and click the End Process button.

Start the mysqld.exe:
  1. Open the C:\Windows\system32 folder.
  2. Find the cmd.exe.
  3. Right click it and select Run as administrator.
  4. Type the following on the command prompt:
    C:\>"C:\Program Files\MySQL\MySQL Server 5.1\bin\mysqld.exe"
    --defaults-file="C:\Program Files\MySQL\MySQL Server 5.1\my.ini"
    --init-file=C:\\mysql-init.txt
  5. Now, click the Start button. Click OK once started.

If you got the error "InnoDB: Operating system error number 5 in a file operation"


you have to give Admin priviledge to mysqld.exe.
  1. Go to MySQL installation directory. In my case C:\Program Files\MySQL\MySQL Server 5.1\bin.
  2. Right click mysqld.exe and click Properties.
  3. Go to Compatibility tab and check out the Run this program as administrator. Click OK.
  4. Try again to start the mysqld.exe with the steps above.

MySQL should be running again. Try to connect using the username 'root' and your new password.