Skip to content

Instantly share code, notes, and snippets.

@jaseclamp
Last active March 31, 2017 05:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaseclamp/d75d82d9d5f5722ed193d5b04edd238a to your computer and use it in GitHub Desktop.
Save jaseclamp/d75d82d9d5f5722ed193d5b04edd238a to your computer and use it in GitHub Desktop.
Stitch data does not delete issues from postgres sql when issues are deleted from jira. This script cleans that up.
<?php
//REPLACE ALL XXX !!
// Create a stream
$opts = array(
'http'=>array(
'method'=>"GET",
'header' => "Content-Type: application/json\r\nAuthorization: Basic " . base64_encode("xxx:xxx")
)
);
$context = stream_context_set_default($opts);
// Connecting, selecting database
$dbconn = pg_connect("host=xxx dbname=xxx user=xxx password=xxx")
or die('Could not connect: ' . pg_last_error());
// Performing SQL query
$query = "select id, key from jira.jira_issues where fields__project__key = 'XXX'";
$result = pg_query($query) or die('Query failed: ' . pg_last_error());
while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
// Open the file using the HTTP headers set above
$file = get_headers("https://XXX.atlassian.net/rest/api/latest/issue/".$line['key']);
if($file[0]=="HTTP/1.1 404 Not Found")
echo "DELETE FROM jira.jira_issues WHERE key = '".$line['key']."';\n\r";
}
// Free resultset
pg_free_result($result);
// Closing connection
pg_close($dbconn);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment