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

View File

@@ -465,6 +465,9 @@ class ReportTable
$pmTable->setDataSource($arrayData['REP_TAB_CONNECTION']); $pmTable->setDataSource($arrayData['REP_TAB_CONNECTION']);
$pmTable->setColumns($columns); $pmTable->setColumns($columns);
$pmTable->setAlterTable($flagAlterTable); $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) { if (isset($arrayData['keepData']) && $arrayData['keepData'] == 1) {
//PM Table //PM Table
@@ -472,7 +475,7 @@ class ReportTable
} }
$pmTable->build(); $pmTable->build();
$buildResult = ob_get_contents(); $buildResult = ob_get_contents();
ob_end_clean(); ob_end_clean();

View File

@@ -779,7 +779,11 @@ 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 || Ext.getCmp("chkKeepData").checked == true) { if (TABLE === false || dataNumRows == 0 || Ext.getCmp("chkKeepData").checked == true) {
createReportTable(); 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 { else {
PMExt.confirm(_('ID_CONFIRM'), _('ID_PMTABLE_SAVE_AND_DATA_LOST'), createReportTable); PMExt.confirm(_('ID_CONFIRM'), _('ID_PMTABLE_SAVE_AND_DATA_LOST'), createReportTable);
@@ -804,7 +808,7 @@ Ext.onReady(function(){
/*** Editing routines ***/ /*** Editing routines ***/
if (TABLE !== false) { if (TABLE !== false) {
Ext.getCmp('REP_TAB_NAME').setValue(TABLE.ADD_TAB_NAME); 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); Ext.getCmp('REP_TAB_DSC').setValue(TABLE.ADD_TAB_DESCRIPTION);
loadTableRowsFromArray(TABLE.FIELDS); loadTableRowsFromArray(TABLE.FIELDS);
@@ -927,6 +931,7 @@ function createReportTable()
REP_TAB_UID: (TABLE !== false)? TABLE.ADD_TAB_UID : "", REP_TAB_UID: (TABLE !== false)? TABLE.ADD_TAB_UID : "",
PRO_UID: "", PRO_UID: "",
REP_TAB_NAME: (TABLE !== false)? tableName : "PMT_" + tableName, 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_DSC: tableDescription,
REP_TAB_CONNECTION: "workflow", REP_TAB_CONNECTION: "workflow",
REP_TAB_TYPE: "", REP_TAB_TYPE: "",