From 05f169d580268e8b52b3c8ae836f91ef08a0d482 Mon Sep 17 00:00:00 2001 From: Freddy Daniel Rojas Valda Date: Wed, 26 Feb 2014 12:22:22 -0400 Subject: [PATCH] Se cambia url para download y delete se actualiza BEHAT en FILESMANAGER. --- .../basic_sequence_files_manager.feature | 47 +++--- features/bootstrap/RestContext.php | 21 ++- .../engine/src/BusinessModel/FilesManager.php | 144 +++++++++--------- .../Api/ProcessMaker/Project/FilesManager.php | 36 ++--- 4 files changed, 117 insertions(+), 131 deletions(-) diff --git a/features/backend/files_manager/basic_sequence_files_manager.feature b/features/backend/files_manager/basic_sequence_files_manager.feature index 06088e786..57423c129 100644 --- a/features/backend/files_manager/basic_sequence_files_manager.feature +++ b/features/backend/files_manager/basic_sequence_files_manager.feature @@ -42,55 +42,52 @@ Feature: Files Manager Resources And store "prf_uid" in session array as variable "prf_uid" Examples: - | test_description | file_name | path | content | http_code | type | - | into public folder | testbehat.txt | public/ | test | 200 | object | - | into maintemplates folder | testbehat.txt | templates/ | test | 200 | object | - | into public subfolder | testbehat.txt | public/test_folder | test | 200 | object | - | into public subfolder | testbehat.txt | templates/test_folder | test | 200 | object | + | test_description | file_name | path | content | http_code | type | i | + | into public folder | testbehat.txt | public/ | test | 200 | object | 0 | + | into mailtemplates folder | testbehat.txt | templates/ | test | 200 | object | 1 | + | into public subfolder | testbehat.txt | public/test_folder | test | 200 | object | 2 | + | into mailtemplates subfolder | testbehat.txt | templates/test_folder | test | 200 | object | 3 | Scenario Outline: Post files Given PUT this data: """ { - "prf_filename": "", "prf_content": "" } """ - And I request "project/1265557095225ff5c688f46031700471/file-manager?path=" + And that I want to update a resource with the key "prf_uid" stored in session array as variable "prf_uid" + And I request "project/1265557095225ff5c688f46031700471/file-manager" Then the response status code should be And the response charset is "UTF-8" And the content type is "application/json" And the type is "" Examples: - | test_description | file_name | path | content | http_code | type | - | put into public folder | testbehat.txt | public/ | put test | 200 | object | - | put into maintemplates folder | testbehat.txt | templates/ | put test | 200 | object | - | put into public subfolder | testbehat.txt | public/test_folder | put test | 200 | object | - | put into public subfolder | testbehat.txt | templates/test_folder | put test | 200 | object | - + | test_description | content | http_code | type | i | + | put into public folder | put test | 200 | object | 0 | + | put into mailtemplates folder | put test | 200 | object | 1 | + | put into public subfolder | put test | 200 | object | 2 | + | put into mailtemplates subfolder | put test | 200 | object | 3 | Scenario Outline: Delete file - Given that I want to delete a "" - And I request "project/1265557095225ff5c688f46031700471/file-manager?path=" - And the content type is "application/json" + Given that I want to delete a resource with the key "prf_uid" stored in session array as variable "prf_uid" + And I request "project/1265557095225ff5c688f46031700471/file-manager" Then the response status code should be 200 And the response charset is "UTF-8" Examples: - | test_description | path | - | delete public folder | public/testbehat.txt | - | delete maintemplates folder | templates/testbehat.txt | - | delete public subfolder | public/test_folder/testbehat.txt | - | delete public subfolder | templates/test_folder/testbehat.txt | + | test_description | i | + | delete public folder | 0 | + | delete mailtemplates folder | 1 | + | delete public subfolder | 2 | + | delete mailtemplates subfolder | 3 | #Para que funcione este test, debe existir el archivo que se quiere subir Scenario: Post files - Given POST I want to upload the file "/home/daniel/test.txt" to path "public". Url to create prf_uid "project/1265557095225ff5c688f46031700471/file-manager" and updload "project/1265557095225ff5c688f46031700471/file-manager" + Given POST I want to upload the file "/home/daniel/test.txt" to path "templates". Url "project/1265557095225ff5c688f46031700471/file-manager" Scenario: Delete file - Given that I want to delete a "public/test.txt" - And I request "project/1265557095225ff5c688f46031700471/file-manager?path=public/test.txt" - And the content type is "application/json" + Given that I want to delete a resource with the key "prf_uid" stored in session array as variable "prf_uid" + And I request "project/1265557095225ff5c688f46031700471/file-manager" Then the response status code should be 200 And the response charset is "UTF-8" diff --git a/features/bootstrap/RestContext.php b/features/bootstrap/RestContext.php index 744373155..8f0051c5c 100644 --- a/features/bootstrap/RestContext.php +++ b/features/bootstrap/RestContext.php @@ -1312,14 +1312,13 @@ class RestContext extends BehatContext $this->iRequest($url); } - //*********** POST - UPLOAD FILE MANAGER + //UPLOAD FILE MANAGER /** - * @Given /^POST I want to upload the file "([^"]*)" to path "([^"]*)". Url to create prf_uid "([^"]*)" and updload "([^"]*)"$/ + * @Given /^POST I want to upload the file "([^"]*)" to path "([^"]*)". Url "([^"]*)"$/ */ - public function postIWantToUploadTheFileToPathPublicUrlToCreatePrfUidAndUpdload($prfFile, $prfPath, $postUrl, $url) + public function postIWantToUploadTheFileToPathPublicUrl($prfFile, $prfPath, $url) { $baseUrl = $this->getParameter('base_url'); - $postUrl = $baseUrl.$postUrl; $url = $baseUrl.$url; $accesstoken = $this->getParameter('access_token'); $headr = array(); @@ -1327,7 +1326,7 @@ class RestContext extends BehatContext $path = rtrim($prfPath, '/') . '/'; $sfile = end(explode("/",$prfFile)); $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL,$postUrl); + curl_setopt($ch, CURLOPT_URL,$url); 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_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'); @@ -1340,7 +1339,7 @@ class RestContext extends BehatContext } else { var_dump($postResult["error"]); } - $url = $url.$prfUid."/upload"; + $url = $url.'/'.$prfUid."/upload"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_HTTPHEADER,$headr); @@ -1349,9 +1348,15 @@ class RestContext extends BehatContext curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $postResult = curl_exec($ch); curl_close($ch); + + //se guarda el prf_uid en una variable + $varName = 'prf_uid'; + $sessionData = new StdClass(); + $sessionData->$varName = $prfUid; + file_put_contents("session.data", json_encode($sessionData)); } - //*********** POST - UPLOAD IMAGE + //UPLOAD IMAGE /** * @Given /^POST I want to upload the image "([^"]*)" to user "([^"]*)". Url "([^"]*)"$/ */ @@ -1378,7 +1383,7 @@ class RestContext extends BehatContext . curl_error($ch)); } curl_close($ch); - echo $postResult; + echo $postResult; } /** diff --git a/workflow/engine/src/BusinessModel/FilesManager.php b/workflow/engine/src/BusinessModel/FilesManager.php index f3777bae3..80fb2eb4b 100644 --- a/workflow/engine/src/BusinessModel/FilesManager.php +++ b/workflow/engine/src/BusinessModel/FilesManager.php @@ -45,6 +45,7 @@ class FilesManager { try { $sMainDirectory = current(explode("/", $path)); + $path = str_replace('/', '', $path); if (strstr($path,'/')) { $sSubDirectory = substr($path, strpos($path, "/")+1). PATH_SEP ; } else { @@ -86,12 +87,12 @@ class FilesManager $fileUid = $arrayFileUid["PRF_UID"]; if ($fileUid) { $oProcessFiles = \ProcessFilesPeer::retrieveByPK($fileUid); - $editable = $oProcessFiles->getPrfEditable(); - if ($editable == 1){ - $editable = 'true'; - } else { - $editable = 'false'; - } + $editable = $oProcessFiles->getPrfEditable(); + if ($editable == 1){ + $editable = 'true'; + } else { + $editable = 'false'; + } $aTheFiles[] = array( 'prf_uid' => $oProcessFiles->getPrfUid(), 'prf_filename' => $aFile['FILE'], 'usr_uid' => $oProcessFiles->getUsrUid(), @@ -104,7 +105,14 @@ class FilesManager 'prf_content' => $fcontent); } else { - $aTheFiles[] = array('prf_uid' => $oProcessFiles->getPrfUid(), + $extention = end(explode(".", $aFile['FILE'])); + if ($extention == 'docx' || $extention == 'doc' || $extention == 'html' || $extention == 'php' || $extention == 'jsp' || + $extention == 'xlsx' || $extention == 'xls' || $extention == 'js' || $extention == 'css' || $extention == 'txt') { + $editable = 'true'; + } else { + $editable = 'false'; + } + $aTheFiles[] = array('prf_uid' => '', 'prf_filename' => $aFile['FILE'], 'usr_uid' => '', 'prf_update_usr_uid' => '', @@ -237,12 +245,15 @@ class FilesManager if ($file == $_FILES['prf_file']['name']) { if ($_FILES['prf_file']['error'] != 1) { if ($_FILES['prf_file']['tmp_name'] != '') { - \G::uploadFile($_FILES['prf_file']['tmp_name'],$path , $_FILES['prf_file']['name']); + \G::uploadFile($_FILES['prf_file']['tmp_name'], $path, $_FILES['prf_file']['name']); } } } else { throw new \Exception(\G::LoadTranslation('ID_PMTABLE_UPLOADING_FILE_PROBLEM')); } + $oProcessFile = array('prf_uid' => $prfUid); + var_dump($oProcessFile); + return $oProcessFile; } catch (Exception $e) { throw $e; } @@ -274,44 +285,41 @@ class FilesManager * Return the Process Files Manager * * @param string $sProcessUID {@min 32} {@max 32} - * @param string $path * @param string $userUID {@min 32} {@max 32} * @param array $aData + * @param string $prfUid {@min 32} {@max 32} * * return array * * @access public */ - public function updateProcessFilesManager($sProcessUID, $userUID, $aData, $path) + public function updateProcessFilesManager($sProcessUID, $userUID, $aData, $prfUid) { try { - $path = rtrim($path, '/') . '/'; - $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 (strstr($path,'/')) { - $sSubDirectory = substr($path, strpos($path, "/")+1) ; + if ($path == ''){ + throw new \Exception('invalid value specified for `prf_uid`.'); + } + $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 = 'mailTemplates'; } else { - $sSubDirectory = ''; + $sMainDirectory = 'public'; } - switch ($sMainDirectory) { - case 'templates': - $sDirectory = PATH_DATA_MAILTEMPLATES . $sProcessUID . PATH_SEP . $sSubDirectory . $aData['prf_filename']; - $sEditable = false; - break; - case 'public': - $sDirectory = PATH_DATA_PUBLIC . $sProcessUID . PATH_SEP . $sSubDirectory . $aData['prf_filename']; - break; - default: - $sDirectory = PATH_DATA_MAILTEMPLATES . $sProcessUID . PATH_SEP . $aData['prf_filename']; - break; - } - $arrayFileUid = $this->getFileManagerUid($sDirectory); - if (!$arrayFileUid) { - throw (new \Exception( 'invalid value specified for `path`.')); - } - $extention = end(explode(".", $aData['prf_filename'])); + $extention = end(explode(".", $sFile)); if ($extention == 'docx' || $extention == 'doc' || $extention == 'html' || $extention == 'php' || $extention == 'jsp' || $extention == 'xlsx' || $extention == 'xls' || $extention == 'js' || $extention == 'css' || $extention == 'txt') { $sEditable = true; @@ -321,20 +329,20 @@ class FilesManager if ($sEditable == false) { throw (new \Exception( 'Can`t edit. Make sure your file has an editable extension.')); } - $fileUid = $arrayFileUid["PRF_UID"]; - $oProcessFiles = \ProcessFilesPeer::retrieveByPK($fileUid); + $oProcessFiles = \ProcessFilesPeer::retrieveByPK($prfUid); $sDate = date('Y-m-d H:i:s'); $oProcessFiles->setPrfUpdateUsrUid($userUID); $oProcessFiles->setPrfUpdateDate($sDate); $oProcessFiles->save(); - $fp = fopen($sDirectory, 'w'); + $fp = fopen($path, 'w'); $content = $aData['prf_content']; fwrite($fp, $content); fclose($fp); $oProcessFile = array('prf_uid' => $oProcessFiles->getPrfUid(), + 'prf_filename' => $sFile, 'usr_uid' => $oProcessFiles->getUsrUid(), 'prf_update_usr_uid' => $oProcessFiles->getPrfUpdateUsrUid(), - 'prf_path' => $sMainDirectory. PATH_SEP . $sSubDirectory, + 'prf_path' => $sMainDirectory.PATH_SEP.$sSubDirectory, 'prf_type' => $oProcessFiles->getPrfType(), 'prf_editable' => $sEditable, 'prf_create_date' => $oProcessFiles->getPrfCreateDate(), @@ -349,53 +357,41 @@ class FilesManager /** * * @param string $sProcessUID {@min 32} {@max 32} - * @param string $path + * @param string $prfUid {@min 32} {@max 32} * * * @access public */ - public function deleteProcessFilesManager($sProcessUID, $path) + public function deleteProcessFilesManager($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') { + if ($path == ''){ + throw new \Exception('invalid value specified for `prf_uid`.'); + } + $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 = 'mailTemplates'; - } - $sfile = end(explode("/",$path)); - $sSubDirectorytemp = substr($path, strpos($path, "/")+1); - if (strstr($sSubDirectorytemp,'/')) { - $sSubDirectory = str_replace('/'.$sfile,"",$sSubDirectorytemp); - $sSubDirectoryCheck = str_replace($sfile,"",$sSubDirectorytemp); } else { - $sSubDirectory = ''; - $sSubDirectoryCheck = ''; - } - switch ($sMainDirectory) { - case 'mailTemplates': - $sDirectory = PATH_DATA_MAILTEMPLATES . $sProcessUID . PATH_SEP . $sSubDirectoryCheck . $sfile; - $sEditable = false; - break; - case 'public': - $sDirectory = PATH_DATA_PUBLIC . $sProcessUID . PATH_SEP . $sSubDirectoryCheck . $sfile; - break; - default: - $sDirectory = PATH_DATA_MAILTEMPLATES . $sProcessUID . PATH_SEP . $sfile; - break; - } - $arrayTaskUid = $this->getFileManagerUid($sDirectory); - if (!$arrayTaskUid){ - throw (new \Exception( 'invalid value specified for `path`.')); + $sMainDirectory = 'public'; } $oProcessMap = new \processMap(new \DBConnection()); - $oProcessMap->deleteFile($sProcessUID, - $sMainDirectory, - $sSubDirectory, - $sfile); + $oProcessMap->deleteFile($sProcessUID, $sMainDirectory, $sSubDirectory, $sFile); $c = new \Criteria("workflow"); - $c->add(\ProcessFilesPeer::PRF_PATH, $sDirectory, \Criteria::EQUAL); + $c->add(\ProcessFilesPeer::PRF_UID, $prfUid, \Criteria::EQUAL); $rs = \ProcessFilesPeer::doDelete($c); } catch (Exception $e) { throw $e; @@ -432,7 +428,7 @@ class FilesManager $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'; + $sMainDirectory = 'mailTemplates'; } else { $sMainDirectory = 'public'; } diff --git a/workflow/engine/src/Services/Api/ProcessMaker/Project/FilesManager.php b/workflow/engine/src/Services/Api/ProcessMaker/Project/FilesManager.php index 3eb5b4ac0..fec254d3b 100644 --- a/workflow/engine/src/Services/Api/ProcessMaker/Project/FilesManager.php +++ b/workflow/engine/src/Services/Api/ProcessMaker/Project/FilesManager.php @@ -67,7 +67,9 @@ class FilesManager extends Api { try { $filesManager = new \BusinessModel\FilesManager(); - $filesManager->uploadProcessFilesManager($prjUid, $prfUid); + $sData = $filesManager->uploadProcessFilesManager($prjUid, $prfUid); + //Response + $response = $sData; } catch (\Exception $e) { //response throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()); @@ -76,18 +78,18 @@ class FilesManager extends Api /** * @param string $prjUid {@min 32} {@max 32} - * @param ProcessFilesManagerStructurePut $request_data - * @param string $path + * @param ProcessFilesManagerStructure $request_data + * @param string $prfUid {@min 32} {@max 32} * - * @url PUT /:prjUid/file-manager + * @url PUT /:prjUid/file-manager/:prfUid */ - public function doPutProcessFilesManager($prjUid, ProcessFilesManagerStructurePut $request_data, $path) + public function doPutProcessFilesManager($prjUid, ProcessFilesManagerStructure $request_data, $prfUid) { try { $userUid = $this->getUserId(); $request_data = (array)($request_data); $filesManager = new \BusinessModel\FilesManager(); - $arrayData = $filesManager->updateProcessFilesManager($prjUid, $userUid, $request_data, $path); + $arrayData = $filesManager->updateProcessFilesManager($prjUid, $userUid, $request_data, $prfUid); //Response $response = $arrayData; } catch (\Exception $e) { @@ -99,15 +101,15 @@ class FilesManager extends Api /** * @param string $prjUid {@min 32} {@max 32} - * @param string $path + * @param string $prfUid {@min 32} {@max 32} * - * @url DELETE /:prjUid/file-manager + * @url DELETE /:prjUid/file-manager/:prfUid */ - public function doDeleteProcessFilesManager($prjUid, $path) + public function doDeleteProcessFilesManager($prjUid, $prfUid) { try { $filesManager = new \BusinessModel\FilesManager(); - $filesManager->deleteProcessFilesManager($prjUid, $path); + $filesManager->deleteProcessFilesManager($prjUid, $prfUid); } catch (\Exception $e) { //response throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()); @@ -150,17 +152,3 @@ class ProcessFilesManagerStructure public $prf_content; } - -class ProcessFilesManagerStructurePut -{ - /** - * @var string {@from body} - */ - public $prf_filename; - - /** - * @var string {@from body} - */ - public $prf_content; -} -