2011-08-29 11:39:22 -04:00
|
|
|
|
<?php
|
2012-07-04 15:11:07 -04:00
|
|
|
|
|
2011-08-29 11:39:22 -04:00
|
|
|
|
require_once 'classes/model/AdditionalTables.php';
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* PmTable Class
|
2012-07-04 15:11:07 -04:00
|
|
|
|
* New class to handle pmTable in native form invoking to Phing & Propel
|
2012-10-09 13:00:37 -04:00
|
|
|
|
*
|
2011-08-29 11:39:22 -04:00
|
|
|
|
*/
|
|
|
|
|
|
class PmTable
|
|
|
|
|
|
{
|
2012-07-04 15:11:07 -04:00
|
|
|
|
private $dom = null;
|
|
|
|
|
|
private $schemaFile = '';
|
|
|
|
|
|
private $tableName;
|
2016-07-26 15:12:49 -04:00
|
|
|
|
private $oldTableName = null;
|
2012-07-04 15:11:07 -04:00
|
|
|
|
private $columns;
|
2014-12-10 16:32:31 -04:00
|
|
|
|
private $primaryKey= array();
|
2012-07-04 15:11:07 -04:00
|
|
|
|
private $baseDir = '';
|
|
|
|
|
|
private $targetDir = '';
|
|
|
|
|
|
private $configDir = '';
|
|
|
|
|
|
private $dataDir = '';
|
|
|
|
|
|
private $classesDir = '';
|
|
|
|
|
|
private $className = '';
|
|
|
|
|
|
private $dataSource = '';
|
|
|
|
|
|
private $rootNode;
|
|
|
|
|
|
private $dbConfig;
|
|
|
|
|
|
private $db;
|
|
|
|
|
|
private $alterTable = true;
|
2013-01-09 13:23:16 -04:00
|
|
|
|
private $keepData = false;
|
2017-04-21 12:04:57 -04:00
|
|
|
|
public $tableClassName = '';
|
2018-02-20 12:02:35 -04:00
|
|
|
|
private $columnsToExclude = ['APP_UID'];
|
2012-07-04 15:11:07 -04:00
|
|
|
|
|
2017-08-04 11:23:34 -04:00
|
|
|
|
public function __construct($tableName = null)
|
2012-07-04 15:11:07 -04:00
|
|
|
|
{
|
2017-08-04 11:23:34 -04:00
|
|
|
|
if (isset($tableName)) {
|
2012-07-04 15:11:07 -04:00
|
|
|
|
$this->tableName = $tableName;
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$this->className = $this->toCamelCase($tableName);
|
2012-07-04 15:11:07 -04:00
|
|
|
|
}
|
2011-08-29 11:39:22 -04:00
|
|
|
|
|
2012-07-04 15:11:07 -04:00
|
|
|
|
$this->dbConfig = new StdClass();
|
|
|
|
|
|
}
|
2011-08-29 11:39:22 -04:00
|
|
|
|
|
2016-07-26 15:12:49 -04:00
|
|
|
|
/**
|
|
|
|
|
|
* Set oldTableName to pmTable
|
2017-04-21 12:04:57 -04:00
|
|
|
|
*
|
2016-07-26 15:12:49 -04:00
|
|
|
|
* @param string $oldTableName
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function setOldTableName($oldTableName)
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->oldTableName = $oldTableName;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2012-07-04 15:11:07 -04:00
|
|
|
|
/**
|
|
|
|
|
|
* Set columns to pmTable
|
2012-10-09 13:00:37 -04:00
|
|
|
|
*
|
2012-07-04 15:11:07 -04:00
|
|
|
|
* @param array $columns contains a array of abjects
|
2012-10-09 13:00:37 -04:00
|
|
|
|
* array(StdClass->field_name, field_type, field_size, field_null, field_key, field_autoincrement,...)
|
2012-07-04 15:11:07 -04:00
|
|
|
|
*/
|
2017-08-04 11:23:34 -04:00
|
|
|
|
public function setColumns($columns)
|
2012-07-04 15:11:07 -04:00
|
|
|
|
{
|
|
|
|
|
|
$this->columns = $columns;
|
|
|
|
|
|
}
|
2011-08-29 11:39:22 -04:00
|
|
|
|
|
2012-07-04 15:11:07 -04:00
|
|
|
|
/**
|
|
|
|
|
|
* Set a data source
|
2012-10-09 13:00:37 -04:00
|
|
|
|
*
|
2012-07-04 15:11:07 -04:00
|
|
|
|
* @param string $dbsUid DBS_UID to relate the pmTable to phisical table
|
|
|
|
|
|
*/
|
2017-08-04 11:23:34 -04:00
|
|
|
|
public function setDataSource($dbsUid)
|
2012-07-04 15:11:07 -04:00
|
|
|
|
{
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$this->dataSource = self::resolveDbSource($dbsUid);
|
2012-07-04 15:11:07 -04:00
|
|
|
|
|
|
|
|
|
|
switch ($this->dataSource) {
|
|
|
|
|
|
case 'workflow':
|
|
|
|
|
|
$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->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();
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$proUid = $oDBSource->getValProUid($this->dataSource);
|
|
|
|
|
|
$dbSource = $oDBSource->load($this->dataSource, $proUid);
|
2012-07-04 15:11:07 -04:00
|
|
|
|
|
2017-08-04 11:23:34 -04:00
|
|
|
|
if (is_object($dbSource)) {
|
2012-07-04 15:11:07 -04:00
|
|
|
|
$this->dbConfig->adapter = $dbSource->getDbsType();
|
|
|
|
|
|
$this->dbConfig->host = $dbSource->getDbsServer();
|
|
|
|
|
|
$this->dbConfig->name = $dbSource->getDbsDatabaseName();
|
|
|
|
|
|
$this->dbConfig->user = $dbSource->getDbsUsername();
|
|
|
|
|
|
$this->dbConfig->passwd = $dbSource->getDbsPassword();
|
|
|
|
|
|
$this->dbConfig->port = $dbSource->getDbsPort();
|
|
|
|
|
|
}
|
2017-08-04 11:23:34 -04:00
|
|
|
|
if (is_array($dbSource)) {
|
2012-07-04 15:11:07 -04:00
|
|
|
|
$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->port = $dbSource['DBS_PORT'];
|
|
|
|
|
|
} else {
|
2017-08-04 11:23:34 -04:00
|
|
|
|
throw new Exception("Db source with id $dbsUid does not exist!");
|
2012-07-04 15:11:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2011-08-29 11:39:22 -04:00
|
|
|
|
|
2017-08-10 15:25:44 -04:00
|
|
|
|
/**
|
|
|
|
|
|
*
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param string $adapter
|
|
|
|
|
|
* @return void
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function setDbConfigAdapter($adapter)
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->dbConfig->adapter = $adapter;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-20 12:02:35 -04:00
|
|
|
|
/**
|
|
|
|
|
|
* Set ColumnsToExclude
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param array $value
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function setColumnsToExclude($value)
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->columnsToExclude = $value;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Get ColumnsToExclude values
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function getColumnsToExclude()
|
|
|
|
|
|
{
|
|
|
|
|
|
return $this->columnsToExclude;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2012-07-04 15:11:07 -04:00
|
|
|
|
/**
|
|
|
|
|
|
* Backward compatibility function
|
|
|
|
|
|
* Resolve a propel data source
|
2012-10-09 13:00:37 -04:00
|
|
|
|
*
|
2012-07-04 15:11:07 -04:00
|
|
|
|
* @param string $dbsUid corresponding to DBS_UID key
|
|
|
|
|
|
* @return string contains resolved DBS_UID
|
|
|
|
|
|
*/
|
2015-03-11 08:56:10 -04:00
|
|
|
|
public static function resolveDbSource($dbsUid)
|
2012-07-04 15:11:07 -04:00
|
|
|
|
{
|
|
|
|
|
|
switch ($dbsUid) {
|
|
|
|
|
|
case 'workflow':
|
|
|
|
|
|
case 'wf':
|
|
|
|
|
|
case '0':
|
|
|
|
|
|
case '':
|
|
|
|
|
|
case null:
|
|
|
|
|
|
$dbsUid = 'workflow';
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 'rp':
|
|
|
|
|
|
case 'report':
|
|
|
|
|
|
$dbsUid = 'rp';
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2011-09-14 08:51:33 -04:00
|
|
|
|
|
2012-07-04 15:11:07 -04:00
|
|
|
|
return $dbsUid;
|
2011-09-14 08:51:33 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-08-04 11:23:34 -04:00
|
|
|
|
public function getDataSource()
|
2012-07-04 15:11:07 -04:00
|
|
|
|
{
|
|
|
|
|
|
return $this->dataSource;
|
2011-08-29 11:39:22 -04:00
|
|
|
|
}
|
2012-07-04 15:11:07 -04:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* get Data base config object
|
2012-10-09 13:00:37 -04:00
|
|
|
|
*
|
2012-07-04 15:11:07 -04:00
|
|
|
|
* @return object containing dbConfig var
|
|
|
|
|
|
*/
|
2017-08-04 11:23:34 -04:00
|
|
|
|
public function getDbConfig()
|
2012-07-04 15:11:07 -04:00
|
|
|
|
{
|
|
|
|
|
|
return $this->dbConfig;
|
2011-08-30 13:15:25 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-08-04 11:23:34 -04:00
|
|
|
|
public function setAlterTable($value)
|
2012-07-04 15:11:07 -04:00
|
|
|
|
{
|
|
|
|
|
|
$this->alterTable = $value;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-01-09 13:23:16 -04:00
|
|
|
|
public function setKeepData($value)
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->keepData = $value;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2012-07-04 15:11:07 -04:00
|
|
|
|
/**
|
|
|
|
|
|
* Build the pmTable with all dependencies
|
|
|
|
|
|
*/
|
2017-08-04 11:23:34 -04:00
|
|
|
|
public function build()
|
2014-12-10 16:32:31 -04:00
|
|
|
|
{
|
2012-07-04 15:11:07 -04:00
|
|
|
|
$this->prepare();
|
|
|
|
|
|
$this->preparePropelIniFile();
|
|
|
|
|
|
$this->buildSchema();
|
|
|
|
|
|
|
|
|
|
|
|
if ($this->alterTable) {
|
|
|
|
|
|
$this->phingbuildModel();
|
|
|
|
|
|
$this->phingbuildSql();
|
|
|
|
|
|
$this->upgradeDatabase();
|
|
|
|
|
|
}
|
2011-09-14 08:51:33 -04:00
|
|
|
|
}
|
2012-07-04 15:11:07 -04:00
|
|
|
|
|
2017-08-04 11:23:34 -04:00
|
|
|
|
public function buildModelFor($dbsUid, $tablesList)
|
2012-07-04 15:11:07 -04:00
|
|
|
|
{
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$this->setDataSource($dbsUid);
|
2012-07-04 15:11:07 -04:00
|
|
|
|
$loadSchema = false;
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$this->prepare($loadSchema);
|
2012-07-04 15:11:07 -04:00
|
|
|
|
$this->phingbuildModel();
|
|
|
|
|
|
$this->phingbuildSql();
|
|
|
|
|
|
//$this->upgradeDatabaseFor($this->dataSource, $tablesList);
|
2011-08-29 11:39:22 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2012-07-04 15:11:07 -04:00
|
|
|
|
/**
|
|
|
|
|
|
* Prepare the pmTable env
|
|
|
|
|
|
*/
|
2017-08-04 11:23:34 -04:00
|
|
|
|
public function prepare($loadSchema = true)
|
2012-07-04 15:11:07 -04:00
|
|
|
|
{
|
|
|
|
|
|
//prevent execute prepare() twice or more
|
2017-08-04 11:23:34 -04:00
|
|
|
|
if (is_object($this->dom)) {
|
2012-07-04 15:11:07 -04:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2011-08-29 11:39:22 -04:00
|
|
|
|
|
2012-07-04 15:11:07 -04:00
|
|
|
|
$this->schemaFilename = 'schema.xml';
|
2017-10-10 12:33:25 -04:00
|
|
|
|
$this->baseDir = PATH_DB . config("system.workspace") . PATH_SEP;
|
2012-07-04 15:11:07 -04:00
|
|
|
|
$this->targetDir = $this->baseDir . 'pmt-propel' . PATH_SEP . $this->dataSource . PATH_SEP;
|
|
|
|
|
|
$this->configDir = $this->targetDir . 'config' . PATH_SEP;
|
|
|
|
|
|
$this->dataDir = $this->targetDir . 'data' . PATH_SEP;
|
|
|
|
|
|
$this->classesDir = $this->baseDir . 'classes' . PATH_SEP;
|
2011-09-14 08:51:33 -04:00
|
|
|
|
|
2012-07-04 15:11:07 -04:00
|
|
|
|
// G::mk_dir create the requested dir and the parents directories if not exists
|
2017-08-04 11:23:34 -04:00
|
|
|
|
G::mk_dir($this->configDir);
|
|
|
|
|
|
G::mk_dir($this->dataDir);
|
2012-07-04 15:11:07 -04:00
|
|
|
|
|
|
|
|
|
|
if ($loadSchema) {
|
|
|
|
|
|
$this->loadSchema();
|
|
|
|
|
|
}
|
2011-08-29 11:39:22 -04:00
|
|
|
|
}
|
2012-07-04 15:11:07 -04:00
|
|
|
|
|
2017-08-04 11:23:34 -04:00
|
|
|
|
public function loadSchema()
|
2012-07-04 15:11:07 -04:00
|
|
|
|
{
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$this->dom = new DOMDocument('1.0', 'utf-8');
|
2012-07-04 15:11:07 -04:00
|
|
|
|
$this->dom->preserveWhiteSpace = false;
|
|
|
|
|
|
$this->dom->formatOutput = true;
|
|
|
|
|
|
|
2017-08-04 11:23:34 -04:00
|
|
|
|
if (file_exists($this->configDir . $this->schemaFilename)) {
|
|
|
|
|
|
if (@$this->dom->load($this->configDir . $this->schemaFilename) !== true) {
|
|
|
|
|
|
throw new Exception('Error: ' . $this->schemaFilename . ' is a invalid xml file!');
|
2012-07-04 15:11:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
$this->rootNode = $this->dom->firstChild;
|
|
|
|
|
|
} else {
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$this->rootNode = $this->dom->createElement('database');
|
|
|
|
|
|
$this->rootNode->setAttribute('name', $this->dataSource);
|
|
|
|
|
|
$this->dom->appendChild($this->rootNode);
|
2012-07-04 15:11:07 -04:00
|
|
|
|
}
|
2011-08-29 11:39:22 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2012-07-04 15:11:07 -04:00
|
|
|
|
/**
|
|
|
|
|
|
* Build the xml schema for propel
|
|
|
|
|
|
*/
|
2017-08-04 11:23:34 -04:00
|
|
|
|
public function buildSchema()
|
2012-07-04 15:11:07 -04:00
|
|
|
|
{
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$tableNode = $this->dom->createElement('table');
|
|
|
|
|
|
$tableNode->setAttribute('name', $this->tableName);
|
2012-07-04 15:11:07 -04:00
|
|
|
|
|
|
|
|
|
|
if ($this->hasAutoIncrementPKey()) {
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$tableNode->setAttribute('idMethod', 'native');
|
2012-07-04 15:11:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// specifying collation
|
|
|
|
|
|
switch ($this->dbConfig->adapter) {
|
|
|
|
|
|
case 'mysql':
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$vendorNode = $this->dom->createElement('vendor');
|
|
|
|
|
|
$vendorNode->setAttribute('type', $this->dbConfig->adapter);
|
|
|
|
|
|
$parameterNode = $this->dom->createElement('parameter');
|
|
|
|
|
|
$parameterNode->setAttribute('name', 'Collation');
|
|
|
|
|
|
$parameterNode->setAttribute('value', 'utf8_general_ci');
|
|
|
|
|
|
$vendorNode->appendChild($parameterNode);
|
|
|
|
|
|
$tableNode->appendChild($vendorNode);
|
2012-07-04 15:11:07 -04:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$indexNode = $this->dom->createElement('index');
|
|
|
|
|
|
$indexNode->setAttribute('name', 'indexTable');
|
2014-09-10 13:34:39 -04:00
|
|
|
|
$flag = false;
|
|
|
|
|
|
|
2012-07-04 15:11:07 -04:00
|
|
|
|
foreach ($this->columns as $column) {
|
|
|
|
|
|
|
|
|
|
|
|
// create the column node
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$columnNode = $this->dom->createElement('column');
|
2012-07-04 15:11:07 -04:00
|
|
|
|
// setting column node attributes
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$columnNode->setAttribute('name', $column->field_name);
|
|
|
|
|
|
$columnNode->setAttribute('type', $column->field_type);
|
2012-07-04 15:11:07 -04:00
|
|
|
|
|
|
|
|
|
|
if ($column->field_size != '' && $column->field_size != 0) {
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$columnNode->setAttribute('size', $column->field_size);
|
2012-07-04 15:11:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-10-16 14:08:25 -04:00
|
|
|
|
if ($column->field_type == 'DECIMAL') {
|
|
|
|
|
|
if ($column->field_size > 2) {
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$columnNode->setAttribute('scale', 2);
|
2014-10-16 14:08:25 -04:00
|
|
|
|
} else {
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$columnNode->setAttribute('scale', 1);
|
2014-10-16 14:08:25 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$columnNode->setAttribute('required', ($column->field_null ? 'false' : 'true'));
|
2012-07-04 15:11:07 -04:00
|
|
|
|
|
|
|
|
|
|
// only define the primaryKey attribute if it is defined
|
|
|
|
|
|
if ($column->field_key) {
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$columnNode->setAttribute('primaryKey', "true");
|
2012-07-04 15:11:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// only define the autoIncrement attribute if it is defined
|
|
|
|
|
|
if ($column->field_autoincrement) {
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$columnNode->setAttribute('autoIncrement', "true");
|
2012-07-04 15:11:07 -04:00
|
|
|
|
}
|
2014-09-10 13:34:39 -04:00
|
|
|
|
|
|
|
|
|
|
// define the Index attribute if it is defined
|
2014-09-12 12:28:15 -04:00
|
|
|
|
if (isset($column->field_index) && $column->field_index) {
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$columnNode->setAttribute('index', "true");
|
|
|
|
|
|
$indexColumnNode = $this->dom->createElement('index-column');
|
|
|
|
|
|
$indexColumnNode->setAttribute('name', $column->field_name);
|
|
|
|
|
|
$indexNode->appendChild($indexColumnNode);
|
2014-09-10 13:34:39 -04:00
|
|
|
|
$flag = true;
|
|
|
|
|
|
}
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$tableNode->appendChild($columnNode);
|
2012-07-04 15:11:07 -04:00
|
|
|
|
}
|
2014-09-10 13:34:39 -04:00
|
|
|
|
if ($flag) {
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$tableNode->appendChild($indexNode);
|
2014-09-10 13:34:39 -04:00
|
|
|
|
}
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$xpath = new DOMXPath($this->dom);
|
|
|
|
|
|
$xtable = $xpath->query('/database/table[@name="' . $this->tableName . '"]');
|
2012-07-04 15:11:07 -04:00
|
|
|
|
|
|
|
|
|
|
if ($xtable->length == 0) {
|
|
|
|
|
|
//the table definition does not exist, then just append the new node
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$this->rootNode->appendChild($tableNode);
|
2012-07-04 15:11:07 -04:00
|
|
|
|
} else {
|
|
|
|
|
|
// the table definition already exist, then replace the node
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$replacedNode = $xtable->item(0);
|
|
|
|
|
|
$this->rootNode->replaceChild($tableNode, $replacedNode);
|
2012-07-04 15:11:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// saving the xml result file
|
|
|
|
|
|
$this->saveSchema();
|
2011-09-14 08:51:33 -04:00
|
|
|
|
}
|
2012-07-04 15:11:07 -04:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Remove the pmTable and all related objects, files and others
|
|
|
|
|
|
*/
|
2017-08-04 11:23:34 -04:00
|
|
|
|
public function remove()
|
2012-07-04 15:11:07 -04:00
|
|
|
|
{
|
|
|
|
|
|
$this->prepare();
|
|
|
|
|
|
$this->removeFromSchema();
|
|
|
|
|
|
$this->removeModelFiles();
|
|
|
|
|
|
$this->dropTable();
|
2011-08-29 11:39:22 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2012-07-04 15:11:07 -04:00
|
|
|
|
/**
|
|
|
|
|
|
* Remove the target pmTable from schema of propel
|
|
|
|
|
|
*/
|
2017-08-04 11:23:34 -04:00
|
|
|
|
public function removeFromSchema()
|
2012-07-04 15:11:07 -04:00
|
|
|
|
{
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$xpath = new DOMXPath($this->dom);
|
2012-07-04 15:11:07 -04:00
|
|
|
|
// locate the node
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$xtable = $xpath->query('/database/table[@name="' . $this->tableName . '"]');
|
2012-07-04 15:11:07 -04:00
|
|
|
|
if ($xtable->length == 0) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2011-08-29 11:39:22 -04:00
|
|
|
|
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$this->rootNode->removeChild($xtable->item(0));
|
2012-07-04 15:11:07 -04:00
|
|
|
|
// saving the xml result file
|
|
|
|
|
|
$this->saveSchema();
|
2011-08-29 11:39:22 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2012-07-04 15:11:07 -04:00
|
|
|
|
/**
|
|
|
|
|
|
* Remove the model related classes files
|
|
|
|
|
|
*/
|
2017-08-04 11:23:34 -04:00
|
|
|
|
public function removeModelFiles()
|
2012-07-04 15:11:07 -04:00
|
|
|
|
{
|
2017-08-04 11:23:34 -04:00
|
|
|
|
@unlink($this->classesDir . $this->className . '.php');
|
|
|
|
|
|
@unlink($this->classesDir . $this->className . 'Peer.php');
|
|
|
|
|
|
@unlink($this->classesDir . 'map' . PATH_SEP . $this->className . 'MapBuilder.php');
|
|
|
|
|
|
@unlink($this->classesDir . 'om' . PATH_SEP . 'Base' . $this->className . '.php');
|
|
|
|
|
|
@unlink($this->classesDir . 'om' . PATH_SEP . 'Base' . $this->className . 'Peer.php');
|
2011-08-29 11:39:22 -04:00
|
|
|
|
}
|
2012-07-04 15:11:07 -04:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Drop the phisical table of target pmTable or any specified as parameter
|
|
|
|
|
|
*/
|
2017-08-04 11:23:34 -04:00
|
|
|
|
public function dropTable($tableName = null)
|
2012-07-04 15:11:07 -04:00
|
|
|
|
{
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$tableName = isset($tableName) ? $tableName : $this->tableName;
|
|
|
|
|
|
$con = Propel::getConnection($this->dataSource);
|
2012-07-04 15:11:07 -04:00
|
|
|
|
$stmt = $con->createStatement();
|
|
|
|
|
|
|
2017-08-04 11:23:34 -04:00
|
|
|
|
if (is_object($con)) {
|
2012-07-04 15:11:07 -04:00
|
|
|
|
try {
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$stmt->executeQuery("DROP TABLE {$tableName}");
|
2012-07-04 15:11:07 -04:00
|
|
|
|
} catch (Exception $e) {
|
2017-08-04 11:23:34 -04:00
|
|
|
|
throw new Exception("Physical table '$tableName' does not exist!");
|
2012-07-04 15:11:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2011-08-29 11:39:22 -04:00
|
|
|
|
}
|
2012-07-04 15:11:07 -04:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Save the xml schema for propel
|
|
|
|
|
|
*/
|
2017-08-04 11:23:34 -04:00
|
|
|
|
public function saveSchema()
|
2014-12-10 16:32:31 -04:00
|
|
|
|
{
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$this->dom->save($this->configDir . $this->schemaFilename);
|
2011-08-29 11:39:22 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2012-07-04 15:11:07 -04:00
|
|
|
|
/**
|
|
|
|
|
|
* Prepare and create if not exists the propel ini file
|
|
|
|
|
|
*/
|
2017-08-04 11:23:34 -04:00
|
|
|
|
public function preparePropelIniFile()
|
2012-07-04 15:11:07 -04:00
|
|
|
|
{
|
|
|
|
|
|
$adapter = $this->dbConfig->adapter;
|
|
|
|
|
|
|
2017-08-04 11:23:34 -04:00
|
|
|
|
if (file_exists($this->configDir . "propel.$adapter.ini")) {
|
2012-07-04 15:11:07 -04:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-08-04 11:23:34 -04:00
|
|
|
|
if (! file_exists(PATH_CORE . PATH_SEP . 'config' . PATH_SEP . "propel.$adapter.ini")) {
|
|
|
|
|
|
throw new Exception("Invalid or not supported engine '$adapter'!");
|
2012-07-04 15:11:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-08-04 11:23:34 -04:00
|
|
|
|
@copy(PATH_CORE . PATH_SEP . 'config' . PATH_SEP . "propel.$adapter.ini", $this->configDir . "propel.$adapter.ini");
|
2011-08-29 11:39:22 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2012-07-04 15:11:07 -04:00
|
|
|
|
/**
|
|
|
|
|
|
* Upgrade the phisical database for the target pmTable
|
|
|
|
|
|
* It executes the schema.sql autogenerated by propel, but just execute the correspondent sentenses
|
|
|
|
|
|
* for the related table
|
|
|
|
|
|
* - this function is not executing other sentenses like 'SET FOREIGN_KEY_CHECKS = 0;' for mysql, and others
|
|
|
|
|
|
*/
|
2017-08-04 11:23:34 -04:00
|
|
|
|
public function upgradeDatabase()
|
2012-07-04 15:11:07 -04:00
|
|
|
|
{
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$con = Propel::getConnection($this->dataSource);
|
2012-07-04 15:11:07 -04:00
|
|
|
|
$stmt = $con->createStatement();
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$lines = file($this->dataDir . $this->dbConfig->adapter . PATH_SEP . 'schema.sql');
|
2012-07-04 15:11:07 -04:00
|
|
|
|
$previous = null;
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$queryStack = array();
|
2012-07-04 15:11:07 -04:00
|
|
|
|
$aDNS = $con->getDSN();
|
2017-12-04 13:25:35 +00:00
|
|
|
|
$dbEngine = $aDNS['phptype'] === 'mysqli' ? 'mysql' : $aDNS['phptype'];
|
|
|
|
|
|
|
2012-07-04 15:11:07 -04:00
|
|
|
|
|
|
|
|
|
|
foreach ($lines as $j => $line) {
|
|
|
|
|
|
switch ($dbEngine) {
|
|
|
|
|
|
case 'mysql':
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$line = trim($line); // Remove comments from the script
|
2012-10-09 13:00:37 -04:00
|
|
|
|
|
2012-07-04 15:11:07 -04:00
|
|
|
|
|
2017-08-04 11:23:34 -04:00
|
|
|
|
if (strpos($line, "--") === 0) {
|
|
|
|
|
|
$line = substr($line, 0, strpos($line, "--"));
|
2012-07-04 15:11:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-08-04 11:23:34 -04:00
|
|
|
|
if (empty($line)) {
|
2019-11-25 16:05:03 -04:00
|
|
|
|
break;
|
2012-07-04 15:11:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-08-04 11:23:34 -04:00
|
|
|
|
if (strpos($line, "#") === 0) {
|
|
|
|
|
|
$line = substr($line, 0, strpos($line, "#"));
|
2012-07-04 15:11:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-08-04 11:23:34 -04:00
|
|
|
|
if (empty($line)) {
|
2019-11-25 16:05:03 -04:00
|
|
|
|
break;
|
2012-07-04 15:11:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Concatenate the previous line, if any, with the current
|
|
|
|
|
|
if ($previous) {
|
|
|
|
|
|
$line = $previous . " " . $line;
|
|
|
|
|
|
}
|
|
|
|
|
|
$previous = null;
|
|
|
|
|
|
|
|
|
|
|
|
// If the current line doesnt end with ; then put this line together
|
|
|
|
|
|
// with the next one, thus supporting multi-line statements.
|
2017-08-04 11:23:34 -04:00
|
|
|
|
if (strrpos($line, ";") != strlen($line) - 1) {
|
2012-07-04 15:11:07 -04:00
|
|
|
|
$previous = $line;
|
2019-11-25 16:05:03 -04:00
|
|
|
|
break;
|
2012-07-04 15:11:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$line = substr($line, 0, strrpos($line, ";"));
|
2012-07-04 15:11:07 -04:00
|
|
|
|
// just execute the drop and create table for target table nad not for others
|
2017-08-04 11:23:34 -04:00
|
|
|
|
if (stripos($line, 'CREATE TABLE') !== false || stripos($line, 'DROP TABLE') !== false) {
|
|
|
|
|
|
$isCreateForCurrentTable = preg_match('/CREATE\sTABLE\s[\[\'\"\`]{1}' . $this->tableName . '[\]\'\"\`]{1}/i', $line, $match);
|
2012-07-04 15:11:07 -04:00
|
|
|
|
if ($isCreateForCurrentTable) {
|
|
|
|
|
|
$queryStack['create'] = $line;
|
|
|
|
|
|
} else {
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$isDropForCurrentTable = preg_match('/DROP TABLE.*[\[\'\"\`]{1}' . $this->tableName . '[\]\'\"\`]{1}/i', $line, $match);
|
2012-07-04 15:11:07 -04:00
|
|
|
|
if ($isDropForCurrentTable) {
|
|
|
|
|
|
$queryStack['drop'] = $line;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 'mssql':
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$line = trim($line); // Remove comments from the script
|
2012-07-04 15:11:07 -04:00
|
|
|
|
|
2012-10-09 13:00:37 -04:00
|
|
|
|
|
2017-08-04 11:23:34 -04:00
|
|
|
|
if (strpos($line, "--") === 0) {
|
|
|
|
|
|
$line = substr($line, 0, strpos($line, "--"));
|
2012-07-04 15:11:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-08-04 11:23:34 -04:00
|
|
|
|
if (empty($line)) {
|
2019-11-25 16:05:03 -04:00
|
|
|
|
break;
|
2012-07-04 15:11:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-08-04 11:23:34 -04:00
|
|
|
|
if (strpos($line, "#") === 0) {
|
|
|
|
|
|
$line = substr($line, 0, strpos($line, "#"));
|
2012-07-04 15:11:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-08-04 11:23:34 -04:00
|
|
|
|
if (empty($line)) {
|
2019-11-25 16:05:03 -04:00
|
|
|
|
break;
|
2012-07-04 15:11:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Concatenate the previous line, if any, with the current
|
|
|
|
|
|
if ($previous) {
|
|
|
|
|
|
$line = $previous . " " . $line;
|
|
|
|
|
|
}
|
|
|
|
|
|
$previous = null;
|
|
|
|
|
|
|
|
|
|
|
|
// If the current line doesnt end with ; then put this line together
|
|
|
|
|
|
// with the next one, thus supporting multi-line statements.
|
2017-08-04 11:23:34 -04:00
|
|
|
|
if (strrpos($line, ";") != strlen($line) - 1) {
|
2012-07-04 15:11:07 -04:00
|
|
|
|
$previous = $line;
|
2019-11-25 16:05:03 -04:00
|
|
|
|
break;
|
2012-07-04 15:11:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$line = substr($line, 0, strrpos($line, ";"));
|
2012-07-04 15:11:07 -04:00
|
|
|
|
|
2017-08-04 11:23:34 -04:00
|
|
|
|
if (strpos($line, $this->tableName) == false) {
|
2019-11-25 16:05:03 -04:00
|
|
|
|
break;
|
2012-07-04 15:11:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$auxCreate = explode('CREATE', $line);
|
|
|
|
|
|
$auxDrop = explode('IF EXISTS', $auxCreate['0']);
|
2012-07-04 15:11:07 -04:00
|
|
|
|
|
2012-10-09 13:00:37 -04:00
|
|
|
|
$queryStack['drop'] = 'IF EXISTS' . $auxDrop['1'];
|
2012-07-04 15:11:07 -04:00
|
|
|
|
$queryStack['create'] = 'CREATE' . $auxCreate['1'];
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 'oracle':
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$line = trim($line); // Remove comments from the script
|
|
|
|
|
|
if (empty($line)) {
|
2019-11-25 16:05:03 -04:00
|
|
|
|
break;
|
2012-07-04 15:11:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
switch (true) {
|
2017-08-04 11:23:34 -04:00
|
|
|
|
case preg_match("/^CREATE TABLE\s/i", $line):
|
|
|
|
|
|
if (strpos($line, $this->tableName) == true) {
|
2012-07-04 15:11:07 -04:00
|
|
|
|
$inCreate = true;
|
|
|
|
|
|
$lineCreate .= $line . ' ';
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
2017-08-04 11:23:34 -04:00
|
|
|
|
case preg_match("/ALTER TABLE\s/i", $line):
|
|
|
|
|
|
if (strpos($line, $this->tableName) == true) {
|
2012-07-04 15:11:07 -04:00
|
|
|
|
$inAlter = true;
|
|
|
|
|
|
$lineAlter .= $line . ' ';
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
2017-08-04 11:23:34 -04:00
|
|
|
|
case preg_match("/^DROP TABLE\s/i", $line):
|
|
|
|
|
|
if (strpos($line, $this->tableName) == true) {
|
2012-07-04 15:11:07 -04:00
|
|
|
|
$inDrop = true;
|
|
|
|
|
|
$lineDrop .= $line . ' ';
|
2017-08-04 11:23:34 -04:00
|
|
|
|
if (strrpos($line, ";") > 0) {
|
2012-07-04 15:11:07 -04:00
|
|
|
|
$queryStack['drop'] = $lineDrop;
|
|
|
|
|
|
$inDrop = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
if ($inCreate) {
|
|
|
|
|
|
$lineCreate .= $line . ' ';
|
2017-08-04 11:23:34 -04:00
|
|
|
|
if (strrpos($line, ";") > 0) {
|
2012-07-04 15:11:07 -04:00
|
|
|
|
$queryStack['create'] = $lineCreate;
|
|
|
|
|
|
$inCreate = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if ($inAlter) {
|
|
|
|
|
|
$lineAlter .= $line . ' ';
|
2017-08-04 11:23:34 -04:00
|
|
|
|
if (strrpos($line, ";") > 0) {
|
2012-07-04 15:11:07 -04:00
|
|
|
|
$queryStack['alter'] = $lineAlter;
|
|
|
|
|
|
$inAlter = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if ($inDrop) {
|
|
|
|
|
|
$lineDrop .= $line . ' ';
|
2017-08-04 11:23:34 -04:00
|
|
|
|
if (strrpos($line, ";") > 0) {
|
2012-07-04 15:11:07 -04:00
|
|
|
|
$queryStack['drop'] = $lineDrop;
|
|
|
|
|
|
$inDrop = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
2012-06-15 18:26:18 -04:00
|
|
|
|
}
|
2012-07-04 15:11:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2013-01-09 13:23:16 -04:00
|
|
|
|
$table = $this->tableName;
|
|
|
|
|
|
$tableBackup = $this->tableName . "_BAK";
|
|
|
|
|
|
|
|
|
|
|
|
$sqlTableBackup = null;
|
|
|
|
|
|
$swTableBackup = 0;
|
|
|
|
|
|
|
|
|
|
|
|
switch ($dbEngine) {
|
|
|
|
|
|
case "mysql":
|
|
|
|
|
|
$sqlTableBackup = "CREATE TABLE $tableBackup SELECT * FROM $table";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "mssql":
|
|
|
|
|
|
$sqlTableBackup = "SELECT * INTO $tableBackup FROM $table";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "oracle":
|
|
|
|
|
|
$sqlTableBackup = "CREATE TABLE $tableBackup AS SELECT * FROM $table";
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2012-07-04 15:11:07 -04:00
|
|
|
|
if ($dbEngine == 'oracle') {
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$queryStack['drop'] = substr($queryStack['drop'], 0, strrpos($queryStack['drop'], ";"));
|
|
|
|
|
|
$queryStack['create'] = substr($queryStack['create'], 0, strrpos($queryStack['create'], ";"));
|
|
|
|
|
|
$queryStack['alter'] = substr($queryStack['alter'], 0, strrpos($queryStack['alter'], ";"));
|
2016-07-26 15:12:49 -04:00
|
|
|
|
$queryIfExistTable = "SELECT TABLE_NAME FROM USER_TABLES WHERE TABLE_NAME = '" . $table . "'";
|
2012-07-04 15:11:07 -04:00
|
|
|
|
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$rs = $stmt->executeQuery($queryIfExistTable);
|
2013-01-09 13:23:16 -04:00
|
|
|
|
|
2012-07-04 15:11:07 -04:00
|
|
|
|
if ($rs->next()) {
|
2013-01-09 13:23:16 -04:00
|
|
|
|
if ($this->keepData && $sqlTableBackup != null) {
|
|
|
|
|
|
//Delete backup if exists
|
|
|
|
|
|
$rs = $stmt->executeQuery(str_replace($table, $tableBackup, $queryStack["drop"]));
|
|
|
|
|
|
|
|
|
|
|
|
//Create backup
|
|
|
|
|
|
$rs = $stmt->executeQuery($sqlTableBackup, ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
|
$swTableBackup = 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$stmt->executeQuery($queryStack['drop']);
|
2012-06-15 18:26:18 -04:00
|
|
|
|
}
|
2013-01-09 13:23:16 -04:00
|
|
|
|
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$stmt->executeQuery($queryStack['create']);
|
|
|
|
|
|
$stmt->executeQuery($queryStack['alter']);
|
2012-07-04 15:11:07 -04:00
|
|
|
|
} else {
|
2017-08-04 11:23:34 -04:00
|
|
|
|
if (isset($queryStack['create'])) {
|
2012-07-04 15:11:07 -04:00
|
|
|
|
// first at all we need to verify if we have a valid schema defined,
|
|
|
|
|
|
// so we verify that creating a dummy table
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$swapQuery = str_replace($table, $table . '_TMP', $queryStack['create']);
|
2012-07-04 15:11:07 -04:00
|
|
|
|
|
|
|
|
|
|
// if there is a problem with user defined table schema executeQuery() will throw a sql exception
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$stmt->executeQuery($swapQuery);
|
2012-07-04 15:11:07 -04:00
|
|
|
|
|
|
|
|
|
|
// if there was not problem above proceced deleting the dummy table and drop and create the target table
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$stmt->executeQuery("DROP TABLE {$table}_TMP");
|
|
|
|
|
|
if (! isset($queryStack['drop'])) {
|
2016-07-26 15:12:49 -04:00
|
|
|
|
$queryStack['drop'] = "DROP TABLE {$table}";
|
2012-06-15 18:26:18 -04:00
|
|
|
|
}
|
2017-08-04 11:23:34 -04:00
|
|
|
|
if (! isset($queryStack['create'])) {
|
|
|
|
|
|
throw new Exception('A problem occurred resolving the schema to update for this table');
|
2012-06-15 18:26:18 -04:00
|
|
|
|
}
|
2013-01-09 13:23:16 -04:00
|
|
|
|
|
|
|
|
|
|
if ($this->keepData && $sqlTableBackup != null) {
|
2016-07-26 15:12:49 -04:00
|
|
|
|
if ($this->oldTableName === $this->tableName) {
|
|
|
|
|
|
//Delete backup if exists
|
|
|
|
|
|
$rs = $stmt->executeQuery(str_replace($table, $tableBackup, $queryStack["drop"]));
|
|
|
|
|
|
|
|
|
|
|
|
//Create backup
|
|
|
|
|
|
$rs = $stmt->executeQuery($sqlTableBackup, ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
|
$swTableBackup = 1;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$table = $this->oldTableName;
|
|
|
|
|
|
$tableBackup = str_replace($this->tableName, $this->oldTableName, $tableBackup);
|
|
|
|
|
|
$sqlTableBackup = str_replace($this->tableName, $this->oldTableName, $sqlTableBackup);
|
2017-04-21 12:04:57 -04:00
|
|
|
|
|
2016-07-26 15:12:49 -04:00
|
|
|
|
//Delete backup if exists
|
|
|
|
|
|
$rs = $stmt->executeQuery(str_replace($table, $tableBackup, $queryStack["drop"]));
|
|
|
|
|
|
|
|
|
|
|
|
//Create backup
|
|
|
|
|
|
$rs = $stmt->executeQuery($sqlTableBackup, ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
|
$swTableBackup = 1;
|
|
|
|
|
|
$table = $this->tableName;
|
|
|
|
|
|
}
|
2013-01-09 13:23:16 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$stmt->executeQuery($queryStack['drop']);
|
|
|
|
|
|
$stmt->executeQuery($queryStack['create']);
|
2012-07-04 15:11:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2013-01-09 13:23:16 -04:00
|
|
|
|
|
|
|
|
|
|
if ($swTableBackup == 1) {
|
|
|
|
|
|
$tableFileName = str_replace("_", " ", strtolower($table));
|
|
|
|
|
|
$tableFileName = str_replace(" ", null, ucwords($tableFileName));
|
|
|
|
|
|
|
2017-08-04 11:23:34 -04:00
|
|
|
|
require_once(PATH_WORKSPACE . "classes" . PATH_SEP . "$tableFileName.php");
|
2013-01-09 13:23:16 -04:00
|
|
|
|
|
|
|
|
|
|
$sql = "SELECT * FROM $tableBackup";
|
|
|
|
|
|
$rs = $stmt->executeQuery($sql, ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
|
|
2014-12-10 16:32:31 -04:00
|
|
|
|
// array the primary keys
|
2017-08-04 11:23:34 -04:00
|
|
|
|
foreach ($this->columns as $value) {
|
2014-12-10 16:32:31 -04:00
|
|
|
|
if ($value->field_key == 1) {
|
|
|
|
|
|
$this->primaryKey[] = $value->field_name;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$flagPrimaryKey = 1;
|
2013-01-09 13:23:16 -04:00
|
|
|
|
while ($rs->next()) {
|
|
|
|
|
|
$row = $rs->getRow();
|
2014-12-10 16:32:31 -04:00
|
|
|
|
if ($flagPrimaryKey) {
|
|
|
|
|
|
// verify row has all primary keys
|
|
|
|
|
|
$keys = 0;
|
|
|
|
|
|
foreach ($row as $colName => $value) {
|
2017-08-04 11:23:34 -04:00
|
|
|
|
if (in_array($colName, $this->primaryKey)) {
|
2014-12-10 16:32:31 -04:00
|
|
|
|
$keys++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if ($keys != count($this->primaryKey)) {
|
|
|
|
|
|
return $stmt->executeQuery(str_replace($table, $tableBackup, $queryStack["drop"]));
|
|
|
|
|
|
}
|
|
|
|
|
|
$flagPrimaryKey = 0;
|
|
|
|
|
|
}
|
2013-01-09 13:23:16 -04:00
|
|
|
|
|
|
|
|
|
|
$oTable = new $tableFileName();
|
|
|
|
|
|
$oTable->fromArray($row, BasePeer::TYPE_FIELDNAME);
|
|
|
|
|
|
$oTable->save();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//Delete backup
|
|
|
|
|
|
$rs = $stmt->executeQuery(str_replace($table, $tableBackup, $queryStack["drop"]));
|
|
|
|
|
|
}
|
2011-08-29 11:39:22 -04:00
|
|
|
|
}
|
2012-06-15 18:26:18 -04:00
|
|
|
|
|
2017-08-04 11:23:34 -04:00
|
|
|
|
public function upgradeDatabaseFor($dataSource, $tablesList = array())
|
2012-07-04 15:11:07 -04:00
|
|
|
|
{
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$con = Propel::getConnection($dataSource);
|
2012-07-04 15:11:07 -04:00
|
|
|
|
$stmt = $con->createStatement();
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$lines = file($this->dataDir . $this->dbConfig->adapter . PATH_SEP . 'schema.sql');
|
2012-07-04 15:11:07 -04:00
|
|
|
|
$previous = null;
|
|
|
|
|
|
$errors = '';
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($lines as $j => $line) {
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$line = trim($line); // Remove comments from the script
|
2012-10-09 13:00:37 -04:00
|
|
|
|
|
2012-07-04 15:11:07 -04:00
|
|
|
|
|
2017-08-04 11:23:34 -04:00
|
|
|
|
if (strpos($line, "--") === 0) {
|
|
|
|
|
|
$line = substr($line, 0, strpos($line, "--"));
|
2012-07-04 15:11:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-08-04 11:23:34 -04:00
|
|
|
|
if (empty($line)) {
|
2012-07-04 15:11:07 -04:00
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-08-04 11:23:34 -04:00
|
|
|
|
if (strpos($line, "#") === 0) {
|
|
|
|
|
|
$line = substr($line, 0, strpos($line, "#"));
|
2012-07-04 15:11:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-08-04 11:23:34 -04:00
|
|
|
|
if (empty($line)) {
|
2012-07-04 15:11:07 -04:00
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Concatenate the previous line, if any, with the current
|
|
|
|
|
|
if ($previous) {
|
|
|
|
|
|
$line = $previous . " " . $line;
|
|
|
|
|
|
}
|
|
|
|
|
|
$previous = null;
|
|
|
|
|
|
|
|
|
|
|
|
// If the current line doesnt end with ; then put this line together
|
|
|
|
|
|
// with the next one, thus supporting multi-line statements.
|
2017-08-04 11:23:34 -04:00
|
|
|
|
if (strrpos($line, ";") != strlen($line) - 1) {
|
2012-07-04 15:11:07 -04:00
|
|
|
|
$previous = $line;
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$line = substr($line, 0, strrpos($line, ";"));
|
2012-07-04 15:11:07 -04:00
|
|
|
|
|
|
|
|
|
|
// execute
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$isCreate = stripos($line, 'CREATE TABLE') !== false;
|
|
|
|
|
|
$isDrop = stripos($line, 'DROP TABLE') !== false;
|
2012-07-04 15:11:07 -04:00
|
|
|
|
|
|
|
|
|
|
if ($isCreate || $isDrop) {
|
2017-08-04 11:23:34 -04:00
|
|
|
|
if (preg_match('/TABLE\s[\'\"\`]+(\w+)[\'\"\`]+/i', $line, $match)) {
|
|
|
|
|
|
if (in_array($match[1], $tablesList)) {
|
2012-07-04 15:11:07 -04:00
|
|
|
|
//error_log($line);
|
|
|
|
|
|
try {
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$stmt->executeQuery($line);
|
2012-07-04 15:11:07 -04:00
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
|
$errors .= $e->getMessage() . "\n";
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2012-06-15 18:26:18 -04:00
|
|
|
|
}
|
2012-07-04 15:11:07 -04:00
|
|
|
|
|
|
|
|
|
|
return $errors;
|
2011-08-29 11:39:22 -04:00
|
|
|
|
}
|
2012-07-04 15:11:07 -04:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* verify if on the columns list was set a column as primary key
|
2012-10-09 13:00:37 -04:00
|
|
|
|
*
|
2012-07-04 15:11:07 -04:00
|
|
|
|
* @return boolean to affirm if was defined a column as pk.
|
|
|
|
|
|
*/
|
2017-08-04 11:23:34 -04:00
|
|
|
|
public function hasAutoIncrementPKey()
|
2012-07-04 15:11:07 -04:00
|
|
|
|
{
|
|
|
|
|
|
foreach ($this->columns as $column) {
|
|
|
|
|
|
if ($column->field_autoincrement) {
|
|
|
|
|
|
return true;
|
2011-10-11 17:13:13 -04:00
|
|
|
|
}
|
2011-10-04 12:11:44 -04:00
|
|
|
|
}
|
2011-08-29 11:39:22 -04:00
|
|
|
|
|
2012-07-04 15:11:07 -04:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2011-08-29 11:39:22 -04:00
|
|
|
|
|
|
|
|
|
|
/**
|
2012-07-04 15:11:07 -04:00
|
|
|
|
*
|
|
|
|
|
|
* @return array contains all supported columns types provided by propel
|
2011-08-29 11:39:22 -04:00
|
|
|
|
*/
|
2017-08-04 11:23:34 -04:00
|
|
|
|
public function getPropelSupportedColumnTypes()
|
2012-07-04 15:11:07 -04:00
|
|
|
|
{
|
|
|
|
|
|
/**
|
|
|
|
|
|
* http://www.propelorm.org/wiki/Documentation/1.2/Schema
|
|
|
|
|
|
* [type = "BOOLEAN|TINYINT|SMALLINT|INTEGER|BIGINT|DOUBLE|FLOAT|REAL|DECIMAL|CHAR|{VARCHAR}
|
2012-10-09 13:00:37 -04:00
|
|
|
|
* |LONGVARCHAR|DATE|TIME|TIMESTAMP|BLOB|CLOB"]
|
2012-07-04 15:11:07 -04:00
|
|
|
|
*/
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$types = array();
|
2012-07-04 15:11:07 -04:00
|
|
|
|
|
|
|
|
|
|
$types['BOOLEAN'] = 'BOOLEAN';
|
|
|
|
|
|
$types['TINYINT'] = 'TINYINT';
|
|
|
|
|
|
$types['SMALLINT'] = 'SMALLINT';
|
|
|
|
|
|
$types['INTEGER'] = 'INTEGER';
|
|
|
|
|
|
$types['BIGINT'] = 'BIGINT';
|
|
|
|
|
|
$types['DOUBLE'] = 'DOUBLE';
|
|
|
|
|
|
$types['FLOAT'] = 'FLOAT';
|
|
|
|
|
|
$types['REAL'] = 'REAL';
|
|
|
|
|
|
$types['DECIMAL'] = 'DECIMAL';
|
|
|
|
|
|
$types['CHAR'] = 'CHAR';
|
|
|
|
|
|
$types['VARCHAR'] = 'VARCHAR';
|
|
|
|
|
|
$types['LONGVARCHAR'] = 'LONGVARCHAR';
|
|
|
|
|
|
$types['DATE'] = 'DATE';
|
|
|
|
|
|
$types['TIME'] = 'TIME';
|
|
|
|
|
|
$types['DATETIME'] = 'DATETIME';
|
2014-05-02 11:19:22 -04:00
|
|
|
|
$types['TIMESTAMP'] = 'TIMESTAMP';
|
2012-07-04 15:11:07 -04:00
|
|
|
|
//$types['BLOB'] = 'BLOB'; <- disabled
|
|
|
|
|
|
//$types['CLOB'] = 'CLOB'; <- disabled
|
|
|
|
|
|
|
2012-10-09 13:00:37 -04:00
|
|
|
|
|
2012-07-04 15:11:07 -04:00
|
|
|
|
return $types;
|
2011-08-29 11:39:22 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2012-07-04 15:11:07 -04:00
|
|
|
|
/**
|
2012-10-09 13:00:37 -04:00
|
|
|
|
*
|
2012-07-04 15:11:07 -04:00
|
|
|
|
* @param string $name any string witha name separated by underscore
|
|
|
|
|
|
* @return string contains a camelcase expresion for $name
|
|
|
|
|
|
*/
|
2017-08-04 11:23:34 -04:00
|
|
|
|
public function toCamelCase($name)
|
2012-07-04 15:11:07 -04:00
|
|
|
|
{
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$tmp = explode('_', trim($name));
|
2012-07-04 15:11:07 -04:00
|
|
|
|
foreach ($tmp as $i => $part) {
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$tmp[$i] = ucFirst(strtolower($part));
|
2012-07-04 15:11:07 -04:00
|
|
|
|
}
|
2017-08-04 11:23:34 -04:00
|
|
|
|
return implode('', $tmp);
|
2011-08-29 11:39:22 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2012-07-04 15:11:07 -04:00
|
|
|
|
/**
|
|
|
|
|
|
* Run om task for phing to build all mdoel classes
|
|
|
|
|
|
*/
|
2017-08-04 11:23:34 -04:00
|
|
|
|
public function phingbuildModel()
|
2012-07-04 15:11:07 -04:00
|
|
|
|
{
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$this->_callPhing('om');
|
2011-08-29 11:39:22 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2012-07-04 15:11:07 -04:00
|
|
|
|
/**
|
|
|
|
|
|
* Run sql task for phing to generate the sql schema
|
|
|
|
|
|
*/
|
2017-08-04 11:23:34 -04:00
|
|
|
|
public function phingbuildSql()
|
2012-07-04 15:11:07 -04:00
|
|
|
|
{
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$this->_callPhing('sql');
|
2011-08-29 11:39:22 -04:00
|
|
|
|
}
|
2012-07-04 15:11:07 -04:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* call phing to execute a determinated task
|
2012-10-09 13:00:37 -04:00
|
|
|
|
*
|
2012-07-04 15:11:07 -04:00
|
|
|
|
* @param string $taskName [om|sql]
|
|
|
|
|
|
*/
|
2017-08-04 11:23:34 -04:00
|
|
|
|
private function _callPhing($taskName)
|
2012-07-04 15:11:07 -04:00
|
|
|
|
{
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$options = array('project.dir' => $this->configDir, 'build.properties' => "propel.{$this->dbConfig->adapter}.ini", 'propel.targetPackage' => 'classes', 'propel.output.dir' => $this->targetDir, 'propel.php.dir' => $this->baseDir
|
2012-07-04 15:11:07 -04:00
|
|
|
|
);
|
|
|
|
|
|
|
2017-08-04 11:23:34 -04:00
|
|
|
|
self::callPhing(array($taskName
|
|
|
|
|
|
), PATH_THIRDPARTY . 'propel-generator/build.xml', $options, false);
|
2011-08-29 11:39:22 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2012-07-04 15:11:07 -04:00
|
|
|
|
/**
|
2012-10-09 13:00:37 -04:00
|
|
|
|
*
|
|
|
|
|
|
* @param string $target - task name to execute
|
2012-07-04 15:11:07 -04:00
|
|
|
|
* @param string $buildFile - build file path
|
2012-10-09 13:00:37 -04:00
|
|
|
|
* @param array $options - array options to override the options on .ini file
|
|
|
|
|
|
* @param bool $verbose - to show a verbose output
|
2012-07-04 15:11:07 -04:00
|
|
|
|
*/
|
2017-08-04 11:23:34 -04:00
|
|
|
|
public static function callPhing($target, $buildFile = '', $options = array(), $verbose = true)
|
2012-07-04 15:11:07 -04:00
|
|
|
|
{
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$args = array();
|
2012-07-04 15:11:07 -04:00
|
|
|
|
foreach ($options as $key => $value) {
|
|
|
|
|
|
$args[] = "-D$key=$value";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($buildFile) {
|
|
|
|
|
|
$args[] = '-f';
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$args[] = realpath($buildFile);
|
2012-07-04 15:11:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2012-10-09 13:00:37 -04:00
|
|
|
|
if (! $verbose) {
|
2012-07-04 15:11:07 -04:00
|
|
|
|
$args[] = '-q';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-08-04 11:23:34 -04:00
|
|
|
|
if (is_array($target)) {
|
|
|
|
|
|
$args = array_merge($args, $target);
|
2012-07-04 15:11:07 -04:00
|
|
|
|
} else {
|
|
|
|
|
|
$args[] = $target;
|
|
|
|
|
|
}
|
2011-08-29 11:39:22 -04:00
|
|
|
|
|
2017-08-04 11:23:34 -04:00
|
|
|
|
if (DIRECTORY_SEPARATOR != '\\' && (function_exists('posix_isatty') && @posix_isatty(STDOUT))) {
|
2012-07-04 15:11:07 -04:00
|
|
|
|
$args[] = '-logger';
|
|
|
|
|
|
$args[] = 'phing.listener.AnsiColorLogger';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Phing::startup();
|
2017-08-04 11:23:34 -04:00
|
|
|
|
Phing::setProperty('phing.home', getenv('PHING_HOME'));
|
2012-07-04 15:11:07 -04:00
|
|
|
|
|
2017-08-11 16:41:04 -04:00
|
|
|
|
$m = new PmPhing();
|
2017-08-04 11:23:34 -04:00
|
|
|
|
$m->execute($args);
|
2012-07-04 15:11:07 -04:00
|
|
|
|
$m->runBuild();
|
|
|
|
|
|
}
|
2016-06-07 11:50:15 -04:00
|
|
|
|
|
|
|
|
|
|
public function addPMFieldsToList($action)
|
|
|
|
|
|
{
|
|
|
|
|
|
$conf = new Configurations();
|
|
|
|
|
|
$confCasesList = $conf->getConfiguration('casesList', $action);
|
|
|
|
|
|
|
|
|
|
|
|
if (!class_exists('AdditionalTables')) {
|
2017-08-04 11:23:34 -04:00
|
|
|
|
require_once("classes/model/AdditionalTables.php");
|
2016-06-07 11:50:15 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$oCriteria = new Criteria('workflow');
|
|
|
|
|
|
$oCriteria->clearSelectColumns();
|
|
|
|
|
|
|
|
|
|
|
|
//If there is PMTable for this case list
|
|
|
|
|
|
if (is_array($confCasesList) && count($confCasesList) > 0 && isset($confCasesList["PMTable"]) && trim($confCasesList["PMTable"]) != "") {
|
|
|
|
|
|
//Getting the table name
|
|
|
|
|
|
$additionalTableUid = $confCasesList["PMTable"];
|
|
|
|
|
|
|
|
|
|
|
|
$additionalTable = AdditionalTablesPeer::retrieveByPK($additionalTableUid);
|
|
|
|
|
|
$tableName = $additionalTable->getAddTabName();
|
2017-04-21 12:04:57 -04:00
|
|
|
|
$this->tableClassName = $additionalTable->getAddTabClassName();
|
2016-06-07 11:50:15 -04:00
|
|
|
|
|
|
|
|
|
|
$additionalTable = new AdditionalTables();
|
|
|
|
|
|
$tableData = $additionalTable->load($additionalTableUid, true);
|
|
|
|
|
|
|
|
|
|
|
|
$tableField = array();
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($tableData["FIELDS"] as $arrayField) {
|
|
|
|
|
|
$tableField[] = $arrayField["FLD_NAME"];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($confCasesList["second"]["data"] as $fieldData) {
|
|
|
|
|
|
$fieldData['name'] = ($fieldData['name'] == 'APP_STATUS_LABEL')? 'APP_STATUS' : $fieldData['name'];
|
|
|
|
|
|
if (in_array($fieldData["name"], $tableField)) {
|
|
|
|
|
|
$fieldTable = $fieldData["name"];
|
|
|
|
|
|
$fieldName = $tableName . "." . $fieldTable;
|
2018-02-20 12:02:35 -04:00
|
|
|
|
//We are not include some columns for the search
|
|
|
|
|
|
if (!in_array($fieldTable, $this->getColumnsToExclude())){
|
|
|
|
|
|
$oCriteria->addSelectColumn($fieldName);
|
|
|
|
|
|
}
|
2016-06-07 11:50:15 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch ($action) {
|
|
|
|
|
|
case "sent":
|
|
|
|
|
|
$listTablePeer = 'ListParticipatedLastPeer';
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "selfservice":
|
|
|
|
|
|
case "unassigned":
|
|
|
|
|
|
$listTablePeer = 'ListUnassignedPeer';
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "paused":
|
|
|
|
|
|
$listTablePeer = 'ListPausedPeer';
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "todo":
|
|
|
|
|
|
case 'draft':
|
|
|
|
|
|
$listTablePeer = 'ListInboxPeer';
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-04-27 16:07:20 -04:00
|
|
|
|
//Some PM tables don’t have the APP NUMBER column; but if exists, we must use it
|
2017-04-21 12:04:57 -04:00
|
|
|
|
if (in_array($tableName.'.APP_NUMBER', $oCriteria->getSelectColumns())) {
|
|
|
|
|
|
$oCriteria->addJoin($listTablePeer::APP_NUMBER, $tableName.'.APP_NUMBER', Criteria::LEFT_JOIN);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$oCriteria->addJoin($listTablePeer::APP_UID, $tableName.'.APP_UID', Criteria::LEFT_JOIN);
|
|
|
|
|
|
}
|
2016-06-07 11:50:15 -04:00
|
|
|
|
}
|
|
|
|
|
|
return $oCriteria;
|
|
|
|
|
|
}
|
2019-04-24 09:43:53 -04:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Get the type of the column ex: string, int, double, boolean
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param string $pmTablePeer
|
|
|
|
|
|
* @param string $tableName
|
|
|
|
|
|
* @param string $columnName
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return string
|
|
|
|
|
|
*/
|
|
|
|
|
|
public static function getTypeOfColumn($pmTablePeer, $tableName, $columnName)
|
|
|
|
|
|
{
|
|
|
|
|
|
try {
|
|
|
|
|
|
$type = $pmTablePeer::getMapBuilder()->getDatabaseMap()->getTable($tableName)->getColumn($columnName)->getCreoleType();
|
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
|
return '';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $type;
|
|
|
|
|
|
}
|
2019-11-04 15:59:50 -04:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Remove the folder "pmt-folder" and all the content inside
|
|
|
|
|
|
*/
|
|
|
|
|
|
public static function removePmtPropelFolder()
|
|
|
|
|
|
{
|
|
|
|
|
|
$pmtPropelFolder = PATH_DB . config('system.workspace') . PATH_SEP . 'pmt-propel';
|
|
|
|
|
|
G::rm_dir($pmtPropelFolder);
|
|
|
|
|
|
}
|
2011-08-29 11:39:22 -04:00
|
|
|
|
}
|