getDocumentList() error on PHP Automation Client

Hi,

I'm using the PHP Automation Client to execute a simple query and I have an error on it, and I don't know how can I resolve it. Obviously I changed the url of Nuxeo, and the correct username and password when I get a session.

Here the code:

$client = new PhpAutomationClient('http://localhost:8080/nuxeo/site/automation');
$session = $client->getSession('Administrator','Administrator');
$answer = $session->newRequest("Document.Query")->set('params', 'query', "SELECT * FROM Document" )->sendRequest();
$documentsArray = $answer->getDocumentList();

And here the error:

Fatal error: Call to a member function getDocumentList() on a non-object in C:\wamp\www\utils\test.php on line 118

But, If before getDocumentList(), I do a var_dump($answer), I see the JSON document listing all documents that means that I received the server answer.

Can someone explain me what's the problem? Thanks in advance!

0 votes

2 answers

1885 views

ANSWER

Hi,

As I didn't test it yet, in the meantime, have you seen these tests examples here:

https://github.com/nuxeo/nuxeo-automation-php-client/blob/master/tests/tests.php

Don't hesitate to give feedback about it

thanks

11/15/2013

Hi Vladimir,

I tried this tests examples, and they give me the same error, I don't know what could happen…

11/18/2013



Ok, you need to modify the file NuxeoAutomationUtilities.php:

a) this is optional

public function NuxeoRequest($url, $headers = "Content-Type:application/json+nxrequest", $requestId) {
    $this->url = $url . "/" . $requestId;
    $this->headers = $headers;
    $this->finalRequest = array(""=>""); // it is treated as array in "set" method
    $this->method = 'POST';
    $this->iterationNumber = 0;
    $this->HEADER_NX_SCHEMAS = 'X-NXDocumentProperties:';
    $this->blobList = null;
    $this->X_NXVoidOperation = 'X-NXVoidOperation: true';
}

b) this is crucial

public function setSchema($schema = '*') {
//        $this->headers = array($this->headers, $this->HEADER_NX_SCHEMAS . $schema); // it is the problem.
    $this->headers = $this->headers."\r\n". $this->HEADER_NX_SCHEMAS . $schema;
    return $this;
}

Best regards

1 votes



Hi,

You should look:

a) what sendRequest method is doing,

b) what constructor NuxeoDocuments is doing.

ad. a)

If json_decode($answer, true) returns null then a result from sendRequest is a pure response from a server.

ad. b)

json_decode($answer, true) returns not null then sendRequest returns the result from calling NuxeoDocuments(json_decode($answer, true)). NuxeoDocuments checks if its parameter contains elements 'entries' or 'uid' then it returns object. Otherwise it returns the parameter or an error 'file not found'.

You should check what case is in your example.

Best regards

1 votes



Hi,

json_decode ($answer, true) returns null, but var_dump($answer) returns a json string, I don't know why conversion don't run.

If I add a "where" clause on the query, then the error doesn't appear, but a new php warning is shown. I ask this question in another post (http://answers.nuxeo.com/questions/7365/array_key_exists-warning-when-sendrequest-on-php-automation-client)

NuxeoDocuments only checks if the parameter contains elements 'entries' or 'uid' if a where clause is added on the query, and if it is, it enters on the first if ((!empty($newDocList['entries'])))

The sendRequest method it's the original one, I don't overwrite any method from the api.

11/18/2013

Could you enclose your var_dump($answer) string?
11/18/2013

I can't attach the complete file because is too big…

var_dump($answer):

string '{"entity-type":"documents","entries":[{"entity-type":"document","repository":"default","uid":"f6a055be-445f-483b-93a6-7f86d9704bcf","path":"/default-domain/UserWorkspaces/crubio/1371467452894","type":"UserProfile","state":"undefined","lock":null,"title":"1371467452894","lastModified":"2013-06-17T11:10:52.89Z","properties":{"dc:creator":"crubio","dc:source":null,"dc:nature":null,"dc:contributors":["crubio"],"dc:created":"2013-06-17T11:10:52.89Z","dc:description":null,"dc:rights":null,"dc:subjects":[],"dc:pub'... (length=35387)
11/19/2013

Could you change the following line in file NuxeoAutomationUtilities.php:

  1. in function NuxeoRequest: $this->finalRequest = '{}'; to $this->finalRequest = array(""=>"");

and try again.

As I remember there was some bugs in this code.

11/19/2013