From 6ceb1098f3a8e3ec278f95065ebccd9ba5c24c92 Mon Sep 17 00:00:00 2001 From: Freddy Daniel Rojas Valda Date: Tue, 25 Feb 2014 12:43:18 -0400 Subject: [PATCH] Se cambia url para download y se mejor BEHAT en FILESMANAGER. --- features/bootstrap/RestContext.php | 2 +- .../engine/src/BusinessModel/FilesManager.php | 57 +++++++++---------- .../Api/ProcessMaker/Project/FilesManager.php | 8 +-- 3 files changed, 33 insertions(+), 34 deletions(-) diff --git a/features/bootstrap/RestContext.php b/features/bootstrap/RestContext.php index 5e577044d..64ab457ed 100644 --- a/features/bootstrap/RestContext.php +++ b/features/bootstrap/RestContext.php @@ -1329,7 +1329,7 @@ class RestContext extends BehatContext $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$postUrl); curl_setopt($ch, CURLOPT_HTTPHEADER,$headr); - curl_setopt($ch, CURLOPT_POSTFIELDS, array('prf_filename'=>$sfile, "prf_path" => $path, "prf_content" => NULL)); + curl_setopt($ch, CURLOPT_POSTFIELDS, array('prf_filename'=>$sfile, "prf_path" => $path, "prf_content" => null)); curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $postResult = curl_exec($ch); diff --git a/workflow/engine/src/BusinessModel/FilesManager.php b/workflow/engine/src/BusinessModel/FilesManager.php index c9d4d9879..1aeabf40a 100644 --- a/workflow/engine/src/BusinessModel/FilesManager.php +++ b/workflow/engine/src/BusinessModel/FilesManager.php @@ -92,7 +92,8 @@ class FilesManager } else { $editable = 'false'; } - $aTheFiles[] = array( 'prf_filename' => $aFile['FILE'], + $aTheFiles[] = array( 'prf_uid' => $oProcessFiles->getPrfUid(), + 'prf_filename' => $aFile['FILE'], 'usr_uid' => $oProcessFiles->getUsrUid(), 'prf_update_usr_uid' => $oProcessFiles->getPrfUpdateUsrUid(), 'prf_path' => $sMainDirectory. PATH_SEP .$sSubDirectory, @@ -103,7 +104,8 @@ class FilesManager 'prf_content' => $fcontent); } else { - $aTheFiles[] = array('prf_filename' => $aFile['FILE'], + $aTheFiles[] = array('prf_uid' => $oProcessFiles->getPrfUid(), + 'prf_filename' => $aFile['FILE'], 'usr_uid' => '', 'prf_update_usr_uid' => '', 'prf_path' => $sMainDirectory. PATH_SEP .$sSubDirectory, @@ -403,44 +405,41 @@ class FilesManager /** * * @param string $sProcessUID {@min 32} {@max 32} - * @param string $path + * @param string $prfUid {@min 32} {@max 32} * * * @access public */ - public function downloadProcessFilesManager($sProcessUID, $path) + public function downloadProcessFilesManager($sProcessUID, $prfUid) { try { - $sMainDirectory = current(explode("/", $path)); - if ($sMainDirectory != 'public' && $sMainDirectory != 'templates') { - throw (new \Exception( 'invalid value specified for `prf_path`. Expecting `templates/` or `public/`')); + $path = ''; + $criteria = new \Criteria("workflow"); + $criteria->addSelectColumn(\ProcessFilesPeer::PRF_PATH); + $criteria->add(\ProcessFilesPeer::PRF_UID, $prfUid, \Criteria::EQUAL); + $rsCriteria = \ProcessFilesPeer::doSelectRS($criteria); + $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC); + $rsCriteria->next(); + while ($aRow = $rsCriteria->getRow()) { + $path = $aRow['PRF_PATH']; + $rsCriteria->next(); } - if ($sMainDirectory == 'templates') { - $sMainDirectory = 'mailTemplates'; + if ($path == ''){ + throw new \Exception('invalid value specified for `prf_uid`.')); } - $sfile = end(explode("/",$path)); - $sSubDirectorytemp = substr($path, strpos($path, "/")+1); - if (strstr($sSubDirectorytemp,'/')) { - $sSubDirectory = str_replace('/'.$sfile,"",$sSubDirectorytemp); - $sSubDirectoryCheck = str_replace($sfile,"",$sSubDirectorytemp); + $sFile = end(explode("/",$path)); + $sPath = str_replace($sFile,'',$path); + $sSubDirectory = str_replace('/','',str_replace($sProcessUID,'',substr($sPath,(strpos($sPath, $sProcessUID))))); + $sMainDirectory = str_replace(substr($sPath, strpos($sPath, $sProcessUID)),'', $sPath); + if ($sMainDirectory == PATH_DATA_MAILTEMPLATES){ + $sMainDirectory = 'mainTemplates'; } else { - $sSubDirectory = ''; - $sSubDirectoryCheck = ''; + $sMainDirectory = 'public'; } - switch ($sMainDirectory) { - case 'mailTemplates': - $sDirectory = PATH_DATA_MAILTEMPLATES . $sProcessUID . PATH_SEP . $sSubDirectoryCheck . $sfile; - break; - case 'public': - $sDirectory = PATH_DATA_PUBLIC . $sProcessUID . PATH_SEP . $sSubDirectoryCheck . $sfile; - break; - default: - $sDirectory = PATH_DATA_MAILTEMPLATES . $sProcessUID . PATH_SEP . $sfile; - break; - } - if (file_exists(PATH_SEP.$sDirectory)) { + if (file_exists($path)) { $oProcessMap = new \processMap(new \DBConnection()); - $oProcessMap->downloadFile($sProcessUID,$sMainDirectory,$sSubDirectory,$sfile); + $oProcessMap->downloadFile($sProcessUID,$sMainDirectory,$sSubDirectory,$sFile); + die(); } else { throw (new \Exception( 'invalid value specified for `path`.')); } diff --git a/workflow/engine/src/Services/Api/ProcessMaker/Project/FilesManager.php b/workflow/engine/src/Services/Api/ProcessMaker/Project/FilesManager.php index 7feb40af8..3eb5b4ac0 100644 --- a/workflow/engine/src/Services/Api/ProcessMaker/Project/FilesManager.php +++ b/workflow/engine/src/Services/Api/ProcessMaker/Project/FilesManager.php @@ -116,15 +116,15 @@ class FilesManager extends Api /** * @param string $prjUid {@min 32} {@max 32} - * @param string $path + * @param string $prfUid {@min 32} {@max 32} * - * @url GET /:prjUid/file-manager/download + * @url GET /:prjUid/file-manager/:prfUid/download */ - public function doGetProcessFilesManagerDownload($prjUid, $path) + public function doGetProcessFilesManagerDownload($prjUid, $prfUid) { try { $filesManager = new \BusinessModel\FilesManager(); - $filesManager->downloadProcessFilesManager($prjUid, $path); + $filesManager->downloadProcessFilesManager($prjUid, $prfUid); } catch (\Exception $e) { //response throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());