User Tools

Site Tools


blog:2009:12:03:changing_dates_in_dokuwiki

Changing Dates in DokuWiki

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.

Copying the Article

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.

Changing the Date

Logging through SSH on my web server, I noticed the following files had been created in data:

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

Locate the Wrong Timestamps

The first thing to do is to locate the timestamps2) of both article creation time and comment creation time. Last line of meta/_dokuwiki.changes is

1259852969	139.165.223.23	C	blog:2009:01:04:booklet_script	csoldani	created

so the article creation time is 1259852969. Similarly, the last line of meta/_comments.changes is

1259853042	139.165.223.23	cc	blog:2009:01:04:booklet_script	csoldani		a7ce21638ac464ec215a49e2ef12db93

so the comment creation time is 1259853042.

Compute the Right Timestamps

The second thing to do is to generate the right timestamps. It is simple with date:

% date +'%s' -d"2009-01-04 10:19"
1231060740
% date +'%s' -d"2009-01-04 12:06"
1231067160

Replace the Timestamps

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

Comment:

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).

Rename the Archived Version

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

Changing Comment Author

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

s:OLD_LENGTH:"OLD_NAME"

with

s:NEW_LENGTH:"NEW_NAME"

Conclusion

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).

1) For those who wonder, my DokuWiki site is under Git control.
2) That is, number of seconds since 00:00:00 UTC on 1 January 1970.

Discussion

Stefano Silvio, 2012/10/03 11:18

This script would be very useful! I have a similar problem with my doku too; I am developing a site which contains a lot of regulation pages and I would like to use the creation date field in order to sort them in pagelist plugin from the newest rule to the oldest with a specific tag inside pages. Do you think it would be possible to do that?

Enter your comment. Wiki syntax is allowed:
 
blog/2009/12/03/changing_dates_in_dokuwiki.txt · Last modified: 2011/02/20 20:28 (external edit)