<commit_before>require 'fileutils'

class SiteDemoDomain < DomainModel

  validates_as_email :login_email
  validates_presence_of :login_email

  has_many :site_demo_log_entries

  belongs_to :site_demo_template
  validates_uniqueness_of :name
  validates_uniqueness_of :domain_index
  validates_presence_of :site_demo_template

  attr_accessor :expiration_minutes

  def self.new_domain(email_address,template_id,expiration_minutes = nil)
    # Make sure they don't have multiple domains
    if dmn = self.find(:first,:conditions => { :login_email => email_address, :active => true })
      dmn.errors.add_to_base("The email is already used on an existing active demo.")
      return dmn
    end

    dmn = self.find(:first,:conditions => [ 'active=0'],:lock => true)
    if dmn
      dmn.update_attributes(:active => true,:login_email => email_address, :site_demo_template_id => template_id,:expires_at => nil )
      dmn.run_worker(:activate_domain, :expiration => expiration_minutes)
      return dmn
    else<commit_msg>Fixed invalid domains sending repeat<commit_after>require 'fileutils'

class SiteDemoDomain < DomainModel

  validates_as_email :login_email
  validates_presence_of :login_email

  has_many :site_demo_log_entries

  belongs_to :site_demo_template
  validates_uniqueness_of :name
  validates_uniqueness_of :domain_index
  validates_presence_of :site_demo_template

  attr_accessor :expiration_minutes

  def self.new_domain(email_address,template_id,expiration_minutes = nil)
    # Make sure they don't have multiple domains
    if dmn = self.find(:first,:conditions => { :login_email => email_address, :active => true })
      dmn.errors.add_to_base("The email is already used on an existing active demo.")
      return dmn
    end


    dmn = self.find(:first,:conditions => [ 'active=0'],:lock => true)
    if dmn
      if dmn.update_attributes(:active => true,:login_email => email_address, :site_demo_template_id => template_id,:expires_at => nil )
        dmn.run_worker(:activate_domain, :expiration => expiration_minutes)
      end
      return dmn
    else
{'fraction_non_alphanumeric': 0.08712302537099091, 'fraction_numerical': 0.0009573958831977022, 'mean_word_length': 4.741758241758242, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, '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': '3926058', 'n_tokens_mistral': 680, 'n_tokens_neox': 654, 'n_words': 143}