PMCORE-1203 Help on how batch routing feature works and help to debug the code with a client
This commit is contained in:
@@ -9,6 +9,8 @@ use ProcessMaker\ChangeLog\ChangeLog;
|
||||
use ProcessMaker\Core\Installer;
|
||||
use ProcessMaker\Core\ProcessesManager;
|
||||
use ProcessMaker\Core\System;
|
||||
use ProcessMaker\Model\Application;
|
||||
use ProcessMaker\Model\Fields;
|
||||
use ProcessMaker\Plugins\Adapters\PluginAdapter;
|
||||
use ProcessMaker\Project\Adapter\BpmnWorkflow;
|
||||
use ProcessMaker\Upgrade\RunProcessUpgradeQuery;
|
||||
@@ -4821,4 +4823,167 @@ class WorkspaceTools
|
||||
$database = $this->getDatabase($rbac);
|
||||
$database->executeQuery($query, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method regenerates data report with the APP_DATA data.
|
||||
* @param string $tableName
|
||||
* @param string $type
|
||||
* @param string $processUid
|
||||
* @param string $gridKey
|
||||
* @param string $addTabUid
|
||||
* @param string $className
|
||||
* @param string $pathWorkspace
|
||||
* @param int $start
|
||||
* @param int $limit
|
||||
* @throws Exception
|
||||
*/
|
||||
public function generateDataReport(
|
||||
$tableName,
|
||||
$type = 'NORMAL',
|
||||
$processUid = '',
|
||||
$gridKey = '',
|
||||
$addTabUid = '',
|
||||
$className = '',
|
||||
$pathWorkspace,
|
||||
int $start = 0,
|
||||
int $limit = 10)
|
||||
{
|
||||
$this->initPropel();
|
||||
$dbHost = explode(':', $this->dbHost);
|
||||
config(['database.connections.workflow.host' => $dbHost[0]]);
|
||||
config(['database.connections.workflow.database' => $this->dbName]);
|
||||
config(['database.connections.workflow.username' => $this->dbUser]);
|
||||
config(['database.connections.workflow.password' => $this->dbPass]);
|
||||
if (count($dbHost) > 1) {
|
||||
config(['database.connections.workflow.port' => $dbHost[1]]);
|
||||
}
|
||||
|
||||
//require file
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . $pathWorkspace);
|
||||
if (!file_exists($pathWorkspace . 'classes/' . $className . '.php')) {
|
||||
throw new Exception("ERROR: " . $pathWorkspace . 'classes/' . $className . '.php' . " class file doesn't exit!");
|
||||
}
|
||||
require_once 'classes/model/AdditionalTables.php';
|
||||
require_once $pathWorkspace . 'classes/' . $className . '.php';
|
||||
|
||||
//get fields
|
||||
$fieldTypes = [];
|
||||
if ($addTabUid != '') {
|
||||
$fields = Fields::where('ADD_TAB_UID', '=', $addTabUid)->get();
|
||||
foreach ($fields as $field) {
|
||||
switch ($field->FLD_TYPE) {
|
||||
case 'FLOAT':
|
||||
case 'DOUBLE':
|
||||
case 'INTEGER':
|
||||
$fieldTypes[] = [$field->FLD_NAME => $field->FLD_TYPE];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$context = Bootstrap::getDefaultContextLog();
|
||||
$case = new Cases();
|
||||
|
||||
//select cases for this Process, ordered by APP_NUMBER
|
||||
$applications = Application::where('PRO_UID', '=', $processUid)
|
||||
->orderBy('APP_NUMBER', 'asc')
|
||||
->offset($start)
|
||||
->limit($limit)
|
||||
->get();
|
||||
foreach ($applications as $application) {
|
||||
//getting the case data
|
||||
$appData = $case->unserializeData($application->APP_DATA);
|
||||
|
||||
//quick fix, map all empty values as NULL for Database
|
||||
foreach ($appData as $appDataKey => $appDataValue) {
|
||||
if (is_array($appDataValue) && count($appDataValue)) {
|
||||
$j = key($appDataValue);
|
||||
$appDataValue = is_array($appDataValue[$j]) ? $appDataValue : $appDataValue[$j];
|
||||
}
|
||||
if (is_string($appDataValue)) {
|
||||
foreach ($fieldTypes as $key => $fieldType) {
|
||||
foreach ($fieldType as $fieldTypeKey => $fieldTypeValue) {
|
||||
if (strtoupper($appDataKey) == $fieldTypeKey) {
|
||||
$appData[$appDataKey] = validateType($appDataValue, $fieldTypeValue);
|
||||
unset($fieldTypeKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
// normal fields
|
||||
if (trim($appDataValue) === '') {
|
||||
$appData[$appDataKey] = null;
|
||||
}
|
||||
} else {
|
||||
// grids
|
||||
if (is_array($appData[$appDataKey])) {
|
||||
foreach ($appData[$appDataKey] as $dIndex => $dRow) {
|
||||
if (is_array($dRow)) {
|
||||
foreach ($dRow as $k => $v) {
|
||||
if (is_string($v) && trim($v) === '') {
|
||||
$appData[$appDataKey][$dIndex][$k] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//populate data
|
||||
if ($type === 'GRID') {
|
||||
list($gridName, $gridUid) = explode('-', $gridKey);
|
||||
$gridData = isset($appData[$gridName]) ? $appData[$gridName] : [];
|
||||
foreach ($gridData as $i => $gridRow) {
|
||||
try {
|
||||
$obj = new $className();
|
||||
$obj->fromArray($appData, BasePeer::TYPE_FIELDNAME);
|
||||
$obj->setAppUid($application->APP_UID);
|
||||
$obj->setAppNumber($application->APP_NUMBER);
|
||||
if (method_exists($obj, 'setAppStatus')) {
|
||||
$obj->setAppStatus($application->APP_STATUS);
|
||||
}
|
||||
$obj->fromArray(array_change_key_case($gridRow, CASE_UPPER), BasePeer::TYPE_FIELDNAME);
|
||||
$obj->setRow($i);
|
||||
$obj->save();
|
||||
} catch (Exception $e) {
|
||||
$context["message"] = $e->getMessage();
|
||||
$context["tableName"] = $tableName;
|
||||
$context["appUid"] = $application->APP_UID;
|
||||
Bootstrap::registerMonolog("sqlExecution", 500, "Sql Execution", $context, $context["workspace"], "processmaker.log");
|
||||
}
|
||||
unset($obj);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
$obj = new $className();
|
||||
$obj->fromArray(array_change_key_case($appData, CASE_UPPER), BasePeer::TYPE_FIELDNAME);
|
||||
$obj->setAppUid($application->APP_UID);
|
||||
$obj->setAppNumber($application->APP_NUMBER);
|
||||
if (method_exists($obj, 'setAppStatus')) {
|
||||
$obj->setAppStatus($application->APP_STATUS);
|
||||
}
|
||||
$obj->save();
|
||||
} catch (Exception $e) {
|
||||
$context["message"] = $e->getMessage();
|
||||
$context["tableName"] = $tableName;
|
||||
$context["appUid"] = $application->APP_UID;
|
||||
Bootstrap::registerMonolog("sqlExecution", 500, "Sql Execution", $context, $context["workspace"], "processmaker.log");
|
||||
}
|
||||
unset($obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method populates the table with a query string.
|
||||
* @param string $query
|
||||
* @param boolean $rbac
|
||||
*/
|
||||
public function populateTableReport($query, $rbac)
|
||||
{
|
||||
$database = $this->getDatabase($rbac);
|
||||
$database->executeQuery($query, true);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user