diff --git a/goss-restorethread.rb b/goss-restorethread.rb index 75641f3..283e122 100644 --- a/goss-restorethread.rb +++ b/goss-restorethread.rb @@ -178,23 +178,23 @@ class GossamerForumsImporter < ImportScripts::Base end def insert_user_id_mapping(old_user_id, new_user_id) - @db.execute "INSERT OR REPLACE INTO user_id_map (old_user_id, new_user_id) VALUES (?, ?)", old_user_id, new_user_id + @db.execute("INSERT OR REPLACE INTO user_id_map (old_user_id, new_user_id) VALUES (?, ?)", [old_user_id, new_user_id]) end def fetch_user_id_mapping(old_user_id) - @db.get_first_value "SELECT new_user_id FROM user_id_map WHERE old_user_id = ?", old_user_id + @db.get_first_value("SELECT new_user_id FROM user_id_map WHERE old_user_id = ?", [old_user_id]) end def insert_category_id_mapping(old_category_id, new_category_id) - @db.execute "INSERT OR REPLACE INTO category_id_map (old_category_id, new_category_id) VALUES (?, ?)", old_category_id, new_category_id + @db.execute("INSERT OR REPLACE INTO category_id_map (old_category_id, new_category_id) VALUES (?, ?)", [old_category_id, new_category_id]) end def fetch_category_id_mapping(old_category_id) - @db.get_first_value "SELECT new_category_id FROM category_id_map WHERE old_category_id = ?", old_category_id + @db.get_first_value("SELECT new_category_id FROM category_id_map WHERE old_category_id = ?", [old_category_id]) end def insert_username_mapping(old_username, new_username, email, real_name) - @db.execute "INSERT OR REPLACE INTO username_map (old_username, new_username, email, real_name) VALUES (?, ?, ?, ?)", old_username, new_username, email, real_name + @db.execute("INSERT OR REPLACE INTO username_map (old_username, new_username, email, real_name) VALUES (?, ?, ?, ?)", [old_username, new_username, email, real_name]) end # Define a method to export the username mapping table to a CSV file @@ -213,7 +213,7 @@ class GossamerForumsImporter < ImportScripts::Base # Insert a URL mapping into the SQLite database def insert_url_mapping(old_post_id, new_url, title) - @db.execute "INSERT OR REPLACE INTO url_map (old_post_id, new_url, title) VALUES (?, ?, ?)", [old_post_id, new_url, title] + @db.execute("INSERT OR REPLACE INTO url_map (old_post_id, new_url, title) VALUES (?, ?, ?)", [old_post_id, new_url, title]) end # Export the URL mappings to a CSV file @@ -240,101 +240,104 @@ class GossamerForumsImporter < ImportScripts::Base # Fetch the highest old_post_id from the url_map table def fetch_highest_old_post_id - @db.get_first_value "SELECT MAX(old_post_id) FROM url_map" + @db.get_first_value("SELECT MAX(old_post_id) FROM url_map") end # Helper methods to interact with the SQLite database for persisting topic-post related values def fetch_db(table, key) - @db.get_first_value "SELECT value FROM #{table} WHERE key = ?", key + @db.get_first_value("SELECT value FROM #{table} WHERE key = ?", [key]) end def update_db(table, key, value) - @db.execute "INSERT OR REPLACE INTO #{table} (key, value) VALUES (?, ?)", key, value + @db.execute("INSERT OR REPLACE INTO #{table} (key, value) VALUES (?, ?)", [key, value]) end def fetch_db_topic_last_post_time(topic_id) - @db.get_first_value "SELECT last_post_time FROM topic_last_post_time_final2 WHERE topic_id = ?", topic_id + @db.get_first_value("SELECT last_post_time FROM topic_last_post_time_final2 WHERE topic_id = ?", [topic_id]) end def fetch_db_topic_last_post_user(topic_id) - @db.get_first_value "SELECT user_id FROM topic_last_post_user_final2 WHERE topic_id = ?", topic_id + @db.get_first_value("SELECT user_id FROM topic_last_post_user_final2 WHERE topic_id = ?", [topic_id]) end def fetch_db_topic_post_count(topic_id) - @db.get_first_value "SELECT post_count FROM topic_post_count_final2 WHERE topic_id = ?", topic_id + @db.get_first_value("SELECT post_count FROM topic_post_count_final2 WHERE topic_id = ?", [topic_id]) end def fetch_db_user_topic_count(user_id) - @db.get_first_value "SELECT topic_count FROM user_topic_count_final2 WHERE user_id = ?", user_id + @db.get_first_value("SELECT topic_count FROM user_topic_count_final2 WHERE user_id = ?", [user_id]) end def fetch_db_user_post_count(user_id) - @db.get_first_value "SELECT post_count FROM user_post_count_final2 WHERE user_id = ?", user_id + @db.get_first_value("SELECT post_count FROM user_post_count_final2 WHERE user_id = ?", [user_id]) end def fetch_db_topic_post_numbers(topic_id) - @db.get_first_value "SELECT post_number FROM topic_post_numbers_final2 WHERE topic_id = ?", topic_id + # @db.get_first_value "SELECT post_number FROM topic_post_numbers_final2 WHERE topic_id = ?", topic_id + @db.get_first_value("SELECT post_number FROM topic_post_numbers_final2 WHERE topic_id = ?", [topic_id]) + end def update_db_topic_last_post_time(topic_id, last_post_time) - puts "zzzzzzzzz1 #{topic_id} #{last_post_time}" - @db.execute "INSERT OR REPLACE INTO topic_last_post_time_final2 (topic_id, last_post_time) VALUES (?, ?)", topic_id, last_post_time + # puts "zzzzzzzzz1 #{topic_id} #{last_post_time}" + # @db.execute "INSERT OR REPLACE INTO topic_last_post_time_final2 (topic_id, last_post_time) VALUES (?, ?)", topic_id, last_post_time + @db.execute("INSERT OR REPLACE INTO topic_last_post_time_final2 (topic_id, last_post_time) VALUES (?, ?)", [topic_id, last_post_time]) end def update_db_topic_last_post_user(topic_id, user_id) - @db.execute "INSERT OR REPLACE INTO topic_last_post_user_final2 (topic_id, user_id) VALUES (?, ?)", topic_id, user_id + @db.execute("INSERT OR REPLACE INTO topic_last_post_user_final2 (topic_id, user_id) VALUES (?, ?)", [topic_id, user_id]) end def update_db_topic_post_count(topic_id, post_count) - @db.execute "INSERT OR REPLACE INTO topic_post_count_final2 (topic_id, post_count) VALUES (?, ?)", topic_id, post_count + @db.execute("INSERT OR REPLACE INTO topic_post_count_final2 (topic_id, post_count) VALUES (?, ?)", [topic_id, post_count]) end def update_db_user_topic_count(user_id, topic_count) - @db.execute "INSERT OR REPLACE INTO user_topic_count_final2 (user_id, topic_count) VALUES (?, ?)", user_id, topic_count + @db.execute("INSERT OR REPLACE INTO user_topic_count_final2 (user_id, topic_count) VALUES (?, ?)", [user_id, topic_count]) end def update_db_user_post_count(user_id, post_count) - @db.execute "INSERT OR REPLACE INTO user_post_count_final2 (user_id, post_count) VALUES (?, ?)", user_id, post_count + @db.execute("INSERT OR REPLACE INTO user_post_count_final2 (user_id, post_count) VALUES (?, ?)", [user_id, post_count]) end def update_db_topic_post_numbers(topic_id, post_number) - @db.execute "INSERT OR REPLACE INTO topic_post_numbers_final2 (topic_id, post_number) VALUES (?, ?)", topic_id, post_number + @db.execute("INSERT OR REPLACE INTO topic_post_numbers_final2 (topic_id, post_number) VALUES (?, ?)", [topic_id, post_number]) end # Fetch the highest processed post_id from the highest_processed_post_id table def fetch_highest_processed_post_id - @db.get_first_value "SELECT post_id FROM highest_processed_post_id WHERE id = 1" + @db.get_first_value("SELECT post_id FROM highest_processed_post_id WHERE id = 1") end # Update the highest processed post_id in the highest_processed_post_id table def update_highest_processed_post_id(post_id) - @db.execute "INSERT OR REPLACE INTO highest_processed_post_id (id, post_id) VALUES (1, ?)", post_id + @db.execute("INSERT OR REPLACE INTO highest_processed_post_id (id, post_id) VALUES (1, ?)", [post_id]) end # Fetch the highest processed personal_id from the highest_processed_personal_id table def fetch_highest_processed_personal_id - @db.get_first_value "SELECT personal_id FROM highest_processed_personal_id WHERE id = 1" + @db.get_first_value("SELECT personal_id FROM highest_processed_personal_id WHERE id = 1") end # Update the highest processed personal_id in the highest_processed_personal_id table def update_highest_processed_personal_id(personal_id) - @db.execute "INSERT OR REPLACE INTO highest_processed_personal_id (id, personal_id) VALUES (1, ?)", personal_id + @db.execute("INSERT OR REPLACE INTO highest_processed_personal_id (id, personal_id) VALUES (1, ?)", [personal_id]) end # Check if post_id exists and its status def fetch_post_status(post_id) - result = @db.execute("SELECT status FROM topic_import_status WHERE post_id = ?", post_id).flatten.first + result = @db.execute("SELECT status FROM topic_import_status WHERE post_id = ?", [post_id]).flatten.first result.nil? ? nil : result.to_i end # Mark post_id as complete def mark_post_as_complete(post_id) - @db.execute("INSERT OR REPLACE INTO topic_import_status (post_id, status) VALUES (?, 1)", post_id) + @db.execute("INSERT OR REPLACE INTO topic_import_status (post_id, status) VALUES (?, 1)", [post_id]) end # Mark post_id as failed def mark_post_as_failed(post_id) - @db.execute("INSERT OR REPLACE INTO topic_import_status (post_id, status) VALUES (?, 0)", post_id) + @db.execute("INSERT OR REPLACE INTO topic_import_status (post_id, status) VALUES (?, 0)", [post_id]) end # Execute an SQL query on the Gossamer Forums database