diff --git a/framework/src/Maveriks/Util/Common.php b/framework/src/Maveriks/Util/Common.php index 2ccbd9c28..afe8a6b75 100644 --- a/framework/src/Maveriks/Util/Common.php +++ b/framework/src/Maveriks/Util/Common.php @@ -52,58 +52,43 @@ class Common } $files = glob("$path/$singlePattern", $flags); - $dirs = glob("$path/*", GLOB_MARK|GLOB_ONLYDIR|GLOB_NOSORT); + $dirs = glob("$path/*", GLOB_MARK | GLOB_ONLYDIR | GLOB_NOSORT); - if(is_array($dirs)){ + if (is_array($dirs)) { foreach ($dirs as $dir) { $files = array_merge($files, self::rglob("$dir/$singlePattern", $flags)); } } if ($onlyFiles) { - $files = array_filter($files, function($v) { return is_dir($v) ? false : true;}); + $files = array_filter($files, function ($v) { + return is_dir($v) ? false : true; + }); } return $files; } /** - * Returns the last version given a pattern of file name - * - * @param string $pattern a valid pattern for glob(...) native function - * @param int $flag php flags for glob(...) native function - * @return int|string - * - * Example: - * - Given the following files inside a directory: - * /example/path/myApplication-v1.tar - * /example/path/myApplication-v2.tar - * /example/path/myApplication-v3.tar - * /example/path/myApplication-v5.tar - * /example/path/myApplication-v7.tar - * - * $lastVer = ProcessMaker\Util\Common::getLastVersion("/example/path/myApplication-*.tar"); - * - * It will returns: 7 + * This method get the last version of file when exists a special characters + * @param $pattern + * @param $extension + * @param int $flag + * @return int */ - public static function getLastVersion($pattern, $flag = 0) + public static function getLastVersionSpecialCharacters($dir, $pattern, $extension, $flag = 0) { - $files = glob($pattern, $flag); + $files = glob($dir . quotemeta($pattern) . "-*." . $extension, $flag); $maxVersion = 0; - - $pattern = str_replace("*", '([0-9\.]+)', basename($pattern)); - + $pattern = preg_quote(basename($pattern)) . '-([0-9\.]+)pmx'; foreach ($files as $file) { $filename = basename($file); - - if (preg_match('/'.$pattern.'/', $filename, $match)) { - + if (preg_match('/' . $pattern . '/', $filename, $match)) { if ($maxVersion < $match[1]) { $maxVersion = $match[1]; } } } - return $maxVersion; } @@ -141,8 +126,8 @@ class Common } while ($parent_folder_path = array_pop($folder_path)) { - if (! @is_dir($parent_folder_path)) { - if (! @mkdir($parent_folder_path, $rights)) { + if (!@is_dir($parent_folder_path)) { + if (!@mkdir($parent_folder_path, $rights)) { umask($oldumask); } } diff --git a/gulliver/system/class.g.php b/gulliver/system/class.g.php index adb4cfab9..435eca3e4 100644 --- a/gulliver/system/class.g.php +++ b/gulliver/system/class.g.php @@ -3238,20 +3238,34 @@ class G * @param (array) additional characteres map * */ - public function inflect ($string, $replacement = '_', $map = array()) + public function inflect($string, $replacement = '_', $map = array()) { - if (is_array( $replacement )) { + if (is_array($replacement)) { $map = $replacement; $replacement = '_'; } - $quotedReplacement = preg_quote( $replacement, '/' ); + $quotedReplacement = preg_quote($replacement, '/'); - $default = array ('/à|á|å|â/' => 'a','/è|é|ê|ẽ|ë/' => 'e','/ì|í|î/' => 'i','/ò|ó|ô|ø/' => 'o','/ù|ú|ů|û/' => 'u','/ç/' => 'c','/ñ/' => 'n','/ä|æ/' => 'ae','/ö/' => 'oe','/ü/' => 'ue','/Ä/' => 'Ae','/Ü/' => 'Ue','/Ö/' => 'Oe','/ß/' => 'ss','/\.|\,|\:|\-|\\|\//' => " ",'/\\s+/' => $replacement - ); + $default = array('/à|á|å|â/' => 'a', + '/è|é|ê|ẽ|ë/' => 'e', + '/ì|í|î/' => 'i', + '/ò|ó|ô|ø/' => 'o', + '/ù|ú|ů|û/' => 'u', + '/ç/' => 'c', + '/ñ/' => 'n', + '/ä|æ/' => 'ae', + '/ö/' => 'oe', + '/ü/' => 'ue', + '/Ä/' => 'Ae', + '/Ü/' => 'Ue', + '/Ö/' => 'Oe', + '/ß/' => 'ss', + '/[\.|\,|\+|\"|\:|\;|\-|\\|\/]/' => " ", + '/\\s+/' => $replacement); - $map = array_merge( $default, $map ); - return preg_replace( array_keys( $map ), array_values( $map ), $string ); + $map = array_merge($default, $map); + return preg_replace(array_keys($map), array_values($map), $string); } /** diff --git a/workflow/engine/methods/processes/processes_Export.php b/workflow/engine/methods/processes/processes_Export.php index 524bbe49a..99c248bfc 100644 --- a/workflow/engine/methods/processes/processes_Export.php +++ b/workflow/engine/methods/processes/processes_Export.php @@ -21,6 +21,7 @@ * For more information, contact Colosa Inc, 2566 Le Jeune Rd., * Coral Gables, FL, 33134, USA, or email info@colosa.com. */ +use ProcessMaker\Util\Common; $response = new StdClass(); $outputDir = PATH_DATA . "sites" . PATH_SEP . SYS_SYS . PATH_SEP . "files" . PATH_SEP . "output" . PATH_SEP; @@ -42,7 +43,7 @@ try { $projectName = $exporter->getProjectName(); $getProjectName = $exporter->truncateName($projectName, false); - $version = ProcessMaker\Util\Common::getLastVersion($outputDir . $getProjectName . "-*.pmx") + 1; + $version = Common::getLastVersionSpecialCharacters($outputDir, $getProjectName, "pmx") + 1; $outputFilename = sprintf("%s-%s.%s", str_replace(" ", "_", $getProjectName), $version, "pmx"); $outputFilename = $exporter->saveExport($outputDir . $outputFilename); /*----------------------------------********---------------------------------*/ diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/GranularExporter.php b/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/GranularExporter.php index 461f17e3d..09b5308f1 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/GranularExporter.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/GranularExporter.php @@ -3,6 +3,7 @@ namespace ProcessMaker\BusinessModel\Migrator; use ProcessMaker\Project; +use ProcessMaker\Util\Common; class GranularExporter { @@ -64,7 +65,7 @@ class GranularExporter $this->prjName = $projectData['PRJ_NAME']; $getProjectName = $this->publisher->truncateName($projectData['PRJ_NAME'], false); $outputDir = PATH_DATA . "sites" . PATH_SEP . SYS_SYS . PATH_SEP . "files" . PATH_SEP . "output" . PATH_SEP; - $version = \ProcessMaker\Util\Common::getLastVersion($outputDir . $getProjectName . "-*.pmx2") + 1; + $version = Common::getLastVersionSpecialCharacters($outputDir, $getProjectName, "pmx2") + 1; $outputFilename = $outputDir . sprintf("%s-%s.%s", str_replace(" ", "_", $getProjectName), $version, "pmx2"); $bpnmDefinition = array( diff --git a/workflow/engine/src/ProcessMaker/Importer/Importer.php b/workflow/engine/src/ProcessMaker/Importer/Importer.php index 1e89f110f..fecb7e164 100644 --- a/workflow/engine/src/ProcessMaker/Importer/Importer.php +++ b/workflow/engine/src/ProcessMaker/Importer/Importer.php @@ -6,6 +6,7 @@ use ProcessMaker\Project; use ProcessMaker\Project\Adapter; use ProcessMaker\BusinessModel\Migrator; use ProcessMaker\BusinessModel\Migrator\ImportException; +use ProcessMaker\Util\Common; abstract class Importer { @@ -771,7 +772,7 @@ abstract class Importer $getProjectName = $exporter->truncateName($exporter->getProjectName(), false); $outputDir = PATH_DATA . "sites" . PATH_SEP . SYS_SYS . PATH_SEP . "files" . PATH_SEP . "output" . PATH_SEP; - $version = \ProcessMaker\Util\Common::getLastVersion($outputDir . $getProjectName . "-*.pmx") + 1; + $version = Common::getLastVersionSpecialCharacters($outputDir, $getProjectName, "pmx") + 1; $outputFilename = $outputDir . sprintf("%s-%s.%s", str_replace(" ", "_", $getProjectName), $version, "pmx"); $exporter->setMetadata("export_version", $version); diff --git a/workflow/engine/src/ProcessMaker/Services/Api/Project.php b/workflow/engine/src/ProcessMaker/Services/Api/Project.php index 0496db5b0..cc38f31a2 100644 --- a/workflow/engine/src/ProcessMaker/Services/Api/Project.php +++ b/workflow/engine/src/ProcessMaker/Services/Api/Project.php @@ -10,6 +10,7 @@ use \ProcessMaker\BusinessModel\Validator; use \ProcessMaker\BusinessModel\Migrator\GranularExporter; use \ProcessMaker\BusinessModel\Migrator\ExportObjects; use \ProcessMaker\Util\IO\HttpStream; +use \ProcessMaker\Util\Common; /** * Class Project @@ -182,7 +183,7 @@ class Project extends Api $getProjectName = $exporter->truncateName($exporter->getProjectName(), false); $outputDir = PATH_DATA . "sites" . PATH_SEP . SYS_SYS . PATH_SEP . "files" . PATH_SEP . "output" . PATH_SEP; - $version = \ProcessMaker\Util\Common::getLastVersion($outputDir . $getProjectName . "-*.pmx") + 1; + $version = Common::getLastVersionSpecialCharacters($outputDir, $getProjectName, "pmx") + 1; $outputFilename = $outputDir . sprintf("%s-%s.%s", str_replace(" ", "_", $getProjectName), $version, "pmx"); $exporter->setMetadata("export_version", $version);