/** * update Youtrack with timing data * @param string $content timing xml * @param string $ticketId ticket reference * @return bool success */ function updateYoutrack($content, $ticketId) { global $youtrackUrl; $getDataFromYoutrack = new getDataFromYoutrack(); $url = $youtrackUrl . '/rest/issue/' . $ticketId . '/timetracking/workitem'; $res = $getDataFromYoutrack->restResponse($url, 'post', ['Content-Type' => 'text/xml; charset=UTF8'], $content); $res = $res->getResponse(); if ($res->getStatusCode() == 201) { return true; } else { return false; } }
<?php /** * time tracker ticket details ajax code */ require_once __DIR__ . '/getCustomSettings.php'; require_once __DIR__ . '/getDataFromYoutrack.php'; $getDataFromYoutrack = new getDataFromYoutrack(); $authenticationAndSecurity = new authenticationAndSecurity(); $response = []; $ticket = htmlspecialchars($authenticationAndSecurity->getGet("ticket")); $response['ticketRef'] = $ticket; $response['summary'] = $getDataFromYoutrack->getTicketSummary($ticket); $response['ticketUrl'] = $GLOBALS['youtrackUrl'] . "/issue/" . $ticket; $project = explode('-', $ticket)[0]; $response['workTypes'] = $getDataFromYoutrack->getTicketWorkTypes($project); echo json_encode($response);
/** * send attachment files to the youtrack * @global type $youtrackUrl * @param string $issueRef * @param array $item */ function stdUserUpdateAttachments($issueRef, $item) { global $youtrackUrl; $getDataFromYoutrack = new getDataFromYoutrack(); $files = isset($item['attachmentFiles']) ? $item['attachmentFiles'] : null; if ($files && ($count = count($files['name']))) { for ($i = 0; $i < $count; $i++) { if (!strlen($files['name'][$i])) { continue; } $header = ['Content-Type' => 'multipart/form-data']; $body = ['name' => $files['name'][$i], 'file' => '@' . $files['tmp_name'][$i], 'Content-Type' => $files['type'][$i]]; // POST /rest/issue/{issue}/attachment $url = $youtrackUrl . '/rest/issue/' . $issueRef . '/attachment'; $getDataFromYoutrack->rest($url, 'post', $header, $body); } $GLOBALS['createByFormAjax'][$issueRef]['attachmentsUpdated'] = true; } }
<?php /** * returns field options for createByForm page */ require_once __DIR__ . '/getCustomSettings.php'; require_once __DIR__ . '/getDataFromYoutrack.php'; $getDataFromYoutrack = new getDataFromYoutrack(); $authenticationAndSecurity = new authenticationAndSecurity(); $project = htmlspecialchars($authenticationAndSecurity->getGet("project")); if (!isset($customFieldList)) { $customFieldList = ''; } $customFieldTypeAndBundle = $getDataFromYoutrack->getCustomFieldTypeAndBundle($customFieldList, $project); unset($customFieldTypeAndBundle['Spent time']); $response = $customFieldTypeAndBundle; $response['assignee'] = ['fieldType' => 'enum[1]', 'innerHtml' => '']; $projectAssignees = $getDataFromYoutrack->getProjectAssignees($project); foreach ($projectAssignees as $assignee) { $response['assignee']['innerHtml'] .= '<option value="' . $assignee . '">' . $assignee . '</option>'; } $customFieldDetails = $getDataFromYoutrack->getCustomFieldsDetails($customFieldList, $project, $customFieldTypeAndBundle); foreach ($customFieldDetails as $key => $list) { if (gettype($list) == 'array') { $response[$key]['innerHtml'] = '<option value=""></option>'; foreach ($customFieldDetails[$key] as $option) { $response[$key]['innerHtml'] .= '<option value="' . $option . '">' . $option . '</option>'; } } } echo json_encode($response);
<?php /** * return ist of projects for rendering the time tracker page */ require_once __DIR__ . '/getCustomSettings.php'; require_once __DIR__ . '/authenticationAndSecurity.php'; require_once __DIR__ . '/getDataFromYoutrack.php'; $getDataFromYoutrack = new getDataFromYoutrack(); $projectList = $getDataFromYoutrack->getProjectsList();
<?php /** * download all issues in a project in a csv */ require_once __DIR__ . '/../../vendor/autoload.php'; require_once __DIR__ . '/getCustomSettings.php'; require_once __DIR__ . '/getDataFromYoutrack.php'; require_once __DIR__ . '/authenticationAndSecurity.php'; $getDataFromYoutrack = new getDataFromYoutrack(); $authenticationAndSecurity = new authenticationAndSecurity(); $filename = $authenticationAndSecurity->getPost('filename'); $url = $youtrackUrl . '/rest/export/' . $authenticationAndSecurity->getPost('project') . '/issues'; $res = $getDataFromYoutrack->rest($url, 'get'); $filepath = '../export/' . $filename; $file = fopen($filepath, "w") or die("Unable to open file!"); fwrite($file, $res); fclose($file); chmod($file, $GLOBALS['filePermissions']); if (file_exists($filepath)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . basename($filepath)); header('Expires: 1'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($filepath)); header('Content-type: text/xml'); readfile($filepath); exit; }
<?php /** * ticket search on time tracker page */ require_once __DIR__ . '/getCustomSettings.php'; require_once __DIR__ . '/getDataFromYoutrack.php'; $getDataFromYoutrack = new getDataFromYoutrack(); $authenticationAndSecurity = new authenticationAndSecurity(); $project = htmlspecialchars($authenticationAndSecurity->getPost("project")); $query = htmlspecialchars($authenticationAndSecurity->getPost("query")); $after = htmlspecialchars($authenticationAndSecurity->getPost("after")); $after = $after ? $after : 0; echo json_encode($getDataFromYoutrack->getTicketsFromSearch($project, $query, $maximumReturned = 100, $after));
<?php /** * download a csv with field options */ require_once __DIR__ . '/../../vendor/autoload.php'; require_once __DIR__ . '/getCustomSettings.php'; require_once __DIR__ . '/getDataFromYoutrack.php'; require_once __DIR__ . '/authenticationAndSecurity.php'; $getYoutrackData = new getDataFromYoutrack(); $authenticationAndSecurity = new authenticationAndSecurity(); require_once __DIR__ . '/csv.php'; $csvClass = new csvClass(); use Ddeboer\DataImport\Writer\CsvWriter; $youtrackFields = []; $filename = $authenticationAndSecurity->getPost('filename'); list($youtrackFieldsList, $youtrackFields) = $getYoutrackData->getCustomFieldsWithDetails(); $youtrackFields['user'] = $getYoutrackData->getUsers(); array_push($youtrackFieldsList, 'user'); /** * organises fields into more usable format, removing empty * @param array $array youtrack fields * @return array */ function reorganiseArray($array) { $newArray = []; foreach ($array as $key => $value) { $i = 0; foreach ($value as $key2 => $val) { if (!isset($newArray[$i])) {
<?php /** * gets data for the createByForm page */ $getDataFromYoutrack = new getDataFromYoutrack(); $customFieldList = []; $customFieldListFull = $getDataFromYoutrack->getCustomFields(); $key = array_search('Spent time', $customFieldListFull); unset($customFieldListFull[$key]); $customFieldListFull = array_merge($customFieldListFull); foreach ($customFieldListFull as $customField) { if (!isset($createByFormSettings['IgnoreCustomFields']) || !in_array($customField, $createByFormSettings['IgnoreCustomFields'])) { array_push($customFieldList, $customField); } } $projectList = $getDataFromYoutrack->getProjectsList(); $projectAssignees = $getDataFromYoutrack->getProjectAssignees($projectList[0]); $customFieldTypeAndBundle = $getDataFromYoutrack->getCustomFieldTypeAndBundle($customFieldList, $projectList[0]); $customFieldDetails = $getDataFromYoutrack->getCustomFieldsDetails($customFieldList, $projectList[0], $customFieldTypeAndBundle); $linkTypes = $getDataFromYoutrack->getLinkTypes();