FayP / JIRA-php

a php class specifically to be used for JIRA's REST API and also a REST Request class which can be more widely used.
26 stars 22 forks source link

Issue when calling queryIssue() more than once #10

Open JOJOKAHANDING opened 8 years ago

JOJOKAHANDING commented 8 years ago

In Jira.php:

OLD CODE

 public function queryIssue($query)
     {
        function createPairs($obj) {
            $str = "";
            foreach ($obj as $key => $value) {
                if ($key != 'jql') {
                    $str .= "$key=$value&";
                } else {
                    $str .= trim($value, '"\'@') . '&';
                }
            }
            return rtrim($str, '&');
        }
        $qs = createPairs($query);

SUGGESTED CHANGE

    protected function createPairs($obj) {
        $str = "";
        foreach ($obj as $key => $value) {
            if ($key != 'jql') {
                $str .= "$key=$value&";
            } else {
                $str .= trim($value, '"\'@') . '&';
            }
        }
        return rtrim($str, '&');
    }

    public function queryIssue($query)
    {
        $qs = $this->createPairs($query);
        $qs = urlencode($qs);
        $this->request->OpenConnect($this->host . 'search?jql=' . $qs);
        $this->request->execute();
        $result = json_decode($this->request->getResponseBody());
        if (isset($result->issues)) {
            return $result->issues;
        }

        return false;
    }