By Guus , 22 June 2009

Frost/Nixon.We saw Frost/Nixon recently. We had heard good things about it and I picked it up from Blockbuster without reading the summary. So it was somewhat surprising that in the first few minutes of the movie the whole Watergate-to-Nixon-resigning story was told. Obviously, the film was not a documentary about the actual affair, but about 4 interviews that President Nixon gave after his resignation to Mr. Frost, a celebrity journalist.

An original angle to take, and the movie was very interesting. The journalist, obviously looking for a spectacular 'scoop' of some kind, is depicted as in an battle against the smart and ex-president, who is looking for redemption in the public view.

Very good acting, especially by Michael Sheen who was playing President Nixon's role.

Topic
By Guus , 20 June 2009

One of the modules on my website, Book Review, is old and hasn't been updated since September 2007. Drupal has a great version/stability tracking system, and it's clear that this module isn't maintained anymore. Over time I want to upgrade my website to Drupal 6 so it's time to move away from unsupported modules.

On a technical level a book review is just a couple of text fields (author, ISBN number) combined with the standard Drupal text fields body and title. That makes it a great candidate for creating of a custom Node using Drupal's Content Creation Kit (CCK).

Here is how I converted from module Book Review CCK using the excellent node_import module and custom MySQL statements to export book reviews to a Comma Separated Value (CSV) file.

I'm using Book Review version 5.x-1.x-dev and CCK version 5.x-1.10. For completeness, my PHP version is 5.2.6 and I'm running MySQL 5.0.15a on OpenBSD.

