This commit is contained in:
Roly Rudy Gutierrez Pinto
2016-07-26 15:12:49 -04:00
parent d58967138c
commit f0953f4ac2
3 changed files with 45 additions and 12 deletions

View File

@@ -39,6 +39,7 @@ class PmTable
private $dom = null;
private $schemaFile = '';
private $tableName;
private $oldTableName = null;
private $columns;
private $primaryKey= array();
private $baseDir = '';
@@ -64,6 +65,16 @@ class PmTable
$this->dbConfig = new StdClass();
}
/**
* Set oldTableName to pmTable
*
* @param string $oldTableName
*/
public function setOldTableName($oldTableName)
{
$this->oldTableName = $oldTableName;
}
/**
* Set columns to pmTable
*
@@ -612,7 +623,7 @@ class PmTable
$queryStack['drop'] = substr( $queryStack['drop'], 0, strrpos( $queryStack['drop'], ";" ) );
$queryStack['create'] = substr( $queryStack['create'], 0, strrpos( $queryStack['create'], ";" ) );
$queryStack['alter'] = substr( $queryStack['alter'], 0, strrpos( $queryStack['alter'], ";" ) );
$queryIfExistTable = "SELECT TABLE_NAME FROM USER_TABLES WHERE TABLE_NAME = '" . $this->tableName . "'";
$queryIfExistTable = "SELECT TABLE_NAME FROM USER_TABLES WHERE TABLE_NAME = '" . $table . "'";
$rs = $stmt->executeQuery( $queryIfExistTable );
@@ -635,27 +646,41 @@ class PmTable
if (isset( $queryStack['create'] )) {
// first at all we need to verify if we have a valid schema defined,
// so we verify that creating a dummy table
$swapQuery = str_replace( $this->tableName, $this->tableName . '_TMP', $queryStack['create'] );
$swapQuery = str_replace( $table, $table . '_TMP', $queryStack['create'] );
// if there is a problem with user defined table schema executeQuery() will throw a sql exception
$stmt->executeQuery( $swapQuery );
// if there was not problem above proceced deleting the dummy table and drop and create the target table
$stmt->executeQuery( "DROP TABLE {$this->tableName}_TMP" );
$stmt->executeQuery( "DROP TABLE {$table}_TMP" );
if (! isset( $queryStack['drop'] )) {
$queryStack['drop'] = "DROP TABLE {$this->tableName}";
$queryStack['drop'] = "DROP TABLE {$table}";
}
if (! isset( $queryStack['create'] )) {
throw new Exception( 'A problem occurred resolving the schema to update for this table' );
}
if ($this->keepData && $sqlTableBackup != null) {
if ($this->oldTableName === $this->tableName) {
//Delete backup if exists
$rs = $stmt->executeQuery(str_replace($table, $tableBackup, $queryStack["drop"]));
//Create backup
$rs = $stmt->executeQuery($sqlTableBackup, ResultSet::FETCHMODE_ASSOC);
$swTableBackup = 1;
} else {
$table = $this->oldTableName;
$tableBackup = str_replace($this->tableName, $this->oldTableName, $tableBackup);
$sqlTableBackup = str_replace($this->tableName, $this->oldTableName, $sqlTableBackup);
//Delete backup if exists
$rs = $stmt->executeQuery(str_replace($table, $tableBackup, $queryStack["drop"]));
//Create backup
$rs = $stmt->executeQuery($sqlTableBackup, ResultSet::FETCHMODE_ASSOC);
$swTableBackup = 1;
$table = $this->tableName;
}
}
$stmt->executeQuery( $queryStack['drop'] );

View File

@@ -465,6 +465,9 @@ class ReportTable
$pmTable->setDataSource($arrayData['REP_TAB_CONNECTION']);
$pmTable->setColumns($columns);
$pmTable->setAlterTable($flagAlterTable);
if (isset($arrayData['REP_TAB_NAME_OLD_NAME'])) {
$pmTable->setOldTableName($arrayData['REP_TAB_NAME_OLD_NAME']);
}
if (isset($arrayData['keepData']) && $arrayData['keepData'] == 1) {
//PM Table

View File

@@ -779,8 +779,12 @@ Ext.onReady(function(){
text: TABLE === false ? _("ID_CREATE") : _("ID_UPDATE"),
handler: function() {
if (TABLE === false || dataNumRows == 0 || Ext.getCmp("chkKeepData").checked == true) {
if (TABLE !== false && TABLE.ADD_TAB_NAME !== Ext.getCmp('REP_TAB_NAME').getValue().trim()) {
PMExt.confirm(_('ID_CONFIRM'), _('ID_THE_NAME_CHANGE_MAY_CAUSE_DATA_LOSS'), createReportTable);
} else {
createReportTable();
}
}
else {
PMExt.confirm(_('ID_CONFIRM'), _('ID_PMTABLE_SAVE_AND_DATA_LOST'), createReportTable);
}
@@ -804,7 +808,7 @@ Ext.onReady(function(){
/*** Editing routines ***/
if (TABLE !== false) {
Ext.getCmp('REP_TAB_NAME').setValue(TABLE.ADD_TAB_NAME);
Ext.getCmp('REP_TAB_NAME').setDisabled(true);
Ext.getCmp('REP_TAB_NAME').setDisabled(false);
Ext.getCmp('REP_TAB_DSC').setValue(TABLE.ADD_TAB_DESCRIPTION);
loadTableRowsFromArray(TABLE.FIELDS);
@@ -927,6 +931,7 @@ function createReportTable()
REP_TAB_UID: (TABLE !== false)? TABLE.ADD_TAB_UID : "",
PRO_UID: "",
REP_TAB_NAME: (TABLE !== false)? tableName : "PMT_" + tableName,
REP_TAB_NAME_OLD_NAME: "PMT_" + ((TABLE !== false) ? TABLE.ADD_TAB_NAME : tableName),
REP_TAB_DSC: tableDescription,
REP_TAB_CONNECTION: "workflow",
REP_TAB_TYPE: "",