PMC-898
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use ProcessMaker\Model\Process;
|
||||||
|
use ProcessMaker\Validation\MySQL57;
|
||||||
|
|
||||||
CLI::taskName('info');
|
CLI::taskName('info');
|
||||||
CLI::taskDescription(<<<EOT
|
CLI::taskDescription(<<<EOT
|
||||||
Print information about the current system and any specified workspaces.
|
Print information about the current system and any specified workspaces.
|
||||||
@@ -372,6 +375,21 @@ EOT
|
|||||||
);
|
);
|
||||||
CLI::taskRun("remove_deprecated_files");
|
CLI::taskRun("remove_deprecated_files");
|
||||||
|
|
||||||
|
/*********************************************************************/
|
||||||
|
CLI::taskName("check-queries-incompatibilities");
|
||||||
|
CLI::taskDescription(<<<EOT
|
||||||
|
Check queries incompatibilities (MySQL 5.7) for the specified workspace(s).
|
||||||
|
|
||||||
|
This command checks the queries incompatibilities (MySQL 5.7) in the specified workspace(s).
|
||||||
|
|
||||||
|
If no workspace is specified, the command will be run in all workspaces.
|
||||||
|
More than one workspace can be specified.
|
||||||
|
EOT
|
||||||
|
);
|
||||||
|
CLI::taskArg("workspace-name", true, true);
|
||||||
|
CLI::taskRun("run_check_queries_incompatibilities");
|
||||||
|
/*********************************************************************/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function run_info
|
* Function run_info
|
||||||
*
|
*
|
||||||
@@ -477,6 +495,7 @@ function run_upgrade_content($args, $opts)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function will upgrade the CONTENT table for a workspace
|
* This function will upgrade the CONTENT table for a workspace
|
||||||
* This function is executed only for one workspace
|
* This function is executed only for one workspace
|
||||||
@@ -1373,3 +1392,74 @@ function remove_deprecated_files()
|
|||||||
$workspaceTools->removeDeprecatedFiles();
|
$workspaceTools->removeDeprecatedFiles();
|
||||||
CLI::logging("<*> The deprecated files has been removed. \n");
|
CLI::logging("<*> The deprecated files has been removed. \n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function review the queries for each workspace or for an specific workspace
|
||||||
|
*
|
||||||
|
* @param array $args
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function run_check_queries_incompatibilities($args)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$workspaces = get_workspaces_from_args($args);
|
||||||
|
if (count($args) === 1) {
|
||||||
|
CLI::logging("> Workspace: " . $workspaces[0]->name . PHP_EOL);
|
||||||
|
check_queries_incompatibilities($workspaces[0]->name);
|
||||||
|
} else {
|
||||||
|
foreach ($workspaces as $workspace) {
|
||||||
|
passthru(PHP_BINARY . " processmaker check-queries-incompatibilities " . $workspace->name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
echo "Done!\n\n";
|
||||||
|
} catch (Exception $e) {
|
||||||
|
G::outRes(CLI::error($e->getMessage()) . "\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check for the incompatibilities in the queries for the specific workspace
|
||||||
|
*
|
||||||
|
* @param string $wsName
|
||||||
|
*/
|
||||||
|
function check_queries_incompatibilities($wsName)
|
||||||
|
{
|
||||||
|
Bootstrap::setConstantsRelatedWs($wsName);
|
||||||
|
require_once(PATH_DB . $wsName . '/db.php');
|
||||||
|
System::initLaravel();
|
||||||
|
|
||||||
|
$query = Process::query()->select('PRO_UID', 'PRO_TITLE');
|
||||||
|
$processesToCheck = $query->get()->values()->toArray();
|
||||||
|
|
||||||
|
$obj = new MySQL57();
|
||||||
|
$resTriggers = $obj->checkIncompatibilityTriggers($processesToCheck);
|
||||||
|
|
||||||
|
if (!empty($resTriggers)) {
|
||||||
|
foreach ($resTriggers as $trigger) {
|
||||||
|
echo ">> The \"" . $trigger['PRO_TITLE'] . "\" process has a trigger called: \"" . $trigger['TRI_TITLE'] . "\" that contains UNION queries. Review the code to discard incompatibilities with MySQL5.7." . PHP_EOL;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echo ">> No MySQL 5.7 incompatibilities in triggers found for this workspace." . PHP_EOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
$resDynaforms = $obj->checkIncompatibilityDynaforms($processesToCheck);
|
||||||
|
|
||||||
|
if (!empty($resDynaforms)) {
|
||||||
|
foreach ($resDynaforms as $dynaform) {
|
||||||
|
echo ">> The \"" . $dynaform['PRO_TITLE'] . "\" process has a dynaform called: \"" . $dynaform['DYN_TITLE'] . "\" that contains UNION queries. Review the code to discard incompatibilities with MySQL5.7." . PHP_EOL;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echo ">> No MySQL 5.7 incompatibilities in dynaforms found for this workspace." . PHP_EOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
$resVariables = $obj->checkIncompatibilityVariables($processesToCheck);
|
||||||
|
|
||||||
|
if (!empty($resVariables)) {
|
||||||
|
foreach ($resVariables as $variable) {
|
||||||
|
echo ">> The \"" . $variable['PRO_TITLE'] . "\" process has a variable called: \"" . $variable['VAR_NAME'] . "\" that contains UNION queries. Review the code to discard incompatibilities with MySQL5.7." . PHP_EOL;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echo ">> No MySQL 5.7 incompatibilities in variables found for this workspace." . PHP_EOL;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@ use Faker;
|
|||||||
use G;
|
use G;
|
||||||
use GzipFile;
|
use GzipFile;
|
||||||
use Illuminate\Database\QueryException;
|
use Illuminate\Database\QueryException;
|
||||||
|
use Illuminate\Foundation\Http\Kernel;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use InputFilter;
|
use InputFilter;
|
||||||
use InstallerModule;
|
use InstallerModule;
|
||||||
@@ -1629,5 +1630,21 @@ class System
|
|||||||
{
|
{
|
||||||
return !empty(self::getServerHostname()) ? self::getServerHostname() : 'processmaker.com';
|
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
|
// end System class
|
||||||
|
|||||||
@@ -61,4 +61,16 @@ class Dynaform extends Model
|
|||||||
->where('DYNAFORM.DYN_UID', '!=', $dynUid)
|
->where('DYNAFORM.DYN_UID', '!=', $dynUid)
|
||||||
->get();
|
->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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
27
workflow/engine/src/ProcessMaker/Model/ProcessVariables.php
Normal file
27
workflow/engine/src/ProcessMaker/Model/ProcessVariables.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
27
workflow/engine/src/ProcessMaker/Model/Triggers.php
Normal file
27
workflow/engine/src/ProcessMaker/Model/Triggers.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
110
workflow/engine/src/ProcessMaker/Validation/MySQL57.php
Normal file
110
workflow/engine/src/ProcessMaker/Validation/MySQL57.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user