-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJira.php
89 lines (73 loc) · 2.82 KB
/
Jira.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/php
<?php
/**
* Created by PhpStorm.
* User: Ryan Noelk
* Date: 6/9/2015
*/
// define the root path for including files. If you use this in a cron, it may not know where to look for the included/required files/classes.
define('__SCRIPT_ROOT', dirname(__FILE__));
// Stores standard PHP PDO MySQL connection information
require_once(__SCRIPT_ROOT . "/../config.php");
Global $conn;
// Include the classes (only once)
include_once(__SCRIPT_ROOT . '/JIRA/JiraIssues.class.php');
include_once(__SCRIPT_ROOT . '/JIRA/JiraDB.class.php');
include_once(__SCRIPT_ROOT . '/JIRA/JiraLogger.class.php');
// Create new log and give the filename and path to the log file
// If a log file is not need just remove the filename and log will be printed to the terminal
$log = new \JIRA\JiraLogger(/*"tmp.txt"*/);
//Loop though each JIRA Project that needs to be tracked
$query = "SELECT * FROM JIRA_MINER WHERE ACTIVE = TRUE;";
foreach ($conn->query($query) as $row)
{
// Set and Initialize vars
$id = $row['JIRA_MINER_ID'];
$search = $jql = array();
$max = $row['MAX'];
$start = 0;
// Fetch all the filters for the query to JIRA
$filter_query = "SELECT * FROM JIRA_FILTERS WHERE JIRA_MINER_ID = $id;";
foreach ($conn->query($filter_query) as $filter_row)
$jql[$filter_row['JIRA_COLUMN']] = $filter_row['FILTER'];
// Fetch all the values to be returned from the query to JIRA
$search_query = "SELECT * FROM JIRA_SEARCH WHERE JIRA_MINER_ID = $id;";
foreach ($conn->query($search_query) as $search_row)
$search[$search_row['JIRA_COLUMN']] = $search_row['DB_COLUMN'];
// Print the above values to the log
$log->print_header("DB Vars:");
$log->print_line(print_r($jql, true));
$log->print_line(print_r($search, true));
$jira = new \JIRA\JiraIssues(
$row['BASE_URL'],
$jql,
$row['CREDENTIALS'],
$row['PROJECT'],
$search,
$row['DAYS']);
while (is_array($data = $jira->GetJIRAData($start, $max)) or $start == 0)
{
// Print the results to the log
$log->print_header("URL:");
$log->print_line($jira->current_url_string);
$log->print_header("Raw Data:");
$log->print_line(print_r($data, true));
// Process the raw data (add it to the array)
$jira->ProcessData($data);
// Increase the start by the max and fetch again
$start += $max;
}
// Print the Process defect array to the Log if its not null
if ($jira->process_array)
{
$log->print_header("Formatted Data:");
$log->print_line(print_r($jira->process_array, true));
}
// Add the processed data to the database
\JIRA\JiraDB::UpdateDatabase(
$jira->process_array,
$row['SAVE_TABLE'],
$row['SAVE_TABLE_PK'],
$row['DOMAIN'],
$row['PROJECT']);
}