After having switched my blog to DokuWiki, I began to import old posts of my Drupal-based blog. In doing so, I wanted to keep the creation dates of articles and comments. If you have to do something similar, here is how I did it.
I will use as example the post Booklet Script which was created at 2009-01-04 10:19. This post also had one comment, at 12:06 the same day.
Warning: Make a backup before proceeding. This instructions are just a quick hack without any reference to DokuWiki documentation.
First, I did not created the post using the blog plugin form, but I rather typed the address directly as
blog/2009/01/04/booklet_script. I clicked on the
Create the page button, copied the post (adapting the syntax were necessary) and saved. That way, the post was already in the right namespace (adapt to your own blog plugin date prefix).
Second, I entered the comment myself and saved it.
So far, DokuWiki assigned today's date (2009-12-03) and hour to both the article and the comment (with a small delay between the article and the comment). As it is my last post, it also display first in the home page.
Logging through SSH on my web server, I noticed the following files had been created in
attic/blog/2009/01/04/booklet_script.1259852969.txt.gz media/blog/2009/01/04/booklet.gz meta/blog/2009/01/04/booklet_script.changes meta/blog/2009/01/04/booklet_script.comments meta/blog/2009/01/04/booklet_script.indexed meta/blog/2009/01/04/booklet_script.meta pages/blog/2009/01/04/booklet_script.txt
while the following files had changed1):
meta/_dokuwiki.changes meta/_comments.changes meta/_media.changes
The first thing to do is to locate the timestamps2) of both article creation time and comment creation time. Last line of
1259852969 22.214.171.124 C blog:2009:01:04:booklet_script csoldani created
so the article creation time is 1259852969. Similarly, the last line of
1259853042 126.96.36.199 cc blog:2009:01:04:booklet_script csoldani a7ce21638ac464ec215a49e2ef12db93
so the comment creation time is 1259853042.
The second thing to do is to generate the right timestamps. It is simple with
% date +'%s' -d"2009-01-04 10:19" 1231060740 % date +'%s' -d"2009-01-04 12:06" 1231067160
Third, you have to replace occurrences of the wrong timestamps by the right ones in all files where they occur. You can use
sed or the editor of your choice.
Article creation date:
sed -i "s/1259852969/1231060740/g" meta/_comments.changes sed -i "s/1259852969/1231060740/g" meta/_dokuwiki.changes sed -i "s/1259852969/1231060740/g" meta/blog/2009/01/04/booklet_script.changes sed -i "s/1259852969/1231060740/g" meta/blog/2009/01/04/booklet_script.meta
sed -i "s/1259853042/1231067160/g" meta/_comments.changes sed -i "s/1259853042/1231067160/g" meta/blog/2009/01/04/booklet_script.comments
Warning: changing the '*.changes' files might not be safe nor necessary, although nothing bad occurred in my case (one can also sort them by timestamp after modification to avoid surprises with plugins).
Finally, you have to move the file in
attic to reflect the new timestamp:
mv attic/blog/2009/01/04/booklet_script.1259852969.txt.gz attic/blog/2009/01/04/booklet_script.1231060740.txt.gz
Although not date related, I also changed the name of the comment author in
meta/blog/2009/01/04/booklet_script.comments. It is simply a matter of replacing
Et voilà ! My post and comment have got their original date back and are handled correctly by the blog plugin.
The process is a bit cumbersome (compared to setting the original date directly in Drupal), but relatively trivial to do. Moreover, the process was easy to find just by having a look at generated files.
Next step would be to write a script or plugin to automate this, but I don't have enough posts to justify the effort. Moreover, the more general Meta plugin might do the trick (but it looks experimental at the moment).