v0.36 Tweaks for new Prod host, code added for Trust Level setting
This commit is contained in:
parent
78d832f2a8
commit
2fe8b483f7
@ -1,5 +1,7 @@
|
||||
# gossamer threads migration-import code
|
||||
# v0.35.1
|
||||
# Federated Computer, Inc.
|
||||
# David Sainty <saint@federated.computer> 2024 A.D.
|
||||
# Gossamer Threads to Discourse -- Migration-Import Script
|
||||
# v0.36
|
||||
|
||||
require 'mysql2'
|
||||
require 'open-uri'
|
||||
@ -13,7 +15,8 @@ require 'csv'
|
||||
require 'time'
|
||||
|
||||
require File.expand_path("../../../../config/environment", __FILE__)
|
||||
require_relative '../base'
|
||||
# require_relative '../base'
|
||||
require File.expand_path("../../../../script/import_scripts/base", __FILE__)
|
||||
|
||||
class GossamerForumsImporter < ImportScripts::Base
|
||||
def initialize
|
||||
@ -1177,6 +1180,26 @@ class GossamerForumsImporter < ImportScripts::Base
|
||||
puts "update_user_stats user_id #{user_id} post_count #{count}"
|
||||
user_stat = UserStat.find_or_initialize_by(user_id: user_id)
|
||||
user_stat.update_columns(post_count: count)
|
||||
|
||||
# Determine the new Trust Level based on post_count
|
||||
user = User.find(user_id)
|
||||
new_trust_level = case count
|
||||
when 0..2 then 1 # basic user
|
||||
when 3..50 then 2 # member
|
||||
else 3 # regular or above when 51..100
|
||||
end
|
||||
|
||||
# Fetch the current user and check if Trust Level needs updating
|
||||
user = User.find(user_id)
|
||||
current_trust_level = user.trust_level || 1 # default to 1 if not set
|
||||
|
||||
# Only update trust level if the new level is higher than the current one
|
||||
if new_trust_level > current_trust_level
|
||||
user.update!(trust_level: new_trust_level)
|
||||
puts "update_user_stats user_id #{user_id} trust_level updated to #{new_trust_level}"
|
||||
else
|
||||
puts "update_user_stats user_id #{user_id} trust_level remains at #{current_trust_level}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1302,6 +1325,26 @@ class GossamerForumsImporter < ImportScripts::Base
|
||||
# Secret trick to disable RateLimiting protection in Discourse
|
||||
RateLimiter.disable
|
||||
|
||||
# ActiveRecord::Base.connection.disconnect! rescue nil
|
||||
# ActiveRecord::Base.clear_active_connections! rescue nil
|
||||
# ActiveRecord::Base.establish_connection(
|
||||
# adapter: 'postgresql',
|
||||
# host: '10.0.0.2', # Use the external DB host
|
||||
# port: 5432, # Default PostgreSQL port
|
||||
# database: 'discourse',
|
||||
# username: 'discourse',
|
||||
# password: 'nhB5FWhQkjdvaD2ViRNO63dQagDnzaTn',
|
||||
# connect_timeout: 10
|
||||
# )
|
||||
#
|
||||
ENV['PGHOST'] = '10.0.0.2'
|
||||
ENV['PGPORT'] = '5432'
|
||||
ENV['PGDATABASE'] = 'discourse'
|
||||
ENV['PGUSER'] = 'discourse'
|
||||
ENV['PGPASSWORD'] = 'nhB5FWhQkjdvaD2ViRNO63dQagDnzaTn'
|
||||
# ActiveRecord::Base.establish
|
||||
|
||||
|
||||
# Set our unique timestamp for this migration run
|
||||
timestamp = Time.now.strftime("-%Y%m%d%H%M%S")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user