Merged in darojas/processmaker (pull request #241)
Se cambia url para download y delete se actualiza BEHAT en FILESMANAGER
This commit is contained in:
@@ -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';
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user