diff --git a/gulliver/system/class.httpProxyController.php b/gulliver/system/class.httpProxyController.php index a55c0b702..301fbba4d 100755 --- a/gulliver/system/class.httpProxyController.php +++ b/gulliver/system/class.httpProxyController.php @@ -86,7 +86,7 @@ class HttpProxyController { } catch (Exception $e) { $result->success = false; - $result->msg = $e->getMessage(); + $result->message = $result->msg = $e->getMessage(); switch(get_class($e)) { case 'Exception': $error = "SYSTEM ERROR"; break; case 'PMException': $error = "PROCESSMAKER ERROR"; break; diff --git a/workflow/engine/classes/class.pmTable.php b/workflow/engine/classes/class.pmTable.php index eaa23ee47..1c9df2a61 100644 --- a/workflow/engine/classes/class.pmTable.php +++ b/workflow/engine/classes/class.pmTable.php @@ -80,6 +80,7 @@ class PmTable switch ($dbsUid) { case 'workflow': case 'wf': case '0': case '': + $this->dataSource = 'workflow'; $this->dbConfig->adapter= DB_ADAPTER; $this->dbConfig->host = DB_HOST; $this->dbConfig->name = DB_NAME; @@ -89,6 +90,7 @@ class PmTable break; case 'rp': case 'report': + $this->dataSource = 'rp'; $this->dbConfig->adapter= DB_ADAPTER; $this->dbConfig->host = DB_REPORT_HOST; $this->dbConfig->name = DB_REPORT_NAME; @@ -112,6 +114,11 @@ class PmTable $this->dbConfig->port = $dbSource->getDbsPort(); } } + + public function getDataSource() + { + return $this->dataSource; + } /** * get Data base config object @@ -396,41 +403,6 @@ class PmTable } - } - - /** - * Populate the report table with all case data - * @param string $sType - * @param string $sProcessUid - * @param string $sGrid - * @return number - */ - public function populateReportTable($sType = 'NORMAL', $sProcessUid = '', $sGrid = '') - { - require_once "classes/model/Application.php"; - - $con = Propel::getConnection($sConnection); - $stmt = $con->createStatement(); - if ($sType == 'GRID') { - $aAux = explode('-', $sGrid); - $sGrid = $aAux[0]; - } - - //select cases for this Process, ordered by APP_NUMBER - $criteria = new Criteria('workflow'); - $criteria->add(ApplicationPeer::PRO_UID, $sProcessUid); - $criteria->addAscendingOrderByColumn(ApplicationPeer::APP_NUMBER); - $dataset = ApplicationPeer::doSelectRS($criteria); - $dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); - - while ($dataset->next()) { - $row = $dataset->getRow(); - $aData = unserialize($aRow['APP_DATA']); - } - - return 0; - - } /** diff --git a/workflow/engine/classes/model/AdditionalTables.php b/workflow/engine/classes/model/AdditionalTables.php index f73b890b2..9b908daad 100644 --- a/workflow/engine/classes/model/AdditionalTables.php +++ b/workflow/engine/classes/model/AdditionalTables.php @@ -20,6 +20,9 @@ require_once 'classes/model/om/BaseAdditionalTables.php'; */ class AdditionalTables extends BaseAdditionalTables { + public $fields = array(); + public $primaryKeys = array(); + /** * Function load * access public @@ -29,37 +32,12 @@ class AdditionalTables extends BaseAdditionalTables { $oAdditionalTables = AdditionalTablesPeer::retrieveByPK($sUID); if (!is_null($oAdditionalTables)) { $aFields = $oAdditionalTables->toArray(BasePeer::TYPE_FIELDNAME); - if ($bFields) { - require_once 'classes/model/Fields.php'; - $oCriteria = new Criteria('workflow'); - $oCriteria->addSelectColumn(FieldsPeer::FLD_UID); - $oCriteria->addSelectColumn(FieldsPeer::FLD_INDEX); - $oCriteria->addSelectColumn(FieldsPeer::FLD_NAME); - $oCriteria->addSelectColumn(FieldsPeer::FLD_DESCRIPTION); - $oCriteria->addSelectColumn(FieldsPeer::FLD_TYPE); - $oCriteria->addSelectColumn(FieldsPeer::FLD_SIZE); - $oCriteria->addSelectColumn(FieldsPeer::FLD_NULL); - $oCriteria->addSelectColumn(FieldsPeer::FLD_AUTO_INCREMENT); - $oCriteria->addSelectColumn(FieldsPeer::FLD_KEY); - $oCriteria->addSelectColumn(FieldsPeer::FLD_FOREIGN_KEY); - $oCriteria->addSelectColumn(FieldsPeer::FLD_FOREIGN_KEY_TABLE); - $oCriteria->addSelectColumn(FieldsPeer::FLD_DYN_NAME); - $oCriteria->addSelectColumn(FieldsPeer::FLD_DYN_UID); - $oCriteria->addSelectColumn(FieldsPeer::FLD_FILTER); - $oCriteria->add(FieldsPeer::ADD_TAB_UID, $sUID); - $oCriteria->addAscendingOrderByColumn(FieldsPeer::FLD_INDEX); - $oDataset = FieldsPeer::doSelectRS($oCriteria); - $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); - $oDataset->next(); - $aFields['FIELDS'] = array(); - $i = 1; - while ($aRow = $oDataset->getRow()) { - $aFields['FIELDS'][$i] = $aRow; - $oDataset->next(); - $i++; - } - } $this->fromArray($aFields, BasePeer::TYPE_FIELDNAME); + + if ($bFields) { + $aFields['FIELDS'] = $this->getFields(); + } + return $aFields; } else { @@ -71,6 +49,53 @@ class AdditionalTables extends BaseAdditionalTables { } } + public function getFields() + { + if (count($this->fields) > 0) { + return $this->fields; + } + + require_once 'classes/model/Fields.php'; + $oCriteria = new Criteria('workflow'); + + $oCriteria->addSelectColumn(FieldsPeer::FLD_UID); + $oCriteria->addSelectColumn(FieldsPeer::FLD_INDEX); + $oCriteria->addSelectColumn(FieldsPeer::FLD_NAME); + $oCriteria->addSelectColumn(FieldsPeer::FLD_DESCRIPTION); + $oCriteria->addSelectColumn(FieldsPeer::FLD_TYPE); + $oCriteria->addSelectColumn(FieldsPeer::FLD_SIZE); + $oCriteria->addSelectColumn(FieldsPeer::FLD_NULL); + $oCriteria->addSelectColumn(FieldsPeer::FLD_AUTO_INCREMENT); + $oCriteria->addSelectColumn(FieldsPeer::FLD_KEY); + $oCriteria->addSelectColumn(FieldsPeer::FLD_FOREIGN_KEY); + $oCriteria->addSelectColumn(FieldsPeer::FLD_FOREIGN_KEY_TABLE); + $oCriteria->addSelectColumn(FieldsPeer::FLD_DYN_NAME); + $oCriteria->addSelectColumn(FieldsPeer::FLD_DYN_UID); + $oCriteria->addSelectColumn(FieldsPeer::FLD_FILTER); + $oCriteria->add(FieldsPeer::ADD_TAB_UID, $this->getAddTabUid()); + $oCriteria->addAscendingOrderByColumn(FieldsPeer::FLD_INDEX); + + $oDataset = FieldsPeer::doSelectRS($oCriteria); + $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); + + while ($oDataset->next()) { + $this->fields[] = $oDataset->getRow(); + } + + return $this->fields; + } + + public function getPrimaryKeys() + { + $this->primaryKeys = array(); + foreach ($this->fields as $field) { + if ($field['FLD_KEY'] == '1') { + $this->primaryKeys[] = $field; + } + } + return $this->primaryKeys; + } + public function loadByName($name) { try { $oCriteria = new Criteria('workflow'); @@ -496,10 +521,73 @@ class AdditionalTables extends BaseAdditionalTables { } + /** + * Populate the report table with all case data + * @param string $sType + * @param string $sProcessUid + * @param string $sGrid + * @return number + */ + public function populateReportTable($tableName, $sConnection = 'rp', $type = 'NORMAL', $processUid = '', $gridKey = '') + { + 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: {$this->className} 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(); + $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(); + //remove old applications references + $deleteSql = "DELETE FROM $tableName WHERE APP_UID = '".$row['APP_UID']."'"; + $rs = $stmt->executeQuery($deleteSql); + // getting the case data + $caseFields = array_change_key_case(unserialize($row['APP_DATA']), CASE_UPPER); + + if ($type == 'GRID') { + list($gridName, $gridUid) = explode('-', $gridKey); + $gridName = strtoupper($gridName); + foreach ($caseFields[$gridName] as $i => $gridRow) { + $gridRow = array_change_key_case($gridRow, CASE_UPPER); + + eval('$obj = new ' .$this->className. '();'); + $obj->fromArray($caseFields, BasePeer::TYPE_FIELDNAME); + $obj->setAppUid($row['APP_UID']); + $obj->setAppNumber($row['APP_NUMBER']); + $obj->fromArray($gridRow, BasePeer::TYPE_FIELDNAME); + $obj->setRow($i); + $obj->save(); + eval('$obj = new ' .$this->className. '();'); + } + } else { + eval('$obj = new ' .$this->className. '();'); + $obj->fromArray($caseFields, BasePeer::TYPE_FIELDNAME); + $obj->setAppUid($row['APP_UID']); + $obj->setAppNumber($row['APP_NUMBER']); + $obj->save(); + $obj = null; + } + } + } + /** * Populate Report Table */ - public function populateReportTable($sTableName, $sConnection = 'rp', $sType = 'NORMAL', $aFields = array(), $sProcessUid = '', $sGrid = '') + public function populateReportTable2($sTableName, $sConnection = 'rp', $sType = 'NORMAL', $aFields = array(), $sProcessUid = '', $sGrid = '') { require_once "classes/model/Application.php"; diff --git a/workflow/engine/controllers/pmTablesProxy.php b/workflow/engine/controllers/pmTablesProxy.php index 1c5c3ea22..9e2e44e31 100644 --- a/workflow/engine/controllers/pmTablesProxy.php +++ b/workflow/engine/controllers/pmTablesProxy.php @@ -279,9 +279,9 @@ class pmTablesProxy extends HttpProxyController $oFields->create($field); } - // if ($isReportTable) { - // $oAdditionalTables->populateReportTable($data['REP_TAB_NAME'], $data['REP_TAB_CONNECTION'], $data['REP_TAB_TYPE'], $fieldsList, $data['PRO_UID'], $data['REP_TAB_GRID']); - // } + if ($isReportTable) { + $oAdditionalTables->populateReportTable($data['REP_TAB_NAME'], $pmTable->getDataSource(), $data['REP_TAB_TYPE'], $data['PRO_UID'], $data['REP_TAB_GRID']); + } $result->success = true; $result->msg = $buildResult; @@ -351,24 +351,19 @@ class pmTablesProxy extends HttpProxyController $start = isset($httpData->start) ? $httpData->start : 0; $limit = isset($httpData->limit) ? $httpData->limit : $limit_size; - $oAdditionalTables = new AdditionalTables(); - $table = $oAdditionalTables->load($httpData->id, true); - $result = $oAdditionalTables->getAllData($httpData->id, $start, $limit); + $additionalTables = new AdditionalTables(); + $table = $additionalTables->load($httpData->id, true); + $result = $additionalTables->getAllData($httpData->id, $start, $limit); - $keys = array(); - foreach ($table['FIELDS'] as $field) { - if ($field['FLD_KEY'] == '1') { - $keys[] = $field['FLD_NAME']; - } - } + $primaryKeys = $additionalTables->getPrimaryKeys(); foreach ($result['rows'] as $i => $row) { - $indexes = array(); - foreach ($keys as $key) { - $indexes[] = $row[$key]; + $primaryKeysValues = array(); + foreach ($primaryKeys as $key) { + $primaryKeysValues[] = isset($row[$key['FLD_NAME']]) ? $row[$key['FLD_NAME']] : ''; } - $result['rows'][$i]['__index__'] = implode('-', $indexes); + $result['rows'][$i]['__index__'] = md5(implode('-', $primaryKeysValues)); } return $result; @@ -376,83 +371,75 @@ class pmTablesProxy extends HttpProxyController /** * create pm tables record - * @param string $httpData->id - * @param string $httpData->start - * @param string $httpData->limit + * @param string $httpData->rows */ public function dataCreate($httpData) { $rows = G::json_decode(stripslashes($httpData->rows)); require_once 'classes/model/AdditionalTables.php'; - $oAdditionalTables = new AdditionalTables(); - $table = $oAdditionalTables->load($httpData->id, true); + $additionalTables = new AdditionalTables(); + $table = $additionalTables->load($httpData->id, true); + $primaryKeys = $additionalTables->getPrimaryKeys(); + $this->className = $table['ADD_TAB_CLASS_NAME']; $this->classPeerName = $this->className . 'Peer'; - $sPath = PATH_DB . SYS_SYS . PATH_SEP . 'classes' . PATH_SEP; + $row = (array) $rows; + $toSave = false; - if (!file_exists ($sPath . $this->className . '.php') ) { - throw new Exception("ERROR: $className class file doesn't exit!"); + if (!file_exists (PATH_WORKSPACE . 'classes/' . $this->className . '.php') ) { + throw new Exception("ERROR: {$this->className} class file doesn't exit!"); } - //require_once $sPath . $this->className . '.php'; - require_once 'classes/' . $this->className . '.php'; - $toSave = false; - - if (is_array($rows)) { //multiple - $c = $cs = 0; - foreach ($rows as $i => $row) { - $fieldsCount = 0; - eval('$obj = new ' .$this->className. '();'); - foreach ($row as $key => $value) { - $action = 'set' . AdditionalTables::getPHPName($key); - $obj->$action($value); - $fieldsCount++; + require_once PATH_WORKSPACE . 'classes/' . $this->className . '.php'; + eval('$obj = new ' .$this->className. '();'); + + if (count($row) > 0) { + try { + eval('$con = Propel::getConnection('.$this->classPeerName.'::DATABASE_NAME);'); + $con->begin(); + $obj->fromArray($row, BasePeer::TYPE_FIELDNAME); + + if ($obj->validate()) { + $obj->save(); $toSave = true; - } - if ($fieldsCount != 0) { - $c++; - if ($obj->save() > 0) { - $cs++; + + $primaryKeysValues = array(); + foreach ($primaryKeys as $primaryKey) { + $method = 'get' . AdditionalTables::getPHPName($primaryKey['FLD_NAME']); + $primaryKeysValues[] = $obj->$method(); } } - } - - if ($toSave) { - $result->success = $cs == $c ? true: false; - $result->message = 'Saved #' . $c . ' records successfully'; - } - else { - $result->success = false; - $result->message = 'Nothing to do'; - } - } - else { //single - eval('$obj = new ' .$this->className. '();'); - foreach ($rows as $key => $value) { - $action = 'set' . AdditionalTables::getPHPName($key); - $obj->$action($value); - $toSave = true; - } - if ($toSave) { - if ($obj->save() > 0) { - $rows->__index__ = 5; - $result->success = true; - $result->message = 'Record saved successfully'; - $result->data = (array) $rows; - } else { - $result->success = false; - $result->message = 'Error Updating records'; + foreach($obj->getValidationFailures() as $objValidationFailure) { + $msg .= $objValidationFailure->getMessage() . "\n"; + } + throw new PropelException($msg); } + } + catch(Exception $e) { + $con->rollback(); + throw new Exception($e->getMessage()); } - else { - $result->success = true; - $result->data = array('__index__'=>1132); - $result->message = 'Nothing to do'; - } + $index = md5(implode('-', $primaryKeysValues)); + } + else { + $toSave = false; } + if ($toSave) { + $result->success = true; + $result->message = 'Record saved successfully'; + $result->rows = $obj->toArray(BasePeer::TYPE_FIELDNAME); + $result->rows['__index__'] = $index; + } + else { + $result->success = false; + $result->rows = array(); + $result->message = 'nothing to do'; + } + + return $result; } @@ -1056,7 +1043,7 @@ class pmTablesProxy extends HttpProxyController $gridIndex->field_key = 1; $gridIndex->field_null = 0; $gridIndex->field_filter = false; - $application->field_autoincrement = false; + $gridIndex->field_autoincrement = false; array_push($defaultColumns, $gridIndex); } diff --git a/workflow/engine/templates/pmTables/data.js b/workflow/engine/templates/pmTables/data.js index ac64ad9e8..af14b25e3 100644 --- a/workflow/engine/templates/pmTables/data.js +++ b/workflow/engine/templates/pmTables/data.js @@ -72,27 +72,35 @@ Ext.onReady(function(){ _fields.push({name: _idProperty}); - if (tableDef.FIELDS.length !== 0) { - for (i in tableDef.FIELDS) { - _columns.push({ - id: tableDef.FIELDS[i].FLD_NAME, - header: tableDef.FIELDS[i].FLD_DESCRIPTION, - dataIndex: tableDef.FIELDS[i].FLD_NAME, - width: 40, - editor:{ - xtype: 'textfield', - allowBlank: true - } - }); - - _fields.push({name: tableDef.FIELDS[i].FLD_NAME}); - - if(_idProperty == '' && tableDef.FIELDS[i].FLD_KEY) { - _idProperty = tableDef.FIELDS[i].FLD_NAME; + for (i=0;i