Update topid, post, user values post topic restoration run

This commit is contained in:
David Sainty 2024-12-09 21:38:48 +11:00
parent 9c0f2fa5cc
commit 75ec9e2725

View File

@ -1859,6 +1859,7 @@ class GossamerForumsImporter < ImportScripts::Base
end end
end end
# Update topic stats for the restored topic.
def update_topic_stats_final11 def update_topic_stats_final11
# Update topics with the correct last post time, post count, and last post user # Update topics with the correct last post time, post count, and last post user
puts "Update topics with the correct last post time, post count, and last post user" puts "Update topics with the correct last post time, post count, and last post user"
@ -1892,6 +1893,42 @@ class GossamerForumsImporter < ImportScripts::Base
end end
end end
# Update (increment) user stats, but don't touch trust levels, after topic restoration.
def update_user_stats_final11
# Update user profiles with the number of topics and posts created
puts "Update user profiles with the number of topics and posts created"
@db.execute("SELECT * FROM user_topic_count_final11").each do |row|
user_id, count = row
puts "update_user_stats user_id #{user_id} topic_count #{count}"
begin
user_stat = UserStat.find_or_initialize_by(user_id: user_id)
# user_stat.update_columns(topic_count: count)
# Accumulate the current topic count with the new count
new_topic_count = user_stat.topic_count.to_i + count.to_i
user_stat.update_columns(topic_count: new_topic_count)
rescue
puts "WARNING: Could not find User with id=#{user_id}. Skipping..."
end
end
@db.execute("SELECT * FROM user_post_count_final11").each do |row|
user_id, count = row
puts "update_user_stats user_id #{user_id} post_count #{count}"
begin
user_stat = UserStat.find_or_initialize_by(user_id: user_id)
# user_stat.update_columns(post_count: count)
# Accumulate the current post count with the new count
new_post_count = user_stat.post_count.to_i + count.to_i
user_stat.update_columns(post_count: new_post_count)
rescue
puts "WARNING: Could not find or modify User with id=#{user_id}. Skipping..."
end
end
end
def update_user_stats def update_user_stats
# Update user profiles with the number of topics and posts created # Update user profiles with the number of topics and posts created
puts "Update user profiles with the number of topics and posts created" puts "Update user profiles with the number of topics and posts created"
@ -1948,6 +1985,7 @@ class GossamerForumsImporter < ImportScripts::Base
end end
end end
# Correct user stats, notably the trust levels, after the final post-migration import run.
def update_user_stats_finalfinal def update_user_stats_finalfinal
@db.execute("SELECT * FROM user_post_count_final").each do |row| @db.execute("SELECT * FROM user_post_count_final").each do |row|
user_id, count = row user_id, count = row
@ -1997,7 +2035,7 @@ class GossamerForumsImporter < ImportScripts::Base
end end
# Set user stats, including the trust levels (albeit incorrectly...) after the final post-migration import run.
def update_user_stats_final def update_user_stats_final
# Update user profiles with the number of topics and posts created # Update user profiles with the number of topics and posts created
puts "Update user profiles with the number of topics and posts created" puts "Update user profiles with the number of topics and posts created"
@ -2234,7 +2272,7 @@ class GossamerForumsImporter < ImportScripts::Base
### import_categories ### import_categories
### import_topics_and_posts ### import_topics_and_posts
threaded_topic_restore(restore_forumpost_id) # threaded_topic_restore(restore_forumpost_id)
### update_topic_stats ### update_topic_stats
### update_user_stats ### update_user_stats
@ -2242,8 +2280,8 @@ class GossamerForumsImporter < ImportScripts::Base
### update_topic_stats_final ### update_topic_stats_final
### update_user_stats_finalfinal ### update_user_stats_finalfinal
# update_topic_stats_final11 update_topic_stats_final11
# update_user_stats_finalfinal11 update_user_stats_final11
### export_url_mapping_to_csv("/bitnami/discourse/sqlite/gossamer-migration-url-mapping#{timestamp}") ### export_url_mapping_to_csv("/bitnami/discourse/sqlite/gossamer-migration-url-mapping#{timestamp}")
### export_nginx_rewrite_rules("/bitnami/discourse/sqlite/gossamer-redirects#{timestamp}.conf") ### export_nginx_rewrite_rules("/bitnami/discourse/sqlite/gossamer-redirects#{timestamp}.conf")