Merge pull request #1174 from victorsl/BUG-0000

BUG 0000 "PM Table, keep the records of the table to the edit" SOLVED
This commit is contained in:
julceslauhub
2013-01-09 10:17:47 -08:00
4 changed files with 115 additions and 18 deletions

View File

@@ -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())

View File

@@ -1,5 +1,4 @@
<?php
/**
* pmTablesProxy
*
@@ -196,8 +195,8 @@ class pmTablesProxy extends HttpProxyController
*/
public function save ($httpData, $alterTable = true)
{
require_once 'classes/model/AdditionalTables.php';
require_once 'classes/model/Fields.php';
//require_once 'classes/model/AdditionalTables.php';
//require_once 'classes/model/Fields.php';
try {
ob_start();
@@ -273,12 +272,18 @@ class pmTablesProxy extends HttpProxyController
}
}
G::loadClass( 'pmTable' );
G::LoadClass("pmTable");
$pmTable = new pmTable( $data['REP_TAB_NAME'] );
$pmTable->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();

View File

@@ -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);

View File

@@ -159,7 +159,7 @@ systemInfo.application = {
},
{
xtype: "displayfield",
fieldLabel: "",
fieldLabel: ""
},
new Ext.Button({
text: _("ID_CHECK_AGAIN"),