From 239eef80e67d2b2ca4fe47588745006c63e24c24 Mon Sep 17 00:00:00 2001 From: Roly Rudy Gutierrez Pinto Date: Fri, 7 Jun 2019 10:21:13 -0400 Subject: [PATCH 1/2] PMC-809-A --- phpunit.xml | 4 + tests/bootstrap.php | 43 ++- .../ProcessMaker/Services/Api/LightTest.php | 355 ++++++++++++++++++ .../src/ProcessMaker/Model/ListUnassigned.php | 11 +- .../src/ProcessMaker/Services/Api/Light.php | 6 +- 5 files changed, 407 insertions(+), 12 deletions(-) create mode 100644 tests/unit/workflow/engine/src/ProcessMaker/Services/Api/LightTest.php diff --git a/phpunit.xml b/phpunit.xml index dad99dd69..5ec9092ee 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -36,6 +36,10 @@ + + + + diff --git a/tests/bootstrap.php b/tests/bootstrap.php index fdee3691a..148d060d1 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -14,26 +14,46 @@ use Illuminate\Support\Facades\Schema; /** * @todo Migrate to configuration parameters */ - define('PATH_TRUNK', dirname(__DIR__)); -define('PATH_CORE', PATH_TRUNK.'/workflow/engine/'); +define('PATH_CORE', PATH_TRUNK . '/workflow/engine/'); define('PATH_CONFIG', PATH_CORE . 'config/'); -define('PATH_RBAC_CORE',dirname(__DIR__).'/rbac/engine/'); -define('PATH_DB', dirname(__DIR__).'/shared/sites/'); -define('PATH_DATA', dirname(__DIR__).'/shared/rbac/'); +$pathData = PATH_CONFIG . 'paths_installed.php'; +if (file_exists($pathData)) { + require_once $pathData; +} else { + define('PATH_DATA', dirname(__DIR__) . '/shared/rbac/'); +} +define('PATH_RBAC_CORE', dirname(__DIR__) . '/rbac/engine/'); +define('PATH_DB', dirname(__DIR__) . '/shared/sites/'); define('PATH_SEP', '/'); -define('PATH_METHODS', dirname(__DIR__).'/workflow/engine/methods/'); +define('PATH_METHODS', dirname(__DIR__) . '/workflow/engine/methods/'); define('SYS_LANG', 'en'); define('DB_ADAPTER', 'mysql'); define('SYS_SKIN', 'neoclassic'); -define('SYS_SYS', 'workflow'); -define('PATH_WORKSPACE',PATH_TRUNK.'/shared/sites/' . SYS_SYS . '/'); -define('PMTABLE_KEY','pmtable'); +define('SYS_SYS', env('MAIN_SYS_SYS', 'workflow')); +define('PATH_WORKSPACE', PATH_TRUNK . '/shared/sites/' . SYS_SYS . '/'); +define('PMTABLE_KEY', 'pmtable'); +define('PATH_WORKFLOW_MYSQL_DATA', PATH_TRUNK . '/workflow/engine/data/mysql/'); +define('PATH_RBAC_MYSQL_DATA', PATH_TRUNK . '/rbac/engine/data/mysql/'); +define('PATH_LANGUAGECONT', PATH_DATA . '/META-INF/'); + +//timezone +$_SESSION['__SYSTEM_UTC_TIME_ZONE__'] = (int) (env('MAIN_SYSTEM_UTC_TIME_ZONE', 'workflow')) == 1; + +//Set Time Zone +ini_set('date.timezone', $_SESSION['__SYSTEM_UTC_TIME_ZONE__'] ? 'UTC' : env('MAIN_TIME_ZONE', 'America/New_York')); +define('TIME_ZONE', ini_get('date.timezone')); // Setup basic app services $app = require __DIR__ . '/../bootstrap/app.php'; $app->make(Kernel::class)->bootstrap(); +//Overwrite with the Processmaker env.ini configuration used in production environments +//@todo: move env.ini configuration to .env +ini_set('date.timezone', TIME_ZONE); //Set Time Zone +date_default_timezone_set(TIME_ZONE); +config(['app.timezone' => TIME_ZONE]); + // Setup our testexternal database config(['database.connections.testexternal' => [ 'driver' => 'mysql', @@ -49,6 +69,11 @@ config(['database.connections.testexternal' => [ 'engine' => null ]]); +//configuration values +config([ + "system.workspace" => SYS_SYS +]); + // Now, drop all test tables and repopulate with schema Schema::connection('testexternal')->dropIfExists('test'); diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Services/Api/LightTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Services/Api/LightTest.php new file mode 100644 index 000000000..c24d476cc --- /dev/null +++ b/tests/unit/workflow/engine/src/ProcessMaker/Services/Api/LightTest.php @@ -0,0 +1,355 @@ +timezone = config('app.timezone'); + $_SESSION['USR_TIME_ZONE'] = $this->timezone; + $this->baseUri = $this->getBaseUri(); + $this->workspace = env("DB_DATABASE", "test"); + $this->clientId = config("oauthClients.pm.clientId"); + $this->clientSecret = config("oauthClients.pm.clientSecret"); + $this->user = "admin"; + $this->password = "admin"; + $this->createTestSite(); + $this->http = new Client([ + "base_uri" => $this->baseUri + ]); + $this->optionsForConvertDatetime = [ + 'newerThan', + 'oldestthan', + 'date', + 'delegateDate', + 'dueDate', + 'delRiskDate' + ]; + } + + /** + * Get base uri for rest applications. + * @return string + */ + private function getBaseUri() + { + $_SERVER = $this->getServerInformation(); + $baseUri = System::getServerProtocolHost(); + + return $baseUri; + } + + /** + * Get server information. + * @return object + */ + private function getServerInformation() + { + $pathData = PATH_DATA . "sites" . PATH_SEP . config("system.workspace") . PATH_SEP . ".server_info"; + $content = file_get_contents($pathData); + $serverInfo = unserialize($content); + + return $serverInfo; + } + + /** + * This method creates a test workspace so that the endpoints can be functional, + * it is necessary to change the permissions of the directory so that other + * users can access and write to the directory, these users can be for + * example: apache2, www-data, httpd, etc... + * This method finds the license file of the active site and uses it to register + * this license in the LICENSE_MANAGER table. If there is no license file in + * the active workspace, an asersion failure will be notified. + */ + private function createTestSite() + { + //We copy the license, otherwise you will not be able to lift the site + $pathTest = PATH_DATA . "sites" . PATH_SEP . $this->workspace; + File::copyDirectory(PATH_DATA . "sites" . PATH_SEP . config("system.workspace"), $pathTest); + + //Write permission for other users for example: apache2, www-data, httpd. + passthru('chmod 777 -R ' . $pathTest . ' >> .log 2>&1'); + + $installer = new Installer(); + $options = [ + 'isset' => true, + 'name' => $this->workspace, + 'admin' => [ + 'username' => $this->user, + 'password' => $this->password + ], + 'advanced' => [ + 'ao_db_drop' => true, + 'ao_db_wf' => $this->workspace, + 'ao_db_rb' => $this->workspace, + 'ao_db_rp' => $this->workspace + ] + ]; + //The false option creates a connection to the database, necessary to create a site. + $installer->create_site($options, false); + //Now create site + $installer->create_site($options, true); + + //Important so that the dates are stored in the same timezone + file_put_contents($pathTest . "/env.ini", "time_zone ='{$this->timezone}'", FILE_APPEND); + + $matchingFiles = File::glob("{$pathTest}/*.dat"); + $this->assertNotEmpty($matchingFiles); + + //set license + $licensePath = array_pop($matchingFiles); + DB::Table("LICENSE_MANAGER")->insert([ + "LICENSE_UID" => G::generateUniqueID(), + "LICENSE_USER" => "ProcessMaker Inc", + "LICENSE_START" => "1490932800", + "LICENSE_END" => 0, + "LICENSE_SPAN" => 0, + "LICENSE_STATUS" => "ACTIVE", + "LICENSE_DATA" => file_get_contents($licensePath), + "LICENSE_PATH" => $licensePath, + "LICENSE_WORKSPACE" => $this->workspace, + "LICENSE_TYPE" => "" + ]); + } + + /** + * Get authorization values. + */ + private function getAuthorization() + { + $request = $this->http->request("POST", "{$this->workspace}/oauth2/token", [ + "form_params" => [ + "grant_type" => "password", + "scope" => "*", + "client_id" => $this->clientId, + "client_secret" => $this->clientSecret, + "username" => $this->user, + "password" => $this->password + ] + ]); + + //Here is to verify if the connection to the endpoint was satisfactory, + //so the connection status should be 200. + $statusCode = $request->getStatusCode(); + $this->assertEquals(200, $statusCode); + + //If the endpoint has responded we can obtain the data and verify if it + //is what we expected. + $contents = $request->getBody()->getContents(); + $credentials = json_decode($contents); + + $this->assertNotNull($credentials); + $this->assertObjectHasAttribute('access_token', $credentials); + $this->assertObjectHasAttribute('expires_in', $credentials); + $this->assertObjectHasAttribute('refresh_token', $credentials); + $this->assertObjectHasAttribute('scope', $credentials); + $this->assertObjectHasAttribute('token_type', $credentials); + + $this->authorization = ucwords($credentials->token_type) . " {$credentials->access_token}"; + } + + /** + * Get current collection list unassigned. + * @return collection + */ + private function getCollectionListUnassigned() + { + //Create process + $process = factory(Process::class)->create(); + + //Get user + $user = User::select() + ->where('USR_USERNAME', '=', $this->user) + ->first(); + + //Create a task self service + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID + ]); + + //Assign a user in the task + factory(TaskUser::class, 1)->create([ + 'TAS_UID' => $task->TAS_UID, + 'USR_UID' => $user->USR_UID, + 'TU_RELATION' => 1, //Related to the user + 'TU_TYPE' => 1 + ]); + + //Create a record in list unassigned + $listUnassigned = factory(ListUnassigned::class, 15)->create([ + 'TAS_ID' => $task->TAS_ID, + 'DEL_PREVIOUS_USR_UID' => $user->USR_UID + ]); + + $result = $listUnassigned->sortByDesc('DEL_DELEGATE_DATE'); + + return $result; + } + + /** + * Changes the data to the format returned by REST API. + * @param array $collection + * @return array + */ + private function normalizeData($collection) + { + $result = []; + $collection->transform(function ($item, $key) use (&$result) { + $value = [ + 'caseId' => $item->APP_UID, + //The current EndPoint returns this value as a string, an Eloquent + //collection takes into account the string and numeric types. + 'delIndex' => (string) $item->DEL_INDEX, + 'task' => [ + 'taskId' => $item->TAS_UID, + 'name' => $item->APP_TAS_TITLE + ], + 'process' => [ + 'processId' => $item->PRO_UID, + 'name' => $item->APP_PRO_TITLE + ], + //The current EndPoint returns this value as a string, an Eloquent + //collection takes into account the string and numeric types. + 'caseNumber' => (string) $item->APP_NUMBER, + 'caseTitle' => $item->APP_TITLE, + 'date' => $item->APP_UPDATE_DATE->format('Y-m-d H:i:s'), + 'delegateDate' => $item->DEL_DELEGATE_DATE->format('Y-m-d H:i:s'), + 'prevUser' => [ + 'userId' => $item->DEL_PREVIOUS_USR_UID, + 'userName' => $item->DEL_PREVIOUS_USR_USERNAME, + 'firstName' => $item->DEL_PREVIOUS_USR_FIRSTNAME, + 'lastName' => $item->DEL_PREVIOUS_USR_LASTNAME + ], + 'dueDate' => $item->DEL_DUE_DATE->format('Y-m-d H:i:s'), + ]; + $result[] = $value; + }); + + $converted = DateTime::convertUtcToIso8601($result, $this->optionsForConvertDatetime); + + //Convert the elements to an object + $object = json_decode(json_encode($converted)); + + return $object; + } + + /** + * This returns an array of arrays to test the $start and $limit parameters. + * The values correspond to the following structure: + * [ + * [$page, $size, $start, $limit], + * [$page, $size, $start, $limit], + * [$page, $size, $start, $limit], + * ] + * $page and $size are necessary to test the pages we expect to have from the + * model collection. + * @return array + */ + public function pagesProvider() + { + return [ + [1, 5, 0, 5], + [2, 5, 5, 5], + [3, 5, 10, 5], + [4, 5, 15, 5], + [5, 5, 20, 5], + [6, 5, 25, 5] + ]; + } + + /** + * This check if the endpoint {workspace}/light/unassigned, is returning all data. + * @test + * @covers ProcessMaker\Services\Api\Light::doGetCasesListUnassigned + */ + public function it_should_get_all_data_without_start_and_limit_values() + { + $listUnassigned = $this->getCollectionListUnassigned(); + + $this->getAuthorization(); + $request = $this->http->request("GET", "api/1.0/{$this->workspace}/light/unassigned", [ + "headers" => [ + "Authorization" => $this->authorization + ] + ]); + + //Here is to verify if the connection to the endpoint was satisfactory, + //so the connection status should be 200. + $statusCode = $request->getStatusCode(); + $this->assertEquals(200, $statusCode); + + //If the endpoint has responded we can obtain the data and verify if it + //is what we expected. + $expected = $this->normalizeData($listUnassigned); + $contents = $request->getBody()->getContents(); + $content = json_decode($contents); + + $this->assertEquals($expected, $content); + } + + /** + * This check if the endpoint {workspace}/light/unassigned, is returning the + * requested data set according to the start and limit parameters. The $start + * and $limit test values are obtained from the data provider pagesProvider(). + * @test + * @covers ProcessMaker\Services\Api\Light::doGetCasesListUnassigned + * @dataProvider pagesProvider + */ + public function it_should_get_data_with_start_and_limit($page, $size, $start, $limit) + { + $listUnassigned = $this->getCollectionListUnassigned(); + $result = $listUnassigned->forPage($page, $size); + + $this->getAuthorization(); + $request = $this->http->request("GET", "api/1.0/{$this->workspace}/light/unassigned?start={$start}&limit={$limit}", [ + "headers" => [ + "Authorization" => $this->authorization + ] + ]); + + //Here is to verify if the connection to the endpoint was satisfactory, + //so the connection status should be 200. + $statusCode = $request->getStatusCode(); + $this->assertEquals(200, $statusCode); + + //If the endpoint has responded we can obtain the data and verify if it + //is what we expected. + $expected = $this->normalizeData($result); + $contents = $request->getBody()->getContents(); + $content = json_decode($contents); + + $this->assertEquals($expected, $content); + } +} diff --git a/workflow/engine/src/ProcessMaker/Model/ListUnassigned.php b/workflow/engine/src/ProcessMaker/Model/ListUnassigned.php index aa69c2f3c..7dab112f8 100644 --- a/workflow/engine/src/ProcessMaker/Model/ListUnassigned.php +++ b/workflow/engine/src/ProcessMaker/Model/ListUnassigned.php @@ -35,6 +35,14 @@ class ListUnassigned extends Model return $this->belongsTo(Process::class, 'PRO_ID', 'PRO_ID'); } + /** + * Return the user this belongs to + */ + public function previousUser() + { + return $this->belongsTo(User::class, 'DEL_PREVIOUS_USR_UID', 'USR_UID'); + } + /** * Scope a query to only include specific tasks * @@ -93,7 +101,7 @@ class ListUnassigned extends Model * @param array $filters * * @return array - */ + */ public static function doCount($userUid, $filters = []) { $list = new PropelListUnassigned(); @@ -155,4 +163,3 @@ class ListUnassigned extends Model return $result; } } - diff --git a/workflow/engine/src/ProcessMaker/Services/Api/Light.php b/workflow/engine/src/ProcessMaker/Services/Api/Light.php index a1f6a80a3..f59ae6bc5 100644 --- a/workflow/engine/src/ProcessMaker/Services/Api/Light.php +++ b/workflow/engine/src/ProcessMaker/Services/Api/Light.php @@ -652,10 +652,11 @@ class Light extends Api if (preg_match($this->regexNull, $newerThan)) { return []; } + $paged = ($start === 0 && $limit === 0) ? false : true; $dataList['userId'] = $this->getUserId(); $dataList['action'] = 'unassigned'; - $dataList['paged'] = false; + $dataList['paged'] = $paged; $dataList['start'] = $start; $dataList['limit'] = $limit; @@ -682,6 +683,9 @@ class Light extends Api /*----------------------------------********---------------------------------*/ } /*----------------------------------********---------------------------------*/ + if ($paged === true) { + $response = $response['data']; + } $result = $this->parserDataUnassigned($response); return DateTime::convertUtcToIso8601($result, $this->arrayFieldIso8601); From cc51c76b1297182cbf8b4246ba55877554ed263e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julio=20Cesar=20Laura=20Avenda=C3=B1o?= Date: Tue, 11 Jun 2019 10:14:02 -0400 Subject: [PATCH 2/2] Revert PMC-602 --- gulliver/system/class.g.php | 113 +++---- tests/bootstrap.php | 1 - .../gulliver/system/ReplaceDataFieldTest.php | 280 ------------------ workflow/engine/classes/Cases.php | 32 +- workflow/engine/classes/WsBase.php | 2 +- .../engine/classes/model/OutputDocument.php | 102 +++---- .../BusinessModel/Cases/OutputDocument.php | 98 +++--- .../engine/src/ProcessMaker/Util/helpers.php | 27 -- 8 files changed, 143 insertions(+), 512 deletions(-) delete mode 100644 tests/unit/gulliver/system/ReplaceDataFieldTest.php diff --git a/gulliver/system/class.g.php b/gulliver/system/class.g.php index a00bdc624..60207b1be 100644 --- a/gulliver/system/class.g.php +++ b/gulliver/system/class.g.php @@ -1636,16 +1636,13 @@ class G /** * Escapes special characters in a string for use in a SQL statement - * @param string $sqlString The string to be escaped - * @param string $dbEngine Target DBMS - * - * @return string - */ - public static function sqlEscape($sqlString, $dbEngine = DB_ADAPTER) + * @param string $sqlString The string to be escaped + * @param string $DBEngine Target DBMS + */ + public function sqlEscape($sqlString, $DBEngine = DB_ADAPTER) { - // @todo: Research why always this value is set with the same constant? - $dbEngine = DB_ADAPTER; - switch ($dbEngine) { + $DBEngine = DB_ADAPTER; + switch ($DBEngine) { case 'mysql': $con = Propel::getConnection('workflow'); return mysqli_real_escape_string($con->getResource(), stripslashes($sqlString)); @@ -1692,15 +1689,9 @@ class G * @# Non-quoted parameter * @! Evaluate string : Replace the parameters in value and then in the sql string * @fn() Evaluate string with the function "fn" - * - * @param string $sqlString - * @param array $result - * @param string $dbEngine - * @param bool $applyHtmlEntities - * - * @return string + * @author David Callizaya */ - public static function replaceDataField($sqlString, $result, $dbEngine = 'mysql', $applyHtmlEntities = false) + public static function replaceDataField($sqlString, $result, $DBEngine = 'mysql') { if (!is_array($result)) { $result = array(); @@ -1719,12 +1710,7 @@ class G $u = $match[0][$r][1] + strlen($match[0][$r][0]); //Mysql quotes scape if (($match[1][$r][0] == '@') && (isset($result[$match[2][$r][0]]))) { - $text = ($applyHtmlEntities && !stringIsValidHtml($result[$match[2][$r][0]])) ? - htmlentities(G::unhtmlentities($result[$match[2][$r][0]]), ENT_COMPAT, 'UTF-8') : - $result[$match[2][$r][0]]; - // Replenish the tag
because is valid - $text = str_replace('<br />', '
', $text); - $__textoEval .= "\"" . G::sqlEscape($text, $dbEngine) . "\""; + $__textoEval .= "\"" . G::sqlEscape($result[$match[2][$r][0]], $DBEngine) . "\""; continue; } //URL encode @@ -1744,7 +1730,7 @@ class G } //Substring (Sub replaceDataField) if (($match[1][$r][0] == '!') && (isset($result[$match[2][$r][0]]))) { - $__textoEval .= G::replaceDataField($result[$match[2][$r][0]], $result, $dbEngine, $applyHtmlEntities); + $__textoEval .= G::replaceDataField($result[$match[2][$r][0]], $result); continue; } //Call function @@ -1762,33 +1748,18 @@ class G } //Non-quoted if (($match[1][$r][0] == '#') && (isset($result[$match[2][$r][0]]))) { - $text = ($applyHtmlEntities && !stringIsValidHtml($result[$match[2][$r][0]]) && $match[2][$r][0] !== '__ABE__') ? - htmlentities(G::unhtmlentities($result[$match[2][$r][0]]), ENT_COMPAT, 'UTF-8') : - $result[$match[2][$r][0]]; - // Replenish the tag
because is valid - $text = str_replace('<br />', '
', $text); - $__textoEval .= G::replaceDataField($text, $result); + $__textoEval .= G::replaceDataField($result[$match[2][$r][0]], $result); continue; } //Non-quoted = if (($match[1][$r][0] == '=') && (isset($result[$match[2][$r][0]]))) { - $text = ($applyHtmlEntities && !stringIsValidHtml($result[$match[2][$r][0]]) && $match[2][$r][0] !== '__ABE__') ? - htmlentities(G::unhtmlentities($result[$match[2][$r][0]]), ENT_COMPAT, 'UTF-8') : - $result[$match[2][$r][0]]; - // Replenish the tag
because is valid - $text = str_replace('<br />', '
', $text); - $__textoEval .= G::replaceDataField($text, $result); + $__textoEval .= G::replaceDataField($result[$match[2][$r][0]], $result); continue; } //Objects attributes if (($match[1][$r][0] == '&') && (isset($result[$match[2][$r][0]]))) { if (isset($result[$match[2][$r][0]]->{$match[6][$r][0]})) { - $text = ($applyHtmlEntities && !stringIsValidHtml($result[$match[2][$r][0]]->{$match[6][$r][0]})) ? - htmlentities(G::unhtmlentities($result[$match[2][$r][0]]->{$match[6][$r][0]}), ENT_COMPAT, 'UTF-8') : - $result[$match[2][$r][0]]->{$match[6][$r][0]}; - // Replenish the tag
because is valid - $text = str_replace('<br />', '
', $text); - $__textoEval .= $text; + $__textoEval .= $result[$match[2][$r][0]]->{$match[6][$r][0]}; } continue; } @@ -1800,35 +1771,27 @@ class G } /** - * Replace Grid Values in a string. - * The tag @>GRID-NAME to open the grid and @sendMessage() - * @see \WsBase->sendMessage() - * @see \OutputDocument->generate() - * @see \ProcessMaker\BusinessModel\Cases\OutputDocument->generate() - */ - public static function replaceDataGridField($content, $fields, $nl2brRecursive = true, $applyHtmlEntities = false) + * Replace Grid Values + * The tag @>GRID-NAME to open the grid and @])([a-zA-Z\_]\w*)|([a-zA-Z\_][\w\-\>\:]*)\(((?:[^\\\\\)]*(?:[\\\\][\w\W])?)*)\))((?:\s*\[[\'"]?\w+[\'"]?\])+)?/', - $strContentAux, $arrayMatch1, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE); + $iOcurrences = preg_match_all('/\@(?:([\>])([a-zA-Z\_]\w*)|([a-zA-Z\_][\w\-\>\:]*)\(((?:[^\\\\\)]*(?:[\\\\][\w\W])?)*)\))((?:\s*\[[\'"]?\w+[\'"]?\])+)?/', $strContentAux, $arrayMatch1, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE); - if ($occurrences) { + if ($iOcurrences) { $arrayGrid = array(); - for ($i = 0; $i <= $occurrences - 1; $i++) { + for ($i = 0; $i <= $iOcurrences - 1; $i++) { $arrayGrid[] = $arrayMatch1[2][$i][0]; } @@ -1854,16 +1817,16 @@ class G while (preg_match($ereg, $strContentAux1, $arrayMatch2)) { $strData = null; - if (isset($fields[$grdName]) && is_array($fields[$grdName])) { - foreach ($fields[$grdName] as $aRow) { + if (isset($aFields[$grdName]) && is_array($aFields[$grdName])) { + foreach ($aFields[$grdName] as $aRow) { if ($nl2brRecursive) { - foreach ($aRow as $key => $item) { - if (!is_array($item)) { - $aRow[$key] = str_replace($nrt, $nrthtml, nl2br($aRow[$key])); + foreach ($aRow as $sKey => $vValue) { + if (!is_array($vValue)) { + $aRow[$sKey] = str_replace($nrt, $nrthtml, nl2br($aRow[$sKey])); } } } - $strData = $strData . G::replaceDataField($arrayMatch2[2], $aRow, 'mysql', $applyHtmlEntities); + $strData = $strData . G::replaceDataField($arrayMatch2[2], $aRow); } } @@ -1878,19 +1841,19 @@ class G $strContentAux = str_replace($nrthtml, $nrt, $strContentAux); - $content = $strContentAux; + $sContent = $strContentAux; if ($nl2brRecursive) { - foreach ($fields as $key => $item) { - if (!is_array($item) && !is_object($item)) { - $fields[$key] = nl2br($fields[$key]); + foreach ($aFields as $sKey => $vValue) { + if (!is_array($vValue) && !is_object($vValue)) { + $aFields[$sKey] = nl2br($aFields[$sKey]); } } } - $content = G::replaceDataField($content, $fields, 'mysql', $applyHtmlEntities); + $sContent = G::replaceDataField($sContent, $aFields); - return $content; + return $sContent; } /** diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 148d060d1..895c470da 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -28,7 +28,6 @@ define('PATH_DB', dirname(__DIR__) . '/shared/sites/'); define('PATH_SEP', '/'); define('PATH_METHODS', dirname(__DIR__) . '/workflow/engine/methods/'); define('SYS_LANG', 'en'); -define('DB_ADAPTER', 'mysql'); define('SYS_SKIN', 'neoclassic'); define('SYS_SYS', env('MAIN_SYS_SYS', 'workflow')); define('PATH_WORKSPACE', PATH_TRUNK . '/shared/sites/' . SYS_SYS . '/'); diff --git a/tests/unit/gulliver/system/ReplaceDataFieldTest.php b/tests/unit/gulliver/system/ReplaceDataFieldTest.php deleted file mode 100644 index c1081304e..000000000 --- a/tests/unit/gulliver/system/ReplaceDataFieldTest.php +++ /dev/null @@ -1,280 +0,0 @@ -value'; - $dbEngine = 'mysql'; // This only affects the way to escape the variables with "@@" prefix - $applyEntities = true; // If a value to replace is a not valid HTML and have HTML reserved characters, entities should be applied - - // Initializing variables to test the assertions, entities should be applied in variable with @@ - $var4 = new stdClass(); - $var4->value = $faker->words(1, true); - $valuesToReplace = [ - 'var1' => 'Java < PHP & Python', - 'var2' => $faker->words(1, true), - 'var3' => $faker->words(1, true), - 'var4' => $var4 - ]; - - // Replace variables in the string - $stringToCheck = G::replaceDataField($stringWithVariablesToReplace, $valuesToReplace, $dbEngine, $applyEntities); - - // Assertions - $this->assertRegExp('/</', $stringToCheck); - $this->assertRegExp('/&/', $stringToCheck); - - // Initializing variables to test the assertions, entities should be applied in variable with @# - $var4 = new stdClass(); - $var4->value = $faker->words(1, true); - $valuesToReplace = [ - 'var1' => $faker->words(1, true), - 'var2' => 'Java < PHP & Python', - 'var3' => $faker->words(1, true), - 'var4' => $var4 - ]; - - // Replace variables in the string - $stringToCheck = G::replaceDataField($stringWithVariablesToReplace, $valuesToReplace, $dbEngine, $applyEntities); - - // Assertions - $this->assertRegExp('/</', $stringToCheck); - $this->assertRegExp('/&/', $stringToCheck); - - // Initializing variables to test the assertions, entities should be applied in variable with @= - $var4 = new stdClass(); - $var4->value = $faker->words(1, true); - $valuesToReplace = [ - 'var1' => $faker->words(1, true), - 'var2' => $faker->words(1, true), - 'var3' => 'Java < PHP & Python', - 'var4' => $var4 - ]; - - // Replace variables in the string - $stringToCheck = G::replaceDataField($stringWithVariablesToReplace, $valuesToReplace, $dbEngine, $applyEntities); - - // Assertions - $this->assertRegExp('/</', $stringToCheck); - $this->assertRegExp('/&/', $stringToCheck); - - // Initializing variables to test the assertions, entities should be applied in variable with @& - $var4 = new stdClass(); - $var4->value = 'Java < PHP & Python'; - $valuesToReplace = [ - 'var1' => $faker->words(1, true), - 'var2' => $faker->words(1, true), - 'var3' => $faker->words(1, true), - 'var4' => $var4 - ]; - - // Replace variables in the string - $stringToCheck = G::replaceDataField($stringWithVariablesToReplace, $valuesToReplace, $dbEngine, $applyEntities); - - // Assertions - $this->assertRegExp('/</', $stringToCheck); - $this->assertRegExp('/&/', $stringToCheck); - } - - /** - * This checks that strings with HTML reserved characters are NOT replaced with entities - * @test - * @covers G::replaceDataField - */ - public function it_should_no_replace_entities() - { - // Initializing Faker instance - $faker = Faker\Factory::create(); - - // Initializing variables to use that will not change - $stringWithVariablesToReplace = 'Hello @@var1 the @#var2 is @=var3 not @&var4->value'; - $dbEngine = 'mysql'; // This only affects the way to escape the variables with "@@" prefix - $applyEntities = false; // The values should not be replaced with entities - - // Initializing variables to test the assertions, entities should be applied in variable with @@ - $var4 = new stdClass(); - $var4->value = $faker->words(1, true); - $valuesToReplace = [ - 'var1' => 'Java < PHP & Python', - 'var2' => $faker->words(1, true), - 'var3' => $faker->words(1, true), - 'var4' => $var4 - ]; - - // Replace variables in the string - $stringToCheck = G::replaceDataField($stringWithVariablesToReplace, $valuesToReplace, $dbEngine, $applyEntities); - - // Assertions - $this->assertRegExp('/assertRegExp('/&/', $stringToCheck); - - // Initializing variables to test the assertions, entities should be applied in variable with @# - $var4 = new stdClass(); - $var4->value = $faker->words(1, true); - $valuesToReplace = [ - 'var1' => $faker->words(1, true), - 'var2' => 'Java < PHP & Python', - 'var3' => $faker->words(1, true), - 'var4' => $var4 - ]; - - // Replace variables in the string - $stringToCheck = G::replaceDataField($stringWithVariablesToReplace, $valuesToReplace, $dbEngine, $applyEntities); - - // Assertions - $this->assertRegExp('/assertRegExp('/&/', $stringToCheck); - - // Initializing variables to test the assertions, entities should be applied in variable with @= - $var4 = new stdClass(); - $var4->value = $faker->words(1, true); - $valuesToReplace = [ - 'var1' => $faker->words(1, true), - 'var2' => $faker->words(1, true), - 'var3' => 'Java < PHP & Python', - 'var4' => $var4 - ]; - - // Replace variables in the string - $stringToCheck = G::replaceDataField($stringWithVariablesToReplace, $valuesToReplace, $dbEngine, $applyEntities); - - // Assertions - $this->assertRegExp('/assertRegExp('/&/', $stringToCheck); - - // Initializing variables to test the assertions, entities should be applied in variable with @& - $var4 = new stdClass(); - $var4->value = 'Java < PHP & Python'; - $valuesToReplace = [ - 'var1' => $faker->words(1, true), - 'var2' => $faker->words(1, true), - 'var3' => $faker->words(1, true), - 'var4' => $var4 - ]; - - // Replace variables in the string - $stringToCheck = G::replaceDataField($stringWithVariablesToReplace, $valuesToReplace, $dbEngine, $applyEntities); - - // Assertions - $this->assertRegExp('/assertRegExp('/&/', $stringToCheck); - } - - /** - * This checks that strings with HTML reserved characters are NOT replaced with entities if is a valid HTML, because - * PS team sometimes build a HTML string to insert in templates (output documents or emails), Ex.- A table to list - * users or results from a query - * @test - * @covers G::replaceDataField - */ - public function it_should_no_replace_entities_if_exists_valid_html() - { - // Initializing Faker instance - $faker = Faker\Factory::create(); - - // Initializing variables to use - $stringWithVariablesToReplace = 'bla @#var1 bla @=listHtml bla @@var2 bla'; - $valuesToReplace = [ - 'var1' => $faker->words(1, true), - 'listHtml' => ' - - - - - - - - - - - - - - - - -
t1t2t3t4t5t6
c1c2c3c4c5c6
', - 'var2' => $faker->words(1, true) - ]; - $dbEngine = 'mysql'; // This only affects the way to escape the variables with "@@" prefix - $applyEntities = true; // Is true because the string will b used in a output document or a email template - - // Replace variables in the string - $stringToCheck = G::replaceDataField($stringWithVariablesToReplace, $valuesToReplace, $dbEngine, $applyEntities); - - // Assertions - $this->assertRegExp('//', $stringToCheck); - $this->assertRegExp('//', $stringToCheck); - $this->assertRegExp('/
/', $stringToCheck); - $this->assertRegExp('//', $stringToCheck); - } - - /** - * This checks that strings with tag
should not be replaced, because is a valid tag - * @test - * @covers G::replaceDataField - */ - public function it_should_no_replace_tag_br() - { - // Initializing variables to use - $stringWithTagBr = nl2br("prospection auprès d'entreprises de CA < 10 M euros -test -a -&a -\"a -'a -¢a -£a -¥a -€a -©a -®a -test"); - $valuesToReplace = []; - $dbEngine = 'mysql'; // This only affects the way to escape the variables with "@@" prefix - $applyEntities = true; // Is true because the string will be used in a output document or a email template - - // Replace variables in the string - $stringToCheck = G::replaceDataField($stringWithTagBr, $valuesToReplace, $dbEngine, $applyEntities); - - // Assertions - $this->assertRegExp("/
/", $stringToCheck); - } - - /** - * Check that the value for the System variable "__ABE__" should not be replaced never - * @test - * @covers G::replaceDataField - */ - public function it_should_no_replace_entities_for_var_abe() - { - // Initializing variables to use - $string = "bla @#__ABE__ bla @#anotherVar bla"; - $valuesToReplace = [// Add a value for reserved system variable "__ABE__" used in Actions By Email feature - '__ABE__' => 'Java < PHP', // The value for System variable "__ABE__" shouldn't be changed never - 'anotherVar' => '.NET < Java' // The value for another variables should be validated/replaced normally - ]; - $dbEngine = 'mysql'; // This only affects the way to escape the variables with "@@" prefix - $applyEntities = true; // Is true because the string will be used in a output document or a email template - - // Replace variables in the string - $stringToCheck = G::replaceDataField($string, $valuesToReplace, $dbEngine, $applyEntities); - - // Assertions - $this->assertRegExp("/Java < PHP/", $stringToCheck); - $this->assertRegExp("/.NET < Java/", $stringToCheck); - } -} diff --git a/workflow/engine/classes/Cases.php b/workflow/engine/classes/Cases.php index 0718aa6bb..85f17b524 100644 --- a/workflow/engine/classes/Cases.php +++ b/workflow/engine/classes/Cases.php @@ -5612,30 +5612,30 @@ class Cases /** * This function send an email for each task in $arrayTask if $to is definded * - * @param array $dataLastEmail - * @param array $arrayData - * @param array $arrayTask + * @param $dataLastEmail + * @param $arrayData + * @param $arrayTask * @return void * * @see \Cases->sendNotifications() */ public function sendMessage($dataLastEmail, $arrayData, $arrayTask) { - foreach ($arrayTask as $theTask) { + foreach ($arrayTask as $aTask) { //Check and fix if Task Id is complex - if (strpos($theTask['TAS_UID'], "/") !== false) { - $aux = explode("/", $theTask['TAS_UID']); + if (strpos($aTask['TAS_UID'], "/") !== false) { + $aux = explode("/", $aTask['TAS_UID']); if (isset($aux[1])) { - $theTask['TAS_UID'] = $aux[1]; + $aTask['TAS_UID'] = $aux[1]; } } //if the next is EOP dont send notification and continue with the next - if ($theTask['TAS_UID'] === '-1') { + if ($aTask['TAS_UID'] === '-1') { continue; } - if (isset($theTask['DEL_INDEX'])) { + if (isset($aTask['DEL_INDEX'])) { $arrayData2 = $arrayData; - $appDelegation = AppDelegationPeer::retrieveByPK($dataLastEmail['applicationUid'], $theTask['DEL_INDEX']); + $appDelegation = AppDelegationPeer::retrieveByPK($dataLastEmail['applicationUid'], $aTask['DEL_INDEX']); if (!is_null($appDelegation)) { $oTaskUpd = new Task(); $aTaskUpdate = $oTaskUpd->load($appDelegation->getTasUid()); @@ -5646,25 +5646,25 @@ class Cases $arrayData2 = $arrayData; } - if (isset($theTask['USR_UID']) && !empty($theTask['USR_UID'])) { + if (isset($aTask['USR_UID']) && !empty($aTask['USR_UID'])) { $user = new \ProcessMaker\BusinessModel\User(); - $arrayUserData = $user->getUser($theTask['USR_UID'], true); + $arrayUserData = $user->getUser($aTask['USR_UID'], true); $arrayData2 = \ProcessMaker\Util\DateTime::convertUtcToTimeZone($arrayData2, (trim($arrayUserData['USR_TIME_ZONE']) != '') ? trim($arrayUserData['USR_TIME_ZONE']) : \ProcessMaker\Util\System::getTimeZone()); } else { $arrayData2 = \ProcessMaker\Util\DateTime::convertUtcToTimeZone($arrayData2); } - $body2 = G::replaceDataGridField($dataLastEmail['body'], $arrayData2, false, true); + $body2 = G::replaceDataGridField($dataLastEmail['body'], $arrayData2, false); $to = null; $cc = ''; - if ($theTask['TAS_UID'] != '-1') { - $respTo = $this->getTo($theTask['TAS_UID'], $theTask['USR_UID'], $arrayData); + if ($aTask['TAS_UID'] != '-1') { + $respTo = $this->getTo($aTask['TAS_UID'], $aTask['USR_UID'], $arrayData); $to = $respTo['to']; $cc = $respTo['cc']; } - if ($theTask["TAS_ASSIGN_TYPE"] === "SELF_SERVICE") { + if ($aTask ["TAS_ASSIGN_TYPE"] === "SELF_SERVICE") { if ($dataLastEmail['swtplDefault'] == 1) { G::verifyPath($dataLastEmail['pathEmail'], true); // Create if it does not exist $fileTemplate = $dataLastEmail['pathEmail'] . G::LoadTranslation('ID_UNASSIGNED_MESSAGE'); diff --git a/workflow/engine/classes/WsBase.php b/workflow/engine/classes/WsBase.php index ebea4bbe4..afedb88ec 100644 --- a/workflow/engine/classes/WsBase.php +++ b/workflow/engine/classes/WsBase.php @@ -990,7 +990,7 @@ class WsBase $subject, G::buildFrom($setup, $from), $to, - G::replaceDataGridField(file_get_contents($fileTemplate), $fieldsCase, false, true), + G::replaceDataGridField(file_get_contents($fileTemplate), $fieldsCase, false), $cc, $bcc, '', diff --git a/workflow/engine/classes/model/OutputDocument.php b/workflow/engine/classes/model/OutputDocument.php index 3d8f393e4..37da4fbf9 100644 --- a/workflow/engine/classes/model/OutputDocument.php +++ b/workflow/engine/classes/model/OutputDocument.php @@ -508,29 +508,20 @@ class OutputDocument extends BaseOutputDocument } } - /** + /* * Generate the output document - * - * @param string $outDocUid - * @param array $caseFields - * @param string $path - * @param string $filename - * @param string $content - * @param bool $landscape - * @param string $typeDocsToGen - * @param array $properties - * - * @return mixed - * - * @see workflow/engine/methods/cases/cases_Step.php - * @see workflow/engine/classes/class.pmFunctions.php:PMFGenerateOutputDocument() + * @param string $sUID + * @param array $aFields + * @param string $sPath + * @return variant */ - public function generate($outDocUid, $caseFields, $path, $filename, $content, $landscape = false, $typeDocsToGen = 'BOTH', $properties = []) - { - if (($outDocUid != '') && is_array($caseFields) && ($path != '')) { - $content = G::replaceDataGridField($content, $caseFields, true, true); - if (strpos($content, ''; - $fp = fopen($path . $filename . '_smarty.html', 'wb'); - fwrite($fp, $content); - fclose($fp); - $template->templateFile = $path . $filename . '_smarty.html'; + $oFile = fopen($sPath . $sFilename . '_smarty.html', 'wb'); + fwrite($oFile, $sContent); + fclose($oFile); + $template->templateFile = $sPath . $sFilename . '_smarty.html'; //assign the variables and use the template $template - $template->assign($caseFields); - $content = $template->fetch($template->templateFile); + $template->assign($aFields); + $sContent = $template->fetch($template->templateFile); unlink($template->templateFile); } - G::verifyPath($path, true); + G::verifyPath($sPath, true); //Start - Create .doc - $fp = fopen($path . $filename . '.doc', 'wb'); + $oFile = fopen($sPath . $sFilename . '.doc', 'wb'); $size = []; $size["Letter"] = "216mm 279mm"; @@ -575,7 +566,6 @@ class OutputDocument extends BaseOutputDocument $size["Screenshot800"] = "800mm 600mm"; $size["Screenshot1024"] = "1024mm 768mm"; - $sizeLandscape = []; $sizeLandscape["Letter"] = "279mm 216mm"; $sizeLandscape["Legal"] = "357mm 216mm"; $sizeLandscape["Executive"] = "267mm 184mm"; @@ -597,41 +587,41 @@ class OutputDocument extends BaseOutputDocument $sizeLandscape["Screenshot800"] = "600mm 800mm"; $sizeLandscape["Screenshot1024"] = "768mm 1024mm"; - if (!isset($properties['media'])) { - $properties['media'] = 'Letter'; + if (!isset($aProperties['media'])) { + $aProperties['media'] = 'Letter'; } - if ($landscape) { - $media = $sizeLandscape[$properties['media']]; + if ($sLandscape) { + $media = $sizeLandscape[$aProperties['media']]; } else { - $media = $size[$properties['media']]; + $media = $size[$aProperties['media']]; } $marginLeft = '15'; - if (isset($properties['margins']['left'])) { - $marginLeft = $properties['margins']['left']; + if (isset($aProperties['margins']['left'])) { + $marginLeft = $aProperties['margins']['left']; } $marginRight = '15'; - if (isset($properties['margins']['right'])) { - $marginRight = $properties['margins']['right']; + if (isset($aProperties['margins']['right'])) { + $marginRight = $aProperties['margins']['right']; } $marginTop = '15'; - if (isset($properties['margins']['top'])) { - $marginTop = $properties['margins']['top']; + if (isset($aProperties['margins']['top'])) { + $marginTop = $aProperties['margins']['top']; } $marginBottom = '15'; - if (isset($properties['margins']['bottom'])) { - $marginBottom = $properties['margins']['bottom']; + if (isset($aProperties['margins']['bottom'])) { + $marginBottom = $aProperties['margins']['bottom']; } - fwrite($fp, ' @@ -677,31 +667,31 @@ class OutputDocument extends BaseOutputDocument
'); - fwrite($fp, $content); - fwrite($fp, "\n
\n\n"); - fclose($fp); + fwrite($oFile, $sContent); + fwrite($oFile, "\n\n\n"); + fclose($oFile); /* End - Create .doc */ - if ($typeDocsToGen == 'BOTH' || $typeDocsToGen == 'PDF') { - $fp = fopen($path . $filename . '.html', 'wb'); - fwrite($fp, $content); - fclose($fp); + if ($sTypeDocToGener == 'BOTH' || $sTypeDocToGener == 'PDF') { + $oFile = fopen($sPath . $sFilename . '.html', 'wb'); + fwrite($oFile, $sContent); + fclose($oFile); /* Start - Create .pdf */ - if (isset($properties['report_generator'])) { - switch ($properties['report_generator']) { + if (isset($aProperties['report_generator'])) { + switch ($aProperties['report_generator']) { case 'TCPDF': - $this->generateTcpdf($outDocUid, $caseFields, $path, $filename, $content, $landscape, $properties); + $this->generateTcpdf($sUID, $aFields, $sPath, $sFilename, $sContent, $sLandscape, $aProperties); break; case 'HTML2PDF': default: - $this->generateHtml2ps_pdf($outDocUid, $caseFields, $path, $filename, $content, $landscape, $properties); + $this->generateHtml2ps_pdf($sUID, $aFields, $sPath, $sFilename, $sContent, $sLandscape, $aProperties); break; } } else { - $this->generateHtml2ps_pdf($outDocUid, $caseFields, $path, $filename, $content, $landscape, $properties); + $this->generateHtml2ps_pdf($sUID, $aFields, $sPath, $sFilename, $sContent, $sLandscape, $aProperties); } } - //end if $typeDocsToGen + //end if $sTypeDocToGener /* End - Create .pdf */ } else { return PEAR::raiseError( diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/OutputDocument.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/OutputDocument.php index 553dd35e5..01652bfd9 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/OutputDocument.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/OutputDocument.php @@ -1,9 +1,6 @@ addCasesOutputDocument() + * @param string $sUID + * @param array $aFields + * @param string $sPath + * @return variant */ - public function generate($outDocUid, $caseFields, $path, $filename, $content, $landscape = false, $typeDocsToGen = 'BOTH', $properties = [], $application = '') + public function generate($sUID, $aFields, $sPath, $sFilename, $sContent, $sLandscape = false, $sTypeDocToGener = 'BOTH', $aProperties = array(), $sApplication) { - if (($outDocUid != '') && is_array($caseFields) && ($path != '')) { - $content = G::replaceDataGridField($content, $caseFields, true, true); - G::verifyPath($path, true); + if (($sUID != '') && is_array($aFields) && ($sPath != '')) { + $sContent = \G::replaceDataGridField($sContent, $aFields); + \G::verifyPath($sPath, true); //Start - Create .doc - $fp = fopen($path . $filename . '.doc', 'wb'); - $size = []; + $oFile = fopen($sPath . $sFilename . '.doc', 'wb'); + $size = array(); $size["Letter"] = "216mm 279mm"; $size["Legal"] = "216mm 357mm"; $size["Executive"] = "184mm 267mm"; @@ -640,7 +627,6 @@ class OutputDocument $size["Screenshot640"] = "640mm 480mm"; $size["Screenshot800"] = "800mm 600mm"; $size["Screenshot1024"] = "1024mm 768mm"; - $sizeLandscape = []; $sizeLandscape["Letter"] = "279mm 216mm"; $sizeLandscape["Legal"] = "357mm 216mm"; $sizeLandscape["Executive"] = "267mm 184mm"; @@ -661,31 +647,31 @@ class OutputDocument $sizeLandscape["Screenshot640"] = "480mm 640mm"; $sizeLandscape["Screenshot800"] = "600mm 800mm"; $sizeLandscape["Screenshot1024"] = "768mm 1024mm"; - if (!isset($properties['media'])) { - $properties['media'] = 'Letter'; + if (!isset($aProperties['media'])) { + $aProperties['media'] = 'Letter'; } - if ($landscape) { - $media = $sizeLandscape[$properties['media']]; + if ($sLandscape) { + $media = $sizeLandscape[$aProperties['media']]; } else { - $media = $size[$properties['media']]; + $media = $size[$aProperties['media']]; } $marginLeft = '15'; - if (isset($properties['margins']['left'])) { - $marginLeft = $properties['margins']['left']; + if (isset($aProperties['margins']['left'])) { + $marginLeft = $aProperties['margins']['left']; } $marginRight = '15'; - if (isset($properties['margins']['right'])) { - $marginRight = $properties['margins']['right']; + if (isset($aProperties['margins']['right'])) { + $marginRight = $aProperties['margins']['right']; } $marginTop = '15'; - if (isset($properties['margins']['top'])) { - $marginTop = $properties['margins']['top']; + if (isset($aProperties['margins']['top'])) { + $marginTop = $aProperties['margins']['top']; } $marginBottom = '15'; - if (isset($properties['margins']['bottom'])) { - $marginBottom = $properties['margins']['bottom']; + if (isset($aProperties['margins']['bottom'])) { + $marginBottom = $aProperties['margins']['bottom']; } - fwrite($fp, ' @@ -730,40 +716,40 @@ class OutputDocument
'); - fwrite($fp, $content); - fwrite($fp, "\n
\n\n"); - fclose($fp); + fwrite($oFile, $sContent); + fwrite($oFile, "\n\n\n"); + fclose($oFile); /* End - Create .doc */ - if ($typeDocsToGen == 'BOTH' || $typeDocsToGen == 'PDF') { - $fp = fopen($path . $filename . '.html', 'wb'); - fwrite($fp, $content); - fclose($fp); + if ($sTypeDocToGener == 'BOTH' || $sTypeDocToGener == 'PDF') { + $oFile = fopen($sPath . $sFilename . '.html', 'wb'); + fwrite($oFile, $sContent); + fclose($oFile); /* Start - Create .pdf */ - if (isset($properties['report_generator'])) { - switch ($properties['report_generator']) { + if (isset($aProperties['report_generator'])) { + switch ($aProperties['report_generator']) { case 'TCPDF': - $o = new ClassesOutputDocument(); - if (strlen($content) == 0) { + $o = new \OutputDocument(); + if (strlen($sContent) == 0) { libxml_use_internal_errors(true); - $o->generateTcpdf($outDocUid, $caseFields, $path, $filename, ' ', $landscape, $properties); + $o->generateTcpdf($sUID, $aFields, $sPath, $sFilename, ' ', $sLandscape, $aProperties); libxml_use_internal_errors(false); } else { - $o->generateTcpdf($outDocUid, $caseFields, $path, $filename, $content, $landscape, $properties); + $o->generateTcpdf($sUID, $aFields, $sPath, $sFilename, $sContent, $sLandscape, $aProperties); } break; case 'HTML2PDF': default: - $this->generateHtml2ps_pdf($outDocUid, $caseFields, $path, $filename, $content, $landscape, $properties, $application); + $this->generateHtml2ps_pdf($sUID, $aFields, $sPath, $sFilename, $sContent, $sLandscape, $aProperties, $sApplication); break; } } else { - $this->generateHtml2ps_pdf($outDocUid, $caseFields, $path, $filename, $content, $landscape, $properties); + $this->generateHtml2ps_pdf($sUID, $aFields, $sPath, $sFilename, $sContent, $sLandscape, $aProperties); } } - //end if $typeDocsToGen + //end if $sTypeDocToGener /* End - Create .pdf */ } else { - return PEAR::raiseError( + return \PEAR::raiseError( null, G_ERROR_USER_UID, null, diff --git a/workflow/engine/src/ProcessMaker/Util/helpers.php b/workflow/engine/src/ProcessMaker/Util/helpers.php index 684569b0f..b3d93a2ae 100644 --- a/workflow/engine/src/ProcessMaker/Util/helpers.php +++ b/workflow/engine/src/ProcessMaker/Util/helpers.php @@ -485,33 +485,6 @@ function csrfToken() return isset($_SESSION['USR_CSRF_TOKEN']) ? $_SESSION['USR_CSRF_TOKEN'] : ''; } -/** - * Check if a string is a valid HTML code - * - * @param string $string - * - * @return bool - * - * @see G::replaceDataField() - */ -function stringIsValidHtml($string) -{ - // To validate we use the DOMDocument class - $doc = new DOMDocument('1.0', 'UTF-8'); - - // Clean previous errors - libxml_clear_errors(); - - // This line have to be silenced because if the string is not an HTML a Warning is displayed - @$doc->loadHTML($string); - - // Get last error parsing the HTML - $libXmlError = libxml_get_last_error(); - - // If the attribute "textContent" is empty or exists libxml errors, is not a valid HTML - return $doc->textContent !== '' && empty($libXmlError); -} - // Methods deleted in PHP 7.x, added in this file in order to keep compatibility with old libraries included/used in ProcessMaker if (!function_exists('set_magic_quotes_runtime')) { function set_magic_quotes_runtime($value) {