Add new file
This commit is contained in:
parent
cc870f1185
commit
0fe150afbf
1 changed files with 17 additions and 0 deletions
17
purge_inactive_users.rake
Normal file
17
purge_inactive_users.rake
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
namespace :zammad do
|
||||||
|
desc "Purge inactive users"
|
||||||
|
task purge_inactive_users: :environment do
|
||||||
|
User.joins('LEFT JOIN tickets ON tickets.customer_id = users.id')
|
||||||
|
.joins(:roles)
|
||||||
|
.where('roles.name = \'Customer\' AND tickets.state_id NOT IN (?) AND tickets.updated_at < ?', Ticket::State.where(name: ['new', 'open']).pluck(:id), 30.days.ago)
|
||||||
|
.distinct
|
||||||
|
.find_each do |user|
|
||||||
|
if Ticket.where(customer_id: user.id)
|
||||||
|
.where('state_id IN (?) AND updated_at >= ?', Ticket::State.where(name: ['new', 'open']).pluck(:id), 30.days.ago)
|
||||||
|
.empty?
|
||||||
|
user.destroy
|
||||||
|
end
|
||||||
|
end
|
||||||
|
puts "Purge complete."
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue