Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Removes obsolete tickets, can be run as often as you choose.
- * Ideally via cron:
- # Every 28 days?
- * * /28 * * nobody /usr/bin/php /path/to/remove_obsolete_tickets.php
- YOU WILL NEED TO CONFIGURE THE FOLLLOWING:
- */
- define('BACKUPDIR','/home/backups/');
- define('DELETEMONTHS', 6); //Any closed ticket older than this many months will be archived/deleted.
- define('MY_USER_ID', 'Grizly');
- define('CRONFRIENDLY', true); //change to false to show more output.
- /**
- * Should be able to ignore from here, until you are ready to start pruning.
- * Then go to bottom, un-comment the line: // return $t->delete();
- * This will start actually deleting tickets, so, make sure its backing them up first.
- */
- if(! php_sapi_name () == 'cli')
- die('Cannot be run from browser.. ');
- $_SERVER ['REMOTE_ADDR'] = 'localhost';
- require_once ('main.inc.php');
- $thisstaff = new Staff(MY_USER_ID);
- // select old messages.. we probably don't need any of them
- $select = 'SELECT ticket_id FROM ' . TICKET_TABLE . " WHERE status='closed' AND closed < DATE_SUB(NOW(), INTERVAL " . DELETEMONTHS . ' MONTH)';
- $res = db_query ( $select );
- if ($res && $num =db_num_rows ( $res )) {
- print "Found $num matching deletables!\n";
- $messages = db_assoc_array ( $res, true );
- if ($messages && !CRONFRIENDLY)
- print "Deleting old Messages\n";
- foreach ( $messages as $ticket) {
- if (! delete_ticket ( $ticket['ticket_id'] ))
- print 'Failed to delete ticket_id: ' . $ticket['ticket_id'] . "\n\n";
- }
- } elseif (!CRONFRIENDLY){
- print "Didn't find anything to delete.";
- }
- /**
- * Uses osTicket functions to remove a ticket correctly.
- */
- function delete_ticket($id) {
- $t = new Ticket ( $id );
- print "Deleting old ticket $id:" . $t->getSubject () . "\n";
- // save backup?
- // If you don't want backups, you don't need a staff-id either.. odd, but there you go.
- // Simply comment out this whole part, and uncomment the $t->delete(); line..
- $pdf = new Ticket2PDF ( $t, 'A4', true );
- $name = 'Ticket-' . $t->getExtId () . '.pdf';
- $file = BACKUPDIR. $name;
- $string = $pdf->Output ( $file, 'F' );
- // return $t->delete();
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement