From 3a242fe8a529f18ebcc86f39448116d726b34905 Mon Sep 17 00:00:00 2001 From: Erik Amaru Ortiz Date: Thu, 15 Sep 2011 11:30:27 -0400 Subject: [PATCH] BUG 0000 Refactoring for propel-generator/Database class to DatabasePropel class - fixes in data editing - fixes in pmtables import --- .../propel/engine/database/model/AppData.php | 6 +- .../engine/database/model/DatabasePropel.php | 463 ++++++++++++++++++ .../propel/engine/database/model/Domain.php | 2 +- .../engine/database/transform/XmlToData.php | 2 +- .../phing/AbstractPropelDataModelTask.php | 2 +- .../propel/phing/PropelDataDumpTask.php | 2 +- .../propel/phing/PropelDataModelTask.php | 2 +- .../propel/phing/PropelDataSQLTask.php | 2 +- .../classes/propel/phing/PropelOldSQLTask.php | 2 +- .../classes/propel/phing/PropelSQLTask.php | 2 +- workflow/engine/controllers/pmTablesProxy.php | 325 ++++++------ workflow/engine/templates/pmTables/data.js | 5 +- workflow/engine/templates/pmTables/list.js | 96 ++-- 13 files changed, 702 insertions(+), 209 deletions(-) create mode 100644 gulliver/thirdparty/propel-generator/classes/propel/engine/database/model/DatabasePropel.php diff --git a/gulliver/thirdparty/propel-generator/classes/propel/engine/database/model/AppData.php b/gulliver/thirdparty/propel-generator/classes/propel/engine/database/model/AppData.php index 0372147d8..aaf9768bd 100755 --- a/gulliver/thirdparty/propel-generator/classes/propel/engine/database/model/AppData.php +++ b/gulliver/thirdparty/propel-generator/classes/propel/engine/database/model/AppData.php @@ -20,7 +20,7 @@ */ 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. @@ -158,7 +158,7 @@ class AppData { */ public function addDatabase($db) { - if ($db instanceof Database) { + if ($db instanceof DatabasePropel) { $db->setAppData($this); if ($db->getPlatform() === null) { $db->setPlatform($this->platform); @@ -167,7 +167,7 @@ class AppData { return $db; } else { // XML attributes array / hash - $d = new Database(); + $d = new DatabasePropel(); $d->loadFromXML($db); return $this->addDatabase($d); // calls self w/ different param type } diff --git a/gulliver/thirdparty/propel-generator/classes/propel/engine/database/model/DatabasePropel.php b/gulliver/thirdparty/propel-generator/classes/propel/engine/database/model/DatabasePropel.php new file mode 100644 index 000000000..3883822ea --- /dev/null +++ b/gulliver/thirdparty/propel-generator/classes/propel/engine/database/model/DatabasePropel.php @@ -0,0 +1,463 @@ +. + */ + +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 (Propel) + * @author Leon Messerschmidt (Torque) + * @author John McNally (Torque) + * @author Martin Poeschl (Torque) + * @author Daniel Rall (Torque) + * @author Byron Foster (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 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 = "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 .= ""; + + return $result; + } +} diff --git a/gulliver/thirdparty/propel-generator/classes/propel/engine/database/model/Domain.php b/gulliver/thirdparty/propel-generator/classes/propel/engine/database/model/Domain.php index 4680d4f00..8b7edef7c 100755 --- a/gulliver/thirdparty/propel-generator/classes/propel/engine/database/model/Domain.php +++ b/gulliver/thirdparty/propel-generator/classes/propel/engine/database/model/Domain.php @@ -95,7 +95,7 @@ class Domain extends XMLElement { /** * 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; } diff --git a/gulliver/thirdparty/propel-generator/classes/propel/engine/database/transform/XmlToData.php b/gulliver/thirdparty/propel-generator/classes/propel/engine/database/transform/XmlToData.php index 0b17ad65f..9b5fbffd9 100755 --- a/gulliver/thirdparty/propel-generator/classes/propel/engine/database/transform/XmlToData.php +++ b/gulliver/thirdparty/propel-generator/classes/propel/engine/database/transform/XmlToData.php @@ -53,7 +53,7 @@ class XmlToData extends AbstractHandler { * * @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->encoding = $encoding; diff --git a/gulliver/thirdparty/propel-generator/classes/propel/phing/AbstractPropelDataModelTask.php b/gulliver/thirdparty/propel-generator/classes/propel/phing/AbstractPropelDataModelTask.php index 234692ab6..90cc08405 100644 --- a/gulliver/thirdparty/propel-generator/classes/propel/phing/AbstractPropelDataModelTask.php +++ b/gulliver/thirdparty/propel-generator/classes/propel/phing/AbstractPropelDataModelTask.php @@ -23,7 +23,7 @@ //include_once 'phing/tasks/ext/CapsuleTask.php'; require_once 'phing/TaskPhing.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'; /** diff --git a/gulliver/thirdparty/propel-generator/classes/propel/phing/PropelDataDumpTask.php b/gulliver/thirdparty/propel-generator/classes/propel/phing/PropelDataDumpTask.php index 315f32ea0..ec046389a 100755 --- a/gulliver/thirdparty/propel-generator/classes/propel/phing/PropelDataDumpTask.php +++ b/gulliver/thirdparty/propel-generator/classes/propel/phing/PropelDataDumpTask.php @@ -349,7 +349,7 @@ class PropelDataDumpTask extends AbstractPropelDataModelTask { * @param Database $database * @return DOMDocument */ - private function createXMLDoc(Database $database) { + private function createXMLDoc(DatabasePropel $database) { $doc = new DOMDocument('1.0', 'utf-8'); $doc->formatOutput = true; // pretty printing diff --git a/gulliver/thirdparty/propel-generator/classes/propel/phing/PropelDataModelTask.php b/gulliver/thirdparty/propel-generator/classes/propel/phing/PropelDataModelTask.php index 083da04da..4be18490b 100755 --- a/gulliver/thirdparty/propel-generator/classes/propel/phing/PropelDataModelTask.php +++ b/gulliver/thirdparty/propel-generator/classes/propel/phing/PropelDataModelTask.php @@ -22,7 +22,7 @@ require_once 'propel/phing/AbstractPropelDataModelTask.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'; /** diff --git a/gulliver/thirdparty/propel-generator/classes/propel/phing/PropelDataSQLTask.php b/gulliver/thirdparty/propel-generator/classes/propel/phing/PropelDataSQLTask.php index 26f4784b4..8e5c4183b 100755 --- a/gulliver/thirdparty/propel-generator/classes/propel/phing/PropelDataSQLTask.php +++ b/gulliver/thirdparty/propel-generator/classes/propel/phing/PropelDataSQLTask.php @@ -21,7 +21,7 @@ */ 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/XmlToData.php'; diff --git a/gulliver/thirdparty/propel-generator/classes/propel/phing/PropelOldSQLTask.php b/gulliver/thirdparty/propel-generator/classes/propel/phing/PropelOldSQLTask.php index be60092b9..027921c5d 100755 --- a/gulliver/thirdparty/propel-generator/classes/propel/phing/PropelOldSQLTask.php +++ b/gulliver/thirdparty/propel-generator/classes/propel/phing/PropelOldSQLTask.php @@ -280,7 +280,7 @@ class PropelOldSQLTask extends AbstractPropelDataModelTask { //'heavyIndexing' => $db->getHeavyIndexing(), ); - $clone = new Database(); + $clone = new DatabasePropel(); $clone->loadFromXML($attributes); return $clone; } diff --git a/gulliver/thirdparty/propel-generator/classes/propel/phing/PropelSQLTask.php b/gulliver/thirdparty/propel-generator/classes/propel/phing/PropelSQLTask.php index 730acce53..ac462e6f6 100755 --- a/gulliver/thirdparty/propel-generator/classes/propel/phing/PropelSQLTask.php +++ b/gulliver/thirdparty/propel-generator/classes/propel/phing/PropelSQLTask.php @@ -251,7 +251,7 @@ class PropelSQLTask extends AbstractPropelDataModelTask { //'heavyIndexing' => $db->getHeavyIndexing(), ); - $clone = new Database(); + $clone = new DatabasePropel(); $clone->loadFromXML($attributes); return $clone; } diff --git a/workflow/engine/controllers/pmTablesProxy.php b/workflow/engine/controllers/pmTablesProxy.php index 8c50e8b19..01fb38eea 100755 --- a/workflow/engine/controllers/pmTablesProxy.php +++ b/workflow/engine/controllers/pmTablesProxy.php @@ -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'"; } diff --git a/workflow/engine/templates/pmTables/data.js b/workflow/engine/templates/pmTables/data.js index 42c3512db..f17f06108 100755 --- a/workflow/engine/templates/pmTables/data.js +++ b/workflow/engine/templates/pmTables/data.js @@ -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 diff --git a/workflow/engine/templates/pmTables/list.js b/workflow/engine/templates/pmTables/list.js index 57341f754..de49be247 100755 --- a/workflow/engine/templates/pmTables/list.js +++ b/workflow/engine/templates/pmTables/list.js @@ -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(); }