Skip to content

Instantly share code, notes, and snippets.

@jmccartie
Created June 7, 2013 15:36
Show Gist options
  • Save jmccartie/5730171 to your computer and use it in GitHub Desktop.
Save jmccartie/5730171 to your computer and use it in GitHub Desktop.
migrate forums from one Zendesk account to another
forum.topics.each do |topic|
topic_hash = topic.to_hash
["url", "created_at", "updated_at", "id", "topic_type", "attachments", "comments_count", "fourm_id"].each { |k| topic_hash.delete(k) }
old_submitter = ZendeskAPI::User.find(chop, id: topic.submitter_id)
new_submitter = find_user_by_email(digerati, old_submitter.email)
topic_hash["submitter_id"] = new_submitter.id rescue next
topic_hash["updater_id"] = new_submitter.id
topic_hash["forum_id"] = 22153347
new_topic = ZendeskAPI::Topic.create(digerati, topic_hash)
topic.comments.each do |comment|
comment_hash = comment.to_hash
["url", "created_at", "updated_at", "id", "attachments", "informative"].each { |k| comment_hash.delete(k) }
old_user = ZendeskAPI::User.find(chop, id: comment.user_id)
new_user = find_user_by_email(digerati, old_user.email)
comment_hash["user_id"] = new_user.id rescue next
comment_hash["topic_id"] = new_topic.id
new_topic.comments << comment_hash
new_topic.save!
end
end
def find_user_by_email(client, email)
results = client.search(query: email, reload: true).fetch
results.each do |result|
return result if result.class == ZendeskAPI::User
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment