app/controllers/discourse-media-wiki-import/import_controller.rb
##
# Finds an existing topic with the associated MediaWiki page ID, or creates a new one if it doesn't exist.
#
Finds an existing topic with the associated MediaWiki page ID, or creates a new one if it doesn't exist.
Finds an existing topic with the associated MediaWiki page ID or creates a new one if it doesn ' t exist .
def find_or_create_topic(wiki_page_id:, category_id:)
      topic = Topic
                .where(id: TopicCustomField
                              .where(
                                  name: 'wiki_page_id',
                                  value: wiki_page_id,
                              )
                              .select(:topic_id)
                ).first
      unless topic
        post = PostCreator.create!(
              current_user,
              category: category_id,
              title: '',
              skip_validations: true
            )
        TopicCustomField.create!(topic_id: post.topic_id, name: 'wiki_page_id', value: wiki_page_id)
        return post.topic
      else
        return topic
      end
    end
def find_or_create_topic ( wiki_page_id : , category_id : ) topic = Topic . where ( id : TopicCustomField . where ( name : 'wiki_page_id' , value : wiki_page_id , ) . select ( :topic_id ) ) . first unless topic post = PostCreator . create! ( current_user , category : category_id , title : '' , skip_validations : true ) TopicCustomField . create! ( topic_id : post . topic_id , name : 'wiki_page_id' , value : wiki_page_id ) return post . topic else return topic end end
Finds an existing topic with the associated MediaWiki page ID, or creates a new one if it doesn't exist.
Finds an existing topic with the associated MediaWiki page ID or creates a new one if it doesn ' t exist .
# topic doesn't exist yet, so create a new one # return existing topic
wiki_page_id
category_id