Ergänze fehlendes Script
This commit is contained in:
parent
4282a7536f
commit
6c6ae8b927
1 changed files with 27 additions and 0 deletions
27
templates/zammad-delete-customers.rb.j2
Normal file
27
templates/zammad-delete-customers.rb.j2
Normal file
|
@ -0,0 +1,27 @@
|
|||
# https://github.com/JBails/PurgeZammad
|
||||
# This script will delete all users that do not have an assigned ticket (open or closed), with no regards as to how long they haven't had a ticket
|
||||
# i.e. doesn't care if the last ticket was deleted 30 seconds or 30 days ago
|
||||
|
||||
ticketless_customers = User.with_permissions('ticket.customer'){% if zammad_preserve_customer_domains is defined %}{% for domain in zammad_preserve_customer_domains %}.where('email NOT LIKE ?', '%{{ domain }}%'){% endfor %}{% endif %}.where('id NOT IN (SELECT customer_id FROM tickets)')
|
||||
count = ticketless_customers.count
|
||||
|
||||
puts "#{count} customers without tickets found."
|
||||
puts
|
||||
|
||||
ticketless_customers.find_each.with_index do |user, i|
|
||||
next if user.permissions?(%w[admin ticket.agent])
|
||||
next if user.id == 1
|
||||
|
||||
display_name = user.fullname + (user.fullname == user.email ? '' : " (#{user.email})")
|
||||
|
||||
User.transaction do
|
||||
begin
|
||||
user.destroy!
|
||||
puts " #{display_name} deleted."
|
||||
rescue => e
|
||||
puts " #{display_name} could not be deleted: #{e.message}"
|
||||
raise ActiveRecord::Rollback
|
||||
next
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue