Merged in bugfix/PMC-898 (pull request #6948)

PMC-898

Approved-by: Julio Cesar Laura Avendaño <contact@julio-laura.com>
This commit is contained in:
Andrea Adamczyk
2019-07-01 19:33:52 +00:00
committed by Julio Cesar Laura Avendaño
6 changed files with 283 additions and 0 deletions

View File

@@ -9,6 +9,7 @@ use Faker;
use G;
use GzipFile;
use Illuminate\Database\QueryException;
use Illuminate\Foundation\Http\Kernel;
use Illuminate\Support\Facades\DB;
use InputFilter;
use InstallerModule;
@@ -1629,5 +1630,21 @@ class System
{
return !empty(self::getServerHostname()) ? self::getServerHostname() : 'processmaker.com';
}
/**
* Initialize laravel database configuration
* @see workflow/engine/bin/tasks/cliWorkspaces.php->check_queries_incompatibilities()
*/
public static function initLaravel()
{
config(['database.connections.workflow.host' => DB_HOST]);
config(['database.connections.workflow.database' => DB_NAME]);
config(['database.connections.workflow.username' => DB_USER]);
config(['database.connections.workflow.password' => DB_PASS]);
app()->useStoragePath(realpath(PATH_DATA));
app()->make(Kernel::class)->bootstrap();
restore_error_handler();
}
}
// end System class

View File

@@ -66,4 +66,16 @@ class Dynaform extends Model
->where('DYNAFORM.DYN_UID', '!=', $dynUid)
->get();
}
/**
* Scope a query to filter an specific process
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $columns
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeProcess($query, string $proUID)
{
return $query->where('PRO_UID', $proUID);
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace ProcessMaker\Model;
use Illuminate\Database\Eloquent\Model;
class ProcessVariables extends Model
{
// Set our table name
protected $table = 'PROCESS_VARIABLES';
// No timestamps
public $timestamps = false;
//primary key
protected $primaryKey = 'VAR_UID';
/**
* Scope a query to filter an specific process
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $columns
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeProcess($query, string $proUID)
{
return $query->where('PRJ_UID', $proUID);
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace ProcessMaker\Model;
use Illuminate\Database\Eloquent\Model;
class Triggers extends Model
{
// Set our table name
protected $table = 'TRIGGERS';
// No timestamps
public $timestamps = false;
//primary key
protected $primaryKey = 'TRI_UID';
/**
* Scope a query to filter an specific process
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $columns
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeProcess($query, string $proUID)
{
return $query->where('PRO_UID', $proUID);
}
}

View File

@@ -0,0 +1,110 @@
<?php
namespace ProcessMaker\Validation;
use ProcessMaker\Model\Dynaform;
use ProcessMaker\Model\Process;
use ProcessMaker\Model\ProcessVariables;
use ProcessMaker\Model\Triggers;
class MySQL57
{
const REGEX = '/(?i)(select|\$).*?UNION.*?(select|\$).*?/ms';
/**
* Checks the queries inside triggers that could have possible incompatibilities with MySQL 5.7
*
* @see workflow/engine/bin/tasks/cliWorkspaces.php->check_queries_incompatibilities()
* @param array $processes
* @return array
*/
public function checkIncompatibilityTriggers($processes)
{
$result = [];
foreach ($processes as $process) {
$triggerQuery = Triggers::query()->select();
//Call the scope method to filter by process
$triggerQuery->process($process['PRO_UID']);
$triggers = $triggerQuery->get()->values()->toArray();
foreach ($triggers as $trigger) {
$resultIncompatibility = $this->analyzeQuery($trigger['TRI_WEBBOT']);
if ($resultIncompatibility) {
$aux = array_merge($process, $trigger);
array_push($result, $aux);
}
}
}
return $result;
}
/**
* Checks the queries inside dynaforms that could have possible incompatibilities with MySQL 5.7
*
* @see workflow/engine/bin/tasks/cliWorkspaces.php->check_queries_incompatibilities()
* @param array $processes
* @return array
*/
public function checkIncompatibilityDynaforms($processes)
{
$result = [];
foreach ($processes as $process) {
$dynaformQuery = Dynaform::query()->select();
//Call the scope method to filter by process
$dynaformQuery->process($process['PRO_UID']);
$dynaforms = $dynaformQuery->get()->values()->toArray();
foreach ($dynaforms as $dynaform) {
$resultIncompatibility = $this->analyzeQuery($dynaform['DYN_CONTENT']);
if ($resultIncompatibility) {
$aux = array_merge($process, $dynaform);
array_push($result, $aux);
}
}
}
return $result;
}
/**
* Checks the queries inside variables that could have possible incompatibilities with MySQL 5.7
*
* @see workflow/engine/bin/tasks/cliWorkspaces.php->check_queries_incompatibilities()
* @param array $processes
* @return array
*/
public function checkIncompatibilityVariables($processes)
{
$result = [];
foreach ($processes as $process) {
$variablesQuery = ProcessVariables::query()->select();
//Call the scope method to filter by process
$variablesQuery->process($process['PRO_UID']);
$variables = $variablesQuery->get()->values()->toArray();
foreach ($variables as $variable) {
$resultIncompatibility = $this->analyzeQuery($variable['VAR_SQL']);
if ($resultIncompatibility) {
$aux = array_merge($process, $variable);
array_push($result, $aux);
}
}
}
return $result;
}
/**
* Analyze the query using the regular expression
*
* @param string $query
* @return bool
*/
public function analyzeQuery($query)
{
preg_match_all($this::REGEX, $query, $matches, PREG_SET_ORDER, 0);
return !empty($matches);
}
}