[fs2zammad] remove previously (half) imported zammad ticket
This commit is contained in:
parent
e3c375a29e
commit
2d3526918e
1 changed files with 20 additions and 0 deletions
20
fs2zammad
20
fs2zammad
|
@ -113,6 +113,25 @@ def maybe_create_zammad_user(userdata, zammad_session, attr="login", default=Non
|
||||||
|
|
||||||
return USERMAP[lowercase_email].get(attr, default)
|
return USERMAP[lowercase_email].get(attr, default)
|
||||||
|
|
||||||
|
def remove_existing_zammad_tickets_for(rt_id, zammad, retries=3):
|
||||||
|
try:
|
||||||
|
matching_zammad_tickets= zammad.ticket.search(f"title: \"[RT-{rt_id}]*\"")
|
||||||
|
if len(matching_zammad_tickets) >= 1:
|
||||||
|
print(f"Found existing ticket:")
|
||||||
|
for zt in matching_zammad_tickets:
|
||||||
|
print(f"{zt["id"]} {zt["title"]}")
|
||||||
|
print(f"Deleting Zammad ticket {zt["id"]}")
|
||||||
|
zammad.ticket.destroy(zt["id"])
|
||||||
|
except:
|
||||||
|
print(f"Failed to cleanup duplicates for RT-{rt_id} .. ({retries} retries left)")
|
||||||
|
if retries > 0:
|
||||||
|
print("Sleeping 5 seconds to give Zammad some air...")
|
||||||
|
time.sleep(5)
|
||||||
|
remove_existing_zammad_tickets_for(rt_id, zammad, retries - 1)
|
||||||
|
else:
|
||||||
|
traceback.print_exc()
|
||||||
|
raise RuntimeError
|
||||||
|
|
||||||
# def ensure_user_is_zammad_agent(user, zammad_session):
|
# def ensure_user_is_zammad_agent(user, zammad_session):
|
||||||
# print(f"Promoting user {user} to Agent")
|
# print(f"Promoting user {user} to Agent")
|
||||||
# id = maybe_create_zammad_user(user, zammad_session, "id")
|
# id = maybe_create_zammad_user(user, zammad_session, "id")
|
||||||
|
@ -297,6 +316,7 @@ ticket_ids.sort()
|
||||||
|
|
||||||
for id in ticket_ids:
|
for id in ticket_ids:
|
||||||
try:
|
try:
|
||||||
|
remove_existing_zammad_tickets_for(id, zammad, 5)
|
||||||
zammad_ticket_id = create_zammad_ticket(id, zammad, h2t, 5)
|
zammad_ticket_id = create_zammad_ticket(id, zammad, h2t, 5)
|
||||||
dumpfile = f"processed/{id}"
|
dumpfile = f"processed/{id}"
|
||||||
with open(dumpfile, "w") as handle:
|
with open(dumpfile, "w") as handle:
|
||||||
|
|
Loading…
Reference in a new issue