diff --git a/workflow/engine/src/ProcessMaker/Util/Common.php b/workflow/engine/src/ProcessMaker/Util/Common.php index 875c1f8aa..f375011d2 100644 --- a/workflow/engine/src/ProcessMaker/Util/Common.php +++ b/workflow/engine/src/ProcessMaker/Util/Common.php @@ -32,7 +32,7 @@ class Common * * Common::rglob("/example/path/*.json"); * - * it will returns: + * It will returns: * * Array * ( @@ -70,17 +70,32 @@ class Common * * @param string $pattern a valid pattern for glob(...) native function * @param int $flag php flags for glob(...) native function - * @return int + * @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 */ public static function getLastVersion($pattern, $flag = 0) { $files = glob($pattern, $flag); $maxVersion = 0; + $pattern = str_replace("*", '([0-9\.]+)', basename($pattern)); + foreach ($files as $file) { $filename = basename($file); - if (preg_match("/-([0-9]+)/", $filename, $match)) { + if (preg_match('/'.$pattern.'/', $filename, $match)) { + if ($maxVersion < $match[1]) { $maxVersion = $match[1]; } diff --git a/workflow/engine/src/ProcessMaker/Util/IO/HttpStream.php b/workflow/engine/src/ProcessMaker/Util/IO/HttpStream.php index d8870fd77..fd85d0016 100644 --- a/workflow/engine/src/ProcessMaker/Util/IO/HttpStream.php +++ b/workflow/engine/src/ProcessMaker/Util/IO/HttpStream.php @@ -301,10 +301,6 @@ class HttpStream header(sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText)); // headers - - - //print_r($this->headers); die; - foreach ($this->headers as $name => $value) { if (is_array($value)) { foreach ($value as $v) { diff --git a/workflow/engine/src/Tests/ProcessMaker/Util/CommonTest.php b/workflow/engine/src/Tests/ProcessMaker/Util/CommonTest.php index 2908bf56e..237cbc4c9 100644 --- a/workflow/engine/src/Tests/ProcessMaker/Util/CommonTest.php +++ b/workflow/engine/src/Tests/ProcessMaker/Util/CommonTest.php @@ -25,10 +25,17 @@ class XmlExporterTest extends \PHPUnit_Framework_TestCase $this->assertEquals(5, $lastVer); } + function testGetLastVersionThr() + { + $lastVer = Util\Common::getLastVersion(__DIR__."/../../fixtures/files_struct/third/sample-*.txt"); + + $this->assertEquals("3.1.9", $lastVer); + } + /** * Negative test, no matched files found */ - function testGetLastVersionThr() + function testGetLastVersionOther() { $lastVer = Util\Common::getLastVersion(sys_get_temp_dir()."/sample-*.txt"); diff --git a/workflow/engine/src/Tests/fixtures/files_struct/third/sample-1.txt b/workflow/engine/src/Tests/fixtures/files_struct/third/sample-1.txt new file mode 100644 index 000000000..c4de27d5a --- /dev/null +++ b/workflow/engine/src/Tests/fixtures/files_struct/third/sample-1.txt @@ -0,0 +1 @@ +file sample-1.txt \ No newline at end of file diff --git a/workflow/engine/src/Tests/fixtures/files_struct/third/sample-2.txt b/workflow/engine/src/Tests/fixtures/files_struct/third/sample-2.txt new file mode 100644 index 000000000..c4de27d5a --- /dev/null +++ b/workflow/engine/src/Tests/fixtures/files_struct/third/sample-2.txt @@ -0,0 +1 @@ +file sample-1.txt \ No newline at end of file diff --git a/workflow/engine/src/Tests/fixtures/files_struct/third/sample-3.1.9.txt b/workflow/engine/src/Tests/fixtures/files_struct/third/sample-3.1.9.txt new file mode 100644 index 000000000..c4de27d5a --- /dev/null +++ b/workflow/engine/src/Tests/fixtures/files_struct/third/sample-3.1.9.txt @@ -0,0 +1 @@ +file sample-1.txt \ No newline at end of file diff --git a/workflow/engine/src/Tests/fixtures/files_struct/third/sample-3.1.txt b/workflow/engine/src/Tests/fixtures/files_struct/third/sample-3.1.txt new file mode 100644 index 000000000..c4de27d5a --- /dev/null +++ b/workflow/engine/src/Tests/fixtures/files_struct/third/sample-3.1.txt @@ -0,0 +1 @@ +file sample-1.txt \ No newline at end of file diff --git a/workflow/engine/src/Tests/fixtures/files_struct/third/sample-3.txt b/workflow/engine/src/Tests/fixtures/files_struct/third/sample-3.txt new file mode 100644 index 000000000..c4de27d5a --- /dev/null +++ b/workflow/engine/src/Tests/fixtures/files_struct/third/sample-3.txt @@ -0,0 +1 @@ +file sample-1.txt \ No newline at end of file