Skip to content

Commit

Permalink
ref #253 workaround for v3 search api
Browse files Browse the repository at this point in the history
  • Loading branch information
lesstif committed May 22, 2019
1 parent f7c3fcd commit db7b229
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 33 deletions.
30 changes: 0 additions & 30 deletions src/Issue/IssueFieldV3.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,6 @@ class IssueFieldV3 extends IssueField
/** @var \JiraRestApi\Issue\DescriptionV3|null */
public $environment;

public function jsonSerialize()
{
$vars = array_filter(get_object_vars($this), function ($var) {
return !is_null($var);
});

// if assignee property has empty value then remove it.
// @see https://github.com/lesstif/php-jira-rest-client/issues/126
// @see https://github.com/lesstif/php-jira-rest-client/issues/177
if (!empty($this->assignee)) {
// do nothing
if ($this->assignee->isWantUnassigned() === true) {
} elseif ($this->assignee->isEmpty()) {
unset($vars['assignee']);
}
}

// clear undefined json property
unset($vars['customFields']);

// repackaging custom field
if (!empty($this->customFields)) {
foreach ($this->customFields as $key => $value) {
$vars[$key] = $value;
}
}

return $vars;
}

/**
* @param \JiraRestApi\Issue\DescriptionV3|null $description
*
Expand Down
30 changes: 30 additions & 0 deletions src/Issue/IssueSearchResultV3.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace JiraRestApi\Issue;

/**
* Issue search result.
*/
class IssueSearchResultV3 extends IssueSearchResult
{
/**
* @var \JiraRestApi\Issue\IssueV3[]
*/
public $issues;

/**
* @return \JiraRestApi\Issue\IssueV3[]
*/
public function getIssues()
{
return $this->issues;
}

/**
* @param \JiraRestApi\Issue\IssueV3[] $issues
*/
public function setIssues($issues)
{
$this->issues = $issues;
}
}
13 changes: 10 additions & 3 deletions src/Issue/IssueService.php
Original file line number Diff line number Diff line change
Expand Up @@ -522,9 +522,16 @@ public function search($jql, $startAt = 0, $maxResults = 15, $fields = [], $expa
$ret = $this->exec('search', $data, 'POST');
$json = json_decode($ret);

$result = $this->json_mapper->map(
$json, new IssueSearchResult()
);
$result = null;
if ($this->isRestApiV3()) {
$result = $this->json_mapper->map(
$json, new IssueSearchResultV3()
);
} else {
$result = $this->json_mapper->map(
$json, new IssueSearchResult()
);
}

return $result;
}
Expand Down
5 changes: 5 additions & 0 deletions src/Issue/IssueV3.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ class IssueV3 extends Issue
{
/** @var \JiraRestApi\Issue\IssueFieldV3 */
public $fields;

public function jsonSerialize()
{
return array_filter(get_object_vars($this));
}
}

0 comments on commit db7b229

Please sign in to comment.