BUG 0000 Refactoring for propel-generator/Database class to DatabasePropel class

- fixes in data editing
- fixes in pmtables import
This commit is contained in:
Erik Amaru Ortiz
2011-09-15 11:30:27 -04:00
parent 07d25773d1
commit 3a242fe8a5
13 changed files with 702 additions and 209 deletions

View File

@@ -183,6 +183,7 @@ class pmTablesProxy extends HttpProxyController
require_once 'classes/model/Fields.php';
try {
ob_start();
$data = (array) $httpData;
$data['PRO_UID'] = trim($data['PRO_UID']);
$data['columns'] = G::json_decode(stripslashes($httpData->columns)); //decofing data columns
@@ -198,16 +199,17 @@ class pmTablesProxy extends HttpProxyController
'INDEX', 'INSERT', 'OPEN', 'REVOKE', 'ROLLBACK', 'SELECT', 'SYNONYM', 'TABLE', 'UPDATE', 'VIEW',
'APP_UID', 'ROW', 'PMTABLE'
);
//$reservedWords = array_merge($reservedWords, array_change_key_case($reservedWords, CASE_LOWER));
// verify if exists.
if ($data['REP_TAB_UID'] == '') { //new report table
if ($data['REP_TAB_UID'] == '' || (isset($httpData->forceUid) && $httpData->forceUid)) { //new report table
if ($isReportTable) { //setting default columns
$defaultColumns = $this->_getReportTableDefaultColumns($data['REP_TAB_TYPE']);
$columns = array_merge($defaultColumns, $columns);
}
/** validations **/
if(is_array($oAdditionalTables->loadByName($data['REP_TAB_NAME']))) {
if(in_array($data['REP_TAB_NAME'], $reservedWords) || (isset($httpData->forceUid) && $httpData->forceUid )) {
throw new Exception('The table "' . $data['REP_TAB_NAME'] . '" already exits.');
}
@@ -225,13 +227,13 @@ class pmTablesProxy extends HttpProxyController
}
G::loadClass('pmTable');
ob_start();
$pmTable = new pmTable($data['REP_TAB_NAME']);
$pmTable->setDataSource($data['REP_TAB_CONNECTION']);
$pmTable->setColumns($columns);
$pmTable->setAlterTable($alterTable);
$pmTable->build();
unset($pmTable);
$buildResult = ob_get_contents();
ob_end_clean();
@@ -641,166 +643,184 @@ class pmTablesProxy extends HttpProxyController
{
require_once 'classes/model/AdditionalTables.php';
try {
$errors = '';
ob_start();
$overWrite = isset($_POST['form']['OVERWRITE'])? true: false;
//save the file
if ($_FILES['form']['error']['FILENAME'] == 0) {
$oAdditionalTables = new AdditionalTables();
$tableNameMap = array();
$processQueue = array();
if ($_FILES['form']['error']['FILENAME'] !== 0) {
throw new Exception('Problem while uploading file');
}
$PUBLIC_ROOT_PATH = PATH_DATA.'sites'.PATH_SEP.SYS_SYS.PATH_SEP.'public'.PATH_SEP;
$filename = $_FILES['form']['name']['FILENAME'];
$tempName = $_FILES['form']['tmp_name']['FILENAME'];
G::uploadFile($tempName, $PUBLIC_ROOT_PATH, $filename );
$oAdditionalTables = new AdditionalTables();
$tableNameMap = array();
$processQueue = array();
$PUBLIC_ROOT_PATH = PATH_DATA.'sites'.PATH_SEP.SYS_SYS.PATH_SEP.'public'.PATH_SEP;
$filename = $_FILES['form']['name']['FILENAME'];
$tempName = $_FILES['form']['tmp_name']['FILENAME'];
G::uploadFile($tempName, $PUBLIC_ROOT_PATH, $filename );
$fileContent = file_get_contents($PUBLIC_ROOT_PATH.$filename);
if(strpos($fileContent, '-----== ProcessMaker Open Source Private Tables ==-----') === false) {
throw new Exception('Invalid File, Import abort');
}
$fileContent = file_get_contents($PUBLIC_ROOT_PATH.$filename);
if(strpos($fileContent, '-----== ProcessMaker Open Source Private Tables ==-----') === false) {
throw new Exception('Invalid File');
}
$fp = fopen($PUBLIC_ROOT_PATH.$filename, "rb");
$fsData = intval(fread($fp, 9)); //reading the metadata
$sType = fread($fp, $fsData); //reading string $oData
while (!feof($fp)) {
switch($sType) {
case '@META':
$fsData = intval(fread($fp, 9));
$METADATA = fread($fp, $fsData);
break;
$fp = fopen($PUBLIC_ROOT_PATH.$filename, "rb");
$fsData = intval(fread($fp, 9)); //reading the metadata
$sType = fread($fp, $fsData); //reading string $oData
while ( !feof($fp) ) {
switch($sType) {
case '@META':
$fsData = intval(fread($fp, 9));
$METADATA = fread($fp, $fsData);
break;
case '@SCHEMA':
$fsUid = intval(fread($fp, 9));
$uid = fread($fp, $fsUid);
$fsData = intval(fread($fp, 9));
$schema = fread($fp, $fsData);
$contentSchema = unserialize($schema);
case '@SCHEMA':
$fsUid = intval(fread($fp, 9));
$uid = fread($fp, $fsUid);
$fsData = intval(fread($fp, 9));
$schema = fread($fp, $fsData);
$contentSchema = unserialize($schema);
$additionalTable = new additionalTables();
$tableExists = $additionalTable->loadByName($contentSchema['ADD_TAB_NAME']);
$tableNameMap[$contentSchema['ADD_TAB_NAME']] = $contentSchema['ADD_TAB_NAME'];
if ($overWrite) {
if($tableExists !== false) {
$additionalTable->deleteAll($tableExists[0]['ADD_TAB_UID']);
}
}
else {
if ($tableExists !== false) {// some table exists with the same name
// renaming...
$tNameOld = $contentSchema['ADD_TAB_NAME'];
$newTableName = $contentSchema['ADD_TAB_NAME'] . '_' . date('YmdHis');
$contentSchema['ADD_TAB_UID'] = G::generateUniqueID();
$contentSchema['ADD_TAB_NAME'] = $newTableName;
$contentSchema['ADD_TAB_CLASS_NAME'] = additionalTables::getPHPName($newTableName);
//mapping the table name for posterior uses
$tableNameMap[$tNameOld] = $contentSchema['ADD_TAB_NAME'];
}
}
// validating invalid bds_uid in old tables definition -> mapped to workflow
if (!$contentSchema['DBS_UID'] || $contentSchema['DBS_UID'] == '0' || !$contentSchema['DBS_UID']) {
$contentSchema['DBS_UID'] = 'workflow';
}
$columns = array();
foreach ($contentSchema['FIELDS'] as $field){
$column = array(
'uid' => '',
'field_uid' => '',
'field_name' => $field['FLD_NAME'],
'field_dyn' => isset($field['FLD_DYN_NAME']) ? $field['FLD_DYN_NAME'] : '',
'field_label'=> isset($field['FLD_DESCRIPTION']) ? $field['FLD_DESCRIPTION'] : '',
'field_type' => $field['FLD_TYPE'],
'field_size' => $field['FLD_SIZE'],
'field_key' => isset($field['FLD_KEY']) ? $field['FLD_KEY'] : 0,
'field_null' => isset($field['FLD_NULL']) ? $field['FLD_NULL'] : 1,
'field_autoincrement' => isset($field['FLD_AUTO_INCREMENT']) ? $field['FLD_AUTO_INCREMENT'] : 0
);
$columns[] = $column;
}
$tableData = new stdClass();
$tableData->REP_TAB_UID = $contentSchema['ADD_TAB_UID'];
$tableData->REP_TAB_NAME = $contentSchema['ADD_TAB_NAME'];
$tableData->REP_TAB_DSC = $contentSchema['ADD_TAB_DESCRIPTION'];
$tableData->REP_TAB_CONNECTION= $contentSchema['DBS_UID'];
$tableData->PRO_UID = isset($contentSchema['PRO_UID'])? $contentSchema['PRO_UID'] : '';
$tableData->REP_TAB_TYPE = isset($contentSchema['ADD_TAB_TYPE'])? $contentSchema['ADD_TAB_TYPE'] : '';
$tableData->REP_TAB_GRID = isset($contentSchema['ADD_TAB_GRID'])? $contentSchema['ADD_TAB_GRID'] : '';
$tableData->columns = G::json_encode($columns);
$tableData->forceUid = true;
//save the table
$alterTable = false;
if (!isset($processQueue[$contentSchema['DBS_UID']])) {
$processQueue[$contentSchema['DBS_UID']] = array();
}
$result = $this->save($tableData, $alterTable);
break;
case '@DATA':
$fstName = intval(fread($fp, 9));
$tableName = fread($fp, $fstName);
$fsData = intval(fread($fp, 9));
//var_dump($fsData);
if ($fsData > 0) {
$data = fread($fp, $fsData);
$contentData = unserialize($data);
$tableName = $tableNameMap[$tableName];
$oAdditionalTables = new AdditionalTables();
$table = $oAdditionalTables->loadByName($tableName);
if($table !== false){
$processQueue[$contentSchema['DBS_UID']][] = array('id'=>$table[0]['ADD_TAB_UID'], 'records'=>$contentData);
}
}
break;
}
$fsData = intval(fread($fp, 9));
if($fsData > 0){
$sType = fread($fp, $fsData);
$additionalTable = new additionalTables();
$tableExists = $additionalTable->loadByName($contentSchema['ADD_TAB_NAME']);
$tableNameMap[$contentSchema['ADD_TAB_NAME']] = $contentSchema['ADD_TAB_NAME'];
if ($overWrite) {
if($tableExists !== false) {
$additionalTable->deleteAll($tableExists[0]['ADD_TAB_UID']);
}
}
else {
break;
}
}
$this->success = true;
$this->message = 'File Imported "'.$filename.'" Successfully';
////////////
G::loadClass('pmTable');
foreach ($processQueue as $dbsUid => $tableData) {
ob_start();
$pmTable = new pmTable();
$pmTable->buildModelFor($dbsUid);
$buildResult = ob_get_contents();
ob_end_clean();
if (count($tableData) > 0) {
foreach ($tableData as $rows) {
foreach ($rows['records'] as $row) {
$data = new StdClass();
$data->id = $rows['id'];
$data->rows = G::json_encode($row);
$this->dataCreate($data);
}
if ($tableExists !== false) {// some table exists with the same name
// renaming...
$tNameOld = $contentSchema['ADD_TAB_NAME'];
$newTableName = $contentSchema['ADD_TAB_NAME'] . '_' . date('YmdHis');
$contentSchema['ADD_TAB_UID'] = G::generateUniqueID();
$contentSchema['ADD_TAB_NAME'] = $newTableName;
$contentSchema['ADD_TAB_CLASS_NAME'] = additionalTables::getPHPName($newTableName);
//mapping the table name for posterior uses
$tableNameMap[$tNameOld] = $contentSchema['ADD_TAB_NAME'];
}
}
}
// validating invalid bds_uid in old tables definition -> mapped to workflow
if (!$contentSchema['DBS_UID'] || $contentSchema['DBS_UID'] == '0' || !$contentSchema['DBS_UID']) {
$contentSchema['DBS_UID'] = 'workflow';
}
$columns = array();
foreach ($contentSchema['FIELDS'] as $field){
$column = array(
'uid' => '',
'field_uid' => '',
'field_name' => $field['FLD_NAME'],
'field_dyn' => isset($field['FLD_DYN_NAME']) ? $field['FLD_DYN_NAME'] : '',
'field_label'=> isset($field['FLD_DESCRIPTION']) ? $field['FLD_DESCRIPTION'] : '',
'field_type' => $field['FLD_TYPE'],
'field_size' => $field['FLD_SIZE'],
'field_key' => isset($field['FLD_KEY']) ? $field['FLD_KEY'] : 0,
'field_null' => isset($field['FLD_NULL']) ? $field['FLD_NULL'] : 1,
'field_autoincrement' => isset($field['FLD_AUTO_INCREMENT']) ? $field['FLD_AUTO_INCREMENT'] : 0
);
$columns[] = $column;
}
$tableData = new stdClass();
$tableData->REP_TAB_UID = $contentSchema['ADD_TAB_UID'];
$tableData->REP_TAB_NAME = $contentSchema['ADD_TAB_NAME'];
$tableData->REP_TAB_DSC = $contentSchema['ADD_TAB_DESCRIPTION'];
$tableData->REP_TAB_CONNECTION= $contentSchema['DBS_UID'];
$tableData->PRO_UID = isset($contentSchema['PRO_UID'])? $contentSchema['PRO_UID'] : '';
$tableData->REP_TAB_TYPE = isset($contentSchema['ADD_TAB_TYPE'])? $contentSchema['ADD_TAB_TYPE'] : '';
$tableData->REP_TAB_GRID = isset($contentSchema['ADD_TAB_GRID'])? $contentSchema['ADD_TAB_GRID'] : '';
$tableData->columns = G::json_encode($columns);
$tableData->forceUid = true;
//save the table
$alterTable = false;
if (!isset($processQueue[$contentSchema['DBS_UID']])) {
$processQueue[$contentSchema['DBS_UID']] = array();
}
$result = $this->save($tableData, $alterTable);
if (!$result->success) {
$errors .= $errors . "\n\n";
}
break;
case '@DATA':
$fstName = intval(fread($fp, 9));
$tableName = fread($fp, $fstName);
$fsData = intval(fread($fp, 9));
if ($fsData > 0) {
$data = fread($fp, $fsData);
$contentData = unserialize($data);
$tableName = $tableNameMap[$tableName];
$oAdditionalTables = new AdditionalTables();
$table = $oAdditionalTables->loadByName($tableName);
if ($table !== false) {
$processQueue[$contentSchema['DBS_UID']][] = array('id'=>$table[0]['ADD_TAB_UID'], 'records'=>$contentData);
}
}
break;
}
$fsData = intval(fread($fp, 9));
if($fsData > 0){
$sType = fread($fp, $fsData);
}
else {
break;
}
}
////////////
G::loadClass('pmTable');
foreach ($processQueue as $dbsUid => $tableData) {
$pmTable = new pmTable();
$pmTable->buildModelFor($dbsUid);
$buildResult = ob_get_contents();
ob_end_clean();
if (count($tableData) > 0) {
foreach ($tableData as $rows) {
foreach ($rows['records'] as $row) {
$data = new StdClass();
$data->id = $rows['id'];
$data->rows = G::json_encode($row);
$this->dataCreate($data);
}
}
}
}
if ($errors == '') {
$msg = 'File Imported "'.$filename.'" Successfully';
$result->type = 0;
}
else {
$msg = 'File Imported "'.$filename.'" but with errors' . "\n\n" . $errors;
$result->type = 1;
}
$result->success = true;
$result->message = $msg;
}
catch(Exception $e) {
$buildResult = ob_get_contents();
$result->type = 2;
$result->buildResult = ob_get_contents();
ob_end_clean();
$result->success = false;
@@ -816,6 +836,8 @@ class pmTablesProxy extends HttpProxyController
$result->trace = $e->getTraceAsString();
}
return $result;
}
/**
@@ -1010,9 +1032,12 @@ class pmTablesProxy extends HttpProxyController
*/
function _dataUpdate($row)
{
$keys = explode('-', $row->__index__);
$keys = G::decrypt($row->__index__, 'pmtable');
$keys = explode('-', $keys);
unset($row->__index__);
$params = array();
foreach ($keys as $key) {
$params[] = is_numeric($key) ? $key : "'$key'";
}

View File

@@ -260,6 +260,7 @@ Ext.onReady(function(){
forceFit:true
},
store: store,
loadMask: true,
cm: cmodel,
sm: smodel,
tbar:[ newButton,
@@ -292,14 +293,14 @@ Ext.onReady(function(){
infoGrid.on('contextmenu', function(evt){evt.preventDefault();}, this);
infoGrid.addListener('rowcontextmenu',onMessageContextMenu, this);
infoGrid.store.load();
viewport = new Ext.Viewport({
layout: 'fit',
autoScroll: false,
items: [infoGrid]
});
infoGrid.store.load();
});
//Funtion Handles Context Menu Opening

View File

@@ -114,7 +114,6 @@ Ext.onReady(function(){
contextMenuItems.push(exportButton);
if (_PLUGIN_SIMPLEREPORTS !== false) {
externalOption = new Ext.Action({
text:'',
handler: function() {
@@ -131,22 +130,22 @@ Ext.onReady(function(){
});
searchText = new Ext.form.TextField ({
id: 'searchTxt',
ctCls:'pm_search_text_field',
allowBlank: true,
width: 150,
emptyText: _('ID_ENTER_SEARCH_TERM'),
listeners: {
specialkey: function(f,e){
if (e.getKey() == e.ENTER) {
DoSearch();
}
},
focus: function(f,e) {
var row = infoGrid.getSelectionModel().getSelected();
infoGrid.getSelectionModel().deselectRow(infoGrid.getStore().indexOf(row));
id: 'searchTxt',
ctCls:'pm_search_text_field',
allowBlank: true,
width: 150,
emptyText: _('ID_ENTER_SEARCH_TERM'),
listeners: {
specialkey: function(f,e){
if (e.getKey() == e.ENTER) {
DoSearch();
}
},
focus: function(f,e) {
var row = infoGrid.getSelectionModel().getSelected();
infoGrid.getSelectionModel().deselectRow(infoGrid.getStore().indexOf(row));
}
}
});
clearTextButton = new Ext.Action({
@@ -182,6 +181,7 @@ Ext.onReady(function(){
comboPageSize.setValue(pageSize);
store = new Ext.data.GroupingStore( {
autoLoad: false,
proxy : new Ext.data.HttpProxy({
url: 'pmTablesProxy/getList' + (PRO_UID? '?pro_uid='+PRO_UID: '')
}),
@@ -293,14 +293,25 @@ Ext.onReady(function(){
forceFit:true
},
store: store,
loadMask: true,
cm: cmodel,
sm: smodel,
tbar:[newButton, editButton, deleteButton,'-', dataButton,'-' , importButton, exportButton,{xtype: 'tbfill'},searchText,clearTextButton,searchButton],
tbar: [
newButton,
editButton,
deleteButton,'-',
dataButton,'-' ,
importButton,
exportButton,
'->',
searchText,
clearTextButton,
searchButton],
bbar: bbarpaging,
listeners: {
rowdblclick: EditPMTable,
render: function(){
this.loadMask = new Ext.LoadMask(this.body, {msg:_('ID_LOADING_GRID')});
this.loadMask = new Ext.LoadMask(this.body, {msg:'loading'});
}
},
view: new Ext.grid.GroupingView({
@@ -310,38 +321,35 @@ Ext.onReady(function(){
});
infoGrid.on('rowcontextmenu',
function (grid, rowIndex, evt) {
var sm = grid.getSelectionModel();
sm.selectRow(rowIndex, sm.isSelected(rowIndex));
function (grid, rowIndex, evt) {
var sm = grid.getSelectionModel();
sm.selectRow(rowIndex, sm.isSelected(rowIndex));
var rowsSelected = Ext.getCmp('infoGrid').getSelectionModel().getSelections();
tag = rowsSelected[0].get('ADD_TAB_TAG');
text = tag? 'Convert to native Report Table': 'Convert to Simple Report';
if (externalOption) {
externalOption.setText(text);
if (rowsSelected[0].get('PRO_UID')) {
externalOption.setDisabled(false);
} else {
externalOption.setDisabled(true);
}
var rowsSelected = Ext.getCmp('infoGrid').getSelectionModel().getSelections();
tag = rowsSelected[0].get('ADD_TAB_TAG');
text = tag? 'Convert to native Report Table': 'Convert to Simple Report';
if (externalOption) {
externalOption.setText(text);
if (rowsSelected[0].get('PRO_UID')) {
externalOption.setDisabled(false);
} else {
externalOption.setDisabled(true);
}
},
this
}
},
this
);
infoGrid.on('contextmenu', function(evt){evt.preventDefault();}, this);
infoGrid.addListener('rowcontextmenu',onMessageContextMenu, this);
infoGrid.store.load();
viewport = new Ext.Viewport({
layout: 'fit',
autoScroll: false,
items: [
infoGrid
]
items: [infoGrid]
});
infoGrid.store.load();
});
//Funtion Handles Context Menu Opening
@@ -482,6 +490,9 @@ ImportPMTable = function(){
url: 'pmTablesProxy/import',
waitMsg: 'Uploading file...',
success: function(o, resp){
console.log(o);
console.log(resp.response.responseText);
w.close();
infoGrid.store.reload();
@@ -511,14 +522,7 @@ ImportPMTable = function(){
}
}]
})
]/*,
listeners:{
show:function() {
this.loadMask = new Ext.LoadMask(this.body, {
msg:'Loading. Please wait...'
});
}
}*/
]
});
w.show();
}