cancel
Showing results for 
Search instead for 
Did you mean: 

Problem creating new Nodes with the PHP Library

plaico
Champ in-the-making
Champ in-the-making
There are two things I'd like to know about the PHP Library. Firstly, I could not manage it to create a new node using the following code:

$new_child = $currentNode->createChild('cm_content', 'cm_contains', 'cm_phpinfo.php');
$new_child->cm_name = 'phpinfo.php';
$new_child->setContent('cm_content', 'text/plain', 'UTF-8', 'blablabla');
I always get the the same error message:

Fatal error: Uncaught SoapFault exception: [soapenv:Server.generalException] WSDoAllReceiver: security 

processing failed; nested exception is: org.apache.ws.security.WSSecurityException: General security error

(WSSecurityEngine: Callback supplied no password for: username) in

/var/www/localhost/htdocs/alfrescophp/Alfresco/Service/WebService/AlfrescoWebService.php:67 Stack trace:

#0 /var/www/localhost/htdocs/alfrescophp/Alfresco/Service/WebService/AlfrescoWebService.php(67):

SoapClient->__soapCall('query', Array, Array, Array, Array) #1

/var/www/localhost/htdocs/alfrescophp/Alfresco/Service/WebService/AlfrescoWebService.php(49):

AlfrescoWebService->__soapCall('query', Array) #2 [internal function]: AlfrescoWebService->__call('query',

Array) #3 /var/www/localhost/htdocs/alfrescophp/Alfresco/Service/Session.php(226):

AlfrescoWebService->query(Array) #4

/var/www/localhost/htdocs/alfrescophp/Alfresco/Service/SpacesStore.php(48):

Session->query(Object(SpacesStore), 'PATH:"app:compa…') #5 /var/www/localhost/htdocs/alfrescoph in

/var/www/localhost/htdocs/alfrescophp/Alfresco/Service/WebService/AlfrescoWebService.php on line 67
Probably, some of the params are wrong, but I couldn't find anything about it in the documentation and all the other forum threads I looked at used the same code as I do.

The next thing I have problems with is the correct way to upload files. There is already a variable in the Node class but the SetContent-function has no line which would set a value to this variable. Therefore, I changed the function to set this variable but due to my first problem, I could not test this properly because I got to the same SOAPFault exception as above.
Are there any more examples?
18 REPLIES 18

plaico
Champ in-the-making
Champ in-the-making
I'm sorry - the code is fine
it just might have worked the first time I tried. After that, the error message appeared because the file already existed.

mmariotti
Champ in-the-making
Champ in-the-making
hi, how do u commit the new node or the new content created? cos to me, the problem is when I call the function $session->save();

i receive back the soap error as u did, but the node is anyway created.(I can have confirmation by take a look at the repository in 8080).

this is the code i'm talking about:

if($_REQUEST['add']){
//AGGIUNGO UN NODO
$new_child_store = $currentNode->createChild('cm_folder', 'cm_contains', 'cm_myStore');
$new_child_store->cm_name = 'myStore';
//print_R($new_child);exit;

$session->save();
//$session->clear();
}

this is the error code:

Fatal error: Uncaught SoapFault exception: [soapenv:Server.generalException] (null) in C:\Programmi\Apache\htdocs\alfresco2\Alfresco\Service\WebService\AlfrescoWebService.php:67 Stack trace: #0 C:\Programmi\Apache\htdocs\alfresco2\Alfresco\Service\WebService\AlfrescoWebService.php(67): SoapClient->__soapCall('update', Array, Array, Array, Array) #1 C:\Programmi\Apache\htdocs\alfresco2\Alfresco\Service\WebService\AlfrescoWebService.php(49): AlfrescoWebService->__soapCall('update', Array) #2 [internal function]: AlfrescoWebService->__call('update', Array) #3 C:\Programmi\Apache\htdocs\alfresco2\Alfresco\Service\Session.php(172): AlfrescoWebService->update(Array) #4 C:\Programmi\Apache\htdocs\alfresco2\Examples\SimpleBrowse\index.php(116): Session->save() #5 {main} thrown in C:\Programmi\Apache\htdocs\alfresco2\Alfresco\Service\WebService\AlfrescoWebService.php on line 67

hope to hear good news, i'm also looing for a solution to upload content.
have a good day

rwetherall
Confirmed Champ
Confirmed Champ
Hi,

Could you help me by providing the code you use to connect to the repository and get the value of $currentNode.

Cheers,
Roy

mmariotti
Champ in-the-making
Champ in-the-making
hi
thks for reply. here's the code:


session_start();

$repository = new Repository();
$ticket = null;
if (isset($_SESSION["ticket"]) == false)
{
      $ticket = $repository->authenticate($user, $password);
      $_SESSION["ticket"] = $ticket;   
}  
else
{
     $ticket = $_SESSION["ticket"];    
}
$session = $repository->createSession($ticket);

$store = new SpacesStore($session);
  
$currentNode = null;

if (isset($_REQUEST['uuid']) == false)
{
      //set the $currentNode the first time
      $currentNode = $store->companyHome;
     
      $path = 'Company Home';

}
else
{
      //set the $currentNode while browsing the repository
      $currentNode = $session->getNode($store, $_REQUEST['uuid']);
     
      $path = $_REQUEST['path'].'|'.$_REQUEST['uuid'].'|'.$_REQUEST['name'];
}

Now i added a button to set a new node while browsing the repository.

