المناقشة الخاصة المستوردة لا تظهر في صندوق وارد المؤلف

مرحبًا، أحاول استيراد الرسائل الخاصة من قاعدة بيانات vBulletin5.

تعمل العملية، لكن في ملف تعريف الكاتب تظهر المناقشة فقط في “المُرسلة” وليس في “صندوق الوارد”.

أما في ملف تعريف المشارك الآخر، فتظهر المناقشة بشكل صحيح في “صندوق الوارد” وكذلك في “المُرسلة”.

ملف تعريف الكاتب:
تظهر في “المُرسلة”

ولكن لا تظهر في “صندوق الوارد”

ملف تعريف المشارك الآخر:
تظهر في كلا القسمين:

كيف يمكنني جعل المناقشة تظهر في صندوق وارد الكاتب؟

إليك كودي الحالي غير المنظم إذا لزم الأمر:

  def import_pm
    puts "", "استيراد مواضيع الرسائل الخاصة..."

    pms_count = mysql_query("SELECT COUNT(nodeid) cnt, starter
        FROM #{DB_PREFIX}node
        WHERE (unpublishdate = 0 OR unpublishdate IS NULL)
        AND (approved = 1 AND showapproved = 1)    
          AND starter = 2676436
        AND contenttypeid=#{@pm};"
    ).first["cnt"]

    batches(BATCH_SIZE) do |offset|
      pms = mysql_query <<-SQL
        SELECT pm.nodeid AS pmid, pm.starter, pm.title, pm.parentid AS parentid,pm.open,pm.userid AS postuserid,pm.publishdate AS dateline,
            nv.count views, 1 AS visible, pm.sticky,
            CONVERT(CAST(rawtext AS BINARY)USING utf8) AS raw
        FROM #{DB_PREFIX}node pm
        LEFT JOIN #{DB_PREFIX}nodeview nv ON nv.nodeid=pm.nodeid
        LEFT JOIN #{DB_PREFIX}text txt ON txt.nodeid=pm.nodeid
        WHERE
          pm.contenttypeid = #{@pm}
          AND (pm.unpublishdate = 0 OR pm.unpublishdate IS NULL)
          AND pm.approved = 1 AND pm.showapproved = 1
          AND pm.starter = 2676436
        ORDER BY pm.nodeid
          LIMIT #{BATCH_SIZE}
          OFFSET #{offset}
      SQL

      break if pms.size < 1

      create_posts(pms, total: pms_count, offset: 0) do |pm|
        p = {}

        p[:id] = "pm-#{pm['pmid']}"
        p[:user_id] = user_id_from_imported_user_id(pm['postuserid']) || Discourse::SYSTEM_USER_ID
        p[:raw] = preprocess_post_raw(pm['raw']) rescue nil
        p[:created_at] = parse_timestamp(pm["dateline"]),

        topic_id = nil

        next if p[:raw].blank?

        # إذا كان المنشور الأول
        if pm['parentid'] == 8 
          #next unless post = topic_lookup_from_imported_post_id("pm-#{pm["pmid"]}")

          target_usernames = []
          target_userids = []
          # جلب قائمة المستخدمين
          userlist = mysql_query("select distinct userid from sentto where nodeid = #{pm["starter"]}")
          userlist.each do |user|
            userid = user_id_from_imported_user_id(user["userid"]) || Discourse::SYSTEM_USER_ID;
            target_userids << userid || Discourse::SYSTEM_USER_ID
            target_usernames << User.find_by(id: userid).try(:username) || "system"
          end

          participants = target_userids
          begin
            participants.sort!
          rescue
            puts "واحد من معرّفات المشاركين هو nil -- #{participants.inspect}"
          end

          p[:title] = @htmlentities.decode(pm['title']).strip[0...255]
          p[:archetype] = Archetype.private_message
          p[:target_usernames] = target_usernames.join(',')

          if p[:target_usernames].size < 1 # رسالة خاصة مع نفسك؟
            # skip = true
            p[:target_usernames] = "system"
            puts "pm-#{pm['nodeid']} ليس لها مستلم مستهدف"
          end
        # إذا لم يكن المنشور الأول
        else
          next unless topic = topic_lookup_from_imported_post_id("pm-#{pm["starter"]}")
          p[:topic_id] = topic[:topic_id]

        end
        puts "منشور: #{p}\n"
        p
      end
    end
    exit
  end

From data explorer, I noticed that the participant_count value is wrong:

It’s written 1, but there are two people in the conversation.
If I update the topic’s field participant_count to 2 like this:

Topic.find_by(id: 218613).update(participant_count: 2)

the topic now appears in the author’s inbox:

I didn’t notice this behavior by updating other fields like reply_count for example, so it seems specific to participant_count and maybe other fields.

In my import script, I tried adding this:

p[:participant_count] = target_usernames.count

But it didn’t work, I guess we can’t set this field in the importers’ methods.

So I’m a bit stuck here. I’d like my users to have all their PMs with replies in their inbox, not only those that they didn’t start themselves.

Any idea?

إعجاب واحد (1)

Any thoughts on this @kris.kotlarek?

إعجاب واحد (1)

Thank you for mentioning that bug. I checked it myself and you are right - when participant_count is incorrect, then message is not visible in message’s author inbox.

Also, you are right that even if you explicitly add that param to create_posts - it is not set correctly.

This is because TopicCreate has explicit list of allowed params:

Today I will create a PR to Discourse to accept that attribute in import mode.

In the meantime, to not wait for latest version of Discourse, you can run at the very end of your script

Topic.private_messages.map(&:update_statistics) - this should correct all numbers

5 إعجابات

PR is ready - FIX: topic_creator accepts participant_count in import mode by KrisKotlarek · Pull Request #10632 · discourse/discourse · GitHub

Once merged and deployed you will be able to use it like:

create_posts(pms, total: pms_count, offset: 0) do |pm|
...
  p[:topic_opts][:participant_count] = target_usernames.count 
...
end

It has to be under [:topic_opts] because create_posts method is evaluating post_creator which triggers topic_creator

3 إعجابات