示例#1
0
<?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);
<?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);
示例#3
0
 /**
  * 
  * @global type $youtrackUrl
  * @param string $issueRef
  * @param array $item
  */
 function stdUserUpdateIssue($issueRef, $item)
 {
     global $youtrackUrl;
     $getDataFromYoutrack = new getDataFromYoutrack();
     $authenticationAndSecurity = new authenticationAndSecurity();
     $customFieldsDetails = $getDataFromYoutrack->getCustomFieldTypeAndBundle('', $item['project']);
     // https://confluence.jetbrains.com/display/YTD65/Apply+Command+to+an+Issue
     // POST /rest/issue/{issue}/execute?{command}&{comment}&{group}&{disableNotifications}&{runAs}
     $cmd = '';
     foreach ($item as $key => $value) {
         switch (trim($key)) {
             case 'project':
             case 'summary':
             case 'description':
             case 'Spent time':
             case 'reporterName':
                 break;
             case 'assignee':
                 $cmd .= ' ' . $key . ' ' . $value;
                 break;
             case 'links':
                 $cmd .= ' ' . $value;
                 break;
             default:
                 // convert into required date format from the xml's import required timestamp format ... youtrack api inconsistant
                 if (!isset($customFieldsDetails[$key])) {
                     // for Scheduled Date, Invoice Id which dont seem to exist for this project so why is itg loading in form????
                     //  $cmd .= ' '.$key.' '.$value;
                 } elseif ($customFieldsDetails[$key]['fieldType'] === 'date') {
                     $value = substr($value, 0, -3);
                     date_default_timezone_set('Europe/London');
                     $value = date('Y-m-d', $value);
                     if ($value) {
                         $cmd .= ' ' . $key . ' ' . $value;
                     }
                 } elseif ($customFieldsDetails[$key]['fieldType'] === 'string') {
                     $cmd .= ' ' . $key . ' "' . $value . '"';
                 } else {
                     $cmd .= ' ' . $key . ' ' . $value;
                 }
                 break;
         }
     }
     //  $url = 'http://tracker.juno.is/youtrack/rest/issue/test-57/execute?command= State Open';
     $url = $youtrackUrl . '/rest/issue/' . $issueRef . '/execute?command=' . $cmd;
     $getDataFromYoutrack->rest($url, 'post');
     $isAjax = $authenticationAndSecurity->getGet("ajax");
     if ($isAjax !== 'true') {
         echo 'updated : <a href="' . $youtrackUrl . '/issue/' . $issueRef . '">' . $issueRef . '</a>';
         echo $GLOBALS["newline"];
     } else {
         $GLOBALS['createByFormAjax'][$issueRef]['updated'] = true;
     }
 }
 /**
  * create tickets from form data
  */
 function submit()
 {
     $authenticationAndSecurity = new authenticationAndSecurity();
     $csvClass = new csvClass();
     $isAjax = $authenticationAndSecurity->getGet("ajax");
     $GLOBALS['newline'] = '<br/>';
     $newLine = $GLOBALS["newline"];
     if ($isAjax !== 'true') {
         echo $newLine . $newLine . "------------------------------" . $newLine . "    Youtrack csv importer     " . $newLine . "------------------------------" . $newLine;
         if (null !== $authenticationAndSecurity->getPost("test")) {
             echo "-- Testing progress --" . $newLine;
         } else {
             echo "-- Progress --" . $newLine;
         }
     }
     $posts = $this->organisePosts();
     $posts = $this->organiseAttachments($posts);
     date_default_timezone_set('Europe/London');
     $csvLogFolder = __DIR__ . '/../../log/createByForm/' . date("Y-m-d");
     $csvLogFileName = time() . '.csv';
     // creates csv log before sending to guzzle as guzzle dosnt fail gracefully
     if ($GLOBALS['createByFormTransferLog']) {
         $this->createFolder($csvLogFolder);
         $csvClass->createCsv($posts, $csvLogFolder . '/' . $csvLogFileName);
     }
     $posts = $this->sendPostData($posts);
     if ($GLOBALS['createByFormTransferLog']) {
         $csvClass->createCsv($posts, $csvLogFolder . '/' . $csvLogFileName);
     } elseif ($GLOBALS['createByFormTransferErrorLog']) {
         $posts = $this->removeSuccessfulPosts($posts);
         $this->createFolder($csvLogFolder);
         $csvClass->createCsv($posts, $csvLogFolder . '/' . $csvLogFileName);
     }
     if ($isAjax !== 'true') {
         if (null !== $authenticationAndSecurity->getPost("test")) {
             echo $newLine . "---- Test Finished -----" . $newLine;
         } else {
             echo $newLine . "---- Upload Finished -----" . $newLine;
         }
     } else {
         echo json_encode($GLOBALS['createByFormAjax']);
     }
 }