<commit_before>require 'identity/importer/tasks/actions'
require 'activerecord-import'

module Identity
  module Importer
    module Tasks
      module CiviCRM
        class Actions < Identity::Importer::Tasks::Actions

          def self.sql(last_action=0)
            anonymize = Identity::Importer.configuration.anonymize

            action_types = Identity::Importer.configuration.action_types
            if action_types.blank?
              raise ArgumentError, "Action Types is empty, please set action_types to a valid array"
            end

            action_types = Identity::Importer::Utils.format_array_for_sql action_types
            action_types_string = action_types.join(',')

            campaigns = Campaign.where.not(controlshift_campaign_id: nil).pluck(:controlshift_campaign_id)
            %{
               SELECT
                #{anonymize ? "concat(sha1(email.email), '@civi.crm')" : "email.email"} as email,
                 act_type.activity_name as type,
                 act.activity_date_time as created_at,
                 camp.id << 8 | FIND_IN_SET(act_type.activity_name, '#{action_types_string}') as external_id,
                 camp.id as campaign_id
               FROM civicrm_campaign camp
                 JOIN civicrm_activity act ON camp.id = act.campaign_id
                 JOIN (SELECT v.value as activity_type_id, v.label as activity_name
                      FROM civicrm_option_group o join civicrm_option_value v ON o.id = v.option_group_id
                      WHERE o.name ='activity_type' AND label IN (#{action_types})) as act_type<commit_msg>fix: fix sql for actions<commit_after>require 'identity/importer/tasks/actions'
require 'activerecord-import'

module Identity
  module Importer
    module Tasks
      module CiviCRM
        class Actions < Identity::Importer::Tasks::Actions

          def self.sql(last_action=0)
            anonymize = Identity::Importer.configuration.anonymize

            action_types = Identity::Importer.configuration.action_types
            if action_types.blank?
              raise ArgumentError, "Action Types is empty, please set action_types to a valid array"
            end

            action_types_arr = Identity::Importer::Utils.format_array_for_sql action_types
            action_types_string = action_types.join(',')

            campaigns = Campaign.where.not(controlshift_campaign_id: nil).pluck(:controlshift_campaign_id)
            %{
               SELECT
                #{anonymize ? "concat(sha1(email.email), '@civi.crm')" : "email.email"} as email,
                 act_type.activity_name as type,
                 act.activity_date_time as created_at,
                 camp.id << 8 | FIND_IN_SET(act_type.activity_name, '#{action_types_string}') as external_id,
                 camp.id as campaign_id
               FROM civicrm_campaign camp
                 JOIN civicrm_activity act ON camp.id = act.campaign_id
                 JOIN (SELECT v.value as activity_type_id, v.label as activity_name
                      FROM civicrm_option_group o join civicrm_option_value v ON o.id = v.option_group_id
                      WHERE o.name ='activity_type' AND label IN (#{action_types_arr})) as act_type
{'fraction_non_alphanumeric': 0.07654167957855594, 'fraction_numerical': 0.0018593120545398203, 'mean_word_length': 2.3381592554291624, 'pattern_counts': {'":': 0, '<': 9, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1879291', 'n_tokens_mistral': 902, 'n_tokens_neox': 865, 'n_words': 207}