Merge remote branch 'upstream/master'

This commit is contained in:
Fernando Ontiveros
2012-07-04 17:58:02 -04:00
4 changed files with 808 additions and 812 deletions

View File

@@ -2094,3 +2094,4 @@ function PMFGetCaseNotes ($applicationID, $type='array', $userUid='')
$response = Cases::getCaseNotes($applicationID, $type, $userUid);
return $response;
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* class.case.php
* @package workflow.engine.classes
@@ -23,7 +24,6 @@
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
*
*/
require_once 'classes/model/AdditionalTables.php';
/**
@@ -33,28 +33,24 @@ require_once 'classes/model/AdditionalTables.php';
*/
class PmTable
{
private $dom = null;
private $schemaFile = '';
private $tableName;
private $columns;
private $baseDir = '';
private $targetDir = '';
private $configDir = '';
private $dataDir = '';
private $classesDir = '';
private $className = '';
private $dataSource = '';
private $rootNode;
private $dbConfig;
private $db;
private $alterTable = true;
function __construct($tableName = null)
public function __construct($tableName=null)
{
if (isset($tableName)) {
$this->tableName = $tableName;
@@ -64,13 +60,12 @@ class PmTable
$this->dbConfig = new StdClass();
}
/**
* Set columns to pmTable
* @param array $columns contains a array of abjects
* array(StdClass->field_name, field_type, field_size, field_null, field_key, field_autoincrement,...)
*/
function setColumns($columns)
public function setColumns($columns)
{
$this->columns = $columns;
}
@@ -79,29 +74,27 @@ class PmTable
* Set a data source
* @param string $dbsUid DBS_UID to relate the pmTable to phisical table
*/
function setDataSource($dbsUid)
public function setDataSource($dbsUid)
{
$this->dataSource = self::resolveDbSource($dbsUid);
switch ($this->dataSource) {
case 'workflow':
$this->dbConfig->adapter= DB_ADAPTER;
$this->dbConfig->adapter = DB_ADAPTER;
$this->dbConfig->host = DB_HOST;
$this->dbConfig->name = DB_NAME;
$this->dbConfig->user = DB_USER;
$this->dbConfig->passwd = DB_PASS;
$this->dbConfig->port = 3306; //FIXME update this when port for workflow dsn will be available
break;
case 'rp':
$this->dbConfig->adapter= DB_ADAPTER;
$this->dbConfig->adapter = DB_ADAPTER;
$this->dbConfig->host = DB_REPORT_HOST;
$this->dbConfig->name = DB_REPORT_NAME;
$this->dbConfig->user = DB_REPORT_USER;
$this->dbConfig->passwd = DB_REPORT_PASS;
$this->dbConfig->port = 3306; //FIXME update this when port for rp dsn will be available
break;
default:
require_once 'classes/model/DbSource.php';
$oDBSource = new DbSource();
@@ -109,7 +102,7 @@ class PmTable
$dbSource = $oDBSource->load($this->dataSource, $proUid);
if (is_object($dbSource)) {
$this->dbConfig->adapter= $dbSource->getDbsType();
$this->dbConfig->adapter = $dbSource->getDbsType();
$this->dbConfig->host = $dbSource->getDbsServer();
$this->dbConfig->name = $dbSource->getDbsDatabaseName();
$this->dbConfig->user = $dbSource->getDbsUsername();
@@ -117,14 +110,13 @@ class PmTable
$this->dbConfig->port = $dbSource->getDbsPort();
}
if (is_array($dbSource)) {
$this->dbConfig->adapter= $dbSource['DBS_TYPE'];
$this->dbConfig->adapter = $dbSource['DBS_TYPE'];
$this->dbConfig->host = $dbSource['DBS_SERVER'];
$this->dbConfig->name = $dbSource['DBS_DATABASE_NAME'];
$this->dbConfig->user = $dbSource['DBS_USERNAME'];
$this->dbConfig->passwd = $dbSource['DBS_PASSWORD'] ;
$this->dbConfig->passwd = $dbSource['DBS_PASSWORD'];
$this->dbConfig->port = $dbSource['DBS_PORT'];
}
else {
} else {
throw new Exception("Db source with id $dbsUid does not exist!");
}
}
@@ -139,10 +131,15 @@ class PmTable
public function resolveDbSource($dbsUid)
{
switch ($dbsUid) {
case 'workflow': case 'wf': case '0': case '': case null:
case 'workflow':
case 'wf':
case '0':
case '':
case null:
$dbsUid = 'workflow';
break;
case 'rp': case 'report':
case 'rp':
case 'report':
$dbsUid = 'rp';
break;
}
@@ -172,7 +169,7 @@ class PmTable
/**
* Build the pmTable with all dependencies
*/
function build()
public function build()
{
$this->prepare();
$this->preparePropelIniFile();
@@ -185,7 +182,7 @@ class PmTable
}
}
function buildModelFor($dbsUid, $tablesList)
public function buildModelFor($dbsUid, $tablesList)
{
$this->setDataSource($dbsUid);
$loadSchema = false;
@@ -198,7 +195,7 @@ class PmTable
/**
* Prepare the pmTable env
*/
function prepare($loadSchema = true)
public function prepare($loadSchema=true)
{
//prevent execute prepare() twice or more
if (is_object($this->dom)) {
@@ -221,7 +218,7 @@ class PmTable
}
}
function loadSchema()
public function loadSchema()
{
$this->dom = new DOMDocument('1.0', 'utf-8');
$this->dom->preserveWhiteSpace = false;
@@ -232,8 +229,7 @@ class PmTable
throw new Exception('Error: ' . $this->schemaFilename . ' is a invalid xml file!');
}
$this->rootNode = $this->dom->firstChild;
}
else {
} else {
$this->rootNode = $this->dom->createElement('database');
$this->rootNode->setAttribute('name', $this->dataSource);
$this->dom->appendChild($this->rootNode);
@@ -243,7 +239,7 @@ class PmTable
/**
* Build the xml schema for propel
*/
function buildSchema()
public function buildSchema()
{
$tableNode = $this->dom->createElement('table');
$tableNode->setAttribute('name', $this->tableName);
@@ -278,7 +274,7 @@ class PmTable
$columnNode->setAttribute('size', $column->field_size);
}
$columnNode->setAttribute('required', ($column->field_null? 'false' : 'true'));
$columnNode->setAttribute('required', ($column->field_null ? 'false' : 'true'));
// only define the primaryKey attribute if it is defined
if ($column->field_key) {
@@ -295,10 +291,11 @@ class PmTable
$xpath = new DOMXPath($this->dom);
$xtable = $xpath->query('/database/table[@name="' . $this->tableName . '"]');
if ($xtable->length == 0) { //the table definition does not exist, then just append the new node
if ($xtable->length == 0) {
//the table definition does not exist, then just append the new node
$this->rootNode->appendChild($tableNode);
}
else { // the table definition already exist, then replace the node
} else {
// the table definition already exist, then replace the node
$replacedNode = $xtable->item(0);
$this->rootNode->replaceChild($tableNode, $replacedNode);
}
@@ -350,7 +347,7 @@ class PmTable
/**
* Drop the phisical table of target pmTable or any specified as parameter
*/
public function dropTable($tableName = null)
public function dropTable($tableName=null)
{
$tableName = isset($tableName) ? $tableName : $this->tableName;
$con = Propel::getConnection($this->dataSource);
@@ -359,8 +356,7 @@ class PmTable
if (is_object($con)) {
try {
$stmt->executeQuery("DROP TABLE {$tableName}");
}
catch (Exception $e) {
} catch (Exception $e) {
throw new Exception("Physical table '$tableName' does not exist!");
}
}
@@ -374,7 +370,6 @@ class PmTable
$this->dom->save($this->configDir . $this->schemaFilename);
}
/**
* Prepare and create if not exists the propel ini file
*/
@@ -386,11 +381,12 @@ class PmTable
return true;
}
if (!file_exists(PATH_CORE. PATH_SEP . 'config' . PATH_SEP . "propel.$adapter.ini")) {
if (!file_exists(PATH_CORE . PATH_SEP . 'config' . PATH_SEP . "propel.$adapter.ini")) {
throw new Exception("Invalid or not supported engine '$adapter'!");
}
@copy(PATH_CORE. PATH_SEP . 'config' . PATH_SEP . "propel.$adapter.ini", $this->configDir . "propel.$adapter.ini");
@copy(PATH_CORE . PATH_SEP . 'config' . PATH_SEP . "propel.$adapter.ini",
$this->configDir . "propel.$adapter.ini");
}
/**
@@ -404,14 +400,14 @@ class PmTable
$con = Propel::getConnection($this->dataSource);
$stmt = $con->createStatement();
$lines = file($this->dataDir . $this->dbConfig->adapter . PATH_SEP . 'schema.sql');
$previous = NULL;
$previous = null;
$queryStack = array();
$aDNS = $con->getDSN();
$dbEngine = $aDNS["phptype"];
foreach ($lines as $j => $line) {
switch($dbEngine) {
case 'mysql' :
switch ($dbEngine) {
case 'mysql':
$line = trim($line); // Remove comments from the script
if (strpos($line, "--") === 0) {
@@ -434,7 +430,7 @@ class PmTable
if ($previous) {
$line = $previous . " " . $line;
}
$previous = NULL;
$previous = null;
// If the current line doesnt end with ; then put this line together
// with the next one, thus supporting multi-line statements.
@@ -446,19 +442,20 @@ class PmTable
$line = substr($line, 0, strrpos($line, ";"));
// just execute the drop and create table for target table nad not for others
if (stripos($line, 'CREATE TABLE') !== false || stripos($line, 'DROP TABLE') !== false) {
$isCreateForCurrentTable = preg_match('/CREATE\sTABLE\s[\[\'\"\`]{1}' . $this->tableName . '[\]\'\"\`]{1}/i', $line, $match);
$isCreateForCurrentTable = preg_match('/CREATE\sTABLE\s[\[\'\"\`]{1}' . $this->tableName
. '[\]\'\"\`]{1}/i', $line, $match);
if ($isCreateForCurrentTable) {
$queryStack['create'] = $line;
}
else {
$isDropForCurrentTable = preg_match('/DROP TABLE.*[\[\'\"\`]{1}' . $this->tableName . '[\]\'\"\`]{1}/i', $line, $match);
} else {
$isDropForCurrentTable = preg_match('/DROP TABLE.*[\[\'\"\`]{1}' . $this->tableName
. '[\]\'\"\`]{1}/i', $line, $match);
if ($isDropForCurrentTable) {
$queryStack['drop'] = $line;
}
}
}
break;
case 'mssql' :
case 'mssql':
$line = trim($line); // Remove comments from the script
if (strpos($line, "--") === 0) {
@@ -481,7 +478,7 @@ class PmTable
if ($previous) {
$line = $previous . " " . $line;
}
$previous = NULL;
$previous = null;
// If the current line doesnt end with ; then put this line together
// with the next one, thus supporting multi-line statements.
@@ -503,12 +500,12 @@ class PmTable
$queryStack['create'] = 'CREATE' . $auxCreate['1'];
break;
case 'oracle' :
$line = trim($line);
case 'oracle':
$line = trim($line); // Remove comments from the script
if (empty($line)) {
continue;
}
switch(true) {
switch (true) {
case preg_match("/^CREATE TABLE\s/i", $line):
if (strpos($line, $this->tableName) == true) {
$inCreate = true;
@@ -531,7 +528,7 @@ class PmTable
}
}
break;
default :
default:
if ($inCreate) {
$lineCreate .= $line . ' ';
if (strrpos($line, ";") > 0) {
@@ -548,7 +545,7 @@ class PmTable
}
if ($inDrop) {
$lineDrop .= $line . ' ';
if (strrpos($line, ";")>0) {
if (strrpos($line, ";") > 0) {
$queryStack['drop'] = $lineDrop;
$inDrop = false;
}
@@ -556,7 +553,6 @@ class PmTable
}
break;
}
}
if ($dbEngine == 'oracle') {
@@ -571,8 +567,7 @@ class PmTable
}
$stmt->executeQuery($queryStack['create']);
$stmt->executeQuery($queryStack['alter']);
}
else {
} else {
if (isset($queryStack['create'])) {
// first at all we need to verify if we have a valid schema defined,
// so we verify that creating a dummy table
@@ -595,12 +590,12 @@ class PmTable
}
}
public function upgradeDatabaseFor($dataSource, $tablesList = array())
public function upgradeDatabaseFor($dataSource, $tablesList=array())
{
$con = Propel::getConnection($dataSource);
$stmt = $con->createStatement();
$lines = file($this->dataDir . $this->dbConfig->adapter . PATH_SEP . 'schema.sql');
$previous = NULL;
$previous = null;
$errors = '';
foreach ($lines as $j => $line) {
@@ -626,7 +621,7 @@ class PmTable
if ($previous) {
$line = $previous . " " . $line;
}
$previous = NULL;
$previous = null;
// If the current line doesnt end with ; then put this line together
// with the next one, thus supporting multi-line statements.
@@ -647,12 +642,10 @@ class PmTable
//error_log($line);
try {
$stmt->executeQuery($line);
}
catch(Exception $e) {
} catch (Exception $e) {
$errors .= $e->getMessage() . "\n";
continue;
}
}
}
}
@@ -665,7 +658,7 @@ class PmTable
* verify if on the columns list was set a column as primary key
* @return boolean to affirm if was defined a column as pk.
*/
function hasAutoIncrementPKey()
public function hasAutoIncrementPKey()
{
foreach ($this->columns as $column) {
if ($column->field_autoincrement) {
@@ -680,11 +673,12 @@ class PmTable
*
* @return array contains all supported columns types provided by propel
*/
function getPropelSupportedColumnTypes()
public function getPropelSupportedColumnTypes()
{
/**
* http://www.propelorm.org/wiki/Documentation/1.2/Schema
* [type = "BOOLEAN|TINYINT|SMALLINT|INTEGER|BIGINT|DOUBLE|FLOAT|REAL|DECIMAL|CHAR|{VARCHAR}|LONGVARCHAR|DATE|TIME|TIMESTAMP|BLOB|CLOB"]
* [type = "BOOLEAN|TINYINT|SMALLINT|INTEGER|BIGINT|DOUBLE|FLOAT|REAL|DECIMAL|CHAR|{VARCHAR}
* |LONGVARCHAR|DATE|TIME|TIMESTAMP|BLOB|CLOB"]
*/
$types = array();
@@ -761,7 +755,7 @@ class PmTable
* @param array $options - array options to override the options on .ini file
* @param bool $verbose - to show a verbose output
*/
public static function callPhing($target, $buildFile = '', $options = array(), $verbose = true)
public static function callPhing($target, $buildFile='', $options=array(), $verbose=true)
{
G::loadClass('pmPhing');
@@ -781,8 +775,7 @@ class PmTable
if (is_array($target)) {
$args = array_merge($args, $target);
}
else {
} else {
$args[] = $target;
}
@@ -798,5 +791,5 @@ class PmTable
$m->execute($args);
$m->runBuild();
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* DbSource.php
* @package workflow.engine.classes.model
@@ -23,11 +24,9 @@
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
*
*/
require_once 'classes/model/Content.php';
require_once 'classes/model/om/BaseDbSource.php';
/**
* Skeleton subclass for representing a row from the 'DB_SOURCE' table.
*
@@ -52,16 +51,17 @@ class DbSource extends BaseDbSource
* Get the rep_tab_title column value.
* @return string
*/
public function getDBSourceDescription() {
if ( $this->getDbsUid() == "" ) {
throw ( new Exception( "Error in getDBSourceDescription, the getDbsUid() can't be blank") );
public function getDBSourceDescription()
{
if ($this->getDbsUid() == "") {
throw ( new Exception("Error in getDBSourceDescription, the getDbsUid() can't be blank") );
}
$lang = defined ( 'SYS_LANG' ) ? SYS_LANG : 'en';
$this->db_source_description = Content::load ( 'DBS_DESCRIPTION', '', $this->getDbsUid(), $lang );
$lang = defined('SYS_LANG') ? SYS_LANG : 'en';
$this->db_source_description = Content::load('DBS_DESCRIPTION', '', $this->getDbsUid(), $lang);
return $this->db_source_description;
}
function getCriteriaDBSList($sProcessUID)
public function getCriteriaDBSList($sProcessUID)
{
$sDelimiter = DBAdapter::getStringDelimiter();
$oCriteria = new Criteria('workflow');
@@ -95,10 +95,9 @@ class DbSource extends BaseDbSource
$this->setNew(false);
return $aFields;
} else {
throw(new Exception( "The row '$Uid'/'$ProUID' in table DbSource doesn't exist!" ));
throw(new Exception("The row '$Uid'/'$ProUID' in table DbSource doesn't exist!"));
}
}
catch (exception $oError) {
} catch (exception $oError) {
throw ($oError);
}
}
@@ -115,24 +114,23 @@ class DbSource extends BaseDbSource
return $aRow[0];
}
function Exists ( $Uid, $ProUID ) {
public function Exists($Uid, $ProUID)
{
try {
$oPro = DbSourcePeer::retrieveByPk( $Uid, $ProUID );
if (is_object($oPro) && get_class ($oPro) == 'DbSource' ) {
$oPro = DbSourcePeer::retrieveByPk($Uid, $ProUID);
if (is_object($oPro) && get_class($oPro) == 'DbSource') {
return true;
}
else {
} else {
return false;
}
}
catch (Exception $oError) {
} catch (Exception $oError) {
throw($oError);
}
}
public function update($fields)
{
if( $fields['DBS_ENCODE'] == '0'){
if ($fields['DBS_ENCODE'] == '0') {
unset($fields['DBS_ENCODE']);
}
$con = Propel::getConnection(DbSourcePeer::DATABASE_NAME);
@@ -148,14 +146,13 @@ class DbSource extends BaseDbSource
$con->rollback();
throw (new Exception("Failed Validation in class " . get_class($this) . "."));
}
}
catch (exception $e) {
} catch (exception $e) {
$con->rollback();
throw ($e);
}
}
function remove($DbsUid, $ProUID )
public function remove($DbsUid, $ProUID)
{
$con = Propel::getConnection(DbSourcePeer::DATABASE_NAME);
try {
@@ -165,30 +162,31 @@ class DbSource extends BaseDbSource
// note added by gustavo cruz gustavo-at-colosa-dot-com
// we assure that the _delete attribute must be set to false
// if a record exists in the database with that uid.
if ($this->Exists($DbsUid, $ProUID)){
if ($this->Exists($DbsUid, $ProUID)) {
$this->setDeleted(false);
}
$result = $this->delete();
$con->commit();
return $result;
}
catch (exception $e) {
} catch (exception $e) {
$con->rollback();
throw ($e);
}
}
function create($aData)
public function create($aData)
{
if( $aData['DBS_ENCODE'] == '0'){
if ($aData['DBS_ENCODE'] == '0') {
unset($aData['DBS_ENCODE']);
}
$con = Propel::getConnection(DbSourcePeer::DATABASE_NAME);
try {
if ( isset ( $aData['DBS_UID'] ) && $aData['DBS_UID']== '' )
unset ( $aData['DBS_UID'] );
if ( !isset ( $aData['DBS_UID'] ) )
if (isset($aData['DBS_UID']) && $aData['DBS_UID'] == '') {
unset($aData['DBS_UID']);
}
if (!isset($aData['DBS_UID'])) {
$aData['DBS_UID'] = G::generateUniqueID();
}
$this->fromArray($aData, BasePeer::TYPE_FIELDNAME);
if ($this->validate()) {
$result = $this->save();
@@ -199,11 +197,11 @@ class DbSource extends BaseDbSource
}
$con->commit();
return $this->getDbsUid();
}
catch (exception $e) {
} catch (exception $e) {
$con->rollback();
throw ($e);
}
}
}
// DbSource
} // DbSource

View File

@@ -53,8 +53,12 @@ try {
$bReturnValue = true;
$displayMode = 'display:block';
$methodreturnDescription = (trim(strtoupper($methodreturnA [3])) == strtoupper(G::LoadTranslation ( 'ID_NONE')) )
? G::LoadTranslation ( 'ID_NOT_REQUIRED') : $methodreturnA [3];
$methodreturnDescription = "";
if (isset($methodreturnA[3])) {
$methodreturnDescription = (trim(strtoupper($methodreturnA [3])) == strtoupper(G::LoadTranslation ('ID_NONE')))
? G::LoadTranslation ( 'ID_NOT_REQUIRED')
: $methodreturnA [3];
}
$methodReturnLabel = isset ( $methodreturnA [3] ) ? $methodreturnDescription : $methodReturn;
if ( (isset($methodreturnA[0]) && isset($methodreturnA[1]))
&& (trim(strtoupper($methodreturnA[0]) ) != strtoupper(G::LoadTranslation ( 'ID_NONE')) ) ) {