PMCORE-1491

This commit is contained in:
Julio Cesar Laura Avendaño
2020-06-10 23:00:46 +00:00
parent 48dc990279
commit 5c34f18a3a
3 changed files with 47 additions and 18 deletions

View File

@@ -23,6 +23,7 @@ class DBQueryTest extends TestCase
/**
* Verify the execution of a common SQL statement.
* Note, this test is now using Laravel DB backend work
* @test
*/
public function testStandardExecuteQuery()

View File

@@ -206,6 +206,7 @@ class DbConnections
});
foreach ($externalDbs as $externalDb) {
$conf['datasources'][$externalDb->DBS_UID] = [];
$laravelConfig = [];
$flagTns = ($externalDb->DBS_TYPE == "oracle" && $externalDb->DBS_CONNECTION_TYPE == "TNS")? 1 : 0;
// Build the appropriate items to add to our Propel configuration
// Let's grab the decrypted password
@@ -235,12 +236,26 @@ class DbConnections
. $externalDb->DBS_USERNAME . ':' . $passw . '@' . $externalDb->DBS_SERVER . $dbsPort . '/'
. $externalDb->DBS_DATABASE_NAME . $encoding;
}
$laravelConfig = [
'driver' => $externalDb->DBS_TYPE === 'mssql' ? 'sqlsrv' : $externalDb->DBS_TYPE, // MSSQL driver is not supported anymore, only SQLSRV
'host' => $externalDb->DBS_SERVER,
'port' => $externalDb->DBS_PORT == '' ? null : $externalDb->DBS_PORT,
'database' => $externalDb->DBS_DATABASE_NAME,
'username' => $externalDb->DBS_USERNAME,
'password' => $passw,
'charset' => trim($externalDb->DBS_ENCODE) == '' ? null : trim($externalDb->DBS_ENCODE),
'options' => [PDO::ATTR_STRINGIFY_FETCHES => true] // For keep the old behaviour, all values are transformed to strings
];
} else {
// Is oracle and TNS, let's provide a TNS based DSN
$conf["datasources"][$externalDb->DBS_UID]["connection"] = $externalDb->DBS_TYPE . "://"
. $externalDb->DBS_USERNAME . ":" . $passw . "@" . $externalDb->DBS_TNS;
}
$conf['datasources'][$externalDb->DBS_UID]['adapter'] = $externalDb->DBS_TYPE;
// Load the config for the external database into laravel
config([
'database.connections.' . $externalDb->DBS_UID => $laravelConfig
]);
}
Propel::initConfiguration($conf);
$lastProcessId = $_SESSION['PROCESS'];

View File

@@ -32,6 +32,7 @@ use ProcessMaker\BusinessModel\Cases as BusinessModelCases;
use ProcessMaker\Core\System;
use ProcessMaker\Plugins\PluginRegistry;
use ProcessMaker\Util\ElementTranslation;
use Illuminate\Support\Facades\DB;
/**
* ProcessMaker has made a number of its PHP functions available be used in triggers and conditions.
@@ -243,8 +244,22 @@ function executeQuery ($SqlStatement, $DBConnectionUID = 'workflow', $aParameter
{
$sysSys = (!empty(config("system.workspace")))? config("system.workspace") : "Undefined";
$aContext = \Bootstrap::getDefaultContextLog();
$con = Propel::getConnection( $DBConnectionUID );
$con->begin();
// This means the DBConnectionUID is not loaded yet, so we'll force DbConnections::loadAdditionalConnections
if (is_null(config('database.connections.' . $DBConnectionUID . '.driver'))) {
// Force to load the external connections
DbConnections::loadAdditionalConnections();
if (config('database.connections.' . $DBConnectionUID . '.driver') !== 'oracle') {
// If the connections drivers are "mysql", "pgsql" or "sqlsrv" we're using Laravel
$con = DB::connection($DBConnectionUID);
$con->beginTransaction();
} else {
// If the connection driver is "oracle" we're using the native oci8 functions
$con = Propel::getConnection($DBConnectionUID);
$con->begin();
}
}
$blackList = System::getQueryBlackList();
$listQueries = explode('|', isset($blackList['queries']) ? $blackList['queries'] : '');
$aListAllTables = explode(
@@ -299,36 +314,34 @@ function executeQuery ($SqlStatement, $DBConnectionUID = 'workflow', $aParameter
$statement = str_replace( '(', '', $statement );
$result = false;
if (getEngineDataBaseName( $con ) != 'oracle') {
// Check to see if we're not running oracle, which is usually a safe default
if (config('database.connections.' . $DBConnectionUID . '.driver') != 'oracle') {
switch (true) {
case preg_match( "/^(SELECT|EXECUTE|EXEC|SHOW|DESCRIBE|EXPLAIN|BEGIN)\s/i", $statement ):
$rs = $con->executeQuery( $SqlStatement );
$result = Array ();
$i = 1;
while ($rs->next()) {
$result[$i ++] = $rs->getRow();
}
$rs->close();
$result = $con->select( $SqlStatement );
// Convert to 1 index key array of array results
$result = collect($result)->map(function($x) { return (array)$x; })->toArray();
array_unshift($result, []);
unset($result[0]);
$con->commit();
break;
case preg_match( "/^INSERT\s/i", $statement ):
$rs = $con->executeUpdate( $SqlStatement );
$result = $con->getUpdateCount();
$result = $con->insert( $SqlStatement );
$con->commit();
break;
case preg_match( "/^REPLACE\s/i", $statement ):
$rs = $con->executeUpdate( $SqlStatement );
$result = $con->getUpdateCount();
$result = $con->update( $SqlStatement );
$con->commit();
break;
case preg_match( "/^UPDATE\s/i", $statement ):
$rs = $con->executeUpdate( $SqlStatement );
$result = $con->getUpdateCount();
$result = $con->update( $SqlStatement );
$con->commit();
break;
case preg_match( "/^DELETE\s/i", $statement ):
$rs = $con->executeUpdate( $SqlStatement );
$result = $con->getUpdateCount();
$result = $con->delete( $SqlStatement );
$con->commit();
break;
}