Last active
March 31, 2017 05:19
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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