Issue with import script


I’m trying to import an old punBB. I have discourse installed and running, I can launch the script but it look fort first_post_id and I have only the last_post_id…

I tried to change the order of import but everything is upside down…

Any Idea on how I change the punBB import script to use the last_post_id?

Here it is the post part of the script I’m using:

def import_posts
    puts "", "creating topics and posts"

    total_count = mysql_query("SELECT count(*) count from boulette_posts").first["count"]

    batches(BATCH_SIZE) do |offset|
      results = mysql_query("
        SELECT id,
               t.forum_id category_id,
               t.subject title,
               t.last_post_id first_post_id,
               p.poster_id user_id,
               p.message raw,
               p.posted created_at
        FROM boulette_posts p,
             boulette_topics t
        WHERE p.topic_id =
        ORDER BY p.posted
        OFFSET #{offset};

      break if results.size < 1
      next if all_records_exist? :posts, { |m| m['id'].to_i }

      create_posts(results, total: total_count, offset: offset) do |m|
        skip = false
        mapped = {}

        mapped[:id] = m['id']
        mapped[:user_id] = user_id_from_imported_user_id(m['user_id']) || -1
        mapped[:raw] = process_punbb_post(m['raw'], m['id'])
        mapped[:created_at] =['created_at'])

        if m['id'] == m['first_post_id']
          mapped[:category] = category_id_from_imported_category_id("child##{m['category_id']}")
          mapped[:title] = CGI.unescapeHTML(m['title'])
          parent = topic_lookup_from_imported_post_id(m['first_post_id'])
          if parent
            mapped[:topic_id] = parent[:topic_id]
            puts "Parent post #{m['first_post_id']} doesn't exist. Skipping #{m["id"]}: #{m["title"][0..40]}"
            skip = true

        skip ? nil : mapped

Thanks for your support


I finaly achieve this by updating my punbb database and add the first_post_id to it with this:

ALTER TABLE boulette_topics ADD COLUMN first_post_id int(10);

UPDATE boulette_topics t SET first_post_id = (SELECT FROM boulette_posts p WHERE p.topic_id = ORDER BY ASC LIMIT 1);