public function indexAction() { $agrData = []; $axis = $series = NULL; $success = FALSE; $form = new \Application\Forms\JiraForm(); $request = $this->getRequest(); if ($request->isPost()) { $form->setData($request->getPost()); if ($form->isValid()) { $cache = $this->getServiceLocator()->get('cache'); $key = $request->getPost()->get('host'); // jira host $cacheData = $cache->getItem($key, $success); if (!$success) { $data = []; $api = new \chobie\Jira\Api($properties->getHost(), new \chobie\Jira\Api\Authentication\Basic($request->getPost()->get('login'), $request->getPost()->get('password'))); $walker = new \chobie\Jira\Issues\Walker($api); $walker->push("ORDER BY createdDate"); $i = 0; foreach ($walker as $issue) { $data[] = $issue; if ($i == 99) { break; } else { $i++; } } $cache->setItem($key, $data); } foreach ($cacheData as $node) { if (!array_key_exists($node->getProject()['name'], $agrData)) { $agrData[$node->getProject()['name']] = 0; } if (preg_match('/^\\d{4}-\\d{2}-\\d{2}.*/', $node->getUpdated())) { $agrData[$node->getProject()['name']]++; } } foreach ($agrData as $key => $value) { $axis .= '\'' . $key . '\','; $series .= $value . ','; } } } return new ViewModel(['axis' => $axis, 'series' => $series, 'form' => $form, 'success' => $success]); }
<?php require dirname(__FILE__) . "/common.php"; $api = getApiClient(); /** * Jira_Issues_Walker implicitly paging search request. * you don't need to care about paging request * * push(string $jql, string $navigable) * * `push` function calls Jira_Api::search($jql, $startAt = 0, $maxResult = 20, $fields = '*navigable') internally. * * @see * https://developer.atlassian.com/static/rest/jira/5.0.html#id202584 */ $walker = new \chobie\Jira\Issues\Walker($api); $walker->push("project = TICKETACEG AND updated > -1d ORDER BY priority DESC", "*navigable"); /** okay, then just do foreach walker variable to pull issues */ foreach ($walker as $k => $issue) { var_dump($issue); }
<?php require dirname(__FILE__) . '/common.php'; $api = getApiClient(); /** * Jira_Issues_Walker implicitly paging search request. * you don't need to care about paging request * * push(string $jql, string $navigable) * * `push` function calls Jira_Api::search($jql, $startAt = 0, $maxResult = 20, $fields = '*navigable') internally. * * @see https://developer.atlassian.com/static/rest/jira/5.0.html#id202584 */ $walker = new \chobie\Jira\Issues\Walker($api); $walker->push('project = TICKETACEG AND updated > -1d ORDER BY priority DESC', '*navigable'); // Okay, then just do foreach walker variable to pull issues. foreach ($walker as $issue) { var_dump($issue); }
// Initialize JIRA REST API require_once 'common.php'; $api = getApiClient(); $walker = new \chobie\Jira\Issues\Walker($api); foreach ($projects as $project) { // Get the latest updated timestamp from the database and find all issues created or updated after that $result = $dbh->query("SELECT MAX(updated) FROM jira_issue WHERE project='{$project}';")->fetch(); if (empty($result[0])) { $result[0] = DATESTART; } // For some reason JQL does NOT accept seconds in datetime $datetime = substr($result[0], 0, -3); // the ORDER BY is critical to catching all updated/created issues incrementally // DO NOT try to sort based on issueKey as this will break the incremental updates! $jqlquery = "project = '{$project}' AND updated >= '{$datetime}' ORDER BY updated ASC"; $walker->push($jqlquery, "*navigable"); $count = 0; foreach ($walker as $k => $issue) { // Clean-up if we already had this issue in the database $stm_id->bindParam(':issue', $issue->getKey()); $stm_id->execute(); // Create or Update the issue itself $stm_ii->bindParam(':jira_id', $issue->getId()); $stm_ii->bindParam(':project', $project); $stm_ii->bindParam(':issue', $issue->getKey()); $stm_ii->bindParam(':summary', $issue->getSummary()); $issueType = $issue->getIssueType(); $stm_ii->bindParam(':type', $issueType['name']); $priority = $issue->getPriority(); $stm_ii->bindParam(':priority', $priority['name']); $security = $issue->get('Security Level');
/** * [getIssues description] * @param string $jql [description] * @return \chobie\Jira\Issues\Walker [description] */ public function getIssues($jql) { $walker = new \chobie\Jira\Issues\Walker($this); $walker->push($jql, "*navigable"); return $walker; }