From fbb10c8ed19bf0cc58d819ba92067afe873fdb39 Mon Sep 17 00:00:00 2001 From: Victor Saisa Lopez Date: Wed, 9 Jan 2013 13:23:16 -0400 Subject: [PATCH] BUG 0000 "PM Table, keep the records of the table to the edit" SOLVED - PM Table, keep the records of the table to the edit - Added checkbox for keep the records of the table * Available from version ProcessMaker-2.0.46 --- workflow/engine/classes/class.pmTable.php | 67 +++++++++++++++++++ workflow/engine/controllers/pmTablesProxy.php | 13 ++-- workflow/engine/templates/pmTables/edit.js | 51 ++++++++++---- workflow/engine/templates/setup/systemInfo.js | 2 +- 4 files changed, 115 insertions(+), 18 deletions(-) diff --git a/workflow/engine/classes/class.pmTable.php b/workflow/engine/classes/class.pmTable.php index 45c082a5d..5a9f950ad 100755 --- a/workflow/engine/classes/class.pmTable.php +++ b/workflow/engine/classes/class.pmTable.php @@ -51,6 +51,7 @@ class PmTable private $dbConfig; private $db; private $alterTable = true; + private $keepData = false; public function __construct ($tableName = null) { @@ -172,6 +173,11 @@ class PmTable $this->alterTable = $value; } + public function setKeepData($value) + { + $this->keepData = $value; + } + /** * Build the pmTable with all dependencies */ @@ -559,6 +565,25 @@ class PmTable } } + $table = $this->tableName; + $tableBackup = $this->tableName . "_BAK"; + + $sqlTableBackup = null; + $swTableBackup = 0; + + switch ($dbEngine) { + case "mysql": + $sqlTableBackup = "CREATE TABLE $tableBackup SELECT * FROM $table"; + break; + case "mssql": + $sqlTableBackup = "SELECT * INTO $tableBackup FROM $table"; + break; + case "oracle": + $sqlTableBackup = "CREATE TABLE $tableBackup AS SELECT * FROM $table"; + break; + + } + if ($dbEngine == 'oracle') { $queryStack['drop'] = substr( $queryStack['drop'], 0, strrpos( $queryStack['drop'], ";" ) ); $queryStack['create'] = substr( $queryStack['create'], 0, strrpos( $queryStack['create'], ";" ) ); @@ -566,9 +591,20 @@ class PmTable $queryIfExistTable = "SELECT TABLE_NAME FROM USER_TABLES WHERE TABLE_NAME = '" . $this->tableName . "'"; $rs = $stmt->executeQuery( $queryIfExistTable ); + if ($rs->next()) { + if ($this->keepData && $sqlTableBackup != null) { + //Delete backup if exists + $rs = $stmt->executeQuery(str_replace($table, $tableBackup, $queryStack["drop"])); + + //Create backup + $rs = $stmt->executeQuery($sqlTableBackup, ResultSet::FETCHMODE_ASSOC); + $swTableBackup = 1; + } + $stmt->executeQuery( $queryStack['drop'] ); } + $stmt->executeQuery( $queryStack['create'] ); $stmt->executeQuery( $queryStack['alter'] ); } else { @@ -588,10 +624,41 @@ class PmTable if (! isset( $queryStack['create'] )) { throw new Exception( 'A problem occurred resolving the schema to update for this table' ); } + + if ($this->keepData && $sqlTableBackup != null) { + //Delete backup if exists + $rs = $stmt->executeQuery(str_replace($table, $tableBackup, $queryStack["drop"])); + + //Create backup + $rs = $stmt->executeQuery($sqlTableBackup, ResultSet::FETCHMODE_ASSOC); + $swTableBackup = 1; + } + $stmt->executeQuery( $queryStack['drop'] ); $stmt->executeQuery( $queryStack['create'] ); } } + + if ($swTableBackup == 1) { + $tableFileName = str_replace("_", " ", strtolower($table)); + $tableFileName = str_replace(" ", null, ucwords($tableFileName)); + + require_once (PATH_WORKSPACE . "classes" . PATH_SEP . "$tableFileName.php"); + + $sql = "SELECT * FROM $tableBackup"; + $rs = $stmt->executeQuery($sql, ResultSet::FETCHMODE_ASSOC); + + while ($rs->next()) { + $row = $rs->getRow(); + + $oTable = new $tableFileName(); + $oTable->fromArray($row, BasePeer::TYPE_FIELDNAME); + $oTable->save(); + } + + //Delete backup + $rs = $stmt->executeQuery(str_replace($table, $tableBackup, $queryStack["drop"])); + } } public function upgradeDatabaseFor ($dataSource, $tablesList = array()) diff --git a/workflow/engine/controllers/pmTablesProxy.php b/workflow/engine/controllers/pmTablesProxy.php index 200289158..62d19d594 100755 --- a/workflow/engine/controllers/pmTablesProxy.php +++ b/workflow/engine/controllers/pmTablesProxy.php @@ -1,5 +1,4 @@ setDataSource( $data['REP_TAB_CONNECTION'] ); $pmTable->setColumns( $columns ); $pmTable->setAlterTable( $alterTable ); + + if (isset($data["keepData"]) && $data["keepData"] == 1) { + //PM Table + $pmTable->setKeepData(true); + } + $pmTable->build(); $buildResult = ob_get_contents(); diff --git a/workflow/engine/templates/pmTables/edit.js b/workflow/engine/templates/pmTables/edit.js index 5be0aaeb2..18c7c138e 100755 --- a/workflow/engine/templates/pmTables/edit.js +++ b/workflow/engine/templates/pmTables/edit.js @@ -340,6 +340,9 @@ Ext.onReady(function(){ handler: removeColumn } ], + + border: false, + listeners: { render: function(grid) { var ddrow = new Ext.dd.DropTarget(grid.getView().mainBody, { @@ -561,17 +564,33 @@ Ext.onReady(function(){ allowBlank: true }); + items.push( + { + layout: "column", + style: "margin-left: 255px;", + hidden: (dataNumRows > 0)? false : true, + items: [ + { + xtype: "checkbox", + id: "chkKeepData", + name: "chkKeepData", + boxLabel: _("ID_PMTABLE_DATA_KEEP") + } + ] + } + ); + //items.push(comboDbConnections); var frmDetails = new Ext.FormPanel({ id :'frmDetails', region : 'north', - labelWidth : 180, + labelWidth: 250, labelAlign :'right', title : ADD_TAB_UID ? _('ID_PMTABLE') : _('ID_NEW_PMTABLE'), bodyStyle :'padding:10px', frame : true, - height : 120, + height: 170, items : items, //tbar : tbar, waitMsgTarget : true, @@ -589,7 +608,7 @@ Ext.onReady(function(){ { text: TABLE === false ? _("ID_CREATE") : _("ID_UPDATE"), handler: function() { - if (TABLE === false || dataNumRows == 0) { + if (TABLE === false || dataNumRows == 0 || Ext.getCmp("chkKeepData").checked == true) { createReportTable(); } else { @@ -730,18 +749,24 @@ function createReportTable() waitConfig: {interval:500} }); + var p = { + REP_TAB_UID: (TABLE !== false)? TABLE.ADD_TAB_UID : "", + PRO_UID: "", + REP_TAB_NAME: (TABLE !== false)? tableName : "PMT_" + tableName, + REP_TAB_DSC: tableDescription, + REP_TAB_CONNECTION: "workflow", + REP_TAB_TYPE: "", + REP_TAB_GRID: "", + columns: Ext.util.JSON.encode(columns) + }; + + if (dataNumRows > 0) { + p.keepData = (Ext.getCmp("chkKeepData").checked == true)? 1 : 0; + } + Ext.Ajax.request({ url: '../pmTablesProxy/save', - params: { - REP_TAB_UID : TABLE !== false ? TABLE.ADD_TAB_UID : '', - PRO_UID : '', - REP_TAB_NAME : TABLE !== false ? tableName : 'PMT_' + tableName, - REP_TAB_DSC : tableDescription, - REP_TAB_CONNECTION : 'workflow', - REP_TAB_TYPE : '', - REP_TAB_GRID : '', - columns : Ext.util.JSON.encode(columns) - }, + params: p, success: function(resp){ try { result = Ext.util.JSON.decode(resp.responseText); diff --git a/workflow/engine/templates/setup/systemInfo.js b/workflow/engine/templates/setup/systemInfo.js index 5d53e5091..1954f2154 100644 --- a/workflow/engine/templates/setup/systemInfo.js +++ b/workflow/engine/templates/setup/systemInfo.js @@ -159,7 +159,7 @@ systemInfo.application = { }, { xtype: "displayfield", - fieldLabel: "", + fieldLabel: "" }, new Ext.Button({ text: _("ID_CHECK_AGAIN"),