<commit_before>require 'identity/importer/tasks/members'

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

          def self.sql
            last_member = Member.where(crypted_password: nil).order("created_at desc").first
            anonymize = Identity::Importer.configuration.anonymize
            %{
              SELECT
                contact.id as contact_id,
                #{anonymize ? "concat(sha1(email.email), '@civi.crm')" : "email.email"} as email,
                contact.first_name as firstname,
                #{anonymize ? "left(sha1(contact.last_name), 10)" : "contact.last_name"} as lastname,
                addr.postal_code as postcode,
                contact.created_date as created_at,
                contact.modified_date as updated_at,
                CASE contact.is_opt_out WHEN 1 THEN FALSE WHEN 0 THEN TRUE END as email_subscription 
                FROM civicrm_email email JOIN civicrm_contact contact ON email.contact_id = contact.id
                LEFT JOIN civicrm_address addr ON contact.id = addr.contact_id
                WHERE is_deleted = 0 
                #{"AND contact.created_date > \"#{last_member.created_at.getlocal.strftime('%Y-%m-%d %H:%M:%S')}\"" unless last_member.nil?}
            }

            # XXX maybe add optout from email model (check column)
          end

        end
      end
    end
  end
end<commit_msg>add: order by for members<commit_after>require 'identity/importer/tasks/members'

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

          def self.sql
            last_member = Member.where(crypted_password: nil).order("created_at desc").first
            anonymize = Identity::Importer.configuration.anonymize
            %{
              SELECT
                contact.id as contact_id,
                #{anonymize ? "concat(sha1(email.email), '@civi.crm')" : "email.email"} as email,
                contact.first_name as firstname,
                #{anonymize ? "left(sha1(contact.last_name), 10)" : "contact.last_name"} as lastname,
                addr.postal_code as postcode,
                contact.created_date as created_at,
                contact.modified_date as updated_at,
                CASE contact.is_opt_out WHEN 1 THEN FALSE WHEN 0 THEN TRUE END as email_subscription 
                FROM civicrm_email email JOIN civicrm_contact contact ON email.contact_id = contact.id
                LEFT JOIN civicrm_address addr ON contact.id = addr.contact_id
                WHERE is_deleted = 0 
                #{"AND contact.created_date > \"#{last_member.created_at.getlocal.strftime('%Y-%m-%d %H:%M:%S')}\"" unless last_member.nil?}
                ORDER BY contact.created_date ASC
            }

            # XXX maybe add optout from email model (check column)
          end

        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.08573342263898191, 'fraction_numerical': 0.004688546550569324, 'mean_word_length': 2.0294117647058822, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2265448', 'n_tokens_mistral': 869, 'n_tokens_neox': 805, 'n_words': 211}