Skip to content

Instantly share code, notes, and snippets.

@apanzerj
Created June 13, 2012 08:34
Show Gist options
  • Save apanzerj/2922811 to your computer and use it in GitHub Desktop.
Save apanzerj/2922811 to your computer and use it in GitHub Desktop.
MaxIncidents PHP Code
<?php
//Get Incident Data
$id = $_GET[id];
$data = curlWrap("/tickets/".$id.".json", null, "GET");
//Find problem ticket and count incidents
$source = $data->ticket->problem_id;
$num = curlWrap("/tickets/".$source."/incidents.json", null, "GET");
$num = count($num->tickets);
//Get tags on existing problem ticket
$pr_tags = curlWrap("/tickets/".$source.".json", null, "GET");
$tag_arr = $pr_tags->ticket->tags;
//Remove old tag and add new tag
foreach($tag_arr as $key => $value){
if(preg_match('/linked_[0-9]+/i',$value)){
unset($tag_arr[$key]);
}
}
array_push($tag_arr, "linked_".$num);
$tag_arr = array_values($tag_arr);
// Create JSON and put it up
$update = json_encode(array( "ticket" => array("tags" => $tag_arr)));
$data = curlWrap("/tickets/".$source.".json", $update, "PUT");
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment