Page 1 of 1

Descargar todos los archivos Contenidos en la Seccion Documentos

Posted: Wed Apr 25, 2018 10:31 am
by chelotero
Estimadas y estimados, Buenos Dias:
Estamos usando PM 2.5 desde hace un tiempo y necesitamos descargar los archivos que se cargaron en el tiempo que pueden ser visualizados en la seccion "Documentos" del PM, si bien encontramos el directorio en donde se encuentran contenidos (opt/processmaker/shared/sites/workflow/files), descubrimos que todos los nombres de los ficheros como la de los archivos estan codificados con un ID, ¿existe alguna forma de descargar todos los archivos de una sola vez, con el nombre del caso y el nombre del archivo tal como aparece en el sistema?, desde ya les agradezco sus respuestas.

mis cordiales saludos !

atte

Más Valdecantos, Marcelo A.

Re: Descargar todos los archivos Contenidos en la Seccion Documentos

Posted: Fri Apr 27, 2018 6:22 pm
by amosbatto
Puedes crear un proceso para ejecutar el siguiente trigger que copia los archivos a un directorio en tu servidor de ProcessMaker:
Code: Select all
$targetDir = "/home/amos/backupDocs"; //set directory where to copy PM documents

$sql = "SELECT * FROM APP_DOCUMENT WHERE APP_DOC_STATUS='ACTIVE' ";
$aFiles = executeQuery($sql);

@%fileCount = 0;
$oDoc = new AppDocument();

//uncomment to delete the files in the target directory
//array_map('unlink', glob($targetDir.PATH_SEP."*"));

foreach ($aFiles as $aFile) { 
   $aFileInfo = $oDoc->Load($aFile['APP_DOC_UID'], $aFile['DOC_VERSION']);
   $filename = $aFileInfo['APP_DOC_FILENAME'];      
   $g = new G();    
   $dirPath = trim($targetDir);
   
   if ($aFile['APP_DOC_TYPE'] == 'OUTPUT') {    
       $filePath = PATH_DOCUMENT. $g->getPathFromUID( $aFile['APP_UID'] ) .PATH_SEP. "outdocs" .
           PATH_SEP. $aFile['APP_DOC_UID'] .'_'. $aFile['DOC_VERSION'];
                
       if (file_exists($filePath.'.pdf')) {
           $copyPath = $dirPath .PATH_SEP. $filename .'.pdf';
           $existsCounter = 1;
           
           while (file_exists($copyPath)) {
              $existsCounter++;
              $copyPath = $dirPath .PATH_SEP. $filename .'_'. $existsCounter .'.pdf';
           }
           copy($filePath.'.pdf', $copyPath);
       }
       if (file_exists($filePath.'.doc')) {
           $copyPath = $dirPath .PATH_SEP. $filename .'.doc';
           $existsCounter = 1;
           while (file_exists($copyPath)) {
              $existsCounter++; 
              $copyPath = $dirPath .PATH_SEP. $filename .'_'. $existsCounter .'.doc';
           }
           copy($filePath.'.doc', $copyPath);
       }
    }
    else { //an Input Document or Attached File:
      $ext = pathinfo($filename, PATHINFO_EXTENSION); 
      $basename = pathinfo($filename, PATHINFO_BASENAME);
           
      $filePath = PATH_DOCUMENT. $g->getPathFromUID( $aFile['APP_UID'] ) .PATH_SEP. 
         $aFile['APP_DOC_UID'] .'_'. $aFile['DOC_VERSION'] .'.'. $ext;
                
       if (file_exists($filePath.'.pdf')) {
           $copyPath = $dirPath .PATH_SEP. $filename;
           $existsCounter = 1;
           while (file_exists($copyPath)) {
              $copyPath = $dirPath .PATH_SEP. $basename .'_'. (++$existsCounter) .'.'. $ext;
           }
           copy($filePath, $copyPath);
       }
       
   }
   @%fileCount++;
}
 

Re: Descargar todos los archivos Contenidos en la Seccion Documentos

Posted: Fri May 04, 2018 10:26 am
by chelotero
Desde ya mil gracias por tu ayuda Amosbatto! hice correr el trigger en mi server, pero da un error el error.log de mi apache, me dice lo siguiente: "PHP Fatal error: Call to undefined method G::getPathFromUID() in...." esa es una funcion propia de PM ? o me estaria faltando editar algo mas ademas del PATH? Saludos!

