2024-09-09 04:19:42 +00:00
|
|
|
# Federated Computer, Inc.
|
|
|
|
# David Sainty <saint@federated.computer> 2024 A.D.
|
|
|
|
# Gossamer Threads to Discourse -- CleanUp Script
|
2024-09-09 04:34:13 +00:00
|
|
|
# v0.3 Other necessary fixes and tidyups
|
2024-09-09 04:19:42 +00:00
|
|
|
|
|
|
|
require 'mysql2'
|
|
|
|
require 'active_record'
|
|
|
|
|
|
|
|
# require 'concurrent-ruby'
|
|
|
|
require File.expand_path("../../../../config/environment", __FILE__)
|
|
|
|
|
2024-09-09 04:27:13 +00:00
|
|
|
class LegacyPost < ActiveRecord::Base
|
2024-09-09 04:28:53 +00:00
|
|
|
self.table_name = 'gforum_Post'
|
2024-09-09 04:27:13 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
class LegacyUser < ActiveRecord::Base
|
2024-09-09 04:28:53 +00:00
|
|
|
self.table_name = 'gforum_User'
|
2024-09-09 04:27:13 +00:00
|
|
|
end
|
|
|
|
|
2024-09-09 04:19:42 +00:00
|
|
|
class GossamerForumsDestroyDeletedPosts
|
|
|
|
# def initialize
|
|
|
|
# super
|
|
|
|
# begin
|
|
|
|
# # Initialize MySQL client to connect to Gossamer Forums database
|
|
|
|
# @mysql_client = Mysql2::Client.new(
|
|
|
|
# host: "slowtwitch.northend.network",
|
|
|
|
# username: "admin",
|
|
|
|
# password: "yxnh93Ybbz2Nm8#mp28zCVv",
|
|
|
|
# database: "slowtwitch"
|
|
|
|
# )
|
|
|
|
# rescue Mysql2::Error => e
|
|
|
|
# puts "Error connecting to MySQL: #{e.message}"
|
|
|
|
# exit 1
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
|
|
|
|
# Define a method to find a post by custom field
|
|
|
|
def find_post_by_custom_field(post_id)
|
2024-09-09 04:34:13 +00:00
|
|
|
puts "DestroyDeletedPosts: Searching for post with original_gossamer_id: #{post_id}"
|
2024-09-09 04:19:42 +00:00
|
|
|
|
|
|
|
post_custom_field = PostCustomField.find_by(name: 'original_gossamer_id', value: post_id.to_s)
|
|
|
|
|
|
|
|
if post_custom_field
|
|
|
|
post = post_custom_field.post
|
2024-09-09 04:34:13 +00:00
|
|
|
puts "DestroyDeletedPosts: Found post with id: #{post.id}"
|
2024-09-09 04:19:42 +00:00
|
|
|
post
|
|
|
|
else
|
2024-09-09 04:34:13 +00:00
|
|
|
puts "DestroyDeletedPosts: No post found with original_gossamer_id: #{post_id}"
|
2024-09-09 04:19:42 +00:00
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Define the method to delete posts based on the Gossamer Forums flag
|
|
|
|
def destroy_deleted_posts_from_gossamer
|
|
|
|
# Connect to the legacy MySQL database
|
|
|
|
ActiveRecord::Base.establish_connection(
|
|
|
|
adapter: 'mysql2',
|
|
|
|
host: 'slowtwitch.northend.network',
|
|
|
|
database: 'slowtwitch',
|
|
|
|
username: 'admin',
|
|
|
|
password: 'yxnh93Ybbz2Nm8#mp28zCVv'
|
|
|
|
)
|
|
|
|
|
|
|
|
# Find all posts marked as deleted in the legacy database
|
|
|
|
LegacyPost.where(post_deleted: 1).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
|
2024-09-09 04:34:13 +00:00
|
|
|
puts "DestroyDeletedPosts: Deleting post with id: #{post.id}"
|
2024-09-09 04:19:42 +00:00
|
|
|
# post.destroy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Define the method to delete posts based on the Gossamer Forums flag
|
|
|
|
def destroy_deleted_posts_from_gossamer_with_user(username)
|
|
|
|
# Connect to the legacy MySQL database
|
|
|
|
ActiveRecord::Base.establish_connection(
|
|
|
|
adapter: 'mysql2',
|
|
|
|
host: 'slowtwitch.northend.network',
|
|
|
|
database: 'slowtwitch',
|
|
|
|
username: 'admin',
|
|
|
|
password: 'yxnh93Ybbz2Nm8#mp28zCVv'
|
|
|
|
)
|
|
|
|
|
|
|
|
# Find the user ID for the given username
|
2024-09-09 04:34:13 +00:00
|
|
|
user = LegacyUser.find_by(user_username: username)
|
2024-09-09 04:19:42 +00:00
|
|
|
if user.nil?
|
2024-09-09 04:34:13 +00:00
|
|
|
puts "DestroyDeletedPosts: No user found with username: #{username}"
|
2024-09-09 04:19:42 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
# Find all posts marked as deleted in the legacy database
|
2024-09-09 04:34:13 +00:00
|
|
|
LegacyPost.where(post_deleted: 1, user_id_fk: user.user_id).find_each do |legacy_post|
|
2024-09-09 04:19:42 +00:00
|
|
|
# Look for the post in Discourse by custom field
|
|
|
|
post = find_post_by_custom_field(legacy_post.post_id)
|
|
|
|
|
|
|
|
if post
|
2024-09-09 04:34:13 +00:00
|
|
|
puts "DestroyDeletedPosts: Mock-Deleting post with id: #{post.id}"
|
2024-09-09 04:19:42 +00:00
|
|
|
# post.destroy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def perform_deleted_destroy
|
|
|
|
puts "Destroy Deleted Posts beginning!"
|
|
|
|
# destroy_deleted_posts_from_gossamer
|
|
|
|
destroy_deleted_posts_from_gossamer_with_user('spudone')
|
|
|
|
puts "Destroy Deleted Posts complete!"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
GossamerForumsDestroyDeletedPosts.new.perform_deleted_destroy
|
|
|
|
|