From a39e435ffec1296903d164a4a2dc33225988a4b9 Mon Sep 17 00:00:00 2001 From: saint Date: Mon, 2 Sep 2024 16:27:07 +1000 Subject: [PATCH] v0.59 Final topic-post import run -- add logic for appending counts since we are adding to a live Discourse host now --- .gossamer_forums.rb.swo | Bin 0 -> 20480 bytes .nfs0000000000163a0500000006 | Bin 4096 -> 0 bytes gossamer_forums.rb | 55 ++++++++++++++++++++++------------- 3 files changed, 35 insertions(+), 20 deletions(-) create mode 100644 .gossamer_forums.rb.swo delete mode 100644 .nfs0000000000163a0500000006 diff --git a/.gossamer_forums.rb.swo b/.gossamer_forums.rb.swo new file mode 100644 index 0000000000000000000000000000000000000000..29d15f273710ef8c7975f689f79f3ea98c7d2eac GIT binary patch literal 20480 zcmeI4TWlOx8OMh}Y1*_6n|%k0iB zN$oU!0iA)Ly`AsOch32r+kR(GT;0A@oTFX29R{xJ3}a>XOl{-%4aU9qY%*fY4HABT zjZ35p{WVeY5qo1X=;Dz=aiPCAE=Tt~JI+cWmbg`un!f2R9$Sa9Vv=E1(t73TOqi0$KsB zfL1^&pcVMPR3K^IXxxpOZBVs4p?<%s=l7q^%ga>vS9|P#RQ6-){@EV;%gTPcy1!Fp zkmmD}ve%UTOFi~KD0@@c&-K`Uuk4>t_L{0t>i>7jzNGAr_1J%_>_?RShIh*k>GLlt z`yI;e_t<}<>}mc__Sk=|?2GF8f%kO#|CO@OD|@TQ{(`c9QrVyAvHw!pOUi!J72W=y z@39~6v7ha+Khb0Vg|esRyZ*i1{(r9QY5nXT`x#|lQ0055$NrqMr~PZgmEHcIRra!a z-s-VGqwLel{&0`|X=P9Q=f8UFN=`!r$MA7vV|V__t^TDI&NAP)@i;wHm510DgN z1tDO-0XKpT;DxJ^20RBI1b2XA;H9e!<0)_&d=uOQD&Qa(16P385%awS9t97A`#=Mj zU;OZ6z*C5^9|4~Ohrv!T z47P%^2uL3XUk1m)64(s}!FAwDa2|UMUjd&1hrkfn49;V3;~aPe+z&nvX22G(0f@FH zac$de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z^f8&R=vJc9?V~r-L~bgFho;j6G^r8{VM9jfmu`QiauJd%SCG#u~>Tx9^uEsXHG^qyX7S&MVer$?88pP#s zTXbbtuSi_hvBWGfMH#AYh%SV^xQ;E=G4pcjGQ?C~E~2Pvy1IHND9eOBP^EuwO?Z(- zH{`X)_5}Y2_59z}^ZO$H|0v#%p94JpPtQL;iP)aM|NkyH4ekX#D1vQ($Nf)%C&ACa zSAhjS1qQ%Ya4q1m|3AT5z<>ja-~h;j9M}wAMa+K=yZ{~tkAVlk7r;H>BjAU4zyAY( zKTTlN0Dt#C3_b?>z!vbTs>?rkee|Uj&Y29CE-Vey25`M{kQi^aJr*{y%U@US;@soRO5!BzL9~W z1O9+BaA06=po|>@o?SncSwi^3aMTLi<2dHh@qzFa;k_GEd-s9Ar^mP!f&YX!u}~5R z7UaQ<9N(*{dT!hho(uC!w+}APEKZcmM;1y`gU3*)!Jx5!=k$@rp*uhAEL&5fOKxd? z;p1b@A*((WoU|$dKYK)^9_1$v>>coaPsvWj))&_soOPM<7c-F4fu<;*SXj^Xp literal 0 HcmV?d00001 diff --git a/.nfs0000000000163a0500000006 b/.nfs0000000000163a0500000006 deleted file mode 100644 index 0501b921bdcb06c038b63dcc99b07545769735c5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4096 zcmeIuJqp4=5QgC`1rbESI%=J4VjA@Z7M8IM`Pt|~)(JZs?7fO-@-kMM)PeN!O*y>7 zz>|lU)7d)&k@(GAh)?{kCdZX{J*R>*eRth{WcrTGNF{_URb7*jH!@20NAe*{%>}iV zm9I@h)}>rn-8hz4V$O`RX+^d*9N2vH0Rjj>U|67amA{`Q@h%FxV7pm+%SAHWVhaHX SKmY;|fB*y_009X6rN9@+ohV@d diff --git a/gossamer_forums.rb b/gossamer_forums.rb index 9d6df1d..8356f70 100644 --- a/gossamer_forums.rb +++ b/gossamer_forums.rb @@ -1572,7 +1572,7 @@ class GossamerForumsImporter < ImportScripts::Base # next if post_id < highest_old_post_id next if post_id <= highest_processed_post_id - puts "Processing post_id #{row['post_id']} post_id #{row['post_root_id']} post_subject/title #{row['post_subject']} forum_id_fk/category_id #{row['forum_id_fk']}" + puts "Processing post_id #{row['post_id']} post_root_id #{row['post_root_id']} post_subject/title #{row['post_subject']} forum_id_fk (category_id) #{row['forum_id_fk']}" # discourse_user_id = @user_id_map[row['user_id_fk']] # Fetch the Discourse user_id based on Gossamer data and mapping @@ -1731,29 +1731,44 @@ class GossamerForumsImporter < ImportScripts::Base # Sanitize the post message sanitized_post_message = sanitize_post_message(row['post_message']) - puts "CREATE REPLY in topic_id #{topic_id} for reply post_id #{row['post_id']}" - # topic_post_numbers[topic_id] += 1 post_number = fetch_db_topic_post_numbers(topic_id).to_i + 1 - update_db_topic_post_numbers(topic_id, post_number) + + puts "CREATE REPLY in topic_id #{topic_id} for reply post_id #{row['post_id']} with post_number #{post_number}" # Create the post in the existing topic - post = Post.create!( - topic_id: topic_id, - user_id: discourse_user_id, - raw: sanitized_post_message, - created_at: Time.at(row['post_time']), - updated_at: Time.at(row['post_time']), - reads: post_views || 0, - post_number: post_number - ) -# raw: import_attachments(row['post_message'], row['post_id']), -# raw: row['post_message'] || "", -# reply_to_post_number: reply_to_post_number, -# like_count: row['post_replies'] || 0, -# reads: post_views || fetch_db_topic_post_count(topic_id).to_i, - post.custom_fields['original_gossamer_id'] = row['post_id'] - post.save! + post_created = false + while ! post_created + begin + post = Post.create!( + topic_id: topic_id, + user_id: discourse_user_id, + raw: sanitized_post_message, + created_at: Time.at(row['post_time']), + updated_at: Time.at(row['post_time']), + reads: post_views || 0, + post_number: post_number + ) +# raw: import_attachments(row['post_message'], row['post_id']), +# raw: row['post_message'] || "", +# reply_to_post_number: reply_to_post_number, +# like_count: row['post_replies'] || 0, +# reads: post_views || fetch_db_topic_post_count(topic_id).to_i, + post.custom_fields['original_gossamer_id'] = row['post_id'] + post.save! + + post_created = true + + rescue ActiveRecord::RecordNotUnique => e + if e.message.include?("duplicate key value violates unique constraint") + post_number = post_number + 1 + else + raise e + end + end + end + + update_db_topic_post_numbers(topic_id, post_number) # Track the number of posts in the topic and by the user # topic_post_count[topic_id] += 1