cancel
Showing results for 
Search instead for 
Did you mean: 

getDocumentList() error on PHP Automation Client

Marc_
Champ on-the-rise
Champ on-the-rise

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!

1 ACCEPTED ANSWER

adam_bo_
Star Contributor
Star Contributor

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

View answer in original post

8 REPLIES 8

Vladimir_Pasqui
Star Collaborator
Star Collaborator

Hi,

Marc_
Champ on-the-rise
Champ on-the-rise

Hi Vladimir,

adam_bo_
Star Contributor
Star Contributor

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

Marc_
Champ on-the-rise
Champ on-the-rise

Hi,

Could you enclose your var_dump($answer) string?

Marc_
Champ on-the-rise
Champ on-the-rise

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

Could you change the following line in file NuxeoAutomationUtilities.php

adam_bo_
Star Contributor
Star Contributor

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