diff --git a/gulliver/system/class.g.php b/gulliver/system/class.g.php old mode 100644 new mode 100755 index 184370e16..db5334508 --- a/gulliver/system/class.g.php +++ b/gulliver/system/class.g.php @@ -313,12 +313,13 @@ class G while ($parent_folder_path = array_pop( $folder_path )) { if (! @is_dir( $parent_folder_path )) { - if (! @mkdir( $parent_folder_path, $rights )) { - //trigger_error ("Can't create folder \"$parent_folder_path\".", E_USER_WARNING); - umask( $oldumask ); + if (! @mkdir( $parent_folder_path, $rights)) { + error_log( "Can't create folder \"$parent_folder_path\""); + //umask( $oldumask ); } } } + umask($oldumask); } /** @@ -359,6 +360,53 @@ class G } } + /** + * Delete all the directory tree cotents. + * @param string $dir + * @return void + */ + public function delTree($dir) + { + $files = glob( $dir . '*', GLOB_MARK ); + foreach ($files as $file ) { + if (substr( $file, -1 ) == '/' ) { + $this->delTree( $file ); + } else { + unlink( $file ); + } + } + if (is_dir($dir)) { + rmdir( $dir ); + } + } + + /** + * Recursive copy + * @param string $source + * @param string $destination + * @return boolean + */ + function recursive_copy ($source, $destination) { + if ($source == $destination) { + return false; + } + $dir = opendir($source); + if (! file_exists($destination)) { + @mkdir($destination); + } + while (false !== ( $file = readdir($dir))) { + if (( $file != '.' ) && ( $file != '..' )) { + if ( is_dir($source . '/' . $file) ) { + self::recursive_copy($source . '/' . $file, $destination . '/' . $file); + } else { + copy($source . '/' . $file, $destination . '/' . $file); + } + } + } + closedir($dir); + return true; + } + /** * verify path * @@ -2414,6 +2462,133 @@ class G return $new_val; } + /** + * Extract the structure version value from serializated table field and check it. + * @return true if the version is bigger than 1 + */ + public function gotDirectoryStructureVer2() + { + G::LoadClass( "configuration" ); + $configuration = new Configurations(); + if (defined('SYS_SYS') && $configuration->exists("ENVIRONMENT_SETTINGS")) { + return ($configuration->getDirectoryStructureVer() > 1); + } + return false; + } + + /** + * Get the default blank directory 0 for external files + */ + public function getBlackHoleDir() + { + //len32:12345678901234567890123456789012 + return "00000000000000000000000000000000"; + } + + /** + * Funtion used to fix 32K issue related to ext3 max subdirectory storage, but checking Version first. + * @param string $uid + * @param int $splitSize + * @param int $pieces + * @return string xxx/xxx/xxx/xxxxxxxxxxxxxxxxxxxxx + */ + public function getPathFromUID($uid, $splitSize = 3, $pieces = 3) + { + if (! G::gotDirectoryStructureVer2()) { + return $uid; + } + return G::getPathFromUIDPlain($uid, $splitSize, $pieces); + } + + /** + * Funtion used to fix 32K issue related to ext3 max subdirectory storage. + * @param string $uid + * @param int $splitSize + * @param int $pieces + * @return string xxx/xxx/xxx/xxxxxxxxxxxxxxxxxxxxx + */ + public function getPathFromUIDPlain($uid, $splitSize = 3, $pieces = 3) + { + $dirArray = array(); + if (is_string($uid) && strlen($uid) >= 32 && $uid != G::getBlackHoleDir()) { + for ($i = 0; $i < $pieces; $i++) { + $dirArray[] = substr($uid, 0, $splitSize); + $len = strlen($uid); + $uid = substr($uid, $splitSize, $len); + } + } + $dirArray[] = $uid; + $newfileStructure = implode($dirArray, '/'); + return $newfileStructure; + } + + /** + * Get the uid from the splitted directory + filename. + * @param string $path + * @return string + */ + public function getUIDfromPath($path) + { + $uid = ''; + $item = explode($path, '/'); + $len = sizeof($item); + for ($i = 0; $i < $len; $i++) { + $uid .= $item[$i]; + } + if (strlen($uid) != 32){ + return "invalid"; + } + return $uid; + } + + /** + * Get the file stored in '0' dir as splitted, but checking version first. + * @param string $appUid + * @param string $fileUid + * @param int $splitSize + * @param int $pieces + * @return array index:0 got the path, index:1 got the filename + */ + public function getPathFromFileUID($appUid, $fileUid, $splitSize = 3, $pieces = 3) + { + if (! G::gotDirectoryStructureVer2()) { + $response = array(); + $response[] = ''; + $response[] = $fileUid; + return $response; + } + return G::getPathFromFileUIDPlain($appUid, $fileUid, $splitSize, $pieces); + } + + /** + * Get the file stored in '0' dir as splitted. + * @param string $appUid + * @param string $fileUid + * @param int $splitSize + * @param int $pieces + * @return array index:0 got the path, index:1 got the filename + */ + public function getPathFromFileUIDPlain($appUid, $fileUid, $splitSize = 3, $pieces = 3) + { + $response = array(); + if ($appUid == G::getBlackHoleDir()) { + $dirArray = array(); + if (is_string($fileUid) && strlen($fileUid) >= 32) { + for ($i = 0; $i < $pieces; $i++) { + $dirArray[] = substr($fileUid, 0, $splitSize); + $len = strlen($fileUid); + $fileUid = substr($fileUid, $splitSize, $len); + } + } + $response[] = implode($dirArray, '/') . '/'; + $response[] = $fileUid; + } else { + $response[] = ''; + $response[] = $fileUid; + } + return $response; + } + /** * Upload a file and then copy to path+ nameToSave * diff --git a/workflow/engine/classes/class.case.php b/workflow/engine/classes/class.case.php index 1ee774349..4b84b8635 100755 --- a/workflow/engine/classes/class.case.php +++ b/workflow/engine/classes/class.case.php @@ -3602,7 +3602,7 @@ class Cases $docVersion = $appDocument->getDocVersion(); $arrayInfo = pathinfo($appDocument->getAppDocFilename()); $extension = (isset($arrayInfo["extension"])) ? $arrayInfo["extension"] : null; - $strPathName = PATH_DOCUMENT . $applicationUid . PATH_SEP; + $strPathName = PATH_DOCUMENT . G::getPathFromUID($applicationUid) . PATH_SEP; $strFileName = $appDocUid . "_" . $docVersion . "." . $extension; switch ($option) { diff --git a/workflow/engine/classes/class.cli.php b/workflow/engine/classes/class.cli.php index 29cc9b454..9c971f1be 100755 --- a/workflow/engine/classes/class.cli.php +++ b/workflow/engine/classes/class.cli.php @@ -46,8 +46,16 @@ class CLI public static function taskName ($name) { self::$currentTask = $name; - self::$tasks[$name] = array ('name' => $name,'description' => null,'args' => array (),'function' => null,'opt' => array ('short' => '','long' => array (),'descriptions' => array () - ) + self::$tasks[$name] = array ( + 'name' => $name, + 'description' => null, + 'args' => array (), + 'function' => null, + 'opt' => array ( + 'short' => '', + 'long' => array (), + 'descriptions' => array () + ) ); } diff --git a/workflow/engine/classes/class.configuration.php b/workflow/engine/classes/class.configuration.php index e33b2599c..b7b113929 100755 --- a/workflow/engine/classes/class.configuration.php +++ b/workflow/engine/classes/class.configuration.php @@ -915,5 +915,29 @@ class Configurations // extends Configuration return array("caseColumns" => $caseColumns, "caseReaderFields" => $caseReaderFields, "rowsperpage" => 20, "dateformat" => "M d, Y"); } + /** + * Set the current Directory structure version, default value 1. + * Note.- TAKE CARE for the version value, input/output couln't work at the wrong version. + * @param integer $version + */ + public function setDirectoryStructureVer($version = 1) + { + $obj = ''; + $this->loadConfig($obj, 'ENVIRONMENT_SETTINGS', ''); + $this->aConfig['directoryStructure'] = $version; + $this->saveConfig('ENVIRONMENT_SETTINGS', $obj); + } + + /** + * Get the current directory structure version if the array iten 'directoryStructure' doesn't exists it will returns 1. + * @return integer + */ + public function getDirectoryStructureVer() + { + $obj = ''; + $this->loadConfig($obj, 'ENVIRONMENT_SETTINGS', ''); + $ver = isset($this->aConfig['directoryStructure']) ? $this->aConfig['directoryStructure'] : 1; + return $ver; + } } \ No newline at end of file diff --git a/workflow/engine/classes/class.pmFunctions.php b/workflow/engine/classes/class.pmFunctions.php index 4b2273f98..fe5d9dc39 100755 --- a/workflow/engine/classes/class.pmFunctions.php +++ b/workflow/engine/classes/class.pmFunctions.php @@ -1708,7 +1708,7 @@ function PMFGenerateOutputDocument ($outputID, $sApplication = null, $index = nu } $sFilename = $aFields['APP_DOC_UID'] . "_" . $lastDocVersion; - $pathOutput = PATH_DOCUMENT . $sApplication . PATH_SEP . 'outdocs' . PATH_SEP; //G::pr($sFilename);die; + $pathOutput = PATH_DOCUMENT . G::getPathFromUID($sApplication) . PATH_SEP . 'outdocs' . PATH_SEP; //G::pr($sFilename);die; G::mk_dir( $pathOutput ); $aProperties = array (); @@ -1747,7 +1747,7 @@ function PMFGenerateOutputDocument ($outputID, $sApplication = null, $index = nu $oAppDocument1 = new AppDocument(); $oAppDocument1->update( $aFields ); - $sPathName = PATH_DOCUMENT . $sApplication . PATH_SEP; + $sPathName = PATH_DOCUMENT . G::getPathFromUID($sApplication) . PATH_SEP; $oData['APP_UID'] = $sApplication; $oData['ATTACHMENT_FOLDER'] = true; diff --git a/workflow/engine/classes/class.processMap.php b/workflow/engine/classes/class.processMap.php index 4cf28d1f8..e4c7a0eaa 100755 --- a/workflow/engine/classes/class.processMap.php +++ b/workflow/engine/classes/class.processMap.php @@ -4426,6 +4426,7 @@ class processMap $aDirectories[] = array('PATH' => ($sCurrentDirectory != '' ? $sCurrentDirectory . PATH_SEP : '') . $sObject, 'DIRECTORY' => $sObject ); } else { $aAux = pathinfo($sPath); + $aAux['extension'] = (isset($aAux['extension'])?$aAux['extension']:''); $aFiles[] = array('FILE' => $sObject, 'EXT' => $aAux['extension'] ); } } diff --git a/workflow/engine/classes/class.wsTools.php b/workflow/engine/classes/class.wsTools.php index 11c5d1dfa..705d643dd 100755 --- a/workflow/engine/classes/class.wsTools.php +++ b/workflow/engine/classes/class.wsTools.php @@ -89,6 +89,13 @@ class workspaceTools $stop = microtime(true); $final = $stop - $start; CLI::logging("<*> Process Updating cache view carried out in $final seconds.\n"); + + $start = microtime(true); + CLI::logging("> Updating cases directories structure...\n"); + $this->upgradeCasesDirectoryStructure($workSpace); + $stop = microtime(true); + $final = $stop - $start; + CLI::logging("<*> Process Updating directories structure carried out in $final seconds.\n"); } /** @@ -482,6 +489,97 @@ class workspaceTools // end of reset } + /** + * fix the 32K issue, by migrating /files directory structure to an uid tree structure based. + * @param $workspace got the site(s) the manager wants to upgrade + */ + public function upgradeCasesDirectoryStructure ($workspace) + { + define('PATH_DOCUMENT', PATH_DATA . 'sites/' . $workspace . '/' . 'files/'); + $doclevel = explode('/', PATH_DOCUMENT); + $length = sizeof(PATH_DOCUMENT); + $filesDir = $doclevel[$length - 1]; + + if (is_dir(PATH_DOCUMENT) && is_writable($filesDir)) { + CLI::logging("Error:" . PATH_DOCUMENT . " is not writable... please check the su permissions.\n"); + return; + } + + $directory = array(); + $blackHoleDir = G::getBlackHoleDir(); + $directory = glob(PATH_DOCUMENT . "*", GLOB_ONLYDIR); + $dirslength = sizeof($directory); + + if (! @chdir(PATH_DOCUMENT)) { + CLI::logging("Cannot use Document directory. The upgrade must be done as root.\n"); + return; + } + + //Start migration + for ($index = 0; $index < $dirslength; $index++) { + $depthdirlevel = explode('/', $directory[$index]); + $lastlength = sizeof($depthdirlevel); + $UIdDir = $depthdirlevel[$lastlength - 1]; + $lenDir = strlen($UIdDir); + + if ($lenDir == 32 && $UIdDir != $blackHoleDir) { + $len = count(scandir($UIdDir)); + if ($len > 2) { + //lenght = 2, because the function check . and .. dir links + $newDiretory = G::getPathFromUIDPlain($UIdDir); + CLI::logging("Migrating $UIdDir to $newDiretory\n"); + G::mk_dir($newDiretory); + //echo `cp -R $UIdDir/* $newDiretory/`; + if (G::recursive_copy($UIdDir, $newDiretory)) { + CLI::logging("Removing $UIdDir...\n"); + G::rm_dir($UIdDir); + rmdir($UIdDir);//remove the diretory itself, G::rm_dir cannot do it + } else { + CLI::logging("Error: Failure at coping from $UIdDir...\n"); + } + } else { + CLI::logging("$UIdDir is empty, removing it\n"); + rmdir($UIdDir);//remove the diretory itself + } + } + } + + //Start '0' directory migration + $black = PATH_DOCUMENT . $blackHoleDir . '/'; + if (is_dir($black)) { + $newpattern = array(); + $file = glob($black . '*.*');//files only + $dirlen = count($file); + + for ($index = 0; $index < $dirlen; $index++) { + $levelfile = explode('/', $file[$index]); + $lastlevel = sizeof($levelfile); + $goalFile = $levelfile[$lastlevel - 1]; + $newpattern = G::getPathFromFileUIDPlain($blackHoleDir, $goalFile); + CLI::logging("Migrating $blackHoleDir file: $goalFile\n"); + G::mk_dir($blackHoleDir . '/' . $newpattern[0]); + //echo `cp -R $black$goalFile $black$newpattern[0]/$newpattern[1]`; + if (copy($black . $goalFile, $black . $newpattern[0] . '/' . $newpattern[1])) { + unlink($file[$index]); + } else { + CLI::logging("Error: Failure at copy $file[$index] files...\n"); + } + } + } + + //Set value of 2 to the directory structure version. + $this->initPropel(true); + G::LoadClass("configuration"); + $conf = new Configurations(); + if ($conf->exists("ENVIRONMENT_SETTINGS")) { + $conf->setDirectoryStructureVer(2); + CLI::logging("Please notice Version Directory Structure is 2 now.\n"); + } else { + CLI::logging("Error: Issue found at try to use ENVIRONMENT_SETTINGS row.\n"); + return; + } + } + /** * Upgrade this workspace database to the latest plugins schema */ diff --git a/workflow/engine/classes/model/AppFolder.php b/workflow/engine/classes/model/AppFolder.php index f689e612e..8f6b31ea5 100755 --- a/workflow/engine/classes/model/AppFolder.php +++ b/workflow/engine/classes/model/AppFolder.php @@ -434,7 +434,7 @@ class AppFolder extends BaseAppFolder $info = pathinfo($oAppDocument->getAppDocFilename()); $version = (!empty($docVersion))? "_" . $docVersion : "_1"; - $outDocPath = PATH_DOCUMENT . $row1["APP_UID"] . PATH_SEP . "outdocs" . PATH_SEP; + $outDocPath = PATH_DOCUMENT . G::getPathFromUID($row1["APP_UID"]) . PATH_SEP . "outdocs" . PATH_SEP; if (file_exists($outDocPath . $appDocUid . $version . ".pdf") || file_exists($outDocPath . $info["basename"] . $version . ".pdf") || diff --git a/workflow/engine/classes/model/Translation.php b/workflow/engine/classes/model/Translation.php index 5462c357c..f748c7ed9 100755 --- a/workflow/engine/classes/model/Translation.php +++ b/workflow/engine/classes/model/Translation.php @@ -177,8 +177,12 @@ class Translation extends BaseTranslation //$json = new Services_JSON(); DEPRECATED $f = fopen( $cacheFileJS, 'w' ); - fwrite( $f, "var G_STRINGS =" . Bootstrap::json_encode( $translationJS ) . ";\n" ); - fclose( $f ); + if ($f==false) { + echo "Error: Cannot write into cachefilejs: $cacheFileJS\n"; + } else { + fwrite( $f, "var G_STRINGS =" . Bootstrap::json_encode( $translationJS ) . ";\n" ); + fclose( $f ); + } $res['cacheFile'] = $cacheFile; $res['cacheFileJS'] = $cacheFileJS; diff --git a/workflow/engine/controllers/installer.php b/workflow/engine/controllers/installer.php old mode 100644 new mode 100755 index ed9e9be0e..bdd54c2f2 --- a/workflow/engine/controllers/installer.php +++ b/workflow/engine/controllers/installer.php @@ -216,7 +216,6 @@ class Installer extends Controller public function getPermissionInfo () { $this->setResponseType( 'json' ); - $info = new StdClass(); $info->success = true; $noWritableFiles = array (); @@ -289,6 +288,7 @@ class Installer extends Controller if (is_dir( $aux['dirname'] )) { if (! file_exists( $_REQUEST['pathLogFile'] )) { @file_put_contents( $_REQUEST['pathLogFile'], '' ); + chmod($_REQUEST['pathShared'], 0770); } } } diff --git a/workflow/engine/methods/appFolder/appFolderAjax.php b/workflow/engine/methods/appFolder/appFolderAjax.php index 74793901c..7eb1f5af4 100755 --- a/workflow/engine/methods/appFolder/appFolderAjax.php +++ b/workflow/engine/methods/appFolder/appFolderAjax.php @@ -1258,7 +1258,7 @@ function uploadExternalDocument() $aID=array('INP_DOC_DESTINATION_PATH'=>$folderStructure['PATH']); } - $oAppDocument = new AppDocument(); + //Get the Custom Folder ID (create if necessary) $oFolder=new AppFolder(); @@ -1272,6 +1272,7 @@ function uploadExternalDocument() $fileTags="EXTERNAL"; } foreach ($quequeUpload as $key => $fileObj) { + $oAppDocument = new AppDocument(); switch ($actionType) { case "R": //replace @@ -1333,15 +1334,18 @@ function uploadExternalDocument() } $sAppDocUid = $oAppDocument->getAppDocUid(); $iDocVersion = $oAppDocument->getDocVersion(); + $info = pathinfo($oAppDocument->getAppDocFilename()); $ext = (isset($info['extension']) ? $info['extension'] : ''); - //save the file //if (!empty($_FILES['form'])) { //if ($_FILES['form']['error']['APP_DOC_FILENAME'] == 0) { - $sPathName = PATH_DOCUMENT . $appId . PATH_SEP; - $sFileName = $sAppDocUid . "_".$iDocVersion. '.' . $ext; - G::uploadFile($fileObj['tempName'], $sPathName, $sFileName); + $sPathName = PATH_DOCUMENT . G::getPathFromUID($appId) . PATH_SEP; + $file = G::getPathFromFileUID($appId, $sAppDocUid); + $sPathName .= $file[0]; + $sFileName = $file[1] . "_" . $iDocVersion . '.' . $ext; + + G::uploadFile($fileObj['tempName'], $sPathName, $sFileName); //upload //Plugin Hook PM_UPLOAD_DOCUMENT for upload document $oPluginRegistry =& PMPluginRegistry::getSingleton(); diff --git a/workflow/engine/methods/appFolder/appFolderSaveDocument.php b/workflow/engine/methods/appFolder/appFolderSaveDocument.php index 32984d8c1..35e9db341 100755 --- a/workflow/engine/methods/appFolder/appFolderSaveDocument.php +++ b/workflow/engine/methods/appFolder/appFolderSaveDocument.php @@ -123,7 +123,7 @@ try { //save the file if (!empty($_FILES['form'])) { if ($_FILES['form']['error']['APP_DOC_FILENAME'] == 0) { - $sPathName = PATH_DOCUMENT . $appId . PATH_SEP; + $sPathName = PATH_DOCUMENT . G::getPathFromUID($appId) . PATH_SEP; $sFileName = $sAppDocUid . "_" . $iDocVersion . '.' . $ext; G::uploadFile($_FILES['form']['tmp_name']['APP_DOC_FILENAME'], $sPathName, $sFileName); diff --git a/workflow/engine/methods/cases/casesGenerateDocumentPage_Ajax.php b/workflow/engine/methods/cases/casesGenerateDocumentPage_Ajax.php index f249c92b4..9aed7a922 100644 --- a/workflow/engine/methods/cases/casesGenerateDocumentPage_Ajax.php +++ b/workflow/engine/methods/cases/casesGenerateDocumentPage_Ajax.php @@ -53,9 +53,9 @@ function casesShowOuputDocumentExist ($url) $ver = '_1'; } - $realPath = PATH_DOCUMENT . $oAppDocument->Fields['APP_UID'] . '/outdocs/' . $sAppDocUid . $ver . '.' . $ext; - $realPath1 = PATH_DOCUMENT . $oAppDocument->Fields['APP_UID'] . '/outdocs/' . $info['basename'] . $ver . '.' . $ext; - $realPath2 = PATH_DOCUMENT . $oAppDocument->Fields['APP_UID'] . '/outdocs/' . $info['basename'] . '.' . $ext; + $realPath = PATH_DOCUMENT . G::getPathFromUID($oAppDocument->Fields['APP_UID']) . '/outdocs/' . $sAppDocUid . $ver . '.' . $ext; + $realPath1 = PATH_DOCUMENT . G::getPathFromUID($oAppDocument->Fields['APP_UID']) . '/outdocs/' . $info['basename'] . $ver . '.' . $ext; + $realPath2 = PATH_DOCUMENT . G::getPathFromUID($oAppDocument->Fields['APP_UID']) . '/outdocs/' . $info['basename'] . '.' . $ext; $sw_file_exists = false; if (file_exists( $realPath )) { $sw_file_exists = true; diff --git a/workflow/engine/methods/cases/cases_SaveData.php b/workflow/engine/methods/cases/cases_SaveData.php index 6f56ae41b..3e8ed85a2 100755 --- a/workflow/engine/methods/cases/cases_SaveData.php +++ b/workflow/engine/methods/cases/cases_SaveData.php @@ -225,6 +225,7 @@ try { //Get the Custom Folder ID (create if necessary) $oFolder = new AppFolder(); + $documentFileStructure = $oFolder->getFolderStructure(); $aFields = array ("APP_UID" => $_SESSION["APPLICATION"],"DEL_INDEX" => $_SESSION["INDEX"],"USR_UID" => $_SESSION["USER_LOGGED"],"DOC_UID" => $indocUid,"APP_DOC_TYPE" => "INPUT","APP_DOC_CREATE_DATE" => date( "Y-m-d H:i:s" ),"APP_DOC_COMMENT" => "","APP_DOC_TITLE" => "","APP_DOC_FILENAME" => $arrayFileName[$i],"FOLDER_UID" => $oFolder->createFromPath( $aID["INP_DOC_DESTINATION_PATH"] ),"APP_DOC_TAGS" => $oFolder->parseTags( $aID["INP_DOC_TAGS"] ),"APP_DOC_FIELDNAME" => $fieldName ); @@ -240,9 +241,9 @@ try { $sAppDocUid = $oAppDocument->getAppDocUid(); $aInfo = pathinfo( $oAppDocument->getAppDocFilename() ); $sExtension = ((isset( $aInfo["extension"] )) ? $aInfo["extension"] : ""); - $sPathName = PATH_DOCUMENT . $_SESSION["APPLICATION"] . PATH_SEP; + $pathUID = G::getPathFromUID($_SESSION["APPLICATION"]); + $sPathName = PATH_DOCUMENT . $pathUID . PATH_SEP;// . $documentFileStructure; $sFileName = $sAppDocUid . "_" . $iDocVersion . "." . $sExtension; - G::uploadFile( $arrayFileTmpName[$i], $sPathName, $sFileName ); //Plugin Hook PM_UPLOAD_DOCUMENT for upload document diff --git a/workflow/engine/methods/cases/cases_ShowDocument.php b/workflow/engine/methods/cases/cases_ShowDocument.php index 3798877aa..17f0b4fc5 100755 --- a/workflow/engine/methods/cases/cases_ShowDocument.php +++ b/workflow/engine/methods/cases/cases_ShowDocument.php @@ -29,6 +29,9 @@ require_once ("classes/model/AppDocumentPeer.php"); +//v = Version +//a = Case UID + $oAppDocument = new AppDocument(); if (! isset( $_GET['v'] )) { //Load last version of the document @@ -42,7 +45,7 @@ $oAppDocument->Fields = $oAppDocument->load( $_GET['a'], $docVersion ); $sAppDocUid = $oAppDocument->getAppDocUid(); $iDocVersion = $oAppDocument->getDocVersion(); $info = pathinfo( $oAppDocument->getAppDocFilename() ); -$ext = $info['extension']; +$ext = (isset($info['extension'])?$info['extension']:'');//BUG fix: must handle files without any extension if (isset( $_GET['b'] )) { if ($_GET['b'] == '0') { @@ -54,8 +57,11 @@ if (isset( $_GET['b'] )) { $bDownload = true; } -$realPath = PATH_DOCUMENT . $oAppDocument->Fields['APP_UID'] . '/' . $sAppDocUid . '_' . $iDocVersion . '.' . $ext; -$realPath1 = PATH_DOCUMENT . $oAppDocument->Fields['APP_UID'] . '/' . $sAppDocUid . '.' . $ext; +$app_uid = G::getPathFromUID($oAppDocument->Fields['APP_UID']); +$file = G::getPathFromFileUID($oAppDocument->Fields['APP_UID'], $sAppDocUid); + +$realPath = PATH_DOCUMENT . $app_uid . '/' . $file[0] . $file[1] . '_' . $iDocVersion . '.' . $ext; +$realPath1 = PATH_DOCUMENT . $app_uid . '/' . $file[0] . $file[1] . '.' . $ext; $sw_file_exists = false; if (file_exists( $realPath )) { $sw_file_exists = true; @@ -65,7 +71,7 @@ if (file_exists( $realPath )) { } if (! $sw_file_exists) { - $error_message = "'" . $oAppDocument->Fields['APP_DOC_FILENAME'] . "' " . G::LoadTranslation( 'ID_ERROR_STREAMING_FILE' ); + $error_message = "'" .$realPath." " .$realPath1." ". $oAppDocument->Fields['APP_DOC_FILENAME'] . "' " . G::LoadTranslation( 'ID_ERROR_STREAMING_FILE' ); if ((isset( $_POST['request'] )) && ($_POST['request'] == true)) { $res['success'] = 'failure'; $res['message'] = $error_message; @@ -83,7 +89,7 @@ if (! $sw_file_exists) { $res['message'] = $oAppDocument->Fields['APP_DOC_FILENAME']; print G::json_encode( $res ); } else { - G::streamFile( $realPath, $bDownload, $oAppDocument->Fields['APP_DOC_FILENAME'] ); + G::streamFile( $realPath, $bDownload, $oAppDocument->Fields['APP_DOC_FILENAME'] ); //download } } diff --git a/workflow/engine/methods/cases/cases_ShowOutputDocument.php b/workflow/engine/methods/cases/cases_ShowOutputDocument.php index 3f0b1014f..ee4620a00 100755 --- a/workflow/engine/methods/cases/cases_ShowOutputDocument.php +++ b/workflow/engine/methods/cases/cases_ShowOutputDocument.php @@ -48,9 +48,9 @@ $ver = (isset( $_GET['v'] ) && $_GET['v'] != '') ? '_' . $_GET['v'] : ''; if (! $ver) //This code is in the case the outputdocument won't be versioned $ver = '_1'; -$realPath = PATH_DOCUMENT . $oAppDocument->Fields['APP_UID'] . '/outdocs/' . $sAppDocUid . $ver . '.' . $ext; -$realPath1 = PATH_DOCUMENT . $oAppDocument->Fields['APP_UID'] . '/outdocs/' . $info['basename'] . $ver . '.' . $ext; -$realPath2 = PATH_DOCUMENT . $oAppDocument->Fields['APP_UID'] . '/outdocs/' . $info['basename'] . '.' . $ext; +$realPath = PATH_DOCUMENT . G::getPathFromUID($oAppDocument->Fields['APP_UID']) . '/outdocs/' . $sAppDocUid . $ver . '.' . $ext; +$realPath1 = PATH_DOCUMENT . G::getPathFromUID($oAppDocument->Fields['APP_UID']) . '/outdocs/' . $info['basename'] . $ver . '.' . $ext; +$realPath2 = PATH_DOCUMENT . G::getPathFromUID($oAppDocument->Fields['APP_UID']) . '/outdocs/' . $info['basename'] . '.' . $ext; $sw_file_exists = false; if (file_exists( $realPath )) { diff --git a/workflow/engine/methods/cases/cases_ShowToReviseOutputDocument.php b/workflow/engine/methods/cases/cases_ShowToReviseOutputDocument.php index f1134d4d0..b10ce629a 100755 --- a/workflow/engine/methods/cases/cases_ShowToReviseOutputDocument.php +++ b/workflow/engine/methods/cases/cases_ShowToReviseOutputDocument.php @@ -57,6 +57,6 @@ if (! isset( $_GET['ext'] )) { } } -$realPath = PATH_DOCUMENT . $_SESSION['APPLICATION'] . '/outdocs/' . $info['basename'] . '.' . $ext; +$realPath = PATH_DOCUMENT . G::getPathFromUID($_SESSION['APPLICATION']) . '/outdocs/' . $info['basename'] . '.' . $ext; G::streamFile( $realPath, true ); diff --git a/workflow/engine/methods/cases/cases_Step.php b/workflow/engine/methods/cases/cases_Step.php index 18760b156..ba01e13af 100755 --- a/workflow/engine/methods/cases/cases_Step.php +++ b/workflow/engine/methods/cases/cases_Step.php @@ -411,7 +411,7 @@ try { $sFilename = $aFields['APP_DOC_UID'] . "_" . $lastDocVersion; - $pathOutput = PATH_DOCUMENT . $_SESSION['APPLICATION'] . PATH_SEP . 'outdocs' . PATH_SEP; + $pathOutput = PATH_DOCUMENT . G::getPathFromUID($_SESSION['APPLICATION']) . PATH_SEP . 'outdocs' . PATH_SEP; G::mk_dir( $pathOutput ); switch ($aOD['OUT_DOC_TYPE']) { case 'HTML': @@ -518,7 +518,7 @@ try { if ($oPluginRegistry->existsTrigger( PM_UPLOAD_DOCUMENT ) && class_exists( 'uploadDocumentData' )) { $triggerDetail = $oPluginRegistry->getTriggerInfo( PM_UPLOAD_DOCUMENT ); - $sPathName = PATH_DOCUMENT . $_SESSION['APPLICATION'] . PATH_SEP; + $sPathName = PATH_DOCUMENT . G::getPathFromUID($_SESSION['APPLICATION']) . PATH_SEP; $oData['APP_UID'] = $_SESSION['APPLICATION']; $oData['ATTACHMENT_FOLDER'] = true; diff --git a/workflow/engine/methods/cases/cases_SupervisorSaveDocument.php b/workflow/engine/methods/cases/cases_SupervisorSaveDocument.php index 0dc8db47b..df68699c3 100755 --- a/workflow/engine/methods/cases/cases_SupervisorSaveDocument.php +++ b/workflow/engine/methods/cases/cases_SupervisorSaveDocument.php @@ -36,7 +36,7 @@ try { //save the file if (! empty( $_FILES['form'] )) { if ($_FILES['form']['error']['APP_DOC_FILENAME'] == 0) { - $sPathName = PATH_DOCUMENT . $_GET['APP_UID'] . PATH_SEP; + $sPathName = PATH_DOCUMENT . G::getPathFromUID($_GET['APP_UID']) . PATH_SEP; $sFileName = $sAppDocUid . '.' . $ext; G::uploadFile( $_FILES['form']['tmp_name']['APP_DOC_FILENAME'], $sPathName, $sFileName ); diff --git a/workflow/engine/methods/services/upload.php b/workflow/engine/methods/services/upload.php index b3e07f7a8..93847b7e8 100755 --- a/workflow/engine/methods/services/upload.php +++ b/workflow/engine/methods/services/upload.php @@ -106,7 +106,7 @@ if (isset( $_FILES ) && $_FILES["ATTACH_FILE"]["error"] == 0) { $ext = (isset( $info["extension"] )) ? $info["extension"] : ""; //Save the file - echo $sPathName = PATH_DOCUMENT . $sAppUid . PATH_SEP; + echo $sPathName = PATH_DOCUMENT . G::getPathFromUID($sAppUid) . PATH_SEP; echo $sFileName = $sAppDocUid . "_" . $iDocVersion . "." . $ext; print G::uploadFile( $_FILES["ATTACH_FILE"]["tmp_name"], $sPathName, $sFileName ); print ("* The file " . $_FILES["ATTACH_FILE"]["name"] . " was uploaded successfully in case " . $sAppUid . " as input document..\n") ; diff --git a/workflow/engine/methods/tracker/tracker_ShowDocument.php b/workflow/engine/methods/tracker/tracker_ShowDocument.php index a8bcc5cba..8837cdd5b 100755 --- a/workflow/engine/methods/tracker/tracker_ShowDocument.php +++ b/workflow/engine/methods/tracker/tracker_ShowDocument.php @@ -47,8 +47,8 @@ if (isset( $_GET['b'] )) { $bDownload = true; } -$realPath = PATH_DOCUMENT . $oAppDocument->Fields['APP_UID'] . '/' . $sAppDocUid . '_' . $iDocVersion . '.' . $ext; -$realPath1 = PATH_DOCUMENT . $oAppDocument->Fields['APP_UID'] . '/' . $sAppDocUid . '.' . $ext; +$realPath = PATH_DOCUMENT . G::getPathFromUID($oAppDocument->Fields['APP_UID']) . '/' . $sAppDocUid . '_' . $iDocVersion . '.' . $ext; +$realPath1 = PATH_DOCUMENT . G::getPathFromUID($oAppDocument->Fields['APP_UID']) . '/' . $sAppDocUid . '.' . $ext; $sw_file_exists = false; if (file_exists( $realPath )) { $sw_file_exists = true; diff --git a/workflow/engine/methods/tracker/tracker_ShowOutputDocument.php b/workflow/engine/methods/tracker/tracker_ShowOutputDocument.php index 6b0b5e830..4aba2f5bd 100755 --- a/workflow/engine/methods/tracker/tracker_ShowOutputDocument.php +++ b/workflow/engine/methods/tracker/tracker_ShowOutputDocument.php @@ -47,9 +47,9 @@ $ver = (isset( $_GET['v'] ) && $_GET['v'] != '') ? '_' . $_GET['v'] : ''; if (! $ver) //This code is in the case the outputdocument won't be versioned $ver = '_1'; -$realPath = PATH_DOCUMENT . $oAppDocument->Fields['APP_UID'] . '/outdocs/' . $sAppDocUid . $ver . '.' . $ext; -$realPath1 = PATH_DOCUMENT . $oAppDocument->Fields['APP_UID'] . '/outdocs/' . $info['basename'] . $ver . '.' . $ext; -$realPath2 = PATH_DOCUMENT . $oAppDocument->Fields['APP_UID'] . '/outdocs/' . $info['basename'] . '.' . $ext; +$realPath = PATH_DOCUMENT . G::getPathFromUID($oAppDocument->Fields['APP_UID']) . '/outdocs/' . $sAppDocUid . $ver . '.' . $ext; +$realPath1 = PATH_DOCUMENT . G::getPathFromUID($oAppDocument->Fields['APP_UID']) . '/outdocs/' . $info['basename'] . $ver . '.' . $ext; +$realPath2 = PATH_DOCUMENT . G::getPathFromUID($oAppDocument->Fields['APP_UID']) . '/outdocs/' . $info['basename'] . '.' . $ext; $sw_file_exists = false; if (file_exists( $realPath )) { $sw_file_exists = true;