<commit_before>module Whitehall
  # Whitehall-specific interface for accessing the Publishing API.
  #
  # This should be used in preference to accessing the API adapter or
  # PublishingApiWorkers directly when publishing or republishing models to the
  # Publishing API.
  #
  # publish and republish raise UnpublishableInstanceError if the model instance
  # is not suitable for publishing to the API.
  class UnpublishableInstanceError < StandardError; end

  class PublishingApi
    def self.publish_async(model_instance, update_type_override=nil, queue_override=nil)
      push_live(model_instance, update_type_override, queue_override)
    end

    def self.save_draft_async(model_instance, update_type_override = nil, queue_override = nil)
      return if skip_sending_to_content_store?(model_instance)
      locales_for(model_instance).each do |locale|
        save_draft_translation_async(model_instance, locale, update_type_override, queue_override)
      end
    end

    def self.save_draft_translation_async(model_instance, locale, update_type_override = nil, queue_override = nil)
      PublishingApiDraftWorker.perform_async_in_queue(queue_override, model_instance.class.name, model_instance.id, update_type_override, locale)
    end

    def self.republish_async(model_instance)
      push_live(model_instance, 'republish')
    end

    def self.schedule_async(edition)
      return unless served_from_content_store?(edition)
      publish_timestamp = edition.scheduled_publication.as_json
      locales_for(edition).each do |locale|
        base_path = Whitehall.url_maker.public_document_path(edition, locale: locale)
        PublishingApiScheduleWorker.perform_async(base_path, publish_timestamp)
        unless edition.document.published?
          PublishingApiComingSoonWorker.perform_async(edition.id, locale)
                                      # perform_async(base_path, publish_timestamp, locale)
        end
      end
    end

    def self.unschedule_async(edition)
      return unless served_from_content_store?(edition)
      locales_for(edition).each do |locale|
        base_path = Whitehall.url_maker.public_document_path(edition, locale: locale)
        PublishingApiUnscheduleWorker.perform_async(base_path)
        self.publish_gone(base_path) unless edition.document.published?
      end
    end

    def self.publish_redirect_async(base_path, redirects, locale = I18n.default_locale.to_s)
      PublishingApiRedirectWorker.perform_async(base_path, redirects, locale)
    end

    def self.publish_gone(base_path)
      PublishingApiGoneWorker.perform_async(base_path)
    end

    def self.discard_draft_async(edition)
      locales_for(edition).each do |locale|
        PublishingApiDiscardDraftWorker.perform_async(edition.content_id, locale)
      end
    end

    def self.discard_translation_async(edition, locale:)
      PublishingApiDiscardDraftWorker.perform_async(edition.content_id, locale)
    end

  private

    def self.locales_for(model_instance)
      if model_instance.respond_to?(:translated_locales) && (locales = model_instance.translated_locales).any?
        locales
      else
        [:en]
      end
    end

    def self.push_live(model_instance, update_type_override=nil, queue_override=nil)
      return if skip_sending_to_content_store?(model_instance)
      self.assert_public_edition!(model_instance)
      locales_for(model_instance).each do |locale|
        PublishingApiWorker.perform_async_in_queue(queue_override, model_instance.class.name, model_instance.id, update_type_override, locale)<commit_msg>Remove a useless private modifier<commit_after>module Whitehall
  # Whitehall-specific interface for accessing the Publishing API.
  #
  # This should be used in preference to accessing the API adapter or
  # PublishingApiWorkers directly when publishing or republishing models to the
  # Publishing API.
  #
  # publish and republish raise UnpublishableInstanceError if the model instance
  # is not suitable for publishing to the API.
  class UnpublishableInstanceError < StandardError; end

  class PublishingApi
    def self.publish_async(model_instance, update_type_override=nil, queue_override=nil)
      push_live(model_instance, update_type_override, queue_override)
    end

    def self.save_draft_async(model_instance, update_type_override = nil, queue_override = nil)
      return if skip_sending_to_content_store?(model_instance)
      locales_for(model_instance).each do |locale|
        save_draft_translation_async(model_instance, locale, update_type_override, queue_override)
      end
    end

    def self.save_draft_translation_async(model_instance, locale, update_type_override = nil, queue_override = nil)
      PublishingApiDraftWorker.perform_async_in_queue(queue_override, model_instance.class.name, model_instance.id, update_type_override, locale)
    end

    def self.republish_async(model_instance)
      push_live(model_instance, 'republish')
    end

    def self.schedule_async(edition)
      return unless served_from_content_store?(edition)
      publish_timestamp = edition.scheduled_publication.as_json
      locales_for(edition).each do |locale|
        base_path = Whitehall.url_maker.public_document_path(edition, locale: locale)
        PublishingApiScheduleWorker.perform_async(base_path, publish_timestamp)
        unless edition.document.published?
          PublishingApiComingSoonWorker.perform_async(edition.id, locale)
                                      # perform_async(base_path, publish_timestamp, locale)
        end
      end
    end

    def self.unschedule_async(edition)
      return unless served_from_content_store?(edition)
      locales_for(edition).each do |locale|
        base_path = Whitehall.url_maker.public_document_path(edition, locale: locale)
        PublishingApiUnscheduleWorker.perform_async(base_path)
        self.publish_gone(base_path) unless edition.document.published?
      end
    end

    def self.publish_redirect_async(base_path, redirects, locale = I18n.default_locale.to_s)
      PublishingApiRedirectWorker.perform_async(base_path, redirects, locale)
    end

    def self.publish_gone(base_path)
      PublishingApiGoneWorker.perform_async(base_path)
    end

    def self.discard_draft_async(edition)
      locales_for(edition).each do |locale|
        PublishingApiDiscardDraftWorker.perform_async(edition.content_id, locale)
      end
    end

    def self.discard_translation_async(edition, locale:)
      PublishingApiDiscardDraftWorker.perform_async(edition.content_id, locale)
    end

    def self.locales_for(model_instance)
      if model_instance.respond_to?(:translated_locales) && (locales = model_instance.translated_locales).any?
        locales
      else
        [:en]
      end
    end

    def self.push_live(model_instance, update_type_override=nil, queue_override=nil)
      return if skip_sending_to_content_store?(model_instance)
      self.assert_public_edition!(model_instance)
      locales_for(model_instance).each do |locale|
        PublishingApiWorker.perform_async_in_queue(queue_override, model_instance.class.name, model_instance.id, update_type_override, locale)
{'fraction_non_alphanumeric': 0.06395754782851557, 'fraction_numerical': 0.0005585812037424941, 'mean_word_length': 4.19361856417694, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6695740', 'n_tokens_mistral': 2084, 'n_tokens_neox': 2060, 'n_words': 400}