Better import for Drupal QA
This commit is contained in:
parent
2f8e28c918
commit
28cbebe5ed
|
@ -17,6 +17,10 @@ class ImportScripts::Drupal < ImportScripts::Base
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def categories_query
|
||||||
|
@client.query("SELECT tid, name, description FROM taxonomy_term_data WHERE vid = 1")
|
||||||
|
end
|
||||||
|
|
||||||
def execute
|
def execute
|
||||||
create_users(@client.query("SELECT uid id, name, mail email, created FROM users;")) do |row|
|
create_users(@client.query("SELECT uid id, name, mail email, created FROM users;")) do |row|
|
||||||
{id: row['id'], username: row['name'], email: row['email'], created_at: Time.zone.at(row['created'])}
|
{id: row['id'], username: row['name'], email: row['email'], created_at: Time.zone.at(row['created'])}
|
||||||
|
@ -27,7 +31,7 @@ class ImportScripts::Drupal < ImportScripts::Base
|
||||||
# * Drupal allows duplicate category names, so you may need to exclude some categories or rename them here.
|
# * Drupal allows duplicate category names, so you may need to exclude some categories or rename them here.
|
||||||
# * Table name may be term_data.
|
# * Table name may be term_data.
|
||||||
# * May need to select a vid other than 1.
|
# * May need to select a vid other than 1.
|
||||||
create_categories(@client.query("SELECT tid, name, description FROM taxonomy_term_data WHERE vid = 1;")) do |c|
|
create_categories(categories_query) do |c|
|
||||||
{id: c['tid'], name: c['name'], description: c['description']}
|
{id: c['tid'], name: c['name'], description: c['description']}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,28 @@ require "mysql2"
|
||||||
|
|
||||||
class ImportScripts::DrupalQA < ImportScripts::Drupal
|
class ImportScripts::DrupalQA < ImportScripts::Drupal
|
||||||
|
|
||||||
|
def categories_query
|
||||||
|
result = @client.query("SELECT n.nid, GROUP_CONCAT(ti.tid) AS tids
|
||||||
|
FROM node AS n
|
||||||
|
INNER JOIN taxonomy_index AS ti ON ti.nid = n.nid
|
||||||
|
WHERE n.type = 'question'
|
||||||
|
AND n.status = 1
|
||||||
|
GROUP BY n.nid")
|
||||||
|
|
||||||
|
categories = {}
|
||||||
|
result.each do |r|
|
||||||
|
tids = r['tids']
|
||||||
|
if tids.present?
|
||||||
|
tids = tids.split(',')
|
||||||
|
categories[tids[0].to_i] = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@client.query("SELECT tid, name, description FROM taxonomy_term_data WHERE tid IN (#{categories.keys.join(',')})")
|
||||||
|
end
|
||||||
|
|
||||||
def create_forum_topics
|
def create_forum_topics
|
||||||
|
|
||||||
puts '', "creating forum topics"
|
puts '', "creating forum topics"
|
||||||
|
|
||||||
total_count = @client.query("
|
total_count = @client.query("
|
||||||
|
@ -20,12 +41,12 @@ class ImportScripts::DrupalQA < ImportScripts::Drupal
|
||||||
results = @client.query("
|
results = @client.query("
|
||||||
SELECT n.nid,
|
SELECT n.nid,
|
||||||
n.title,
|
n.title,
|
||||||
MIN(t.field_question_tags_tid) AS tid,
|
GROUP_CONCAT(t.tid) AS tid,
|
||||||
n.uid,
|
n.uid,
|
||||||
n.created,
|
n.created,
|
||||||
f.body_value AS body
|
f.body_value AS body
|
||||||
FROM node AS n
|
FROM node AS n
|
||||||
LEFT OUTER JOIN field_data_field_question_tags AS t on t.entity_id = n.nid
|
LEFT OUTER JOIN taxonomy_index AS t on t.nid = n.nid
|
||||||
INNER JOIN field_data_body AS f ON f.entity_id = n.nid
|
INNER JOIN field_data_body AS f ON f.entity_id = n.nid
|
||||||
WHERE n.type = 'question'
|
WHERE n.type = 'question'
|
||||||
AND n.status = 1
|
AND n.status = 1
|
||||||
|
@ -40,7 +61,7 @@ class ImportScripts::DrupalQA < ImportScripts::Drupal
|
||||||
{
|
{
|
||||||
id: "nid:#{row['nid']}",
|
id: "nid:#{row['nid']}",
|
||||||
user_id: user_id_from_imported_user_id(row['uid']) || -1,
|
user_id: user_id_from_imported_user_id(row['uid']) || -1,
|
||||||
category: category_from_imported_category_id(row['tid']).try(:name),
|
category: category_from_imported_category_id((row['tid'] || '').split(',')[0]).try(:name),
|
||||||
raw: row['body'],
|
raw: row['body'],
|
||||||
created_at: Time.zone.at(row['created']),
|
created_at: Time.zone.at(row['created']),
|
||||||
pinned_at: nil,
|
pinned_at: nil,
|
||||||
|
|
Loading…
Reference in New Issue