Giter Site home page Giter Site logo

phptracrpc's People

Contributors

h4cc avatar jakoch avatar mpedrummer avatar scrutinizer-auto-fixer avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

h4cc mpedrummer

phptracrpc's Issues

doRequest() mangles datetimes

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?

Issue with empty "attr" data arrays when calling Trac XML-RPC methods in JSON

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?

Release request :)

Hey @jakoch - when you release next, can you release 7d71470 (7d71470) as 1.0.2 before releasing the rest as 1.0.3? That would simplify my testing procedure for implementation/rollout.

Looks like you've had a busy weekend :)

Composer autoloader isn't finding TracRPC class

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.

getTicketVersion() fails for create

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.

XMLRPC does not seem to work at all

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.