Re: Descargar todos los archivos Contenidos en la Seccion Documentos

Posted: Fri May 04, 2018 6:16 pm
by amosbatto
Tienes una version antigua de ProcessMaker que no tiene la función G::getPathFromUID().

Puedes usar este código:
Code: Select all
$targetDir = "/home/amos/backupDocs"; //set directory where to copy PM documents

$sql = "SELECT * FROM APP_DOCUMENT WHERE APP_DOC_STATUS='ACTIVE' ";
$aFiles = executeQuery($sql);

@%fileCount = 0;
$oDoc = new AppDocument();

//uncomment to delete the files in the target directory
//array_map('unlink', glob($targetDir.PATH_SEP."*"));

foreach ($aFiles as $aFile) { 
   $aFileInfo = $oDoc->Load($aFile['APP_DOC_UID'], $aFile['DOC_VERSION']);
   $filename = $aFileInfo['APP_DOC_FILENAME'];      
   $g = new G();    
   $dirPath = trim($targetDir);
   
   if ($aFile['APP_DOC_TYPE'] == 'OUTPUT') {    
       $filePath = PATH_DOCUMENT. $aFile['APP_UID'] .PATH_SEP. "outdocs" .
           PATH_SEP. $aFile['APP_DOC_UID'] .'_'. $aFile['DOC_VERSION'];
                
       if (file_exists($filePath.'.pdf')) {
           $copyPath = $dirPath .PATH_SEP. $filename .'.pdf';
           $existsCounter = 1;
           
           while (file_exists($copyPath)) {
              $existsCounter++;
              $copyPath = $dirPath .PATH_SEP. $filename .'_'. $existsCounter .'.pdf';
           }
           copy($filePath.'.pdf', $copyPath);
       }
       if (file_exists($filePath.'.doc')) {
           $copyPath = $dirPath .PATH_SEP. $filename .'.doc';
           $existsCounter = 1;
           while (file_exists($copyPath)) {
              $existsCounter++; 
              $copyPath = $dirPath .PATH_SEP. $filename .'_'. $existsCounter .'.doc';
           }
           copy($filePath.'.doc', $copyPath);
       }
    }
    else { //an Input Document or Attached File:
      $ext = pathinfo($filename, PATHINFO_EXTENSION); 
      $basename = pathinfo($filename, PATHINFO_BASENAME);
           
      $filePath = PATH_DOCUMENT. $aFile['APP_UID'] .PATH_SEP. 
         $aFile['APP_DOC_UID'] .'_'. $aFile['DOC_VERSION'] .'.'. $ext;
                
       if (file_exists($filePath.'.pdf')) {
           $copyPath = $dirPath .PATH_SEP. $filename;
           $existsCounter = 1;
           while (file_exists($copyPath)) {
              $copyPath = $dirPath .PATH_SEP. $basename .'_'. (++$existsCounter) .'.'. $ext;
           }
           copy($filePath, $copyPath);
       }
       
   }
   @%fileCount++;
}
 

Re: Descargar todos los archivos Contenidos en la Seccion Documentos

Posted: Wed May 09, 2018 12:10 pm
by chelotero
Nuevamente mil gracias por tu ayuda Amos! ejecute el trigger nuevo, y ahora, no da ningun error (en el log de apache), pero no esta haciendo nada (no se si debo fijarme en otro log ademas del de apache), tambien me fije en los permisos del directorio backupDocs les puse los mismos de PM "www-data" y le otorgue todos los permisos de lectura/escritura por las dudas, pero nada, :cry:
mis cordiales saludos !

Re: Descargar todos los archivos Contenidos en la Seccion Documentos

Posted: Wed May 09, 2018 2:33 pm
by amosbatto
En tu archivo php.ini, debes tener esta configuración:
Code: Select all
max_execution_time = 0
memory_limit = 1024M
y reiniciar Apache.

Tambien, debes usar esta configuración en tu archivo env.ini:
Code: Select all
debug = 1
Así, puedes ver errors en el archivo workflow/public_html/php_errors.log.

Re: Descargar todos los archivos Contenidos en la Seccion Documentos

