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

@@ -20,7 +20,7 @@
*/ */
include_once 'propel/engine/EngineException.php'; include_once 'propel/engine/EngineException.php';
include_once 'propel/engine/database/model/Database.php'; include_once 'propel/engine/database/model/DatabasePropel.php';
/** /**
* A class for holding application data structures. * A class for holding application data structures.
@@ -158,7 +158,7 @@ class AppData {
*/ */
public function addDatabase($db) public function addDatabase($db)
{ {
if ($db instanceof Database) { if ($db instanceof DatabasePropel) {
$db->setAppData($this); $db->setAppData($this);
if ($db->getPlatform() === null) { if ($db->getPlatform() === null) {
$db->setPlatform($this->platform); $db->setPlatform($this->platform);
@@ -167,7 +167,7 @@ class AppData {
return $db; return $db;
} else { } else {
// XML attributes array / hash // XML attributes array / hash
$d = new Database(); $d = new DatabasePropel();
$d->loadFromXML($db); $d->loadFromXML($db);
return $this->addDatabase($d); // calls self w/ different param type return $this->addDatabase($d); // calls self w/ different param type
} }

View File

@@ -0,0 +1,463 @@
<?php
/*
* $Id: Database.php 576 2007-02-09 19:08:40Z hans $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://propel.phpdb.org>.
*/
require_once 'propel/engine/database/model/XMLElement.php';
include_once 'propel/engine/database/model/IDMethod.php';
include_once 'propel/engine/database/model/NameGenerator.php';
include_once 'propel/engine/database/model/Table.php';
/**
* A class for holding application data structures.
*
* @author Hans Lellelid <hans@xmpl.org> (Propel)
* @author Leon Messerschmidt <leon@opticode.co.za> (Torque)
* @author John McNally<jmcnally@collab.net> (Torque)
* @author Martin Poeschl<mpoeschl@marmot.at> (Torque)
* @author Daniel Rall<dlr@collab.net> (Torque)
* @author Byron Foster <byron_foster@yahoo.com> (Torque)
* @version $Revision: 576 $
* @package propel.engine.database.model
*/
class DatabasePropel extends XMLElement {
private $platform;
private $tableList = array();
private $curColumn;
private $name;
private $pkg;
private $baseClass;
private $basePeer;
private $defaultIdMethod;
private $defaultPhpType;
private $defaultPhpNamingMethod;
private $defaultTranslateMethod;
private $dbParent;
private $tablesByName = array();
private $tablesByPhpName = array();
private $heavyIndexing;
private $domainMap = array();
/**
* Sets up the Database object based on the attributes that were passed to loadFromXML().
* @see parent::loadFromXML()
*/
protected function setupObject()
{
$this->name = $this->getAttribute("name");
$this->pkg = $this->getAttribute("package");
$this->baseClass = $this->getAttribute("baseClass");
$this->basePeer = $this->getAttribute("basePeer");
$this->defaultPhpType = $this->getAttribute("defaultPhpType");
$this->defaultIdMethod = $this->getAttribute("defaultIdMethod");
$this->defaultPhpNamingMethod = $this->getAttribute("defaultPhpNamingMethod", NameGenerator::CONV_METHOD_UNDERSCORE);
$this->defaultTranslateMethod = $this->getAttribute("defaultTranslateMethod", Validator::TRANSLATE_NONE);
$this->heavyIndexing = $this->booleanValue($this->getAttribute("heavyIndexing"));
}
/**
* Returns the Platform implementation for this database.
*
* @return Platform a Platform implementation
*/
public function getPlatform()
{
return $this->platform;
}
/**
* Sets the Platform implementation for this database.
*
* @param Platform $platform A Platform implementation
*/
public function setPlatform($platform)
{
$this->platform = $platform;
}
/**
* Get the name of the Database
*/
public function getName()
{
return $this->name;
}
/**
* Set the name of the Database
*/
public function setName($name)
{
$this->name = $name;
}
/**
* Get the value of package.
* @return value of package.
*/
public function getPackage()
{
return $this->pkg;
}
/**
* Set the value of package.
* @param v Value to assign to package.
*/
public function setPackage($v)
{
$this->pkg = $v;
}
/**
* Get the value of baseClass.
* @return value of baseClass.
*/
public function getBaseClass()
{
return $this->baseClass;
}
/**
* Set the value of baseClass.
* @param v Value to assign to baseClass.
*/
public function setBaseClass($v)
{
$this->baseClass = $v;
}
/**
* Get the value of basePeer.
* @return value of basePeer.
*/
public function getBasePeer()
{
return $this->basePeer;
}
/**
* Set the value of basePeer.
* @param v Value to assign to basePeer.
*/
public function setBasePeer($v)
{
$this->basePeer = $v;
}
/**
* Get the value of defaultIdMethod.
* @return value of defaultIdMethod.
*/
public function getDefaultIdMethod()
{
return $this->defaultIdMethod;
}
/**
* Set the value of defaultIdMethod.
* @param v Value to assign to defaultIdMethod.
*/
public function setDefaultIdMethod($v)
{
$this->defaultIdMethod = $v;
}
/**
* Get the value of defaultPHPNamingMethod which specifies the
* method for converting schema names for table and column to PHP names.
* @return string The default naming conversion used by this database.
*/
public function getDefaultPhpNamingMethod()
{
return $this->defaultPhpNamingMethod;
}
/**
* Set the value of defaultPHPNamingMethod.
* @param string $v The default naming conversion for this database to use.
*/
public function setDefaultPhpNamingMethod($v)
{
$this->defaultPhpNamingMethod = $v;
}
/**
* Get the value of defaultTranslateMethod which specifies the
* method for translate validator error messages.
* @return string The default translate method.
*/
public function getDefaultTranslateMethod()
{
return $this->defaultTranslateMethod;
}
/**
* Set the value of defaultTranslateMethod.
* @param string $v The default translate method to use.
*/
public function setDefaultTranslateMethod($v)
{
$this->defaultTranslateMethod = $v;
}
/**
* Get the value of heavyIndexing.
* @return boolean Value of heavyIndexing.
*/
public function isHeavyIndexing()
{
return $this->heavyIndexing;
}
/**
* Set the value of heavyIndexing.
* @param boolean $v Value to assign to heavyIndexing.
*/
public function setHeavyIndexing($v)
{
$this->heavyIndexing = (boolean) $v;
}
/**
* Return an array of all tables
*/
public function getTables()
{
return $this->tableList;
}
/**
* Return the table with the specified name.
* @param string $name The name of the table (e.g. 'my_table')
* @return Table a Table object or null if it doesn't exist
*/
public function getTable($name)
{
if (isset($this->tablesByName[$name])) {
return $this->tablesByName[$name];
}
return null; // just to be explicit
}
/**
* Return the table with the specified phpName.
* @param string $phpName the PHP Name of the table (e.g. 'MyTable')
* @return Table a Table object or null if it doesn't exist
*/
public function getTableByPhpName($phpName)
{
if (isset($this->tablesByPhpName[$phpName])) {
return $this->tablesByPhpName[$phpName];
}
return null; // just to be explicit
}
/**
* An utility method to add a new table from an xml attribute.
*/
public function addTable($data)
{
if ($data instanceof Table) {
$tbl = $data; // alias
$tbl->setDatabase($this);
if (isset($this->tablesByName[$tbl->getName()])) {
throw new EngineException("Duplicate table declared: " . $tbl->getName());
}
$this->tableList[] = $tbl;
$this->tablesByName[ $tbl->getName() ] = $tbl;
$this->tablesByPhpName[ $tbl->getPhpName() ] = $tbl;
if ($tbl->getPackage() === null) {
$tbl->setPackage($this->getPackage());
}
return $tbl;
} else {
$tbl = new Table();
$tbl->setDatabase($this);
$tbl->loadFromXML($data);
return $this->addTable($tbl); // call self w/ different param
}
}
/**
* Set the parent of the database
*/
public function setAppData(AppData $parent)
{
$this->dbParent = $parent;
}
/**
* Get the parent of the table
*/
public function getAppData()
{
return $this->dbParent;
}
/**
* Adds Domain object from <domain> tag.
* @param mixed XML attributes (array) or Domain object.
*/
public function addDomain($data) {
if ($data instanceof Domain) {
$domain = $data; // alias
$domain->setDatabase($this);
$this->domainMap[ $domain->getName() ] = $domain;
return $domain;
} else {
$domain = new Table();
$domain->setDatabase($this);
$domain->loadFromXML($data);
return $this->addDomain($domain); // call self w/ different param
}
}
/**
* Get already configured Domain object by name.
* @return Domain
*/
public function getDomain($domainName) {
if (!isset($this->domainMap[$domainName])) {
return null;
}
return $this->domainMap[$domainName];
}
public function doFinalInitialization()
{
$tables = $this->getTables();
for($i=0,$size=count($tables); $i < $size; $i++) {
$currTable = $tables[$i];
// check schema integrity
// if idMethod="autoincrement", make sure a column is
// specified as autoIncrement="true"
// FIXME: Handle idMethod="native" via DB adapter.
/*
--- REMOVING THIS BECAUSE IT'S ANNOYING
if ($currTable->getIdMethod() == IDMethod::NATIVE ) {
$columns = $currTable->getColumns();
$foundOne = false;
for ($j=0, $cLen=count($columns); $j < $cLen && !$foundOne; $j++) {
$foundOne = $columns[$j]->isAutoIncrement();
}
if (!$foundOne) {
$errorMessage = "Table '" . $currTable->getName()
. "' is set to use native id generation, but it does not "
. "have a column which declared as the one to "
. "auto increment (i.e. autoIncrement=\"true\")";
throw new BuildException($errorMessage);
}
}
*/
$currTable->doFinalInitialization();
// setup reverse fk relations
$fks = $currTable->getForeignKeys();
for ($j=0, $fksLen=count($fks); $j < $fksLen; $j++) {
$currFK = $fks[$j];
$foreignTable = $this->getTable($currFK->getForeignTableName());
if ($foreignTable === null) {
throw new BuildException("ERROR!! Attempt to set foreign"
. " key to nonexistent table, "
. $currFK->getForeignTableName() . "!");
}
$referrers = $foreignTable->getReferrers();
if ($referrers === null || ! in_array($currFK,$referrers) ) {
$foreignTable->addReferrer($currFK);
}
// local column references
$localColumnNames = $currFK->getLocalColumns();
for($k=0,$lcnLen=count($localColumnNames); $k < $lcnLen; $k++) {
$local = $currTable->getColumn($localColumnNames[$k]);
// give notice of a schema inconsistency.
// note we do not prevent the npe as there is nothing
// that we can do, if it is to occur.
if ($local === null) {
throw new BuildException("ERROR!! Attempt to define foreign"
. " key with nonexistent column, "
. $localColumnNames[$k] . ", in table, "
. $currTable->getName() . "!");
}
//check for foreign pk's
if ($local->isPrimaryKey()) {
$currTable->setContainsForeignPK(true);
}
} // for each local col name
// foreign column references
$foreignColumnNames = $currFK->getForeignColumns();
for($k=0,$fcnLen=count($localColumnNames); $k < $fcnLen; $k++) {
$foreign = $foreignTable->getColumn($foreignColumnNames[$k]);
// if the foreign column does not exist, we may have an
// external reference or a misspelling
if ($foreign === null) {
throw new BuildException("ERROR!! Attempt to set foreign"
. " key to nonexistent column, "
. $foreignColumnNames[$k] . ", in table, "
. $foreignTable->getName() . "!");
} else {
$foreign->addReferrer($currFK);
}
} // for each foreign col ref
}
}
}
/**
* Creats a string representation of this Database.
* The representation is given in xml format.
*/
public function toString()
{
$result = "<database name=\"" . $this->getName() . '"'
. " package=\"" . $this->getPackage() . '"'
. " defaultIdMethod=\"" . $this->getDefaultIdMethod()
. '"'
. " baseClass=\"" . $this->getBaseClass() . '"'
. " basePeer=\"" . $this->getBasePeer() . '"'
. ">\n";
for ($i=0, $size=count($this->tableList); $i < $size; $i++) {
$result .= $this->tableList[$i]->toString();
}
$result .= "</database>";
return $result;
}
}

View File

@@ -95,7 +95,7 @@ class Domain extends XMLElement {
/** /**
* Sets the owning database object (if this domain is being setup via XML). * Sets the owning database object (if this domain is being setup via XML).
*/ */
public function setDatabase(Database $database) { public function setDatabase(DatabasePropel $database) {
$this->database = $database; $this->database = $database;
} }

View File

@@ -53,7 +53,7 @@ class XmlToData extends AbstractHandler {
* *
* @param Database $database * @param Database $database
*/ */
public function __construct(Database $database, $encoding = 'iso-8859-1') public function __construct(DatabasePropel $database, $encoding = 'iso-8859-1')
{ {
$this->database = $database; $this->database = $database;
$this->encoding = $encoding; $this->encoding = $encoding;

View File

@@ -23,7 +23,7 @@
//include_once 'phing/tasks/ext/CapsuleTask.php'; //include_once 'phing/tasks/ext/CapsuleTask.php';
require_once 'phing/TaskPhing.php'; require_once 'phing/TaskPhing.php';
include_once 'propel/engine/database/model/AppData.php'; include_once 'propel/engine/database/model/AppData.php';
include_once 'propel/engine/database/model/Database.php'; include_once 'propel/engine/database/model/DatabasePropel.php';
include_once 'propel/engine/database/transform/XmlToAppData.php'; include_once 'propel/engine/database/transform/XmlToAppData.php';
/** /**

View File

@@ -349,7 +349,7 @@ class PropelDataDumpTask extends AbstractPropelDataModelTask {
* @param Database $database * @param Database $database
* @return DOMDocument * @return DOMDocument
*/ */
private function createXMLDoc(Database $database) { private function createXMLDoc(DatabasePropel $database) {
$doc = new DOMDocument('1.0', 'utf-8'); $doc = new DOMDocument('1.0', 'utf-8');
$doc->formatOutput = true; // pretty printing $doc->formatOutput = true; // pretty printing

View File

@@ -22,7 +22,7 @@
require_once 'propel/phing/AbstractPropelDataModelTask.php'; require_once 'propel/phing/AbstractPropelDataModelTask.php';
include_once 'propel/engine/database/model/AppData.php'; include_once 'propel/engine/database/model/AppData.php';
include_once 'propel/engine/database/model/Database.php'; include_once 'propel/engine/database/model/DatabasePropel.php';
include_once 'propel/engine/database/transform/XmlToAppData.php'; include_once 'propel/engine/database/transform/XmlToAppData.php';
/** /**

View File

@@ -21,7 +21,7 @@
*/ */
include_once 'propel/engine/database/model/AppData.php'; include_once 'propel/engine/database/model/AppData.php';
include_once 'propel/engine/database/model/Database.php'; include_once 'propel/engine/database/model/DatabasePropel.php';
include_once 'propel/engine/database/transform/XmlToAppData.php'; include_once 'propel/engine/database/transform/XmlToAppData.php';
include_once 'propel/engine/database/transform/XmlToData.php'; include_once 'propel/engine/database/transform/XmlToData.php';

View File

@@ -280,7 +280,7 @@ class PropelOldSQLTask extends AbstractPropelDataModelTask {
//'heavyIndexing' => $db->getHeavyIndexing(), //'heavyIndexing' => $db->getHeavyIndexing(),
); );
$clone = new Database(); $clone = new DatabasePropel();
$clone->loadFromXML($attributes); $clone->loadFromXML($attributes);
return $clone; return $clone;
} }

View File

@@ -251,7 +251,7 @@ class PropelSQLTask extends AbstractPropelDataModelTask {
//'heavyIndexing' => $db->getHeavyIndexing(), //'heavyIndexing' => $db->getHeavyIndexing(),
); );
$clone = new Database(); $clone = new DatabasePropel();
$clone->loadFromXML($attributes); $clone->loadFromXML($attributes);
return $clone; return $clone;
} }

View File

@@ -183,6 +183,7 @@ class pmTablesProxy extends HttpProxyController
require_once 'classes/model/Fields.php'; require_once 'classes/model/Fields.php';
try { try {
ob_start();
$data = (array) $httpData; $data = (array) $httpData;
$data['PRO_UID'] = trim($data['PRO_UID']); $data['PRO_UID'] = trim($data['PRO_UID']);
$data['columns'] = G::json_decode(stripslashes($httpData->columns)); //decofing data columns $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', 'INDEX', 'INSERT', 'OPEN', 'REVOKE', 'ROLLBACK', 'SELECT', 'SYNONYM', 'TABLE', 'UPDATE', 'VIEW',
'APP_UID', 'ROW', 'PMTABLE' 'APP_UID', 'ROW', 'PMTABLE'
); );
//$reservedWords = array_merge($reservedWords, array_change_key_case($reservedWords, CASE_LOWER));
// verify if exists. // 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 if ($isReportTable) { //setting default columns
$defaultColumns = $this->_getReportTableDefaultColumns($data['REP_TAB_TYPE']); $defaultColumns = $this->_getReportTableDefaultColumns($data['REP_TAB_TYPE']);
$columns = array_merge($defaultColumns, $columns); $columns = array_merge($defaultColumns, $columns);
} }
/** validations **/ /** 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.'); throw new Exception('The table "' . $data['REP_TAB_NAME'] . '" already exits.');
} }
@@ -225,13 +227,13 @@ class pmTablesProxy extends HttpProxyController
} }
G::loadClass('pmTable'); G::loadClass('pmTable');
ob_start();
$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);
$pmTable->build(); $pmTable->build();
unset($pmTable);
$buildResult = ob_get_contents(); $buildResult = ob_get_contents();
ob_end_clean(); ob_end_clean();
@@ -641,166 +643,184 @@ class pmTablesProxy extends HttpProxyController
{ {
require_once 'classes/model/AdditionalTables.php'; require_once 'classes/model/AdditionalTables.php';
try { try {
$errors = '';
ob_start();
$overWrite = isset($_POST['form']['OVERWRITE'])? true: false; $overWrite = isset($_POST['form']['OVERWRITE'])? true: false;
//save the file //save the file
if ($_FILES['form']['error']['FILENAME'] == 0) { if ($_FILES['form']['error']['FILENAME'] !== 0) {
$oAdditionalTables = new AdditionalTables(); throw new Exception('Problem while uploading file');
$tableNameMap = array(); }
$processQueue = array();
$PUBLIC_ROOT_PATH = PATH_DATA.'sites'.PATH_SEP.SYS_SYS.PATH_SEP.'public'.PATH_SEP; $oAdditionalTables = new AdditionalTables();
$filename = $_FILES['form']['name']['FILENAME']; $tableNameMap = array();
$tempName = $_FILES['form']['tmp_name']['FILENAME']; $processQueue = array();
G::uploadFile($tempName, $PUBLIC_ROOT_PATH, $filename );
$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); $fp = fopen($PUBLIC_ROOT_PATH.$filename, "rb");
$fsData = intval(fread($fp, 9)); //reading the metadata
if(strpos($fileContent, '-----== ProcessMaker Open Source Private Tables ==-----') === false) { $sType = fread($fp, $fsData); //reading string $oData
throw new Exception('Invalid File');
} while (!feof($fp)) {
switch($sType) {
case '@META':
$fsData = intval(fread($fp, 9));
$METADATA = fread($fp, $fsData);
break;
$fp = fopen($PUBLIC_ROOT_PATH.$filename, "rb"); case '@SCHEMA':
$fsData = intval(fread($fp, 9)); //reading the metadata $fsUid = intval(fread($fp, 9));
$sType = fread($fp, $fsData); //reading string $oData $uid = fread($fp, $fsUid);
$fsData = intval(fread($fp, 9));
while ( !feof($fp) ) { $schema = fread($fp, $fsData);
switch($sType) { $contentSchema = unserialize($schema);
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);
$additionalTable = new additionalTables(); $additionalTable = new additionalTables();
$tableExists = $additionalTable->loadByName($contentSchema['ADD_TAB_NAME']); $tableExists = $additionalTable->loadByName($contentSchema['ADD_TAB_NAME']);
$tableNameMap[$contentSchema['ADD_TAB_NAME']] = $contentSchema['ADD_TAB_NAME']; $tableNameMap[$contentSchema['ADD_TAB_NAME']] = $contentSchema['ADD_TAB_NAME'];
if ($overWrite) { if ($overWrite) {
if($tableExists !== false) { if($tableExists !== false) {
$additionalTable->deleteAll($tableExists[0]['ADD_TAB_UID']); $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);
} }
else { else {
break; if ($tableExists !== false) {// some table exists with the same name
} // renaming...
} $tNameOld = $contentSchema['ADD_TAB_NAME'];
$newTableName = $contentSchema['ADD_TAB_NAME'] . '_' . date('YmdHis');
$this->success = true; $contentSchema['ADD_TAB_UID'] = G::generateUniqueID();
$this->message = 'File Imported "'.$filename.'" Successfully'; $contentSchema['ADD_TAB_NAME'] = $newTableName;
$contentSchema['ADD_TAB_CLASS_NAME'] = additionalTables::getPHPName($newTableName);
//////////// //mapping the table name for posterior uses
G::loadClass('pmTable'); $tableNameMap[$tNameOld] = $contentSchema['ADD_TAB_NAME'];
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);
}
} }
} }
}
// 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) { catch(Exception $e) {
$buildResult = ob_get_contents(); $result->type = 2;
$result->buildResult = ob_get_contents();
ob_end_clean(); ob_end_clean();
$result->success = false; $result->success = false;
@@ -816,6 +836,8 @@ class pmTablesProxy extends HttpProxyController
$result->trace = $e->getTraceAsString(); $result->trace = $e->getTraceAsString();
} }
return $result;
} }
/** /**
@@ -1010,9 +1032,12 @@ class pmTablesProxy extends HttpProxyController
*/ */
function _dataUpdate($row) function _dataUpdate($row)
{ {
$keys = explode('-', $row->__index__); $keys = G::decrypt($row->__index__, 'pmtable');
$keys = explode('-', $keys);
unset($row->__index__); unset($row->__index__);
$params = array(); $params = array();
foreach ($keys as $key) { foreach ($keys as $key) {
$params[] = is_numeric($key) ? $key : "'$key'"; $params[] = is_numeric($key) ? $key : "'$key'";
} }

View File

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

View File

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