From e788ac335191bff4997da8e8c9278c76cccae94d Mon Sep 17 00:00:00 2001 From: "michael@discoursehosting.com" Date: Sun, 2 Apr 2017 20:23:03 +0000 Subject: [PATCH 1/8] Add permalinks creator for PrettyURL plugin --- script/import_scripts/smf2.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/script/import_scripts/smf2.rb b/script/import_scripts/smf2.rb index 2ee607a2286..96cabaf0c51 100644 --- a/script/import_scripts/smf2.rb +++ b/script/import_scripts/smf2.rb @@ -65,6 +65,7 @@ class ImportScripts::Smf2 < ImportScripts::Base import_categories import_posts postprocess_posts + make_prettyurl_permalinks('/forum') end def import_groups @@ -662,6 +663,31 @@ class ImportScripts::Smf2 < ImportScripts::Base end #MessageDependencyGraph + def make_prettyurl_permalinks(prefix) + puts 'creating permalinks for prettyurl plugin' + begin + serialized = query(<<-SQL, as: :single) + SELECT value FROM {prefix}settings + WHERE variable='pretty_board_urls'; + SQL + board_slugs = Array.new + ser = /\{(.*)\}/.match(serialized)[1] + ser.scan(/i:(\d+);s:\d+:\"(.*?)\";/).each do |nv| + board_slugs[nv[0].to_i] = nv[1] + end + topic_urls = query(<<-SQL, as: :array) + SELECT t.id_first_msg, t.id_board,u.pretty_url + FROM smf_topics t + LEFT JOIN smf_pretty_topic_urls u ON u.id_topic = t.id_topic ; + SQL + topic_urls.each do |url| + t = topic_lookup_from_imported_post_id(url[:id_first_msg]) + Permalink.create(url: "#{prefix}/#{board_slugs[url[:id_board]]}/#{url[:pretty_url]}", topic_id: t[:topic_id]) + end + rescue + end + end + end ImportScripts::Smf2.run From 332d655a1db0db4e82a28932b8fca887c15cfbad Mon Sep 17 00:00:00 2001 From: "michael@discoursehosting.com" Date: Sun, 2 Apr 2017 20:25:08 +0000 Subject: [PATCH 2/8] Use html_for_upload instead of broken v8 stuff --- script/import_scripts/smf2.rb | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/script/import_scripts/smf2.rb b/script/import_scripts/smf2.rb index 96cabaf0c51..059e4a4be37 100644 --- a/script/import_scripts/smf2.rb +++ b/script/import_scripts/smf2.rb @@ -391,30 +391,8 @@ class ImportScripts::Smf2 < ImportScripts::Base return opts[:ignore_quotes] ? body : convert_quotes(body) end - def v8 - @ctx ||= begin - ctx = PrettyText.create_new_context - PrettyText.decorate_context(ctx) - # provides toHumanSize but restores I18n.t which we need to fix again - ctx.load(Rails.root + "app/assets/javascripts/locales/i18n.js") - helper = PrettyText::Helpers.new - ctx['I18n']['t'] = proc {|_,key,opts| helper.t(key, opts) } - # from i18n_helpers.js -- can't load it directly because Ember is missing - ctx.eval(<<-'end') - var oldI18ntoHumanSize = I18n.toHumanSize; - I18n.toHumanSize = function(number, options) { - options = options || {}; - options.format = I18n.t("number.human.storage_units.format"); - return oldI18ntoHumanSize.apply(this, [number, options]); - }; - end - ctx - end - end - def get_upload_markdown(upload) - @func ||= v8.eval("Discourse.Utilities.getUploadMarkdown") - return @func.call(upload).to_s + html_for_upload(upload, upload.original_filename) end def convert_quotes(body) From a72f56c3a7c4ca375098dff7ca1ad8528b8493a9 Mon Sep 17 00:00:00 2001 From: "michael@discoursehosting.com" Date: Sun, 2 Apr 2017 20:27:57 +0000 Subject: [PATCH 3/8] Add migratepassword plugin hash --- script/import_scripts/smf2.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/script/import_scripts/smf2.rb b/script/import_scripts/smf2.rb index 059e4a4be37..638c6e70780 100644 --- a/script/import_scripts/smf2.rb +++ b/script/import_scripts/smf2.rb @@ -94,6 +94,7 @@ class ImportScripts::Smf2 < ImportScripts::Base create_users(query(<<-SQL), total: total) do |member| SELECT a.id_member, a.member_name, a.date_registered, a.real_name, a.email_address, + CONCAT(LCASE(a.member_name),':', a.passwd) AS password, a.is_activated, a.last_login, a.birthdate, a.member_ip, a.id_group, a.additional_groups, b.id_attach, b.file_hash, b.filename FROM {prefix}members AS a @@ -106,6 +107,7 @@ class ImportScripts::Smf2 < ImportScripts::Base { id: member[:id_member], username: member[:member_name], + password: member[:password], created_at: create_time, name: member[:real_name], email: member[:email_address], From 7d09af141e2cecc525ee2d360be89bd869e339e7 Mon Sep 17 00:00:00 2001 From: "michael@discoursehosting.com" Date: Sun, 2 Apr 2017 20:28:16 +0000 Subject: [PATCH 4/8] Apparently need to save --- script/import_scripts/smf2.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/script/import_scripts/smf2.rb b/script/import_scripts/smf2.rb index 638c6e70780..9512135016c 100644 --- a/script/import_scripts/smf2.rb +++ b/script/import_scripts/smf2.rb @@ -121,6 +121,7 @@ class ImportScripts::Smf2 < ImportScripts::Base post_create_action: proc do |user| user.update(created_at: create_time) if create_time < user.created_at + user.save GroupUser.transaction do group_ids.each do |gid| group_id = group_id_from_imported_group_id(gid) and From 60be3e0d38343cb367fb1611a16e7311caf303e1 Mon Sep 17 00:00:00 2001 From: "michael@discoursehosting.com" Date: Sun, 2 Apr 2017 20:31:06 +0000 Subject: [PATCH 5/8] Get rid of the weird and broken message graph --- script/import_scripts/smf2.rb | 55 +---------------------------------- 1 file changed, 1 insertion(+), 54 deletions(-) diff --git a/script/import_scripts/smf2.rb b/script/import_scripts/smf2.rb index 9512135016c..74a273cff85 100644 --- a/script/import_scripts/smf2.rb +++ b/script/import_scripts/smf2.rb @@ -184,58 +184,6 @@ class ImportScripts::Smf2 < ImportScripts::Base end end - topics = Enumerator.new do |y| - last_topic_id = nil - topic_messages = nil - query("SELECT id_msg, id_topic, body FROM {prefix}messages ORDER BY id_topic ASC, id_msg ASC") do |message| - if last_topic_id != message[:id_topic] - y << topic_messages - last_topic_id = message[:id_topic] - topic_messages = [ message ] - else - topic_messages << message - end - end - y << topic_messages - end - - graph = MessageDependencyGraph.new - topics.each do |messages| - next unless messages.present? - (messages.reverse << nil).each_cons(2) do |message, prev| - graph.add_message(message[:id_msg], prev ? prev[:id_msg] : nil, - extract_quoted_message_ids(message[:body]).to_a) - end - print "\r#{spinner.next}" - end - - begin - cycles = graph.cycles - print "\r#{spinner.next}" - cycles.each do |cycle| - candidate = cycle.detect {|n| ((cycle - [n]) & n.quoted).present? } - candidate.ignore_quotes = true - end - end while cycles.present? - message_order = graph.tsort - print "\r#{spinner.next}" - - query(<<-SQL, as: :array) - CREATE TEMPORARY TABLE {prefix}import_message_order ( - message_id int(11) NOT NULL, - message_order int(11) NOT NULL AUTO_INCREMENT, - ignore_quotes tinyint(1) NOT NULL, - PRIMARY KEY (message_id), - UNIQUE KEY message_order (message_order) - ) ENGINE=MEMORY - SQL - message_order.each_slice(100) do |nodes| - query(<<-SQL, as: :array) - INSERT INTO {prefix}import_message_order (message_id, ignore_quotes) - VALUES #{ nodes.map {|n| "(#{n.id}, #{n.ignore_quotes? ? 1 : 0})" }.join(',') } - SQL - print "\r#{spinner.next}" - end db2 = create_db_connection @@ -243,11 +191,10 @@ class ImportScripts::Smf2 < ImportScripts::Base SELECT m.id_msg, m.id_topic, m.id_member, m.poster_time, m.body, o.ignore_quotes, m.subject, t.id_board, t.id_first_msg, COUNT(a.id_attach) AS attachment_count FROM {prefix}messages AS m - LEFT JOIN {prefix}import_message_order AS o ON o.message_id = m.id_msg LEFT JOIN {prefix}topics AS t ON t.id_topic = m.id_topic LEFT JOIN {prefix}attachments AS a ON a.id_msg = m.id_msg AND a.attachment_type = 0 GROUP BY m.id_msg - ORDER BY o.message_order ASC + ORDER BY m.id_topic ASC, m.id_msg ASC SQL skip = false ignore_quotes = (message[:ignore_quotes] == 1) From 7e27559f3e7fd5c096ba17a731cd73b2a3a20a38 Mon Sep 17 00:00:00 2001 From: "michael@discoursehosting.com" Date: Sun, 2 Apr 2017 20:33:48 +0000 Subject: [PATCH 6/8] We need to get rid of the ignore_quotes thing as well --- script/import_scripts/smf2.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/script/import_scripts/smf2.rb b/script/import_scripts/smf2.rb index 74a273cff85..7f1ffd9186f 100644 --- a/script/import_scripts/smf2.rb +++ b/script/import_scripts/smf2.rb @@ -188,7 +188,7 @@ class ImportScripts::Smf2 < ImportScripts::Base db2 = create_db_connection create_posts(query(<<-SQL), total: total) do |message| - SELECT m.id_msg, m.id_topic, m.id_member, m.poster_time, m.body, o.ignore_quotes, + SELECT m.id_msg, m.id_topic, m.id_member, m.poster_time, m.body, m.subject, t.id_board, t.id_first_msg, COUNT(a.id_attach) AS attachment_count FROM {prefix}messages AS m LEFT JOIN {prefix}topics AS t ON t.id_topic = m.id_topic @@ -197,7 +197,7 @@ class ImportScripts::Smf2 < ImportScripts::Base ORDER BY m.id_topic ASC, m.id_msg ASC SQL skip = false - ignore_quotes = (message[:ignore_quotes] == 1) + ignore_quotes = false post = { id: message[:id_msg], user_id: user_id_from_imported_user_id(message[:id_member]) || -1, From 6168bcb4c4a7aa096b064eb0e3fbdd10bb2b0143 Mon Sep 17 00:00:00 2001 From: "michael@discoursehosting.com" Date: Sun, 2 Apr 2017 20:35:43 +0000 Subject: [PATCH 7/8] Someone broke/disabled? the php check --- script/import_scripts/smf2.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/import_scripts/smf2.rb b/script/import_scripts/smf2.rb index 7f1ffd9186f..2f1be2eed30 100644 --- a/script/import_scripts/smf2.rb +++ b/script/import_scripts/smf2.rb @@ -465,7 +465,7 @@ class ImportScripts::Smf2 < ImportScripts::Base private def get_php_timezone - phpinfo, status = Open3.capture2('phpnope', '-i') + phpinfo, status = Open3.capture2('php', '-i') phpinfo.lines.each do |line| key, *vals = line.split(' => ').map(&:strip) break vals[0] if key == 'Default timezone' From 17b5303449ede7284de59621de048a69f3e492a7 Mon Sep 17 00:00:00 2001 From: "michael@discoursehosting.com" Date: Sun, 2 Apr 2017 20:38:23 +0000 Subject: [PATCH 8/8] Convert nested quotes --- script/import_scripts/smf2.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/script/import_scripts/smf2.rb b/script/import_scripts/smf2.rb index 2f1be2eed30..c65d13bedbf 100644 --- a/script/import_scripts/smf2.rb +++ b/script/import_scripts/smf2.rb @@ -355,9 +355,9 @@ class ImportScripts::Smf2 < ImportScripts::Base tl = topic_lookup_from_imported_post_id($~[:msg].to_i) quote << ", post:#{tl[:post_number]}, topic:#{tl[:topic_id]}" if tl end - quote << "\"]#{inner}[/quote]" + quote << "\"]#{convert_quotes(inner)}[/quote]" else - "
#{inner}
" + "
#{convert_quotes(inner)}
" end end end