Alfresco

From pmusers
Jump to: navigation, search

ProcessMaker's Alfresco functions do not work with recent versions of Alfresco, because its API has changed. If needing to connect to Alfresco, it is recommended to create custom triggers in ProcessMaker which call the Alfresco REST API.

For example, the REST endpoint POST /alfresco/service/api/upload can be used to upload files from a ProcessMaker case to Alfresco.

The following trigger is used to upload all the files in the current case to Alfresco:

$caseId = @@APPLICATION;
$aFiles= executeQuery("select APP_DOC_FILENAME, APP_DOC_UID from APP_DOCUMENT where APP_UID='$caseId'");

for ($i=0; $i <= count($aFiles); $i++) {
    $APP_DOC_FILENAME = $aFiles[$i]['APP_DOC_FILENAME'];
    $APP_DOC_UID = $aFiles[$i]['APP_DOC_UID'];
      
    $EXT = executeQuery("SELECT CON_VALUE FROM CONTENT WHERE CON_ID='$APP_DOC_UID' AND CON_CATEGORY='APP_DOC_FILENAME'");
      
    $CON_VALUE = $EXT[1]['CON_VALUE'];     
    $EXTENSION = substr($CON_VALUE, strpos($CON_VALUE, ".") );
       
    $g = new G();
    $filePath  = PATH_DOCUMENT . $g->getPathFromUID($caseId) . PATH_SEP . $APP_DOC_UID . "_1" . $EXTENSION;  
    $data['filedata'] = new CURLFile($filePath,'text/plain', $APP_DOC_FILENAME);
     
    $ch = curl_init('http://localhost:9080/alfresco/api/-default-/public/alfresco/versions/1/nodes/node-id/children');
    curl_setopt($ch, CURLOPT_USERPWD, 'admin:password');  
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 
    curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type:multipart/form-data'));
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);                                                                  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  
    $result = curl_exec($ch);
    
    @@Result = $result;
}

Change http://localhost:9080 to the address of your installation of Alfresco.

Thanks to ShaliniJain1403 on the forum for this code example.