/** * Select incidents awaiting closure for more than a week where the next action time is not set or has passed * @author Ivan Lucas * @param $closure_delay int. The amount of time (in seconds) to wait before closing **/ function saction_CloseIncidents($closure_delay) { $success = TRUE; global $dbIncidents, $dbUpdates, $CONFIG, $crlf, $now; if ($closure_delay < 1) { $closure_delay = 554400; } // Default six days and 10 hours // Code added back in to fix mark as closure incidents // http://bugs.sitracker.org/view.php?id=717 $sql = "UPDATE `{$dbIncidents}` SET lastupdated='{$now}', "; $sql .= "closed='{$now}', status='" . STATUS_CLOSED . "', closingstatus='4', "; $sql .= "timeofnextaction='0' WHERE status='" . STATUS_CLOSING . "' "; $sql .= "AND (({$now} - lastupdated) > '{$closure_delay}') "; $sql .= "AND (timeofnextaction='0' OR timeofnextaction <= '{$now}')"; $result = mysql_query($sql); if (mysql_error()) { trigger_error(mysql_error(), E_USER_WARNING); $success = FALSE; } // Billing $sql = "SELECT id, owner, status FROM `{$dbIncidents}` WHERE status='" . STATUS_CLOSING . "' "; $sql .= "AND (({$now} - lastupdated) > '{$closure_delay}') "; $sql .= "AND (timeofnextaction='0' OR timeofnextaction<='{$now}') "; $result = mysql_query($sql); if (mysql_error()) { trigger_error(mysql_error(), E_USER_WARNING); $success = FALSE; } while ($obj = mysql_fetch_object($result)) { $bill = close_billable_incident($obj->id); // Do the close tasks if necessary if ($bill) { $sqlc = "INSERT INTO `{$dbUpdates}` (incidentid, userid, type, currentowner, currentstatus, bodytext, timestamp, nextaction, customervisibility) "; $sqlc .= "VALUES ('{$obj->id}', '0', 'closing', '{$obj->owner}', '{$obj->status}', 'Incident Closed by {$CONFIG['application_shortname']}', '{$now}', '', 'show' ) "; $resultc = mysql_query($sqlc); if (mysql_error()) { trigger_error(mysql_error(), E_USER_WARNING); $success = FALSE; } } else { $success = FALSE; } } return $success; }
$sql = "SELECT params FROM `{$dbScheduler}` WHERE action = 'CloseIncidents' LIMIT 1"; $result = mysql_query($sql); if (mysql_error()) { trigger_error("MySQL Query Error " . mysql_error(), E_USER_WARNING); $closure_delay = 554400; } else { list($closure_delay) = mysql_fetch_row($result); } $timeofnextaction = $now + $closure_delay; $sql = "UPDATE `{$dbIncidents}` SET status='7', lastupdated='{$now}', timeofnextaction='{$timeofnextaction}' WHERE id='{$id}'"; $result = mysql_query($sql); if (mysql_error()) { trigger_error("MySQL Query Error " . mysql_error(), E_USER_ERROR); } } else { $bill = close_billable_incident($id); if (!$bill) { $addition_errors = 1; $addition_errors_string .= "<p class='error'>{$strBilling}: {$strAdditionFail}</p>\n"; } else { // mark incident as closed $sql = "UPDATE `{$dbIncidents}` SET status='2', closingstatus='{$closingstatus}', lastupdated='{$now}', closed='{$now}' WHERE id='{$id}'"; $result = mysql_query($sql); if (mysql_error()) { trigger_error("MySQL Query Error " . mysql_error(), E_USER_ERROR); } } } if (!$result) { $addition_errors = 1; $addition_errors_string .= "<p class='error'>{$strIncident}: {$strUpdateFailed}</p>\n";
} } } if (is_array($kbrestricted)) { foreach ($kbrestricted as $article) { $articleID = intval($article); $sql = "UPDATE `{$dbKBArticles}` SET visibility='restricted' WHERE id='{$articleID}'"; mysql_query($sql); if (mysql_error()) { trigger_error(mysql_error(), E_USER_ERROR); } } } if (is_array($billing_upgrade)) { foreach ($billing_upgrade as $incident) { $r = close_billable_incident($incident); if (!$r) { trigger_error("Error upgrading {$incident} to new billing format", E_USER_WARNING); } } } } if ($installed_version < 3.4) { //remove any brackets from checks as per mantis 197 $sql = "UPDATE `triggers` SET `checks` = REPLACE(`checks`, '(', ''); "; $sql .= "UPDATE `triggers` SET `checks` = REPLACE(`checks`, ')', '')"; mysql_query($sql); if (mysql_error()) { trigger_error(mysql_error(), E_USER_ERROR); } }