Merged in bugfix/HOR-4765 (pull request #6573)
HOR-4765: clone of HOR-4025 Approved-by: Julio Cesar Laura Avendaño <contact@julio-laura.com>
This commit is contained in:
@@ -707,50 +707,29 @@ class AdditionalTables extends BaseAdditionalTables
|
||||
*/
|
||||
public function populateReportTable($tableName, $sConnection = 'rp', $type = 'NORMAL', $processUid = '', $gridKey = '', $addTabUid = '')
|
||||
{
|
||||
require_once "classes/model/Application.php";
|
||||
|
||||
$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!");
|
||||
throw new Exception("ERROR: " . PATH_WORKSPACE . 'classes/' . $this->className . '.php' . " class file doesn't exit!");
|
||||
}
|
||||
|
||||
require_once PATH_WORKSPACE . 'classes/' . $this->className . '.php';
|
||||
|
||||
//select cases for this Process, ordered by APP_NUMBER
|
||||
$con = Propel::getConnection($sConnection);
|
||||
$stmt = $con->createStatement();
|
||||
//get fields
|
||||
$fieldTypes = [];
|
||||
if ($addTabUid != '') {
|
||||
$criteria = new Criteria('workflow');
|
||||
$criteria->add(ApplicationPeer::PRO_UID, $processUid);
|
||||
$criteria->addAscendingOrderByColumn(ApplicationPeer::APP_NUMBER);
|
||||
$dataset = ApplicationPeer::doSelectRS($criteria);
|
||||
$criteria->add(FieldsPeer::ADD_TAB_UID, $addTabUid);
|
||||
$dataset = FieldsPeer::doSelectRS($criteria);
|
||||
$dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
while ($dataset->next()) {
|
||||
$row = $dataset->getRow();
|
||||
//remove old applications references
|
||||
$deleteSql = "DELETE FROM $tableName WHERE APP_UID = '" . $row['APP_UID'] . "'";
|
||||
$rs = $stmt->executeQuery($deleteSql);
|
||||
// getting the case data
|
||||
$caseData = unserialize($row['APP_DATA']);
|
||||
|
||||
$fieldTypes = array();
|
||||
|
||||
if ($addTabUid != '') {
|
||||
require_once 'classes/model/Fields.php';
|
||||
$criteriaField = new Criteria('workflow');
|
||||
$criteriaField->add(FieldsPeer::ADD_TAB_UID, $addTabUid);
|
||||
$datasetField = FieldsPeer::doSelectRS($criteriaField);
|
||||
$datasetField->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
||||
while ($datasetField->next()) {
|
||||
$rowfield = $datasetField->getRow();
|
||||
switch ($rowfield['FLD_TYPE']) {
|
||||
switch ($row['FLD_TYPE']) {
|
||||
case 'FLOAT':
|
||||
case 'DOUBLE':
|
||||
case 'INTEGER':
|
||||
$fieldTypes[] = array($rowfield['FLD_NAME'] => $rowfield['FLD_TYPE']);
|
||||
$fieldTypes[] = array($row['FLD_NAME'] => $row['FLD_TYPE']);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -758,34 +737,54 @@ class AdditionalTables extends BaseAdditionalTables
|
||||
}
|
||||
}
|
||||
|
||||
// quick fix
|
||||
// map all empty values as NULL for Database
|
||||
foreach ($caseData as $dKey => $dValue) {
|
||||
if (is_array($dValue) && count($dValue)) {
|
||||
$j = key($dValue);
|
||||
$dValue = (is_array($dValue[$j])) ? $dValue : $dValue[$j];
|
||||
//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($dValue)) {
|
||||
if (is_string($appDataValue)) {
|
||||
foreach ($fieldTypes as $key => $fieldType) {
|
||||
foreach ($fieldType as $name => $theType) {
|
||||
if (strtoupper($dKey) == $name) {
|
||||
$caseData[$dKey] = validateType($dValue, $theType);
|
||||
unset($name);
|
||||
foreach ($fieldType as $fieldTypeKey => $fieldTypeValue) {
|
||||
if (strtoupper($appDataKey) == $fieldTypeKey) {
|
||||
$appData[$appDataKey] = validateType($appDataValue, $fieldTypeValue);
|
||||
unset($fieldTypeKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
// normal fields
|
||||
if (trim($dValue) === '') {
|
||||
$caseData[$dKey] = null;
|
||||
if (trim($appDataValue) === '') {
|
||||
$appData[$appDataKey] = null;
|
||||
}
|
||||
} else {
|
||||
// grids
|
||||
if (is_array($caseData[$dKey])) {
|
||||
foreach ($caseData[$dKey] as $dIndex => $dRow) {
|
||||
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) === '') {
|
||||
$caseData[$dKey][$dIndex][$k] = null;
|
||||
$appData[$appDataKey][$dIndex][$k] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -794,13 +793,15 @@ class AdditionalTables extends BaseAdditionalTables
|
||||
}
|
||||
}
|
||||
|
||||
//populate data
|
||||
$className = $this->className;
|
||||
if ($type === 'GRID') {
|
||||
list($gridName, $gridUid) = explode('-', $gridKey);
|
||||
$gridData = isset($caseData[$gridName]) ? $caseData[$gridName] : array();
|
||||
|
||||
$gridData = isset($appData[$gridName]) ? $appData[$gridName] : [];
|
||||
foreach ($gridData as $i => $gridRow) {
|
||||
eval('$obj = new ' . $this->className . '();');
|
||||
$obj->fromArray($caseData, BasePeer::TYPE_FIELDNAME);
|
||||
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')) {
|
||||
@@ -809,18 +810,31 @@ class AdditionalTables extends BaseAdditionalTables
|
||||
$obj->fromArray(array_change_key_case($gridRow, CASE_UPPER), BasePeer::TYPE_FIELDNAME);
|
||||
$obj->setRow($i);
|
||||
$obj->save();
|
||||
eval('$obj = new ' . $this->className . '();');
|
||||
} 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 {
|
||||
eval('$obj = new ' . $this->className . '();');
|
||||
$obj->fromArray(array_change_key_case($caseData, CASE_UPPER), BasePeer::TYPE_FIELDNAME);
|
||||
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();
|
||||
$obj = null;
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1152,6 +1152,12 @@ class pmTablesProxy extends HttpProxyController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* It eliminates and generates the data report from the cases of a process.
|
||||
*
|
||||
* @param object $httpData
|
||||
* @return object
|
||||
*/
|
||||
public function genDataReport($httpData)
|
||||
{
|
||||
$result = new stdClass();
|
||||
@@ -1161,11 +1167,25 @@ class pmTablesProxy extends HttpProxyController
|
||||
|
||||
$additionalTables = new AdditionalTables();
|
||||
$table = $additionalTables->load($httpData->id);
|
||||
if ($table['PRO_UID'] != '') {
|
||||
$additionalTables->populateReportTable( $table['ADD_TAB_NAME'], PmTable::resolveDbSource( $table['DBS_UID'] ), $table['ADD_TAB_TYPE'], $table['PRO_UID'], $table['ADD_TAB_GRID'], $table['ADD_TAB_UID'] );
|
||||
$result->message = 'generated for table ' . $table['ADD_TAB_NAME'];
|
||||
}
|
||||
|
||||
if (!empty($table) && $table['PRO_UID'] != '') {
|
||||
try {
|
||||
$additionalTables->populateReportTable($table['ADD_TAB_NAME'], PmTable::resolveDbSource($table['DBS_UID']), $table['ADD_TAB_TYPE'], $table['PRO_UID'], $table['ADD_TAB_GRID'], $table['ADD_TAB_UID']);
|
||||
$result->message = 'Generated for table ' . $table['ADD_TAB_NAME'];
|
||||
} catch (Exception $e) {
|
||||
$context = Bootstrap::getDefaultContextLog();
|
||||
$context['proUid'] = $table['PRO_UID'];
|
||||
$context['tableName'] = $table['ADD_TAB_NAME'];
|
||||
$context['message'] = $e->getMessage();
|
||||
Bootstrap::registerMonolog('dataReport', 500, 'Generation of data report could not be completed', $context, $context['workspace'], 'processmaker.log');
|
||||
|
||||
$result->message = 'Generation of data report could not be completed. Please check the processmaker.log for more details.';
|
||||
$result->success = false;
|
||||
}
|
||||
} else {
|
||||
$result->message = 'Unable to retrieve the table for this id: ' . $httpData->id . '.';
|
||||
$result->success = false;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
@@ -818,17 +818,26 @@ UpdatePageConfig = function(pageSize){
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Regenerate data report
|
||||
*
|
||||
* @returns void
|
||||
*/
|
||||
genDataReport = function ()
|
||||
{
|
||||
genDataReportButton.setDisabled(true);
|
||||
Ext.Ajax.request({
|
||||
url: '../pmTablesProxy/genDataReport',
|
||||
params: {id: tableDef.ADD_TAB_UID},
|
||||
success: function (resp) {
|
||||
genDataReportButton.setDisabled(false);
|
||||
response = Ext.util.JSON.decode(resp.responseText);
|
||||
PMExt.notify(_('ID_UPDATE'), response.message)
|
||||
Ext.getCmp('infoGrid').store.reload();
|
||||
|
||||
},
|
||||
failure: function (obj, resp) {
|
||||
genDataReportButton.setDisabled(false);
|
||||
PMExt.error(_('ID_ERROR'), resp.result.message);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user