Posted: Thu May 10, 2018 9:38 am
by chelotero
Buen Dia Amos! configure como me dijiste el php.ini y el archivo env.ini pero lo mismo no funciono, incluso probe poniendo memory_limit = 2048M (obviamente reiniciando posteriormente el servidor apache) y lo mismo, con debug = 1 nunca aparecio el archivo "php_errors.log" en el directorio que me indicaste ni en ninguna parte del server (busque con el comando "find / -name php_errors.log") :(
Como siempre agradezco tu invaluable ayuda, mis cordiales saludos!

Re: Descargar todos los archivos Contenidos en la Seccion Documentos

Posted: Thu May 10, 2018 3:34 pm
by amosbatto
He creado una versión que puede ser ejecutado afuera de ProcessMaker desde la línea de comando:
https://sourceforge.net/p/pmcommunity/c ... format=raw

Ejecutalo en la línea de tu servidor de ProcessMaker:
php copyPMFiles.php

Tienes que modificarlo para tu ambiente:
Code: Select all
<?php
/********************************************************************
 * Script to copy all the files in a ProcessMaker installation to a directory. 
 * Usage:
 *  php copyPMFiles.php
 * 
 * Change the following lines in this script to match your environment:
 * $caseIdsIn4Dirs = true; 
 * 
 * $targetDir = "/home/amos/backupDocs"; //set directory where to copy PM documents
 * define("PATH_DOCUMENT", "/opt/processmaker/shared/sites/workflow/files/");
 * 
 * $conn = mysql_connect('localhost:3306', 'root', 'p4sSw0rD') or
 *    die("Error connecting to MySQL database.\n");
 * mysql_select_db('wf_workflow');
 *
 * Author: Amos Batto (amos@processmaker.com)
 * License: Public Domain
 ********************************************************************************/ 

//function to break case IDs into 4 directories
function getPathFromUID($id) {
   //set to true if case IDs are broken into 4 directories which is usually in PM 3.0 and later:
   $caseIdsIn4Dirs = true; 
   if ($id != '00000000000000000000000000000000' and $caseIdsIn4Dirs) {
      $id = preg_replace('/^([a-f0-9]{3})([a-f0-9]{3})([a-f0-9]{3})([a-f0-9]{23})$/', '\1/\2/\3/\4', $id);
   }
   return $id;
}

$targetDir = "/home/amos/backupDocs"; //set directory where to copy PM documents
define("PATH_DOCUMENT", "/opt/processmaker/shared/sites/workflow/files/");

//comment out the next line if don't want to delete all the files in the target directory:
array_map('unlink', glob($targetDir.'/*'));

$conn = mysql_connect('localhost:3306', 'root', 'p4sSw0rD') or
   die("Error connecting to MySQL database.\n");
mysql_select_db('wf_workflow');

$sql = "SELECT * FROM APP_DOCUMENT WHERE APP_DOC_STATUS='ACTIVE' ";
$fileCount = 0;

$result = mysql_query($sql) or
   die("Error: Unable to query the APP_DOCUMENT table.\n");

while ($aFile = mysql_fetch_array($result, MYSQL_ASSOC)) {

   $filename = $aFile['APP_DOC_FILENAME'];      
   
   $dirPath = $targetDir;
   
   if ($aFile['APP_DOC_TYPE'] == 'OUTPUT') {    
       $filePath = PATH_DOCUMENT. getPathFromUID($aFile['APP_UID']) ."/outdocs/".
           $aFile['APP_DOC_UID'] .'_'. $aFile['DOC_VERSION'];
                
       if (file_exists($filePath.'.pdf')) {
           $copyPath = $dirPath .'/'. $filename .'.pdf';
           $existsCounter = 1;
           
           while (file_exists($copyPath)) {
              $existsCounter++;
              $copyPath = $dirPath .'/'. $filename .'_'. $existsCounter .'.pdf';
           }
           copy($filePath.'.pdf', $copyPath);
           print "Copied {$filePath}.pdf to $copyPath\n";
           $fileCount++;
       }
       if (file_exists($filePath.'.doc')) {
           $copyPath = $dirPath .'/'. $filename .'.doc';
           $existsCounter = 1;
           while (file_exists($copyPath)) {
              $existsCounter++; 
              $copyPath = $dirPath .'/'. $filename .'_'. $existsCounter .'.doc';
           }
           copy($filePath.'.doc', $copyPath);
           print "Copied {$filePath}.doc to $copyPath\n";
           $fileCount++;
       }
    }
    else { //an Input Document or Attached File:
      $ext = pathinfo($filename, PATHINFO_EXTENSION); 
      $basename = pathinfo($filename, PATHINFO_BASENAME);
           
      $filePath = PATH_DOCUMENT. getPathFromUID($aFile['APP_UID']) .'/'. 
         $aFile['APP_DOC_UID'] .'_'. $aFile['DOC_VERSION'] .'.'. $ext;
                
       if (file_exists($filePath)) {
           $copyPath = $dirPath .'/'. $filename;
           $existsCounter = 1;
           while (file_exists($copyPath)) {
              $copyPath = $dirPath .'/'. $basename .'_'. (++$existsCounter) .'.'. $ext;
           }
           copy($filePath, $copyPath);
           print "Copied {$filePath} to $copyPath\n";
           $fileCount++;
       }
       
   }
}

print "\n$fileCount files copied\n";

?>

Re: Descargar todos los archivos Contenidos en la Seccion Documentos

Posted: Thu May 17, 2018 11:07 am
by chelotero
Amos finalmente no funciono el script que me enviaste,igual he creado 2 scripts basados en el que me enviaste, el primero para generar los ficheros
Code: Select all
<?php 
$targetDir = "/home/chelo/backupDocs"; //set directory where to copy PM documents
define("PATH_DOCUMENT", "/home/chelo/filesPM");  //directorio origen
//comment out the next line if don't want to delete all the files in the target directory:
array_map('unlink', glob($targetDir.'/*'));

$conn = mysql_connect('localhost:3306', 'root', '') or
   die("Error connecting to MySQL database.\n");
mysql_select_db('wf_workflow');

$sql = "SELECT * FROM `APP_DOCUMENT` ad join APP_FOLDER af on ad.FOLDER_UID = af.FOLDER_UID group by af.FOLDER_UID, FOLDER_NAME";
$fileCount = 0;

$result = mysql_query($sql) or
   die("Error: Unable to query the APP_DOCUMENT table.\n");


while ($aFile = mysql_fetch_array($result, MYSQL_ASSOC)) {

        $foldername = utf8_encode($aFile['FOLDER_NAME']);
        $dirPath = $targetDir; 
        if(!mkdir($targetDir.'/'.$foldername, 0777, true)) {
              die('Fallo al crear las carpetas...');
   }
  
}
?>
Una vez que tuve los ficheros creados ejecute el siguiente script para llenarlos con los archivos correspondientes
Code: Select all
<?php 
$targetDir = "/home/chelo/backupDocs"; //set directory where to copy PM documents
define("PATH_DOCUMENT", "/home/chelo/filesPM"); //directorio origen

//comment out the next line if don't want to delete all the files in the target directory:
array_map('unlink', glob($targetDir.'/*'));

$conn = mysql_connect('localhost:3306', 'root', '') or
   die("Error connecting to MySQL database.\n");
mysql_select_db('wf_workflow');

$sql = "SELECT * FROM `APP_DOCUMENT` ad join APP_FOLDER af on ad.FOLDER_UID = af.FOLDER_UID
join CONTENT c on c.CON_ID = ad.APP_DOC_UID  where CON_CATEGORY = 'APP_DOC_FILENAME'
group by c.CON_ID;";


$result = mysql_query($sql) or
   die("Error: Unable to query the APP_DOCUMENT table.\n");


while ($aFile = mysql_fetch_array($result, MYSQL_ASSOC)) {

        $foldername = utf8_encode($aFile['FOLDER_NAME']);
        $filename =  utf8_encode($aFile['CON_VALUE']);
        //echo "Archivo - ".$filemame." - ".$foldername; 

        $ext = substr(strrchr($filename,'.'),1);
        $filePath_origen   = PATH_DOCUMENT."/".$aFile['APP_UID'].'/'.$aFile['CON_ID'].'_1'.".".$ext;
        $filePath_destino  = "/home/chelo/backupDocs".'/'.$foldername .'/'. $filename;
        //echo $filePath_origen."\n";
        copy($filePath_origen, $filePath_destino);
  
}
?>
Estos Son aplicables para PM 2.5 :D , bueno sin mas que agregar, agredezco nuevamente la ayuda ! mis cordiales saludos!