[fs2zammad] do not crash on failed ticket import
This commit is contained in:
parent
74886ee784
commit
8e8ff86f9f
1 changed files with 36 additions and 23 deletions
59
fs2zammad
59
fs2zammad
|
@ -110,28 +110,7 @@ def maybe_create_zammad_user(userdata, zammad_session, attr="login", default=Non
|
||||||
# id, {"roles": roles.append("Agent")}
|
# id, {"roles": roles.append("Agent")}
|
||||||
# )
|
# )
|
||||||
|
|
||||||
### main logic ###
|
def create_zammad_ticket(id, zammad, h2t):
|
||||||
|
|
||||||
if not os.path.exists("rt2zammad.json"):
|
|
||||||
print("Missing rt2zammad.json!")
|
|
||||||
print("Create one based on following template:")
|
|
||||||
print(TEMPLATE)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
with open("rt2zammad.json") as handle:
|
|
||||||
config = json.load(handle)
|
|
||||||
|
|
||||||
h2t = html2text.HTML2Text()
|
|
||||||
zammad = get_zammad_session()
|
|
||||||
|
|
||||||
os.makedirs("users", exist_ok=True)
|
|
||||||
os.makedirs("tickets", exist_ok=True)
|
|
||||||
os.makedirs("attachments", exist_ok=True)
|
|
||||||
|
|
||||||
ticket_ids = os.listdir("tickets/")
|
|
||||||
print(f"Found {len(ticket_ids)} tickets on filesystem.")
|
|
||||||
|
|
||||||
for id in ticket_ids:
|
|
||||||
with open(f"tickets/{id}", "rb") as handle:
|
with open(f"tickets/{id}", "rb") as handle:
|
||||||
rt_ticket = pickle.load(handle)
|
rt_ticket = pickle.load(handle)
|
||||||
|
|
||||||
|
@ -186,7 +165,7 @@ for id in ticket_ids:
|
||||||
|
|
||||||
# Ignore comments for merged tickets.
|
# Ignore comments for merged tickets.
|
||||||
if merged:
|
if merged:
|
||||||
continue
|
return
|
||||||
|
|
||||||
# Internal note regarding the RT-Zammad import.
|
# Internal note regarding the RT-Zammad import.
|
||||||
TicketArticle(zammad).create(
|
TicketArticle(zammad).create(
|
||||||
|
@ -258,3 +237,37 @@ for id in ticket_ids:
|
||||||
|
|
||||||
if restore_creator_to != None:
|
if restore_creator_to != None:
|
||||||
zammad.ticket.update(zammad_ticket["id"], {"customer_id": restore_creator_to})
|
zammad.ticket.update(zammad_ticket["id"], {"customer_id": restore_creator_to})
|
||||||
|
|
||||||
|
### main logic ###
|
||||||
|
|
||||||
|
if not os.path.exists("rt2zammad.json"):
|
||||||
|
print("Missing rt2zammad.json!")
|
||||||
|
print("Create one based on following template:")
|
||||||
|
print(TEMPLATE)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
with open("rt2zammad.json") as handle:
|
||||||
|
config = json.load(handle)
|
||||||
|
|
||||||
|
h2t = html2text.HTML2Text()
|
||||||
|
zammad = get_zammad_session()
|
||||||
|
|
||||||
|
os.makedirs("users", exist_ok=True)
|
||||||
|
os.makedirs("tickets", exist_ok=True)
|
||||||
|
os.makedirs("attachments", exist_ok=True)
|
||||||
|
os.makedirs("failed", exist_ok=True)
|
||||||
|
|
||||||
|
ticket_ids = os.listdir("tickets/")
|
||||||
|
print(f"Found {len(ticket_ids)} tickets on filesystem.")
|
||||||
|
|
||||||
|
for id in ticket_ids:
|
||||||
|
try:
|
||||||
|
create_zammad_ticket(id, zammad, h2t)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print("Received keyboard interrupt. Exiting.")
|
||||||
|
sys.exit()
|
||||||
|
except:
|
||||||
|
print(f"Failed to import RT#{id}")
|
||||||
|
dumpfile = f"failed/{id}"
|
||||||
|
with open(dumpfile, "wb") as handle:
|
||||||
|
pickle.dump(id, handle)
|
||||||
|
|
Loading…
Reference in a new issue