From 4fcabe81255faed08809913164e770719ba4c64a Mon Sep 17 00:00:00 2001 From: Leandro Nunes dos Santos Date: Thu, 15 Oct 2015 11:08:18 -0300 Subject: [PATCH] Adding comment paragraph script --- script/comment_group2comment_paragraph | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+), 0 deletions(-) create mode 100755 script/comment_group2comment_paragraph diff --git a/script/comment_group2comment_paragraph b/script/comment_group2comment_paragraph new file mode 100755 index 0000000..d1e6a8d --- /dev/null +++ b/script/comment_group2comment_paragraph @@ -0,0 +1,70 @@ +#!/usr/bin/env ruby +require File.dirname(__FILE__) + '/../config/environment' + +#http://ruby.bastardsbook.com/chapters/html-parsing/ + +puts "Runing script" + +article = Article.find(410) +new_article = TinyMceArticle.new + +doc = Nokogiri::HTML(article.body) +html_body = '' +doc.css("p").map do |element| + html_body += '

' + element.text + '

' +end + +comments = article.comments.reorder(:group_id) +comment_association = {} + +puts 'antes' +comments.map do |c| + comment_association[c.id] = c.group_id + puts c.group_id.inspect +end + +puts "Set comment group to nil" +article.comments.map do |comment| + comment.group_id = nil + comment.save +end + +puts "Change article body" +article.body = html_body +article.save +puts article.body +article.comment_paragraph_plugin_activate = !article.comment_paragraph_plugin_activate +article.save! +puts article.body + + + +puts 'depois' +comments.map do |c| + puts c.group_id.inspect +end +puts 'Migrating comments' + +doc = Nokogiri::HTML(article.body) +group = 0 +doc.css("[data-macro-paragraph_uuid]").map do |paragraph| + uid = paragraph.attributes['data-macro-paragraph_uuid'].value + puts "Paragraph: #{uid}" + puts "Cheking paragraph group #{group} in comment #{comments[0].inspect}" + comment = comments.shift if !comments.empty? && comments[0].group_id.to_s == group.to_s + group += 1 + next if comment.nil? + puts "Change coment #{comment.id} to paragraph_uuid #{uid}" + comment.paragraph_uuid = uid + comment.save + comment = nil +end + +#nil, :comment_paragraph_selected_content=>nil}, paragraph_id: nil, paragraph_uuid: nil, group_id: 0> + +#nil, :comment_paragraph_selected_content=>nil}, paragraph_id: nil, paragraph_uuid: "9445dee8-0a65-4d5b-a654-5dd0e68b1db3", group_id: nil> + + + +puts new_article.body +# -- libgit2 0.21.2