Auto open stalled tickets after 14 days script

From Request Tracker Wiki
Jump to navigation Jump to search

PHP Script for auto-opening Tickets that has been stalled X days (in this case 14):

Requirements

  • Requesttracker (tested on 3.8)
  • PHP + mysql (tested on PHP5)
  • RT CLI
<?php

$link = mysql_connect("server", "username", "passwd") or die("cannot connect " . mysql_error());
mysql_select_db("rtdb") or die("seldb err: " . mysql_error());
$result = mysql_query("select id,Subject,LastUpdated,date(LastUpdated)-curdate() as diff From Tickets where Status='stalled' and date(LastUpdated)-curdate() < -14 order by LastUpdated;");

for ($i=0;$i < mysql_num_rows($result);$i++) {
$id=mysql_result($result,$i,"id");
system("RTUSER=user RTPASSWD=password rt comment -m 'Autoopening stalled ticket after 14 days.' " . $id);
system("RTUSER=user RTPASSWD=password rt edit " . $id . " set status='open'");
}
?>