Merged in bugfix/HOR-4025 (pull request #6300)

HOR-4025

Approved-by: Julio Cesar Laura Avendaño <contact@julio-laura.com>
This commit is contained in:
Roly
2018-03-23 18:22:04 +00:00
committed by Paula Quispe
parent d47af21c30
commit 189eedbe36
3 changed files with 128 additions and 85 deletions

View File

@@ -707,85 +707,84 @@ class AdditionalTables extends BaseAdditionalTables
*/ */
public function populateReportTable($tableName, $sConnection = 'rp', $type = 'NORMAL', $processUid = '', $gridKey = '', $addTabUid = '') public function populateReportTable($tableName, $sConnection = 'rp', $type = 'NORMAL', $processUid = '', $gridKey = '', $addTabUid = '')
{ {
require_once "classes/model/Application.php";
$this->className = $this->getPHPName($tableName); $this->className = $this->getPHPName($tableName);
$this->classPeerName = $this->className . 'Peer'; $this->classPeerName = $this->className . 'Peer';
if (!file_exists(PATH_WORKSPACE . 'classes/' . $this->className . '.php')) { if (!file_exists(PATH_WORKSPACE . 'classes/' . $this->className . '.php')) {
throw new Exception("ERROR: " . PATH_WORKSPACE . 'classes/' . $this->className . '.php' throw new Exception("ERROR: " . PATH_WORKSPACE . 'classes/' . $this->className . '.php' . " class file doesn't exit!");
. " class file doesn't exit!");
} }
require_once PATH_WORKSPACE . 'classes/' . $this->className . '.php'; 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 //select cases for this Process, ordered by APP_NUMBER
$con = Propel::getConnection($sConnection);
$stmt = $con->createStatement();
$criteria = new Criteria('workflow'); $criteria = new Criteria('workflow');
$criteria->add(ApplicationPeer::PRO_UID, $processUid); $criteria->add(ApplicationPeer::PRO_UID, $processUid);
$criteria->addAscendingOrderByColumn(ApplicationPeer::APP_NUMBER); $criteria->addAscendingOrderByColumn(ApplicationPeer::APP_NUMBER);
$dataset = ApplicationPeer::doSelectRS($criteria); $dataset = ApplicationPeer::doSelectRS($criteria);
$dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); $dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
while ($dataset->next()) { while ($dataset->next()) {
$row = $dataset->getRow(); $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(); //getting the case data
$appData = $case->unserializeData($row['APP_DATA']);
if ($addTabUid != '') { //quick fix, map all empty values as NULL for Database
require_once 'classes/model/Fields.php'; foreach ($appData as $appDataKey => $appDataValue) {
$criteriaField = new Criteria('workflow'); if (is_array($appDataValue) && count($appDataValue)) {
$criteriaField->add(FieldsPeer::ADD_TAB_UID, $addTabUid); $j = key($appDataValue);
$datasetField = FieldsPeer::doSelectRS($criteriaField); $appDataValue = is_array($appDataValue[$j]) ? $appDataValue : $appDataValue[$j];
$datasetField->setFetchmode(ResultSet::FETCHMODE_ASSOC);
while ($datasetField->next()) {
$rowfield = $datasetField->getRow();
switch ($rowfield['FLD_TYPE']) {
case 'FLOAT':
case 'DOUBLE':
case 'INTEGER':
$fieldTypes[] = array($rowfield['FLD_NAME'] => $rowfield['FLD_TYPE']);
break;
default:
break;
}
} }
} if (is_string($appDataValue)) {
// 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];
}
if (is_string($dValue)) {
foreach ($fieldTypes as $key => $fieldType) { foreach ($fieldTypes as $key => $fieldType) {
foreach ($fieldType as $name => $theType) { foreach ($fieldType as $fieldTypeKey => $fieldTypeValue) {
if (strtoupper($dKey) == $name) { if (strtoupper($appDataKey) == $fieldTypeKey) {
$caseData[$dKey] = validateType($dValue, $theType); $appData[$appDataKey] = validateType($appDataValue, $fieldTypeValue);
unset($name); unset($fieldTypeKey);
} }
} }
} }
// normal fields // normal fields
if (trim($dValue) === '') { if (trim($appDataValue) === '') {
$caseData[$dKey] = null; $appData[$appDataKey] = null;
} }
} else { } else {
// grids // grids
if (is_array($caseData[$dKey])) { if (is_array($appData[$appDataKey])) {
foreach ($caseData[$dKey] as $dIndex => $dRow) { foreach ($appData[$appDataKey] as $dIndex => $dRow) {
if (is_array($dRow)) { if (is_array($dRow)) {
foreach ($dRow as $k => $v) { foreach ($dRow as $k => $v) {
if (is_string($v) && trim($v) === '') { if (is_string($v) && trim($v) === '') {
$caseData[$dKey][$dIndex][$k] = null; $appData[$appDataKey][$dIndex][$k] = null;
} }
} }
} }
@@ -794,33 +793,48 @@ class AdditionalTables extends BaseAdditionalTables
} }
} }
//populate data
$className = $this->className;
if ($type === 'GRID') { if ($type === 'GRID') {
list($gridName, $gridUid) = explode('-', $gridKey); list($gridName, $gridUid) = explode('-', $gridKey);
$gridData = isset($caseData[$gridName]) ? $caseData[$gridName] : array(); $gridData = isset($appData[$gridName]) ? $appData[$gridName] : [];
foreach ($gridData as $i => $gridRow) { foreach ($gridData as $i => $gridRow) {
eval('$obj = new ' . $this->className . '();'); try {
$obj->fromArray($caseData, BasePeer::TYPE_FIELDNAME); $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->setAppUid($row['APP_UID']);
$obj->setAppNumber($row['APP_NUMBER']); $obj->setAppNumber($row['APP_NUMBER']);
if (method_exists($obj, 'setAppStatus')) { if (method_exists($obj, 'setAppStatus')) {
$obj->setAppStatus($row['APP_STATUS']); $obj->setAppStatus($row['APP_STATUS']);
} }
$obj->fromArray(array_change_key_case($gridRow, CASE_UPPER), BasePeer::TYPE_FIELDNAME);
$obj->setRow($i);
$obj->save(); $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");
} }
} else { unset($obj);
eval('$obj = new ' . $this->className . '();');
$obj->fromArray(array_change_key_case($caseData, 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;
} }
} }
} }

View File

@@ -1152,7 +1152,13 @@ class pmTablesProxy extends HttpProxyController
} }
} }
public function genDataReport ($httpData) /**
* 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(); $result = new stdClass();
@@ -1160,12 +1166,26 @@ class pmTablesProxy extends HttpProxyController
$result->success = true; $result->success = true;
$additionalTables = new AdditionalTables(); $additionalTables = new AdditionalTables();
$table = $additionalTables->load( $httpData->id ); $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; return $result;
} }

View File

@@ -818,18 +818,27 @@ UpdatePageConfig = function(pageSize){
}); });
}; };
genDataReport = function() /**
* Regenerate data report
*
* @returns void
*/
genDataReport = function ()
{ {
Ext.Ajax.request({ genDataReportButton.setDisabled(true);
url: '../pmTablesProxy/genDataReport', Ext.Ajax.request({
params: {id: tableDef.ADD_TAB_UID}, url: '../pmTablesProxy/genDataReport',
success: function(resp){ params: {id: tableDef.ADD_TAB_UID},
response = Ext.util.JSON.decode(resp.responseText); success: function (resp) {
PMExt.notify(_('ID_UPDATE'), response.message) genDataReportButton.setDisabled(false);
Ext.getCmp('infoGrid').store.reload(); response = Ext.util.JSON.decode(resp.responseText);
}, PMExt.notify(_('ID_UPDATE'), response.message)
failure: function(obj, resp){ Ext.getCmp('infoGrid').store.reload();
PMExt.error( _('ID_ERROR'), resp.result.message);
} },
}); failure: function (obj, resp) {
genDataReportButton.setDisabled(false);
PMExt.error(_('ID_ERROR'), resp.result.message);
}
});
} }