Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perform transition independent of localization? #323

Open
wivaku opened this issue May 12, 2020 · 7 comments
Open

perform transition independent of localization? #323

wivaku opened this issue May 12, 2020 · 7 comments

Comments

@wivaku
Copy link

wivaku commented May 12, 2020

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
		}
@lesstif
Copy link
Owner

lesstif commented May 13, 2020

@wivaku hi there.

i was add new setter method setUntranslatedName in the IssueService.

could you confirm it working correctly please?

@wivaku
Copy link
Author

wivaku commented May 13, 2020

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
Copy link
Author

wivaku commented May 13, 2020

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
Copy link
Author

wivaku commented May 13, 2020

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);

@lesstif
Copy link
Owner

lesstif commented May 13, 2020

sorry, I coded carelessly.

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

@lesstif lesstif reopened this May 13, 2020
@wivaku
Copy link
Author

wivaku commented May 13, 2020

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.

@lesstif
Copy link
Owner

lesstif commented May 17, 2020

@wivaku thanks for your comments.

could you make PR with your suggestion please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants