mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
FEATURE: vanilla_mysql importer can import tags
This commit is contained in:
parent
f3905fd99a
commit
32b22996d0
1 changed files with 26 additions and 1 deletions
|
@ -19,9 +19,22 @@ class ImportScripts::VanillaSQL < ImportScripts::Base
|
||||||
password: "pa$$word",
|
password: "pa$$word",
|
||||||
database: VANILLA_DB
|
database: VANILLA_DB
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@import_tags = false
|
||||||
|
begin
|
||||||
|
r = @client.query("select count(*) count from #{TABLE_PREFIX}Tag where countdiscussions > 0")
|
||||||
|
@import_tags = true if r.first["count"].to_i > 0
|
||||||
|
rescue => e
|
||||||
|
puts "Tags won't be imported. #{e.message}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute
|
def execute
|
||||||
|
if @import_tags
|
||||||
|
SiteSetting.tagging_enabled = true
|
||||||
|
SiteSetting.max_tags_per_topic = 10
|
||||||
|
end
|
||||||
|
|
||||||
import_users
|
import_users
|
||||||
import_avatars
|
import_avatars
|
||||||
import_categories
|
import_categories
|
||||||
|
@ -182,6 +195,8 @@ class ImportScripts::VanillaSQL < ImportScripts::Base
|
||||||
def import_topics
|
def import_topics
|
||||||
puts "", "importing topics..."
|
puts "", "importing topics..."
|
||||||
|
|
||||||
|
tag_names_sql = "select t.name as tag_name from GDN_Tag t, GDN_TagDiscussion td where t.tagid = td.tagid and td.discussionid = {discussionid} and t.name != '';"
|
||||||
|
|
||||||
total_count = mysql_query("SELECT count(*) count FROM #{TABLE_PREFIX}Discussion;").first['count']
|
total_count = mysql_query("SELECT count(*) count FROM #{TABLE_PREFIX}Discussion;").first['count']
|
||||||
|
|
||||||
batches(BATCH_SIZE) do |offset|
|
batches(BATCH_SIZE) do |offset|
|
||||||
|
@ -203,7 +218,13 @@ class ImportScripts::VanillaSQL < ImportScripts::Base
|
||||||
title: discussion['Name'],
|
title: discussion['Name'],
|
||||||
category: category_id_from_imported_category_id(discussion['CategoryID']),
|
category: category_id_from_imported_category_id(discussion['CategoryID']),
|
||||||
raw: clean_up(discussion['Body']),
|
raw: clean_up(discussion['Body']),
|
||||||
created_at: Time.zone.at(discussion['DateInserted'])
|
created_at: Time.zone.at(discussion['DateInserted']),
|
||||||
|
post_create_action: proc do |post|
|
||||||
|
if @import_tags
|
||||||
|
tag_names = @client.query(tag_names_sql.gsub('{discussionid}', discussion['DiscussionID'].to_s)).map {|row| row['tag_name']}
|
||||||
|
DiscourseTagging.tag_topic_by_names(post.topic, staff_guardian, tag_names)
|
||||||
|
end
|
||||||
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -327,6 +348,10 @@ class ImportScripts::VanillaSQL < ImportScripts::Base
|
||||||
raw
|
raw
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def staff_guardian
|
||||||
|
@_staff_guardian ||= Guardian.new(Discourse.system_user)
|
||||||
|
end
|
||||||
|
|
||||||
def mysql_query(sql)
|
def mysql_query(sql)
|
||||||
@client.query(sql)
|
@client.query(sql)
|
||||||
# @client.query(sql, cache_rows: false) #segfault: cache_rows: false causes segmentation fault
|
# @client.query(sql, cache_rows: false) #segfault: cache_rows: false causes segmentation fault
|
||||||
|
|
Loading…
Reference in a new issue