discourse/plugins/discourse-zendesk-plugin/lib/discourse_zendesk_plugin/post_extension.rb
Régis Hanol 495cbbab1f
FIX: replies not syncing to Zendesk for linked topics (#36560)
Replies to topics linked to Zendesk were not being synced.

The `after_commit` callback used `topic.custom_fields[...]` which
returns memoized data. If a Zendesk ticket was linked by another process
after the topic was loaded, the stale cache would return empty and skip
the sync job.

Query `TopicCustomField.exists?` directly instead of relying on the
cached `custom_fields` hash.

Internal ref - t/169124
2025-12-09 14:59:05 +01:00

23 lines
664 B
Ruby

# frozen_string_literal: true
module DiscourseZendeskPlugin
module PostExtension
def self.prepended(base)
base.after_commit :generate_zendesk_ticket, on: [:create]
end
private
def generate_zendesk_ticket
return unless SiteSetting.zendesk_enabled?
has_zendesk_ticket =
TopicCustomField.exists?(topic_id:, name: DiscourseZendeskPlugin::ZENDESK_ID_FIELD)
in_autogeneration_category =
DiscourseZendeskPlugin::Helper.autogeneration_category?(topic.category_id)
return if !has_zendesk_ticket && !in_autogeneration_category
Jobs.enqueue_in(5.seconds, :zendesk_job, post_id: id)
end
end
end