From 931d8cf8c06c18015b72eb62b7ee9198d433eab9 Mon Sep 17 00:00:00 2001 From: saint Date: Mon, 9 Sep 2024 14:34:13 +1000 Subject: [PATCH] v0.3 Other necessary fixes and tidyups --- goss-destroydeletedposts.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/goss-destroydeletedposts.rb b/goss-destroydeletedposts.rb index 3fb7c7d..4ce0b3f 100644 --- a/goss-destroydeletedposts.rb +++ b/goss-destroydeletedposts.rb @@ -1,7 +1,7 @@ # Federated Computer, Inc. # David Sainty 2024 A.D. # Gossamer Threads to Discourse -- CleanUp Script -# v0.2 Fix class definition +# v0.3 Other necessary fixes and tidyups require 'mysql2' require 'active_record' @@ -36,16 +36,16 @@ class GossamerForumsDestroyDeletedPosts # Define a method to find a post by custom field def find_post_by_custom_field(post_id) - Rails.logger.info("DestroyDeletedPosts: Searching for post with original_gossamer_id: #{post_id}") + puts "DestroyDeletedPosts: Searching for post with original_gossamer_id: #{post_id}" post_custom_field = PostCustomField.find_by(name: 'original_gossamer_id', value: post_id.to_s) if post_custom_field post = post_custom_field.post - Rails.logger.info("DestroyDeletedPosts: Found post with id: #{post.id}") + puts "DestroyDeletedPosts: Found post with id: #{post.id}" post else - Rails.logger.warn("DestroyDeletedPosts: No post found with original_gossamer_id: #{post_id}") + puts "DestroyDeletedPosts: No post found with original_gossamer_id: #{post_id}" nil end end @@ -67,7 +67,7 @@ class GossamerForumsDestroyDeletedPosts post = find_post_by_custom_field(legacy_post.post_id) if post - Rails.logger.info("DestroyDeletedPosts: Deleting post with id: #{post.id}") + puts "DestroyDeletedPosts: Deleting post with id: #{post.id}" # post.destroy end end @@ -85,19 +85,19 @@ class GossamerForumsDestroyDeletedPosts ) # Find the user ID for the given username - user = LegacyUser.find_by(username: username) + user = LegacyUser.find_by(user_username: username) if user.nil? - Rails.logger.warn("DestroyDeletedPosts: No user found with username: #{username}") + puts "DestroyDeletedPosts: No user found with username: #{username}" return end # Find all posts marked as deleted in the legacy database - LegacyPost.where(post_deleted: 1, user_id: user.id).find_each do |legacy_post| + LegacyPost.where(post_deleted: 1, user_id_fk: user.user_id).find_each do |legacy_post| # Look for the post in Discourse by custom field post = find_post_by_custom_field(legacy_post.post_id) if post - Rails.logger.info("DestroyDeletedPosts: Mock-Deleting post with id: #{post.id}") + puts "DestroyDeletedPosts: Mock-Deleting post with id: #{post.id}" # post.destroy end end