php-jira-rest-client icon indicating copy to clipboard operation
php-jira-rest-client copied to clipboard

perform transition independent of localization?

Open wivaku opened this issue 5 years ago • 7 comments

I use this to prepare a transition.

    $transition->setTransitionName('Done');

However, when I use the API key of a different user it does not work. That user has set his profile to Dutch.

This results in an error message: JiraRestApi\JiraException: Transition name 'Done' not found on JIRA Server

Is there a way to perform the transition or set the transition name independent of the local language of the user? The API seems to have (for a Status) both property name and untranslatedName.

				"name": "Gereed",
				"untranslatedName": "Done",

(the Dutch translation for Done is Gereed)

https://xyz.atlassian.net/rest/api/2/project/JIR/statuses

			{
				"self": "https://xyz.atlassian.net/rest/api/2/status/10307",
				"description": "",
				"iconUrl": "https://xyz.atlassian.net/images/icons/statuses/closed.png",
				"name": "Gereed",
				"untranslatedName": "Done",
				"id": "10307",
				"statusCategory": {
					"self": "https://xyz.atlassian.net/rest/api/2/statuscategory/3",
					"id": 3,
					"key": "done",
					"colorName": "green",
					"name": "Gereed"
				}
			}

https://xyz.atlassian.net/rest/api/2/issue/JIR-2360/transitions

		{
			"id": "41",
			"name": "Gereed",
			"to": {
				"self": "https://xyz.atlassian.net/rest/api/2/status/10307",
				"description": "",
				"iconUrl": "https://xyz.atlassian.net/images/icons/statuses/closed.png",
				"name": "Gereed",
				"id": "10307",
				"statusCategory": {
					"self": "https://xyz.atlassian.net/rest/api/2/statuscategory/3",
					"id": 3,
					"key": "done",
					"colorName": "green",
					"name": "Gereed"
				}
			},
			"hasScreen": false,
			"isGlobal": true,
			"isInitial": false,
			"isAvailable": true,
			"isConditional": false
		}

wivaku avatar May 12 '20 15:05 wivaku

@wivaku hi there.

i was add new setter method setUntranslatedName in the IssueService.

could you confirm it working correctly please?

lesstif avatar May 13 '20 12:05 lesstif

thanks for the super quick response.

It gives me the following error:

PHP Notice:  Undefined index: name in .../vendor/lesstif/php-jira-rest-client/src/Issue/IssueService.php on line 507

Notice: Undefined index: name in .../vendor/lesstif/php-jira-rest-client/src/Issue/IssueService.php on line 507
JiraRestApi\JiraException: Transition name '' not found on JIRA Server. in .../vendor/lesstif/php-jira-rest-client/src/Issue/IssueService.php:489
JiraRestApi\Issue\Transition Object
(
    [id] =>
    [name] =>
    [to] =>
    [fields] =>
    [issueFields] =>
    [transition] => Array
        (
            [untranslatedName] => Done
        )

    [update] =>
)

wivaku avatar May 13 '20 12:05 wivaku

findTransitonId() (note the typo, should be findTransitionId()) will fail as it tries to match the (localized) transition names with the untranslatedName. getTransition() method returns all transitions but these contain only the localized names.

I guess approach will have to be to get the localized State name based on the untranslatedName. After that this localized State name can be used for the existing findTransitonId().

wivaku avatar May 13 '20 13:05 wivaku

this is the workaround that I am using

if (!isset($this->statuses)) {
	$this->statuses = json_decode($this->issueService->exec('/status', null));
}

$untranslatedName = "Done";
$translatedName = array_values(
	array_filter($this->statuses, function($e) use($untranslatedName) {
		 return $e->untranslatedName == $untranslatedName; 
	})
)[0]->name ?? $untranslatedName;
// $transition->setTransitionName($translatedName);

wivaku avatar May 13 '20 14:05 wivaku

sorry, I coded carelessly.

i'm making hot fix now, could you confirm again please?

lesstif avatar May 13 '20 14:05 lesstif

Don't think this will work, $transitionArray = $prj->getProjectTransitionsToArray($pkey[0]); (in findTransitonIdByUntranslatedName()) will get all the possible transitions. These only contain localized names.

It is Statuses that contain both localized and untranslated names. So we need to find the translated status name for e.g. "Done" and then use that one for the transition (no change needed there).

See my workaround.

wivaku avatar May 13 '20 15:05 wivaku

@wivaku thanks for your comments.

could you make PR with your suggestion please?

lesstif avatar May 17 '20 13:05 lesstif