The first step is to create a new content type. Go to /admin/content/types/add and create a new content type. I'd recommend to use the name "Book review" and type "book_review" (notice the underscore). The other field names and options are matter of personal preference and don't matter for the conversion. The Name and Type fields need to be unique, so on my system I renamed the existing (module's) content type to "Book review old".

I did not use all fields of the book review module. Here are the fields that I used:

Title - the title of the book. This will be mapped to the title field of the CCK node.
Review - the actual review. This will be mapped to the 'body' of the CCK node.
Date - the date of the review. This will be mapped to the date field of the CCK node.
Author - author of the book.
ISBN - ISBN of the book
Cover picture - a link to an image file on my site. Example: "/images/books/otherpeoplestrades.jpg".
In addition we'll port a couple of other Drupal internal fields such as "promote to frontpage", "comment settings etc".
Old_nid - For the migration of our comments, we'll add a tempory field.

The fields "Title", "Review" and "Date" are part of the standard Drupal Node. Let's create the Author, ISBN and Cover Picture fields to the CCK node.

Fields.

For simplicity I'm assuming each bookreview has 1 author (table bookreview_authors). I don't have anything in bookreview_links.

mysql>SELECT 'nid','status','created','changed','comment', 'promote','moderate', 'sticky', 
'uid','booktitle','author', 'cover', 'isbn', 'review' UNION SELECT bookreview.nid, status, 
created, changed, comment, promote, moderate, sticky, uid, booktitle, author, cover, isbn, 
review INTO OUTFILE '/tmp/export.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' ESCAPED BY '\\' 
LINES TERMINATED BY '\n' FROM (bookreview LEFT JOIN bookreview_authors ON bookreview.nid = bookreview_authors.nid) 
INNER JOIN node ON bookreview.nid = node.nid;

This will result in a 'export.csv' file in your /tmp directory, and contains the content of all your bookreviews.

To clean up the file:

sed 's/\\N//g' export.csv > export.tmp
perl -p -e 's/\\\n/<br \/>\n/g' export.tmp > export.tmp2
tr -d '\r' < export.tmp2 > export.csv

This will create a file with a structure like this:

"nid","status","created","changed","comment","promote","moderate","sticky","uid","booktitle",
"author","cover","isbn","review"

"1755","1","1036105200","1036105200","2","0","0","0","24","Ooggetuigen van de vaderlandse geschiedenis",
,"http://www.guusbosman.nl/images/books/ooggetuigen.jpg","","A compilation of articles ... "

Now, install the node_import module (http://drupal.org/project/node_import), activate it and go to /admin/content/node_import. Select your CSV file, choose "Book review" for Type. Map all the fields appropriately; there's no need to customize the Options. Here's the mapping I used:

nid
old_nid_value (field_old_nid)
status
Node: Published
created
Node: Authored on
changed
Node: Last updated on
comment
Node: Comment options
promote
Node: Promoted to frontpage
moderate
Node: In moderation queue
sticky
Node: Sticky at top of lists
uid
Node: Authored by
booktitle
Title
author
Author value (field_author)
cover
cover_picture value (field_cover_picture)
isbn
ISBN value (field_isbn)
review
Body

Drupal module node_import in action.

Now you'll have 2 versions of each of your book reviews, one of the old 'bookreview' type, and one of the new 'book_review' type. The last thing remaining is to migrate any comments.

Here's how you can check if you have any comments assigned to book reviews:

SELECT node.type, node.title, node_comment_statistics.comment_count
FROM node INNER JOIN node_comment_statistics ON node.nid = node_comment_statistics.nid
WHERE (((node.type)="bookreview") AND ((node_comment_statistics.comment_count)>0));

This is how you see what the mapping from the old nid to the new nid is:

SELECT field_old_nid_value AS old, content_type_book_review.nid AS new FROM comments, content_type_book_review 
WHERE comments.nid = content_type_book_review.field_old_nid_value;

For each combination, do the following: (I had only 3 comments in my database so I didn't feel like automating this completely. You may want to script this if you have more than a trivial amount of comments).

UPDATE node_comment_statistics AS a JOIN node_comment_statistics AS b ON (a.nid=2843 AND b.nid=1790) 
JOIN node_comment_statistics AS c ON (c.nid=a.nid) SET a.nid=-a.nid,b.nid=2843,c.nid=1790; 
UPDATE comments set nid = 2840 WHERE nid = 1790;

In the example above 2843 is the new nid for the old 1790 nid.

After this, you're essentially done with the migration; all you have to do is update your Views appropriately. You can now delete the old "Book review Old" nodes, and over time you can delete the old_nid column from "Book review".

Notes & suggestions for improvements:

- The newly created nodes may use '<br />' to create line breaks. Make sure that your HTML filter allows this for the Input format that you selected for Book Reviews
- If you care about tracking how often an article is read, you'd need to update table node_counter manually
- It would be good to automate the comment conversion.
- This conversion doesn't work very nicely for non-ASCII characters in the author or title field (body field is fine).

Topic
By Guus , 20 June 2009

GusGrown up Soda, or... Gus.

We saw this in a supermarket and gave it a try. "Gus is the first soda made truly for adult palates. It's less sweet than typical flavored sodas, juice drinks and bottled teas."

See also: Gus Busman.

Gus

Topic
By Guus , 18 June 2009

Had another great run with NCRC tonight. It is so much fun to run with a group; makes me run faster.

Started running from the car which was parked 0.5 mile from the start since I was late (always like that of course -- the closer you are to an event the later you arrive ;)). Then caught up with the main group. Very humid, very warm.

By Guus , 16 June 2009

Turtle.I had a great run after work. Nowadays it doesn't get dark until late, and Umstead Park is open until 9.00 pm so with some planning I can do a long run.

I saw two deer (one of them scared me a lot) and all the way at the end of my run a small turtle on the trail. I wonder how long it would take to cross the trail.

Turtle.

I carry my cell phone, which has a camera, on my long runs.

Topic
By Guus , 13 June 2009

I ran the Race for the Cure again. I really enjoyed it last year and this year was great again. I ran with the NCRC team.

My time was around 26:15 but I forgot to switch off my watch at the finish so I'm not sure. That's very close to my time last year. I noticed that the heat slowed me down. Even though we started at 7.00 am it was around 75 degrees, and the humidity was 84%.

The recreational run at 9.00 am had around 20,000 participants, and the event raised around $2 million for breast cancer research, treatment and prevention.

On my way to Raleigh there was a traffic jam due to a car that had crashed into a firetruck.

Topic
By Guus , 12 June 2009

I'm looking forward to tomorrow morning; I'll be running the Race for the Cure in Raleigh. A short, friendly race and I'm running with NCRC.

Today was a long day; I worked from home and did a lot of small bug fixing. Addicting stuff.

Topic
By Guus , 9 June 2009

Went for a nice run on the standard course around Duke; my last run before Saturday's 5k race.

Made the traffic light 29:45. End time was 33:37 -- 9.6 minutes/mile.

By Guus , 7 June 2009

Great trail run. Loblolly trail to the end (took 30 minutes), then 8 minutes on gravel trail back to intersection with Loblolly, back to beginning. 12.8 minutes/mile