diff --git a/workflow/engine/bin/tasks/cliWorkspaces.php b/workflow/engine/bin/tasks/cliWorkspaces.php index 689392806..8dc2477b1 100755 --- a/workflow/engine/bin/tasks/cliWorkspaces.php +++ b/workflow/engine/bin/tasks/cliWorkspaces.php @@ -505,47 +505,52 @@ function run_workspace_backup($args, $opts) { } function run_workspace_restore($args, $opts) { - $filename = $args[0]; + if (sizeof($args) > 0) { - G::verifyPath(PATH_DATA . 'upgrade', true); + $filename = $args[0]; - if (strpos($filename, "/") === false && strpos($filename, '\\') === false) { - $filename = PATH_DATA . "backups/$filename"; - if (!file_exists($filename) && substr_compare($filename, ".tar", -4, 4, true) != 0) - $filename .= ".tar"; - } - $info = array_key_exists("info", $opts); - $lang = array_key_exists("lang", $opts) ? $opts['lang'] : 'en'; - $port = array_key_exists("port", $opts) ? $opts['port'] : ''; - if ($info) { - workspaceTools::getBackupInfo($filename); + G::verifyPath(PATH_DATA . 'upgrade', true); + + if (strpos($filename, "/") === false && strpos($filename, '\\') === false) { + $filename = PATH_DATA . "backups/$filename"; + if (!file_exists($filename) && substr_compare($filename, ".tar", -4, 4, true) != 0) + $filename .= ".tar"; + } + $info = array_key_exists("info", $opts); + $lang = array_key_exists("lang", $opts) ? $opts['lang'] : 'en'; + $port = array_key_exists("port", $opts) ? $opts['port'] : ''; + if ($info) { + workspaceTools::getBackupInfo($filename); + } else { + CLI::logging("Restoring from $filename\n"); + $workspace = array_key_exists("workspace", $opts) ? $opts['workspace'] : NULL; + $overwrite = array_key_exists("overwrite", $opts); + $multiple = array_key_exists("multiple", $opts); + $dstWorkspace = isset($args[1]) ? $args[1] : null; + if(!empty($multiple)){ + if(!Bootstrap::isLinuxOs()){ + CLI::error("This is not a Linux enviroment, cannot use this multiple [-m] feature.\n"); + return; + } + multipleFilesBackup::letsRestore ($filename,$workspace,$dstWorkspace,$overwrite); + } + else{ + $anotherExtention = ".*"; //if there are files with and extra extention: e.g. .tar.number + $multiplefiles = glob($filename . $anotherExtention);// example: //shared/workflow_data/backups/myWorkspace.tar.* + if(count($multiplefiles) > 0) + { + CLI::error("Processmaker found these files: .\n"); + foreach($multiplefiles as $index => $value){ + CLI::logging($value . "\n"); + } + CLI::error("Please, you should use -m parameter to restore them.\n"); + return; + } + workspaceTools::restore($filename, $workspace, $dstWorkspace, $overwrite, $lang, $port ); + } + } } else { - CLI::logging("Restoring from $filename\n"); - $workspace = array_key_exists("workspace", $opts) ? $opts['workspace'] : NULL; - $overwrite = array_key_exists("overwrite", $opts); - $multiple = array_key_exists("multiple", $opts); - $dstWorkspace = isset($args[1]) ? $args[1] : null; - if(!empty($multiple)){ - if(!Bootstrap::isLinuxOs()){ - CLI::error("This is not a Linux enviroment, cannot use this multiple [-m] feature.\n"); - return; - } - multipleFilesBackup::letsRestore ($filename,$workspace,$dstWorkspace,$overwrite); - } - else{ - $anotherExtention = ".*"; //if there are files with and extra extention: e.g. .tar.number - $multiplefiles = glob($filename . $anotherExtention);// example: //shared/workflow_data/backups/myWorkspace.tar.* - if(count($multiplefiles) > 0) - { - CLI::error("Processmaker found these files: .\n"); - foreach($multiplefiles as $index => $value){ - CLI::logging($value . "\n"); - } - CLI::error("Please, you should use -m parameter to restore them.\n"); - return; - } - workspaceTools::restore($filename, $workspace, $dstWorkspace, $overwrite, $lang, $port ); - } + throw new Exception("No workspace specified for restore"); } } diff --git a/workflow/engine/classes/class.case.php b/workflow/engine/classes/class.case.php index 5d9983008..c651f551e 100755 --- a/workflow/engine/classes/class.case.php +++ b/workflow/engine/classes/class.case.php @@ -594,7 +594,11 @@ class Cases $aFields['CURRENT_USER'][]= $oCurUser->getUsrFirstname() . ' ' . $oCurUser->getUsrLastname(); $aFields['TAS_UID'].= $value['TAS_UID'].'-'; } - $aFields['CURRENT_USER'] = implode(" - ", array_values($aFields['CURRENT_USER'])); + $aFields['CURRENT_USER'] = implode(" - ", array_values($aFields['CURRENT_USER'])); + $tasksArray = array_filter(explode("-",$aFields['TAS_UID'])); + if(count($tasksArray) == 1) { + $aFields['TAS_UID'] = $tasksArray[0]; + } } else { $oCurUser->load($aAppDel['USR_UID']); $aFields['CURRENT_USER'] = $oCurUser->getUsrFirstname() . ' ' . $oCurUser->getUsrLastname(); diff --git a/workflow/engine/classes/class.cli.php b/workflow/engine/classes/class.cli.php index 21b0c7077..b26865a09 100755 --- a/workflow/engine/classes/class.cli.php +++ b/workflow/engine/classes/class.cli.php @@ -150,17 +150,36 @@ class CLI $tasks = join( "\n", $tasks ); echo $tasks . "\n\n"; } else { - $valid_args = array (); - foreach (self::$tasks[$taskName]['args'] as $arg => $data) { - $arg = strtoupper( $arg ); - if ($data['multiple']) { - $arg = "$arg..."; - } - if ($data['optional']) { - $arg = "[$arg]"; - } - $valid_args[] = $arg; + $options = array(); + $tasks = array(); + ksort( self::$tasks ); + foreach (self::$tasks as $name => $data) { + $description = explode( "\n", $data['description'] ); + $options[] = "$name"; } + if (!in_array($taskName, $options)) { + echo "\nThe task does not exist \n"; + echo "Use one of the following tasks:\n"; + $tasks = array (); + ksort( self::$tasks ); + foreach (self::$tasks as $name => $data) { + $description = explode( "\n", $data['description'] ); + $tasks[] = " $name"; + } + $tasks = join( "\n", $tasks ); + echo $tasks . "\n\n"; + } else{ + $valid_args = array (); + foreach (self::$tasks[$taskName]['args'] as $arg => $data) { + $arg = strtoupper( $arg ); + if ($data['multiple']) { + $arg = "$arg..."; + } + if ($data['optional']) { + $arg = "[$arg]"; + } + $valid_args[] = $arg; + } $valid_args = join( " ", $valid_args ); $description = explode( "\n", self::$tasks[$taskName]['description'] ); $taskDescription = trim( array_shift( $description ) ); @@ -195,6 +214,7 @@ EOT; } echo $message . "\n"; } + } } /** diff --git a/workflow/engine/classes/class.multipleFilesBackup.php b/workflow/engine/classes/class.multipleFilesBackup.php index fa955c7bc..dc8b5bcae 100644 --- a/workflow/engine/classes/class.multipleFilesBackup.php +++ b/workflow/engine/classes/class.multipleFilesBackup.php @@ -14,14 +14,14 @@ class multipleFilesBackup private $dir_to_compress = ""; private $filename = "backUpProcessMaker.tar"; private $fileSize = "1000"; - // 1 GB by default. + // 1 GB by default. private $sizeDescriptor = "m"; - //megabytes + //megabytes private $tempDirectories = array (); - /* Constructor - * @filename contains the path and filename of the comppress file(s). - * @size got the Max size of the compressed files, by default if the $size less to zero will mantains 1000 Mb as Max size. + /* Constructor + * @filename contains the path and filename of the comppress file(s). + * @size got the Max size of the compressed files, by default if the $size less to zero will mantains 1000 Mb as Max size. */ public function multipleFilesBackup ($filename, $size) { @@ -33,24 +33,24 @@ class multipleFilesBackup } } - /* Gets workspace information enough to make its backup. + /* Gets workspace information enough to make its backup. * @workspace contains the workspace to be add to the commpression process. */ public function addToBackup ($workspace) { - //verifing if workspace exists. + //verifing if workspace exists. if (! $workspace->workspaceExists()) { echo "Workspace {$workspace->name} not found\n"; return false; } - //create destination path + //create destination path if (! file_exists( PATH_DATA . "upgrade/" )) { mkdir( PATH_DATA . "upgrade/" ); } $tempDirectory = PATH_DATA . "upgrade/" . basename( tempnam( __FILE__, '' ) ); mkdir( $tempDirectory ); $metadata = $workspace->getMetadata(); - CLI::logging( "Temporing up database...\n" ); + CLI::logging( "Creating temporary files on database...\n" ); $metadata["databases"] = $workspace->exportDatabase( $tempDirectory ); $metadata["directories"] = array ("{$workspace->name}.files"); $metadata["version"] = 1; @@ -65,8 +65,8 @@ class multipleFilesBackup $this->tempDirectories[] = $tempDirectory; } - /* Add a directory containing Db files or info files to be commpressed - * @directory the name and path of the directory to be add to the commpression process. + /* Add a directory containing Db files or info files to be commpressed + * @directory the name and path of the directory to be add to the commpression process. */ private function addDirToBackup ($directory) { @@ -75,37 +75,37 @@ class multipleFilesBackup } } - // Commpress the DB and files into a single or several files with numerical series extentions + // Commpress the DB and files into a single or several files with numerical series extentions public function letsBackup () { - // creating command + // creating command $CommpressCommand = "tar czv "; $CommpressCommand .= $this->dir_to_compress; $CommpressCommand .= "| split -b "; $CommpressCommand .= $this->fileSize; $CommpressCommand .= "m -d - "; $CommpressCommand .= $this->filename . "."; - //executing command to create the files + //executing command to create the files echo exec( $CommpressCommand ); - //Remove leftovers dirs. + //Remove leftovers dirs. foreach ($this->tempDirectories as $tempDirectory) { CLI::logging( "Deleting: " . $tempDirectory . "\n" ); G::rm_dir( $tempDirectory ); } } - /* Restore from file(s) commpressed by letsBackup function, into a temporary directory - * @ filename got the name and path of the compressed file(s), if there are many files with file extention as a numerical series, the extention should be discriminated. - * @ srcWorkspace contains the workspace to be restored. - * @ dstWorkspace contains the workspace to be overwriting. - * @ overwrite got the option true if the workspace will be overwrite. + /* Restore from file(s) commpressed by letsBackup function, into a temporary directory + * @ filename got the name and path of the compressed file(s), if there are many files with file extention as a numerical series, the extention should be discriminated. + * @ srcWorkspace contains the workspace to be restored. + * @ dstWorkspace contains the workspace to be overwriting. + * @ overwrite got the option true if the workspace will be overwrite. */ static public function letsRestore ($filename, $srcWorkspace, $dstWorkspace = null, $overwrite = true) { - // Needed info: - // TEMPDIR /shared/workflow_data/upgrade/ - // BACKUPS /shared/workflow_data/backups/ - // Creating command cat myfiles_split.tgz_* | tar xz + // Needed info: + // TEMPDIR /shared/workflow_data/upgrade/ + // BACKUPS /shared/workflow_data/backups/ + // Creating command cat myfiles_split.tgz_* | tar xz $DecommpressCommand = "cat " . $filename . ".* "; $DecommpressCommand .= " | tar xzv"; @@ -116,13 +116,13 @@ class multipleFilesBackup } else { throw new Exception( "Could not create directory:" . $parentDirectory ); } - //Extract all backup files, including database scripts and workspace files + //Extract all backup files, including database scripts and workspace files CLI::logging( "Restoring into " . $tempDirectory . "\n" ); chdir( $tempDirectory ); echo exec( $DecommpressCommand ); CLI::logging( "\nUncompressed into: " . $tempDirectory . "\n" ); - //Search for metafiles in the new standard (the old standard would contain meta files. + //Search for metafiles in the new standard (the old standard would contain meta files. $metaFiles = glob( $tempDirectory . "/*.meta" ); if (empty( $metaFiles )) { $metaFiles = glob( $tempDirectory . "/*.txt" ); diff --git a/workflow/engine/classes/class.wsTools.php b/workflow/engine/classes/class.wsTools.php index 1b10c32d3..0fd712208 100755 --- a/workflow/engine/classes/class.wsTools.php +++ b/workflow/engine/classes/class.wsTools.php @@ -1564,9 +1564,11 @@ class workspaceTools $version = explode('-', $version); $versionPresent = ( isset($version[0])) ? $version[0] : ''; CLI::logging(CLI::warning(" - Note.- If you try to execute a restore from a generated backup on a recent version of Processmaker - than version you are using currently to restore it, it may be occur errors on the restore process, - it shouldn't be restaured generated backups on later versions than version when the restore is executed") . "\n"); + 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) { $metadata = G::json_decode(file_get_contents($metaFile)); diff --git a/workflow/engine/methods/cases/cases_Open.php b/workflow/engine/methods/cases/cases_Open.php index f279a9bf6..3f3f19d5b 100755 --- a/workflow/engine/methods/cases/cases_Open.php +++ b/workflow/engine/methods/cases/cases_Open.php @@ -169,6 +169,17 @@ try { /* Redirect to next step */ unset( $_SESSION['bNoShowSteps'] ); + + /* Execute Before Triggers for first Task*/ + $oStep = new Step; + $oStep = $oStep->loadByProcessTaskPosition($_SESSION['PROCESS'], $_SESSION['TASK'], 1); + if($oStep) { + $triggerFields["APP_DATA"] = $oCase->ExecuteTriggers( $_SESSION['TASK'], $oStep->getStepTypeObj(), $oStep->getStepUidObj(), 'BEFORE', $aFields['APP_DATA'] ); + $oCase->updateCase( $_SESSION['APPLICATION'], $triggerFields ); + $_SESSION['beforeTriggersExecuted'] = true; + } + /*end Execute Before Triggers for first Task*/ + $aNextStep = $oCase->getNextStep( $_SESSION['PROCESS'], $_SESSION['APPLICATION'], $_SESSION['INDEX'], $_SESSION['STEP_POSITION'] ); $sPage = $aNextStep['PAGE']; G::header( 'location: ' . $sPage ); diff --git a/workflow/engine/methods/cases/cases_Step.php b/workflow/engine/methods/cases/cases_Step.php index 9b273a682..faa18cd32 100755 --- a/workflow/engine/methods/cases/cases_Step.php +++ b/workflow/engine/methods/cases/cases_Step.php @@ -159,7 +159,11 @@ if ($flagExecuteBeforeTriggers) { if (! isset( $_SESSION['_NO_EXECUTE_TRIGGERS_'] )) { //Execute before triggers - Start - $Fields['APP_DATA'] = $oCase->ExecuteTriggers( $_SESSION['TASK'], $_GET['TYPE'], $_GET['UID'], 'BEFORE', $Fields['APP_DATA'] ); + if (!isset($_SESSION['beforeTriggersExecuted'])) { + $Fields['APP_DATA'] = $oCase->ExecuteTriggers( $_SESSION['TASK'], $_GET['TYPE'], $_GET['UID'], 'BEFORE', $Fields['APP_DATA'] ); + } else { + unset($_SESSION['beforeTriggersExecuted']); + } //Execute before triggers - End } else { unset( $_SESSION['_NO_EXECUTE_TRIGGERS_'] );