v0.3 Other necessary fixes and tidyups
This commit is contained in:
parent
dcafdb4f44
commit
931d8cf8c0
@ -1,7 +1,7 @@
|
|||||||
# Federated Computer, Inc.
|
# Federated Computer, Inc.
|
||||||
# David Sainty <saint@federated.computer> 2024 A.D.
|
# David Sainty <saint@federated.computer> 2024 A.D.
|
||||||
# Gossamer Threads to Discourse -- CleanUp Script
|
# Gossamer Threads to Discourse -- CleanUp Script
|
||||||
# v0.2 Fix class definition
|
# v0.3 Other necessary fixes and tidyups
|
||||||
|
|
||||||
require 'mysql2'
|
require 'mysql2'
|
||||||
require 'active_record'
|
require 'active_record'
|
||||||
@ -36,16 +36,16 @@ class GossamerForumsDestroyDeletedPosts
|
|||||||
|
|
||||||
# Define a method to find a post by custom field
|
# Define a method to find a post by custom field
|
||||||
def find_post_by_custom_field(post_id)
|
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)
|
post_custom_field = PostCustomField.find_by(name: 'original_gossamer_id', value: post_id.to_s)
|
||||||
|
|
||||||
if post_custom_field
|
if post_custom_field
|
||||||
post = post_custom_field.post
|
post = post_custom_field.post
|
||||||
Rails.logger.info("DestroyDeletedPosts: Found post with id: #{post.id}")
|
puts "DestroyDeletedPosts: Found post with id: #{post.id}"
|
||||||
post
|
post
|
||||||
else
|
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
|
nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -67,7 +67,7 @@ class GossamerForumsDestroyDeletedPosts
|
|||||||
post = find_post_by_custom_field(legacy_post.post_id)
|
post = find_post_by_custom_field(legacy_post.post_id)
|
||||||
|
|
||||||
if post
|
if post
|
||||||
Rails.logger.info("DestroyDeletedPosts: Deleting post with id: #{post.id}")
|
puts "DestroyDeletedPosts: Deleting post with id: #{post.id}"
|
||||||
# post.destroy
|
# post.destroy
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -85,19 +85,19 @@ class GossamerForumsDestroyDeletedPosts
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Find the user ID for the given username
|
# Find the user ID for the given username
|
||||||
user = LegacyUser.find_by(username: username)
|
user = LegacyUser.find_by(user_username: username)
|
||||||
if user.nil?
|
if user.nil?
|
||||||
Rails.logger.warn("DestroyDeletedPosts: No user found with username: #{username}")
|
puts "DestroyDeletedPosts: No user found with username: #{username}"
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
# Find all posts marked as deleted in the legacy database
|
# 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
|
# Look for the post in Discourse by custom field
|
||||||
post = find_post_by_custom_field(legacy_post.post_id)
|
post = find_post_by_custom_field(legacy_post.post_id)
|
||||||
|
|
||||||
if post
|
if post
|
||||||
Rails.logger.info("DestroyDeletedPosts: Mock-Deleting post with id: #{post.id}")
|
puts "DestroyDeletedPosts: Mock-Deleting post with id: #{post.id}"
|
||||||
# post.destroy
|
# post.destroy
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user