- Edited
I built a MySQL query that easily helps me find all duplicate tickets in the database:
Feel free to use this by the way, this will work with anyone using MySQL. This was used on osTicket 1.11 with no issue:
SELECT t.ticket_id FROM ost_ticket__cdata t WHERE EXISTS
(SELECT 1 FROM ost_ticket__cdata WHERE ticket_id <> t.ticket_id AND subject = t.subject)
ORDER BY t.ticket_id,
This returns the ticket number and count of duplicates.
I wish to build a script that then takes this data and deletes all duplicates of the ticket, but keeps the ticket with the lowest ticket# (keeps the first version of the ticket that comes in).
Could someone point me to the function/PHP file that is used in osTicket when tickets are deleted? I would like to use this function to run the delete on the duplicates.
ADDITIONAL:
If you want to run this on the command line, and want it to output the ticket# and subject information into a text file you can run the query like so, or even put it in a PHP script to run on a cronjob or something:
SELECT t.ticket_id, t.subject FROM ost_ticket__cdata t WHERE EXISTS
(SELECT 1 FROM ost_ticket__cdata WHERE ticket_id <> t.ticket_id AND subject = t.subject)
ORDER BY t.ticket_id INTO OUTFILE '/var/lib/mysql-files/duplicates.txt';
Obviously adjust the path for your mysql-files location accordingly. You may change the location of the mysql-files in the MySQL configuration file (my.cnf). I believe SQL is weird and only lets you output to certain locations on your server, and it also CANNOT over-write files or append to files, so if you run this on a cron you need to make sure it deletes the old/previous file and then writes a new one.