/** * @return string json string of timer data */ function getJson() { $authenticationAndSecurity = new authenticationAndSecurity(); $reporterCookieName = 'timerCookie'; if (null !== $authenticationAndSecurity->getcookie($reporterCookieName)) { $reporterName = $authenticationAndSecurity->getSingleCookie($reporterCookieName); } else { die('Error: no reporter cookie'); } $json = $this->getTimeJsonFile($reporterName); return $json; }
/** * send request to Youtrack api, dosnt check the cache. Use the rest function in this class instead * @param string $url request url * @param string $postOrGet get|post|put request type * @param array $headers * @param string $body * @param array $options * @return object request object */ function restResponse($url, $postOrGet = 'get', $headers = null, $body = null, $options = null) { $client = new \Guzzle\Http\Client(); $authenticationAndSecurity = new authenticationAndSecurity(); $authentication = $authenticationAndSecurity->getAuthentication(); if ($authentication['type'] !== 'password' && $authentication['type'] !== 'cookie' && $authentication['type'] !== 'file') { echo 'authentication type unknown. please check its set in the customSettings.php file'; return; } if (!isset($options)) { if ($authentication['type'] === 'password') { $options = ['auth' => [$authentication['details']['user'], $authentication['details']['password']]]; } else { $options = []; } } if ($postOrGet === 'get') { $request = $client->get($url, $headers, $options); } elseif ($postOrGet === 'post') { $request = $client->post($url, $headers, $body, $options); } elseif ($postOrGet === 'put') { $request = $client->put($url, $headers, $body, $options); } // if( $postOrGet === 'put' && isset($headers) ){ // foreach($headers as $key => $value){ // $request->addHeader($key,$value); // } // } if ($authentication['type'] === 'cookie' && $authentication['details']) { foreach ($authentication['details'] as $singleCookie) { foreach ($singleCookie as $cookieName => $cookieValue) { $request->addCookie($cookieName, $cookieValue); } } } $request->send(); return $request; }
/** * save the timing data * @param $json * @return bool */ function saveJson($json) { $authenticationAndSecurity = new authenticationAndSecurity(); $reporterCookieName = 'timerCookie'; if (null !== $authenticationAndSecurity->getcookie($reporterCookieName)) { $reporterName = $authenticationAndSecurity->getSingleCookie($reporterCookieName); } else { die('Error: no reporter cookie'); } if ($this->createTimeJsonFile($reporterName, $json)) { $this->removeOldFiles($reporterName); 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);
/** * get the cookies values extracted * @return null|array array of cookie data */ function getBrowserCookies() { $authenticationAndSecurity = new authenticationAndSecurity(); if (null === $authenticationAndSecurity->getCookie('Set-Cookie0') || $authenticationAndSecurity->getCookie('Set-Cookie0') === null) { $cookies = null; } else { $cookie0 = $this->getSingleCookie('Set-Cookie0'); $cookie1 = $this->getSingleCookie('Set-Cookie1'); $cookies[0] = $this->splitCookie($cookie0); $cookies[1] = $this->splitCookie($cookie1); } return $cookies; }
/** * * @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; } }
<?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 require_once __DIR__ . '/code/getCustomSettings.php'; require_once __DIR__ . '/code/authenticationAndSecurity.php'; $authenticationAndSecurity = new authenticationAndSecurity(); $cookies = $authenticationAndSecurity->getBrowserCookies(); ?> <!DOCTYPE html> <head> <script type="text/javascript" src="js/bootstrap/bootstrap-3.3.7-dist/bootstrap.min.js"></script> <link rel="stylesheet" href="css/bootstrap/bootstrap-3.3.7-dist/bootstrap.min.css"> <link rel="stylesheet" href="css/bootstrap/bootstrap-3.3.7-dist/bootstrap-theme.min.css"> </head> <html> <body> <?php if ($authenticationType === 'password') { ?> <header> <?php require_once __DIR__ . '/header.phtml'; ?> </header> <?php } else { ?> <?php if ($cookies === null) { ?> <form action="code/youtrackLogin.php" method="post" enctype="multipart/form-data"> <h1>Login</h1>
<?php $GLOBALS['newline'] = '\\n'; // keep at the top needed by getCustomSettings 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(); /** * set login cookie */ function LoginToYouTrack() { global $getDataFromYoutrack; global $youtrackUrl; global $authenticationAndSecurity; $url = $youtrackUrl . "/rest/user/login"; $response = $getDataFromYoutrack->restResponse($url, 'post', null, ["login" => $authenticationAndSecurity->getPost("user"), "password" => $authenticationAndSecurity->getPost("password")], array()); $response = $response->getResponse(); if ($response->getStatusCode() == 200) { $cookies = $response->getHeader('set-cookie'); foreach ($cookies as $key => $singleCookie) { $authenticationAndSecurity->setCookie("Set-Cookie" . $key, $singleCookie, 0, '/'); } $reporterCookieName = 'myCookie'; $authenticationAndSecurity->setCookie($reporterCookieName, $authenticationAndSecurity->getPost("user"), 0, '/'); return true; } else { return false;
/** * 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']); } }
/** * format & send timing data to Youtrack * @return array */ function submit() { $authenticationAndSecurity = new authenticationAndSecurity(); $this->checkForCookie(); $posts = $authenticationAndSecurity->getAllPosts(); $ticketId = $posts['project'] . '-' . $posts['ticketnumber']; $organisedPosts = $this->organisePosts($posts); foreach ($organisedPosts as $key => $timeRow) { $xml = $this->createXml($timeRow); $organisedPosts[$key]['success'] = $this->postData($xml, $ticketId); } return $organisedPosts; }
<?php /** * clear login cookie */ require_once __DIR__ . '/authenticationAndSecurity.php'; $authenticationAndSecurity = new authenticationAndSecurity(); $authenticationAndSecurity->removeCookies(); $authenticationAndSecurity->redirectBackToIndex();
<?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 /** * csv ticket importer */ require_once __DIR__ . '/bootstrap.php'; require_once __DIR__ . '/authenticationAndSecurity.php'; ini_set('display_errors', true); use Juno\Workflow; use Ddeboer\DataImport\Reader\CsvReader; use Ddeboer\DataImport\ItemConverter\MappingItemConverter; use Guzzle\Client; use Ddeboer\DataImport\Writer\WriterInterface; $authenticationAndSecurity = new authenticationAndSecurity(); /** * upload file * @return bool */ function fileUpload() { $currentdir = getcwd(); $targetDir = $currentdir . "/../uploads/"; $fileType = $targetDir . 'current.csv'; $uploadOk = 1; $imageFileType = pathinfo($_FILES["fileToUpload"]["name"], PATHINFO_EXTENSION); // //Check file size if ($_FILES["fileToUpload"]["size"] > 50000) { echo "Sorry, your file is too large."; $uploadOk = 0; }