I got the problem in the __Soapcall method of AlfrescoWebSevice.php when it call the parent method ::__soapCall() of soapClient.
Strange also the fact that the code smtimes is working.

cheers
mirko

rwetherall
Confirmed Champ
Confirmed Champ
Hi,

Yes it is odd that the problem in intermittent.

I'm guessing the issue is coming from the repository (unfortunately error handling in the PHP lib is not something I have been able to get to yet!) and the web service errors we receive are generally not very helpful.

Perhaps inspecting the repository log will help to uncover what the issue is here. 

Also you could try running the Unit tests shipped with the library.  This may help to flush out any issue that might be there.  ( see http://wiki.alfresco.com/wiki/Alfresco_PHP_Library_Installation_Instructions#Running_The_Unit_Tests )


Cheers,
Roy

mmariotti
Champ in-the-making
Champ in-the-making
thks roy,
i found a way out of this problem.
soon i'll post the solution.
In my case the problem concern the value I post to create the currentNode obj, in particular the uuid values passed by get.

Can u tell me if is possible with the actual API upload document from file?

rwetherall
Confirmed Champ
Confirmed Champ
Hi,

Here is an example of how you can set content from a file using the PHP library:


    public function testWriteContentFromFile()
    {
       $contentData = $this->getContentNode()->cm_content;
       $contentData->mimetype = "image/jpeg";
       $contentData->encoding = "UTF-8";
       $contentData->writeContentFromFile("alfresco/resources/quick.jpg");
      
       $this->getContentNode()->cm_content = $contentData;
       $this->getContentNode()->cm_name = "1myDoc_" . time() . ".jpg";
       $this->getSession()->save();
    }

Hope this helps,
Roy

mmariotti
Champ in-the-making
Champ in-the-making
hi roy,
i'm just one step from the result(..hope).

i try to follow yr example and this is the situation.

now i'm writing in the node class (name:node.php; i downloaded the PHP Client Library 2.1 RC from the community library)the follow code, but in the final saving session i'll get just a soap error:


public function updocformfile(){

//$this CONTAIN THE NODE OBJECT   
   
    $upload = $this->createChild('cm_content', 'cm_contains', 'cm_ciccio.txt');

    $contentData = new ContentData($upload, $property, $mimetype, $encoding);
   
    //$contentData->getContent();
   
    $contentData->mimetype = "text/plain";
    $contentData->encoding = "UTF-8";
    $contentData->writeContentFromFile("c:/path.txt");

//AT THIS POINT $contentData->content CONTAIN THE CONTENT OF THE FILE
   
    $upload->cm_content = $contentData;
    $upload->cm_name = "ciccio.txt";

//HERE IN THE OBJ $upload I HAVE ALL THE PARAMETERS SET UNDER [_properties:private] - I'LL SHOW IT BELOW   
   
    $this->getSession()->save();
  }
just  a portion of $upload object

[_id:private] => sessionTICKET_c29e3208f85cb2a64509fef12c45dd6c4c80cc350
    [_type:private] => {http://www.alfresco.org/model/content/1.0}content
    [_aspects:private] => Array
        (
        )

    [_properties:private] => Array
        (
            [{http://www.alfresco.org/model/content/1.0}content] => ContentData Object
                (
                    [_isPopulated:private] =>
                    [_isDirty:private] => 1
                    [_node:private] => Node Object
*RECURSION*
                    [_property:private] => {http://www.alfresco.org/model/content/1.0}content
                    [_mimetype:private] => text/plain
                    [_size:private] =>
                    [_encoding:private] => UTF-8
                    [_url:private] =>
                    [_newContent:private] =>
                    [_newFileContent:private] => c:/path.txt
                )

            [{http://www.alfresco.org/model/content/1.0}name] => ciccio.txt
        )

    [_children:private] => Array
        (
        )

    [_parents:private] => Array
        (
        )

without the saving session, the file(named ciccio.txt) appear in the right position (even if isn't possible to open).
Appling the last instruction ($this->getSession()->save()), i got this error

Fatal error: Uncaught SoapFault exception: [HTTP] Internal Server Error in C:\Programmi\Apache\htdocs\alfresco2\Alfresco\Service\WebService\AlfrescoWebService.php:115 Stack trace: #0 C:\Programmi\Apache\htdocs\alfresco2\Alfresco\Service\WebService\AlfrescoWebService.php(115): SoapClient->__doRequest('<?xml version="…', 'http://localhos…', 'http://www.alfr…', 1) #1 [internal function]: AlfrescoWebService->__doRequest('<?xml version="…', 'http://localhos…', 'http://www.alfr…', 1, 0) #2 C:\Programmi\Apache\htdocs\alfresco2\Alfresco\Service\WebService\AlfrescoWebService.php(67): SoapClient->__soapCall('update', Array, Array, Array, Array) #3 C:\Programmi\Apache\htdocs\alfresco2\Alfresco\Service\WebService\AlfrescoWebService.php(50): AlfrescoWebService->__soapCall('update', Array) #4 [internal function]: AlfrescoWebService->__call('update', Array) #5 C:\Programmi\Apache\htdocs\alfresco2\Alfresco\Service\Session.php(172): AlfrescoWebService->update(Array) #6 C:\Programmi\Apache\htdocs\alfresco2\Alfresco\Service\Node in C:\Programmi\Apache\htdocs\alfresco2\Alfresco\Service\WebService\AlfrescoWebService.php on line 115

need a little help
thks
mirko

mmariotti
Champ in-the-making
Champ in-the-making
I still didn't solve the problemsSmiley Sad..someone has a tips?