jakoch / phptracrpc Goto Github PK
View Code? Open in Web Editor NEWA PHP library to interact with the Trac Bugtracker API via remote procedure calls.
A PHP library to interact with the Trac Bugtracker API via remote procedure calls.
Inside doRequest()
, the code does a json_encode, and then modifies the resulting string somewhat. What's the purpose of that?
// json_encode $this->_request
if (is_array($this->request) === true) {
$this->request = json_encode(array_pop($this->request));
$this->request = str_replace(':', ': ', $this->request);
$this->request = str_replace(',', ', ', $this->request);
$this->request = str_replace('[]', '{}', $this->request);
}
The second line of code, replacing the ':'
with ': '
, modifies date values passed in, and results in an error from the Trac server.
'message' => 'JsonProtocolException details : Invalid datetime string (2016-03-16 08: 46: 29)', 'code' => -32700, 'name' => 'JSONRPCError'
If this conversion is just for prettification (commenting it out hasn't broken anything, yet), perhaps looking for '":'
, and replacing with '": '
would work just as well, without mangling the dates?
The "require" section is incorrect, the actual package name on Packagist is php-trac-rpc, not PHPTracRPC
There's a check to see if $id === true, and I think it should be $id !== true, given that the line inside that check looks to see if $id is an array, which is impossible if $id === true.
Just a typo, the if(isMulticall) check happens AFTER the request has already been made.
The function incrementRequestId does not actually update the id as expected.
Hi everyone,
I had an issue with PHPTracRPC when creating Trac tickets.
Specifically, when I have an empty "attr" data array:
$ticket_data = array();
$ticket_data['summary'] = 'The ticket summary text';
$ticket_data['desc'] = 'The ticket description text';
$ticket_data['attr'] = array();
$ticket_data['notify'] = false;
$credentials = array('username' => 'theuser', 'password' => 'thepassword');
$trac = new TracRPC('http://trac.example.com/login/jsonrc', $credentials);
$trac->setMultiCall(true);
$ticket = $trac->getTicketUpdate('create','',$ticket_data);
$trac->doRequest();
$ticket = $trac->getResponse($ticket);
If executed, the above code will produce the following JSON error response:
{
"result": null,
"error": {
"name": "JSONRPCError",
"message": "'list' object has no attribute 'iteritems'",
"code": -32603
},
"id": 1
}
I analyzed a little bit the PHPTracRPC code and I found the problem when encoding the request in JSON. It seems that empty "attr" data array produces "[]" instead of "{}":
if (is_array($this->request) === true) {
$this->request = json_encode(array_pop($this->request)); // it produces "[]"
$this->request = str_replace(':', ': ', $this->request);
$this->request = str_replace(',', ', ', $this->request);
}
The produced $ticket_data
JSON request is:
{
"method": "system.multicall",
"params": [
{
"method": "ticket.create",
"params": [
"The ticket summary text",
"The ticket description text",
[],
false
],
"id": 1
}
],
"id": 1
}
When changing "[]" to "{}" the problem dissappears.
When using a keyed and filled "attr" data array the problem also dissappears.
Maybe this is a bug?
I think that the composer.json file should be set as psr-4 in the autoload section, not psr-0. I'm actually just guessing there, though.
If I include the file directly, as in your example in the README.md, it works just fine.
I'm not entirely sure the "right" way to fix this one - the API is a real bear to figure out, since all the parameters are just documented as "struct attributes" without documenting the name/value pairs that the struct should contain!
Anyway, for 'create' and 'update' the $attr array is not passed in appropriately - the $params array is never updated, so it remains at the default value, which is an empty array.
https://github.com/jakoch/PHPTracRPC/blob/master/lib/TracRPC.php#L923
Its not search.getSearchFilters
, but search.performSearch
array search.performSearch(string query, array filters=None)
Trying to troubleshoot some problems, I my URL from login/jsonrpc
to login/xmlrpc
, mainly grasping at straws. Unfortunately, doRequest()
will json_encode()
ALL requests, regardless of content type.
This results in an XML response of:
<?xml version='1.0'?>
<methodResponse>
<fault>
<value>
<struct>
<member>
<name>faultCode</name>
<value><int>-32700</int></value>
</member>
<member>
<name>faultString</name>
<value><string>not well-formed (invalid token): line 1, column 0</string></value>
</member>
</struct>
</value>
</fault>
</methodResponse>
Which makes some sense, because it was passed a json-encoded string.
Compounding the problem, $this->error
was not set.
I'm not sure how to fix this one. From my perspective, I'd just drop xmlrpc support, and simplify the class by using jsonrpc only. Since the class should be normalizing the input and output for Trac to be native PHP, I don't see significant value in supporting both, or at least not enough to justify the extra work required at this point to implement xmlrpc.
The tests are currently failing (see https://travis-ci.org/jakoch/PHPTracRPC/jobs/114876495#L190), because they were written as live tests against a Trac endpoint (which is now out-of-service) and not as mocks.
Todo
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.