@LeaJustLea
Here is a mysql query I created (with the help of ChatGPT) to mass delete certain tickets and all associated data, proceed with caution as this is very dangerous... and i'm also not sure if I missed any other tables (besides handling attachments)
START TRANSACTION;
-- Store the ticket IDs, related object IDs, and associated thread IDs for data to be deleted in a temporary table
CREATE TEMPORARY TABLE temp_ids_to_delete
(
temp_id INT AUTO_INCREMENT PRIMARY KEY,
ticket_id INT,
object_id INT,
thread_id INT
);
INSERT INTO temp_ids_to_delete (ticket_id, object_id, thread_id)
SELECT ot.ticket_id, th.object_id, th.id AS thread_id
FROM ost_ticket ot
JOIN ost_thread th ON ot.ticket_id = th.object_id
-- You can modify the where selection to match your needs
WHERE ot.ticket_id = 313;
-- Delete associated records from ost_thread_entry_email first since it queries live data
DELETE
FROM ost_thread_entry_email
WHERE thread_entry_id IN (SELECT id FROM ost_thread_entry WHERE thread_id IN (SELECT thread_id FROM temp_ids_to_delete));
-- Delete from ost_ticket for specified ticket ID
DELETE
FROM ost_ticket
WHERE ticket_id IN (SELECT ticket_id FROM temp_ids_to_delete);
-- Delete from ost_ticket__cdata for specified ticket ID
DELETE
FROM ost_ticket__cdata
WHERE ticket_id IN (SELECT ticket_id FROM temp_ids_to_delete);
-- Delete from ost_thread row(s) for specified object ID
DELETE
FROM ost_thread
WHERE id IN (SELECT thread_id FROM temp_ids_to_delete);
-- Delete associated records from ost_thread_entry
DELETE
FROM ost_thread_entry
WHERE thread_id IN (SELECT thread_id FROM temp_ids_to_delete);
-- Delete associated records from ost_thread_collaborator
DELETE
FROM ost_thread_collaborator
WHERE thread_id IN (SELECT thread_id FROM temp_ids_to_delete);
-- Delete from ost_thread_event
DELETE
FROM ost_thread_event
WHERE thread_id IN (SELECT thread_id FROM temp_ids_to_delete);
-- Delete from ost_thread_referral
DELETE
FROM ost_thread_referral
WHERE thread_id IN (SELECT thread_id FROM temp_ids_to_delete);
-- Drop the temporary table
DROP TEMPORARY TABLE IF EXISTS temp_ids_to_delete;
COMMIT;