Migration from Drupal/Static Blog Site

Hi, I have a site with an eleven year old Drupal blog on it (there are about six more years of entries on there too that were translated to Drupal). I’ve had a good experience building a Kirby site from scratch, but now I’m going to want to migrate my main site.

My thoughts are that I should export the site to a static directory and write a Python script (I’m ok with Python and it’s usually simple to code) to do the conversion. The script should

  1. strip off and discard anything that doesn’t belong in the post.
  2. translate the date to a kirby MD field … will this date be the date by which files will be sorted?
  3. keep comments, they will be static for those pages (at least)…new disqus comments for new pages

Seems pretty simple. Am I missing anything?

I migrated some data from a Drupal 6 Website to Kirby using the Toolkit database API in combination with $page->create(). Unfortunately I can’t share the code completely. But if you wanna go that way I could help you a bit …

An alternative would be to use Kirby’s/PHP methods to connect to the (dumped) database and create the pages using $pages->create(). Did that once to convert stuff from a Joomla project. Pretty straightforward as well (at least the blog part of the project).

@flokosiol: you beat me :slight_smile:

First time and only by a few seconds :laughing:

You can choose by which field your posts are sorted in the front-end. And yes you can use date!

Interesting! I would rather code in Python but php isn’t very tough either.

are there any examples of similar code out there? Doesn’t have to be Drupal, just something using $page->create() to iteratively create pages…

Ok, here is a simple script:

In your config.php, set up your database settings:

c::set('db.host', 'localhost');
c::set('db.user', 'your_user');
c::set('db.password', 'your_password');
c::set('db.name', 'your_db');

In your template or route:

<?php

$results= db::query('SELECT  title, date, text FROM your_table WHERE x=z ORDER BY title desc');

foreach($results as $article) {
   try {

    $newPage = page('blog')->children()->create(str::slug($article->title()), 'new-template', array(
      'title' => $article->title(),
      'date'  => $article->date(),
      'text'  => $article->text(),
    ));

    echo 'The new page has been created';

  } catch(Exception $e) {

    echo $e->getMessage();

  }
 
  $newPage->sort($newPage->date('Ymd'));

}
?>

You will have to adapt this basic script to fit your fields/needs and maybe format/sanitize your output, before creating the new pages.

Edit: There’s more left to do for images and links etc. Also, if you want to convert html to markdown.

1 Like