Remote upload and update of document from a php application

Hi There,

We're using Nuxeo-DM 5.4.2(open source version) with an intention to replace our own bespoke document management system which is outdated in terms of functionality. We wish to transfer all the existing documents from the bespoke DM to Nuxeo-DM. And we've initially used PHP CMIS client to perform the migration of document.

Upon testing various options of PHP CMIS Client and PHP Automation Client we've found a problem. Basically, on our bespoke DM we have versions of documents. What we intend to do through remotely running script (either of the above mentioned clients) is upload a document on Nuxeo (which we can) and then update the same document with new'er content (which we could't coz what I learnt is, for that we need versioning/document checkout) instead of uploading new document for each version. I tried to checkout a document through PHP Automation Client (CMIS client doesn't have the method implemented yet) using following code.

getSession('Administrator','Administrator'); $request = $session->newRequest(“Document.CheckOut”); $x= $request->set(“value”,“f621f2f5-55ess0-4afb-b302-32476a1323c2”); $x->sendRequest(); ?>

where the value parameter is document's ID.

But the above code doesn't seem to be working. I'm not sure if I've written it correctly or not.

Can anyone please help and explain how I can update the content of an existing document remotely (preferably using PHP Script)?

Thanks in advance,

1 votes

2 answers

949 views

ANSWER

Thank you very much Arthur for your quick reply!

The initial tests are successfull and I could upload two different versions(files) of the same document with the code that you've provided above. I'll let you know more if I get any trouble or so.

08/26/2011

Megha, please note that I converted your followup question to an actual question: http://answers.nuxeo.com/questions/140/updating-many-properties-with-the-php-client
08/26/2011



Hello !

First of all, you need to configure your PHP client with your ID, password, and server url like this:

//your nuxeo automation url 
// $nuxeoAutomationUrl contains the url of your nuxeo automation API
$client = new PhpAutomationClient($nuxeoAutomationUrl);

//your nuxeo ids
// $Username contains your username
// $Password contains your password
$session = $client->getSession($Username, $Password);

Then, you may need to create remotly a new Nuxeo Document, setting a new request like this:

//We create the document that will hold the file
// $filePath contains the nuxeo's document path
// $name contains the name of the future document
// $type contains the nuxeo type of the document
$answer = $session->newRequest("Document.Create")
->set('input', 'doc:' . $filePath)
->set('params', 'type', $type)
->set('params', 'name', $name)
->sendRequest();

When you create a document, you may need his path in order to execute some actions on this newly-created document. Nuxeo will send back a document object which will be store in the field $answer, which will be a list of documents. To retreive the path of the document, use this:

$path = $answer->getDocument(0)->getPath();

Then, you may need to update some properties in this document, such as the document title:

//We create the document that will hold the file
// $filePath contains the nuxeo's document path
// $value contains the value of the field
// $type contains the xpath of the field
$answer = $session->newRequest("Document.SetProperty")
->set('input', 'doc:' . $path)
->set('params', 'value', $value)
->set('params', 'xpath', $xpath)
->sendRequest();

Now, if you need to upload a blob (a xls file for example) as an attachment to this document, use this:

//We upload the file
// $blob contains the path of the document you are trying to attach to the file
// $blobtype contains the mime type of the document
// $path contains the path (or id) of the nuxeo document
$answer = $session->newRequest("Blob.Attach")
->set('params', 'document', $path)
->loadBlob($blob, $blobtype)
->sendRequest();

You need some versionning ? No problem. Just change the document version. It will save the current state of the document and store it into Document=>History tab=>Versions in Nuxeo. In ored to change the document version, use this:

//$upgrade is a string which contains :
// "Minor" if you upgrade to a minor version
// "Major" if you upgrade to a major version
// $path contains the path (or id) of the nuxeo document
$answer = $session->newRequest("Document.CreateVersion")
->set('input', 'doc:' . $path)
->set('params', 'increment', 'Major')
->sendRequest();

At last, if you need some examples for the different variables, check here:

//variables used for a default Nuxeo Server
$nuxeoAutomationUrl='http://localhost:8080/nuxeo/site/automation';
$Username='Administrator';
$Password=$Username;
$filePath='/default-domain/workspaces/test';
$type='File';
$name='TestFile';
$blob='/test1.rtf';
$blobtype='text/rtf';
$upgrade='Major';
$nextBlob='/test2.rtf';
$nextBlobtype='text/rtf';
$value='testTitle';
$xpath='dc:title';

Enjoy !

Arthur Gallouin

5 votes



Hi Arthur Gallouin.

I'm trying to use the nuxeo-automation-php-client (https://github.com/nuxeo/nuxeo-automation-php-client) API to upload a document from PHP to Nuxeo 5.6.

I don't know how relate the file with the document I create with “Document.Create” operation, could you give me an example please?

Any help will be appreciated.

Raul Chavarria

0 votes



This is not a forum. You did not post an answer to the original question. So please ask a new question, or post a comment, but don't add another answer.
08/15/2013

Hi Florent.

I'm sorry, you have the reason, I'll take your advice into consideration next time.

Regards,

08/15/2013