PMCORE-1203 Help on how batch routing feature works and help to debug the code with a client

This commit is contained in:
Roly Rudy Gutierrez Pinto
2020-03-20 11:26:49 -04:00
parent 67df02497f
commit 2fdcc30aad
15 changed files with 771 additions and 356 deletions

View File

@@ -1,23 +1,12 @@
<?php
/**
* AdditionalTables.php
* @package workflow.engine.classes.model
*/
require_once 'classes/model/om/BaseAdditionalTables.php';
use Illuminate\Support\Facades\DB;
use ProcessMaker\Commands\GenerateDataReport;
use ProcessMaker\Core\MultiProcOpen;
use ProcessMaker\Model\Application;
use ProcessMaker\Model\Fields;
/**
* Skeleton subclass for representing a row from the 'ADDITIONAL_TABLES' table.
*
*
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
* <juliocesar@colosa.com, julces2000@gmail.com>
*
* @package workflow.engine.classes.model
*/
require_once 'classes/model/om/BaseAdditionalTables.php';
function validateType($value, $type)
{
@@ -740,136 +729,34 @@ class AdditionalTables extends BaseAdditionalTables
*/
public function populateReportTable($tableName, $sConnection = 'rp', $type = 'NORMAL', $processUid = '', $gridKey = '', $addTabUid = '')
{
$this->className = $this->getPHPName($tableName);
$this->classPeerName = $this->className . 'Peer';
if (!file_exists(PATH_WORKSPACE . 'classes/' . $this->className . '.php')) {
throw new Exception("ERROR: " . PATH_WORKSPACE . 'classes/' . $this->className . '.php' . " class file doesn't exit!");
}
require_once PATH_WORKSPACE . 'classes/' . $this->className . '.php';
//get fields
$fieldTypes = [];
if ($addTabUid != '') {
$criteria = new Criteria('workflow');
$criteria->add(FieldsPeer::ADD_TAB_UID, $addTabUid);
$dataset = FieldsPeer::doSelectRS($criteria);
$dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
while ($dataset->next()) {
$row = $dataset->getRow();
switch ($row['FLD_TYPE']) {
case 'FLOAT':
case 'DOUBLE':
case 'INTEGER':
$fieldTypes[] = array($row['FLD_NAME'] => $row['FLD_TYPE']);
break;
default:
break;
}
}
}
//remove old applications references
$connection = Propel::getConnection($sConnection);
$statement = $connection->createStatement();
$sql = "TRUNCATE " . $tableName;
$statement->executeQuery($sql);
$case = new Cases();
$context = Bootstrap::getDefaultContextLog();
//select cases for this Process, ordered by APP_NUMBER
$criteria = new Criteria('workflow');
$criteria->add(ApplicationPeer::PRO_UID, $processUid);
$criteria->addAscendingOrderByColumn(ApplicationPeer::APP_NUMBER);
$dataset = ApplicationPeer::doSelectRS($criteria);
$dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
while ($dataset->next()) {
$row = $dataset->getRow();
//getting the case data
$appData = $case->unserializeData($row['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
$className = $this->className;
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($row['APP_UID']);
$obj->setAppNumber($row['APP_NUMBER']);
if (method_exists($obj, 'setAppStatus')) {
$obj->setAppStatus($row['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"] = $row['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($row['APP_UID']);
$obj->setAppNumber($row['APP_NUMBER']);
if (method_exists($obj, 'setAppStatus')) {
$obj->setAppStatus($row['APP_STATUS']);
}
$obj->save();
} catch (Exception $e) {
$context["message"] = $e->getMessage();
$context["tableName"] = $tableName;
$context["appUid"] = $row['APP_UID'];
Bootstrap::registerMonolog("sqlExecution", 500, "Sql Execution", $context, $context["workspace"], "processmaker.log");
}
unset($obj);
}
}
$this->className = $className = $this->getPHPName($tableName);
$this->classPeerName = $classPeerName = $className . 'Peer';
DB::statement("TRUNCATE " . $tableName);
$workspace = config("system.workspace");
$pathWorkspace = PATH_WORKSPACE;
$n = Application::count();
$processesManager = new MultiProcOpen();
$processesManager->chunk($n, 1000, function($size, $start, $limit) use(
$workspace,
$tableName,
$type,
$processUid,
$gridKey,
$addTabUid,
$className,
$pathWorkspace) {
return new GenerateDataReport(
$workspace,
$tableName,
$type,
$processUid,
$gridKey,
$addTabUid,
$className,
$pathWorkspace,
$start,
$limit);
});
}
/**