diff --git a/app/models/domain.rb b/app/models/domain.rb index 450aa0d9c..09e4c875d 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -148,27 +148,48 @@ class Domain < ActiveRecord::Base end def start_expire_period - Domain.where('valid_to <= ?', Time.zone.now).each do |x| + logger.info "#{Time.zone.now.utc} - Expiring domains\n" + + d = Domain.where('valid_to <= ?', Time.zone.now) + d.each do |x| x.domain_statuses.create(value: DomainStatus::EXPIRED) if x.expirable? end + + logger.info "#{Time.zone.now.utc} - Successfully expired #{d.count} domains\n" end def start_redemption_grace_period - Domain.where('outzone_at <= ?', Time.zone.now).each do |x| + logger.info "#{Time.zone.now.utc} - Setting server_hold to domains\n" + + d = Domain.where('outzone_at <= ?', Time.zone.now) + d.each do |x| x.domain_statuses.create(value: DomainStatus::SERVER_HOLD) if x.server_holdable? end + + logger.info "#{Time.zone.now.utc} - Successfully set server_hold to #{d.count} domains\n" end def start_delete_period - Domain.where('delete_at <= ?', Time.zone.now).each do |x| + logger.info "#{Time.zone.now.utc} - Setting delete_candidate to domains\n" + + d = Domain.where('delete_at <= ?', Time.zone.now) + d.each do |x| x.domain_statuses.create(value: DomainStatus::DELETE_CANDIDATE) if x.delete_candidateable? end + + logger.info "#{Time.zone.now.utc} - Successfully set delete_candidate to #{d.count} domains\n" end def destroy_delete_candidates + logger.info "#{Time.zone.now.utc} - Destroying domains\n" + + c = 0 DomainStatus.where(value: DomainStatus::DELETE_CANDIDATE).each do |x| x.domain.destroy + c += 1 end + + logger.info "#{Time.zone.now.utc} - Successfully destroyed #{c} domains\n" end end diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index 323b7302c..407d100e3 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -437,6 +437,9 @@ class Epp::Domain < Domain self.period = period self.period_unit = unit + domain_statuses.where(value: DomainStatus::SERVER_HOLD).destroy_all + domain_statuses.where(value: DomainStatus::EXPIRED).destroy_all + save end diff --git a/db/data/20150610111019_add_expire_settings.rb b/db/data/20150610111019_add_expire_settings.rb new file mode 100644 index 000000000..9f8b9cce8 --- /dev/null +++ b/db/data/20150610111019_add_expire_settings.rb @@ -0,0 +1,10 @@ +class AddExpireSettings < ActiveRecord::Migration + def self.up + Setting.expire_warning_period = 15 + Setting.redemption_grace_period = 30 + end + + def self.down + raise ActiveRecord::IrreversibleMigration + end +end diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index 7162db690..89e60de00 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -2067,6 +2067,33 @@ describe 'EPP Domain', epp: true do response[:results][0][:result_code].should == '2105' end + it 'should renew a expired domain' do + domain.valid_to = Time.zone.now - 50.days + domain.outzone_at = Time.zone.now - 50.days + domain.save + + Domain.start_expire_period + Domain.start_redemption_grace_period + + domain.domain_statuses.where(value: DomainStatus::EXPIRED).count.should == 1 + domain.domain_statuses.where(value: DomainStatus::SERVER_HOLD).count.should == 1 + + exp_date = domain.valid_to.to_date + + xml = @epp_xml.domain.renew( + name: { value: domain.name }, + curExpDate: { value: exp_date.to_s }, + period: { value: '1', attrs: { unit: 'y' } } + ) + + response = epp_plain_request(xml) + response[:results][0][:msg].should == 'Command completed successfully' + response[:results][0][:result_code].should == '1000' + + domain.domain_statuses.where(value: DomainStatus::EXPIRED).count.should == 0 + domain.domain_statuses.where(value: DomainStatus::SERVER_HOLD).count.should == 0 + end + it 'does not renew foreign domain' do login_as :registrar2 do exp_date = 1.year.since.to_date