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
This commit is contained in:
@@ -51,6 +51,7 @@ class PmTable
|
|||||||
private $dbConfig;
|
private $dbConfig;
|
||||||
private $db;
|
private $db;
|
||||||
private $alterTable = true;
|
private $alterTable = true;
|
||||||
|
private $keepData = false;
|
||||||
|
|
||||||
public function __construct ($tableName = null)
|
public function __construct ($tableName = null)
|
||||||
{
|
{
|
||||||
@@ -172,6 +173,11 @@ class PmTable
|
|||||||
$this->alterTable = $value;
|
$this->alterTable = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setKeepData($value)
|
||||||
|
{
|
||||||
|
$this->keepData = $value;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build the pmTable with all dependencies
|
* 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') {
|
if ($dbEngine == 'oracle') {
|
||||||
$queryStack['drop'] = substr( $queryStack['drop'], 0, strrpos( $queryStack['drop'], ";" ) );
|
$queryStack['drop'] = substr( $queryStack['drop'], 0, strrpos( $queryStack['drop'], ";" ) );
|
||||||
$queryStack['create'] = substr( $queryStack['create'], 0, strrpos( $queryStack['create'], ";" ) );
|
$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 . "'";
|
$queryIfExistTable = "SELECT TABLE_NAME FROM USER_TABLES WHERE TABLE_NAME = '" . $this->tableName . "'";
|
||||||
|
|
||||||
$rs = $stmt->executeQuery( $queryIfExistTable );
|
$rs = $stmt->executeQuery( $queryIfExistTable );
|
||||||
|
|
||||||
if ($rs->next()) {
|
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['drop'] );
|
||||||
}
|
}
|
||||||
|
|
||||||
$stmt->executeQuery( $queryStack['create'] );
|
$stmt->executeQuery( $queryStack['create'] );
|
||||||
$stmt->executeQuery( $queryStack['alter'] );
|
$stmt->executeQuery( $queryStack['alter'] );
|
||||||
} else {
|
} else {
|
||||||
@@ -588,10 +624,41 @@ class PmTable
|
|||||||
if (! isset( $queryStack['create'] )) {
|
if (! isset( $queryStack['create'] )) {
|
||||||
throw new Exception( 'A problem occurred resolving the schema to update for this table' );
|
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['drop'] );
|
||||||
$stmt->executeQuery( $queryStack['create'] );
|
$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())
|
public function upgradeDatabaseFor ($dataSource, $tablesList = array())
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* pmTablesProxy
|
* pmTablesProxy
|
||||||
*
|
*
|
||||||
@@ -196,8 +195,8 @@ class pmTablesProxy extends HttpProxyController
|
|||||||
*/
|
*/
|
||||||
public function save ($httpData, $alterTable = true)
|
public function save ($httpData, $alterTable = true)
|
||||||
{
|
{
|
||||||
require_once 'classes/model/AdditionalTables.php';
|
//require_once 'classes/model/AdditionalTables.php';
|
||||||
require_once 'classes/model/Fields.php';
|
//require_once 'classes/model/Fields.php';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ob_start();
|
ob_start();
|
||||||
@@ -273,12 +272,18 @@ class pmTablesProxy extends HttpProxyController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
G::loadClass( 'pmTable' );
|
G::LoadClass("pmTable");
|
||||||
|
|
||||||
$pmTable = new pmTable( $data['REP_TAB_NAME'] );
|
$pmTable = new pmTable( $data['REP_TAB_NAME'] );
|
||||||
$pmTable->setDataSource( $data['REP_TAB_CONNECTION'] );
|
$pmTable->setDataSource( $data['REP_TAB_CONNECTION'] );
|
||||||
$pmTable->setColumns( $columns );
|
$pmTable->setColumns( $columns );
|
||||||
$pmTable->setAlterTable( $alterTable );
|
$pmTable->setAlterTable( $alterTable );
|
||||||
|
|
||||||
|
if (isset($data["keepData"]) && $data["keepData"] == 1) {
|
||||||
|
//PM Table
|
||||||
|
$pmTable->setKeepData(true);
|
||||||
|
}
|
||||||
|
|
||||||
$pmTable->build();
|
$pmTable->build();
|
||||||
|
|
||||||
$buildResult = ob_get_contents();
|
$buildResult = ob_get_contents();
|
||||||
|
|||||||
@@ -340,6 +340,9 @@ Ext.onReady(function(){
|
|||||||
handler: removeColumn
|
handler: removeColumn
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
|
border: false,
|
||||||
|
|
||||||
listeners: {
|
listeners: {
|
||||||
render: function(grid) {
|
render: function(grid) {
|
||||||
var ddrow = new Ext.dd.DropTarget(grid.getView().mainBody, {
|
var ddrow = new Ext.dd.DropTarget(grid.getView().mainBody, {
|
||||||
@@ -561,17 +564,33 @@ Ext.onReady(function(){
|
|||||||
allowBlank: true
|
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);
|
//items.push(comboDbConnections);
|
||||||
|
|
||||||
var frmDetails = new Ext.FormPanel({
|
var frmDetails = new Ext.FormPanel({
|
||||||
id :'frmDetails',
|
id :'frmDetails',
|
||||||
region : 'north',
|
region : 'north',
|
||||||
labelWidth : 180,
|
labelWidth: 250,
|
||||||
labelAlign :'right',
|
labelAlign :'right',
|
||||||
title : ADD_TAB_UID ? _('ID_PMTABLE') : _('ID_NEW_PMTABLE'),
|
title : ADD_TAB_UID ? _('ID_PMTABLE') : _('ID_NEW_PMTABLE'),
|
||||||
bodyStyle :'padding:10px',
|
bodyStyle :'padding:10px',
|
||||||
frame : true,
|
frame : true,
|
||||||
height : 120,
|
height: 170,
|
||||||
items : items,
|
items : items,
|
||||||
//tbar : tbar,
|
//tbar : tbar,
|
||||||
waitMsgTarget : true,
|
waitMsgTarget : true,
|
||||||
@@ -589,7 +608,7 @@ Ext.onReady(function(){
|
|||||||
{
|
{
|
||||||
text: TABLE === false ? _("ID_CREATE") : _("ID_UPDATE"),
|
text: TABLE === false ? _("ID_CREATE") : _("ID_UPDATE"),
|
||||||
handler: function() {
|
handler: function() {
|
||||||
if (TABLE === false || dataNumRows == 0) {
|
if (TABLE === false || dataNumRows == 0 || Ext.getCmp("chkKeepData").checked == true) {
|
||||||
createReportTable();
|
createReportTable();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -730,18 +749,24 @@ function createReportTable()
|
|||||||
waitConfig: {interval:500}
|
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({
|
Ext.Ajax.request({
|
||||||
url: '../pmTablesProxy/save',
|
url: '../pmTablesProxy/save',
|
||||||
params: {
|
params: 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)
|
|
||||||
},
|
|
||||||
success: function(resp){
|
success: function(resp){
|
||||||
try {
|
try {
|
||||||
result = Ext.util.JSON.decode(resp.responseText);
|
result = Ext.util.JSON.decode(resp.responseText);
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ systemInfo.application = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
xtype: "displayfield",
|
xtype: "displayfield",
|
||||||
fieldLabel: "",
|
fieldLabel: ""
|
||||||
},
|
},
|
||||||
new Ext.Button({
|
new Ext.Button({
|
||||||
text: _("ID_CHECK_AGAIN"),
|
text: _("ID_CHECK_AGAIN"),
|
||||||
|
|||||||
Reference in New Issue
Block a user