diff --git a/workflow/engine/classes/class.wsTools.php b/workflow/engine/classes/class.wsTools.php index 0717333be..8cc4fd197 100755 --- a/workflow/engine/classes/class.wsTools.php +++ b/workflow/engine/classes/class.wsTools.php @@ -111,70 +111,18 @@ class workspaceTools $final = $stop - $start; CLI::logging("<*> Backup log files Process took $final seconds.\n"); - CLI::logging("> Updating Files Manager...\n\n"); - $this->upgradeFilesManager($workSpace); - $start = microtime(true); CLI::logging("> Migrate new lists...\n"); $this->migrateList($workSpace); $stop = microtime(true); $final = $stop - $start; CLI::logging("<*> Migrate new lists Process took $final seconds.\n"); - } - /** - * Function upgradeFilesManager - * access public - */ - public function upgradeFilesManager($workSpace) { - $this->initPropel(true); - $con = Propel::getConnection("root"); - $stmt = $con->createStatement(); - $sDirectory = glob(PATH_DATA . "sites/" . $workSpace . "/" . "mailTemplates/*"); - $sDirectoryPublic = glob(PATH_DATA . "sites/" . $workSpace . "/" . "public/*"); - $files = array(); - foreach($sDirectory as $mailTemplate) { - if (is_dir($mailTemplate)) { - $inner_files = listFiles($mailTemplate); - if (is_array($inner_files)) $files = array_merge($files, $inner_files); - } - if (is_file($mailTemplate)) { - array_push($files, $mailTemplate); - } - } - foreach($sDirectoryPublic as $publicFile) { - if (is_dir($publicFile)) { - $inner_files = listFiles($publicFile); - if (is_array($inner_files)) $files = array_merge($files, $inner_files); - } - if (is_file($publicFile)) { - array_push($files, $publicFile); - } - } - $sDir = PATH_DATA . "sites/" . $workSpace . "/" . "mailTemplates/"; - $sDirPublic = PATH_DATA . "sites/" . $workSpace . "/" . "public/"; - foreach ($files as $aFile) { - if (strpos($aFile, $sDir) !== false){ - $processUid = current(explode("/", str_replace($sDir,'',$aFile))); - } else { - $processUid = current(explode("/", str_replace($sDirPublic,'',$aFile))); - } - $sql = "SELECT PROCESS_FILES.PRF_PATH FROM PROCESS_FILES WHERE PROCESS_FILES.PRF_PATH='" . $aFile ."'"; - $appRows = $stmt->executeQuery($sql, ResultSet::FETCHMODE_ASSOC); - $fileUid = ''; - foreach ($appRows as $row) { - $fileUid = $row["PRF_PATH"]; - } - if ($fileUid !== $aFile) { - $sPkProcessFiles = G::generateUniqueID(); - $sDate = date('Y-m-d H:i:s'); - $sql = "INSERT INTO PROCESS_FILES (PRF_UID, PRO_UID, USR_UID, PRF_UPDATE_USR_UID, - PRF_PATH, PRF_TYPE, PRF_EDITABLE, PRF_CREATE_DATE, PRF_UPDATE_DATE) - VALUES ('".$sPkProcessFiles."', '".$processUid."', '00000000000000000000000000000001', '', - '".$aFile."', 'file', 'true', '".$sDate."', NULL)"; - $stmt->executeQuery($sql, ResultSet::FETCHMODE_ASSOC); - } - } + $start = microtime(true); + CLI::logging("> Updating Files Manager...\n"); + $this->processFilesUpgrade(); + $stop = microtime(true); + CLI::logging("<*> Updating Files Manager took " . ($stop - $start) . " seconds.\n"); } /** @@ -1564,10 +1512,10 @@ class workspaceTools $version = explode('-', $version); $versionPresent = ( isset($version[0])) ? $version[0] : ''; CLI::logging(CLI::warning(" - Warning: A workspace from a newer version of ProcessMaker can NOT be restored in an older version of - ProcessMaker. For example, restoring from v.3.0 to v.2.5 will not work. However, it may be possible - to restore a workspace from an older version to an newer version of ProcessMaker, although error - messages may be displayed during the restore process. Make sure to run the \"processmaker cacheview-repair\" + Warning: A workspace from a newer version of ProcessMaker can NOT be restored in an older version of + ProcessMaker. For example, restoring from v.3.0 to v.2.5 will not work. However, it may be possible + to restore a workspace from an older version to an newer version of ProcessMaker, although error + messages may be displayed during the restore process. Make sure to run the \"processmaker cacheview-repair\" and \"processmaker migrate-new-cases-lists\" commands after restoring a workspace.") . "\n"); foreach ($metaFiles as $metaFile) { @@ -2226,5 +2174,31 @@ class workspaceTools throw $e; } } + + /** + * Process-Files upgrade + * + * return void + */ + public function processFilesUpgrade() + { + try { + if (!defined("PATH_DATA_MAILTEMPLATES")) { + define("PATH_DATA_MAILTEMPLATES", PATH_DATA_SITE . "mailTemplates" . PATH_SEP); + } + + if (!defined("PATH_DATA_PUBLIC")) { + define("PATH_DATA_PUBLIC", PATH_DATA_SITE . "public" . PATH_SEP); + } + + $this->initPropel(true); + + $filesManager = new \ProcessMaker\BusinessModel\FilesManager(); + + $filesManager->processFilesUpgrade(); + } catch (Exception $e) { + throw $e; + } + } } diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/FilesManager.php b/workflow/engine/src/ProcessMaker/BusinessModel/FilesManager.php index 14d342d46..3ea4b80e3 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/FilesManager.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/FilesManager.php @@ -194,7 +194,7 @@ class FilesManager $directory = $sMainDirectory. PATH_SEP . $sSubDirectory . $aData['prf_filename']; throw new \Exception(\G::LoadTranslation("ID_EXISTS_FILE", array($directory))); } - + if (!file_exists($sCheckDirectory)) { $sPkProcessFiles = \G::generateUniqueID(); $oProcessFiles = new \ProcessFiles(); @@ -242,31 +242,31 @@ class FilesManager throw $e; } } - + public function addProcessFilesManagerInDb($aData) { try { $oProcessFiles = new \ProcessFiles(); $aData = array_change_key_case($aData, CASE_UPPER); $oProcessFiles->fromArray($aData, \BasePeer::TYPE_FIELDNAME); - + if($this->existsProcessFile($aData['PRF_UID'])) { $sPkProcessFiles = \G::generateUniqueID(); $oProcessFiles->setPrfUid($sPkProcessFiles); - + $sDirectory = PATH_DATA_MAILTEMPLATES . $aData['PRO_UID'] . PATH_SEP . basename($aData['PRF_PATH']); $oProcessFiles->setPrfPath($sDirectory); - + $emailEvent = new \ProcessMaker\BusinessModel\EmailEvent(); $emailEvent->updatePrfUid($aData['PRF_UID'], $sPkProcessFiles, $aData['PRO_UID']); } - + $result = $oProcessFiles->save(); } catch (Exception $e) { throw $e; } } - + public function existsProcessFile($prfUid) { try { @@ -462,10 +462,10 @@ class FilesManager if ($path == '') { throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_FOR", array('prf_uid'))); } - + $sFile = end(explode("/",$path)); $path = PATH_DATA_MAILTEMPLATES.$sProcessUID.DIRECTORY_SEPARATOR.$sFile; - + if (file_exists($path) && !is_dir($path)) { unlink($path); } @@ -601,4 +601,115 @@ class FilesManager throw $e; } } + + /** + * Process-Files upgrade + * + * @param string $projectUid Unique id of Project + * + * return void + */ + public function processFilesUpgrade($projectUid = "") + { + try { + //Set variables + $conf = new \Configuration(); + + //Create/Get PROCESS_FILES_CHECKED + $arrayProjectUid = array(); + + $configuration = \ConfigurationPeer::retrieveByPK("PROCESS_FILES_CHECKED", "", "", "", ""); + + if (is_null($configuration)) { + $result = $conf->create(array( + "CFG_UID" => "PROCESS_FILES_CHECKED", + "OBJ_UID" => "", + "CFG_VALUE" => serialize($arrayProjectUid), + "PRO_UID" => "", + "USR_UID" => "", + "APP_UID" => "" + )); + } else { + $arrayProjectUid = unserialize($configuration->getCfgValue()); + } + + //Set variables + $arrayPath = array("templates" => PATH_DATA_MAILTEMPLATES, "public" => PATH_DATA_PUBLIC); + $flagProjectUid = false; + + //Query + $criteria = new \Criteria("workflow"); + + $criteria->addSelectColumn(\BpmnProjectPeer::PRJ_UID); + + if ($projectUid != "") { + $criteria->add( + $criteria->getNewCriterion(\BpmnProjectPeer::PRJ_UID, $arrayProjectUid, \Criteria::NOT_IN)->addAnd( + $criteria->getNewCriterion(\BpmnProjectPeer::PRJ_UID, $projectUid, \Criteria::EQUAL)) + ); + } else { + $criteria->add(\BpmnProjectPeer::PRJ_UID, $arrayProjectUid, \Criteria::NOT_IN); + } + + $rsCriteria = \BpmnProjectPeer::doSelectRS($criteria); + $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC); + + while ($rsCriteria->next()) { + $row = $rsCriteria->getRow(); + + foreach ($arrayPath as $key => $value) { + $path = $key; + $dir = $value . $row["PRJ_UID"]; + + if (is_dir($dir)) { + if ($dirh = opendir($dir)) { + while (($file = readdir($dirh)) !== false) { + if ($file != "" && $file != "." && $file != "..") { + $f = $dir . PATH_SEP . $file; + + if (is_file($f)) { + $arrayProcessFilesData = $this->getFileManagerUid($f); + + if (is_null($arrayProcessFilesData["PRF_UID"])) { + rename($dir . PATH_SEP . $file, $dir . PATH_SEP . $file . ".tmp"); + + $arrayData = array( + "prf_path" => $path, + "prf_filename" => $file, + "prf_content" => "" + ); + + $arrayData = $this->addProcessFilesManager($row["PRJ_UID"], "00000000000000000000000000000001", $arrayData); + + rename($dir . PATH_SEP . $file . ".tmp", $dir . PATH_SEP . $file); + } + } + } + } + + closedir($dirh); + } + } + } + + $arrayProjectUid[$row["PRJ_UID"]] = $row["PRJ_UID"]; + $flagProjectUid = true; + } + + //Update PROCESS_FILES_CHECKED + if ($flagProjectUid) { + $result = $conf->update(array( + "CFG_UID" => "PROCESS_FILES_CHECKED", + "OBJ_UID" => "", + "CFG_VALUE" => serialize($arrayProjectUid), + "PRO_UID" => "", + "USR_UID" => "", + "APP_UID" => "" + )); + } + } catch (\Exception $e) { + throw $e; + } + } } + diff --git a/workflow/engine/src/ProcessMaker/Importer/Importer.php b/workflow/engine/src/ProcessMaker/Importer/Importer.php index cde85e5c0..10cf796b1 100755 --- a/workflow/engine/src/ProcessMaker/Importer/Importer.php +++ b/workflow/engine/src/ProcessMaker/Importer/Importer.php @@ -402,6 +402,11 @@ abstract class Importer $workflow->update($arrayWorkflowTables["process"]); + //Process-Files upgrade + $filesManager = new \ProcessMaker\BusinessModel\FilesManager(); + + $filesManager->processFilesUpgrade($projectUid); + //Return return $projectUid; } @@ -559,7 +564,7 @@ abstract class Importer throw $e; } } - + public function saveAs($prj_uid, $prj_name, $prj_description, $prj_category) { try { @@ -594,3 +599,4 @@ abstract class Importer } } } + diff --git a/workflow/engine/src/ProcessMaker/Project/Workflow.php b/workflow/engine/src/ProcessMaker/Project/Workflow.php index cefd7613b..e499b82cf 100755 --- a/workflow/engine/src/ProcessMaker/Project/Workflow.php +++ b/workflow/engine/src/ProcessMaker/Project/Workflow.php @@ -581,6 +581,26 @@ class Workflow extends Handler $oCaseTracker = new \CaseTracker(); $oCaseTrackerObject = new \CaseTrackerObject(); + //Update PROCESS_FILES_CHECKED + $configuration = \ConfigurationPeer::retrieveByPK("PROCESS_FILES_CHECKED", "", "", "", ""); + + if (!is_null($configuration)) { + $arrayProjectUid = unserialize($configuration->getCfgValue()); + + unset($arrayProjectUid[$sProcessUID]); + + $conf = new \Configuration(); + + $result = $conf->update(array( + "CFG_UID" => "PROCESS_FILES_CHECKED", + "OBJ_UID" => "", + "CFG_VALUE" => serialize($arrayProjectUid), + "PRO_UID" => "", + "USR_UID" => "", + "APP_UID" => "" + )); + } + //Delete the applications of process if ($flagRemoveCases) { $case = new \Cases();