Delete Users from exchange synchronisation

Hi,

i want to delete all Users from the Exchange synchronisation, how can i do that?
i tried with the shell like:
User.find_by(created_by_id: ‘1’).destroy

but i get this error:
ActiveRecord::InvalidForeignKey: PG::ForeignKeyViolation: ERROR: update or delete on table “users” violates foreign key constraint “fk_rails_45307c95a3” on table "users"
DETAIL: Key (id)=(1) is still referenced from table “users”.
: DELETE FROM “users” WHERE “users”.“id” = $1
from (irb):9

it would also help to delete all Users with the customer role

regards

celevra

That’s not that easy. You can try:

ExternalSync.where(source: ‘Exchange::FolderContact’, object: ‘User’).each { |entry| User.destroy(entry.o_id) }

JFI: ‘Exchange::FolderContact’ might be ‘EWS::FolderContact’, depending on your Zammad version.

This probably fails due to created tickets, users with phone numbers and other causes. Feel free to contact us for advanced support on a commercial base. Thanks for your understanding.

1 Like