Merged in bugfix/PMCORE-2364 (pull request #7545)
PMCORE-2364 Approved-by: Julio Cesar Laura Avendaño <contact@julio-laura.com>
This commit is contained in:
@@ -1243,12 +1243,15 @@ class WorkspaceTools
|
|||||||
if ($action == 'ADD') {
|
if ($action == 'ADD') {
|
||||||
$tablesToAddColumns[$tableName] = $actionData;
|
$tablesToAddColumns[$tableName] = $actionData;
|
||||||
|
|
||||||
// In a very old schema the primary key for table "LOGIN_LOG" was changed and we need to delete the
|
// In a very old schema the primary key for tables "LOGIN_LOG" and "APP_SEQUENCE" were changed and we need to delete the
|
||||||
// primary index to avoid errors in the database upgrade
|
// primary index to avoid errors in the database upgrade
|
||||||
// TO DO: The change of a Primary Key in a table should be generic
|
// TO DO: The change of a Primary Key in a table should be generic
|
||||||
if ($tableName == 'LOGIN_LOG' && array_key_exists('LOG_ID', $actionData)) {
|
if ($tableName == 'LOGIN_LOG' && array_key_exists('LOG_ID', $actionData)) {
|
||||||
$database->executeQuery('DROP INDEX `PRIMARY` ON LOGIN_LOG;');
|
$database->executeQuery('DROP INDEX `PRIMARY` ON LOGIN_LOG;');
|
||||||
}
|
}
|
||||||
|
if ($tableName == 'APP_SEQUENCE' && array_key_exists('APP_TYPE', $actionData)) {
|
||||||
|
$database->executeQuery('DROP INDEX `PRIMARY` ON APP_SEQUENCE;');
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
foreach ($actionData as $columnName => $meta) {
|
foreach ($actionData as $columnName => $meta) {
|
||||||
switch ($action) {
|
switch ($action) {
|
||||||
@@ -3285,22 +3288,46 @@ class WorkspaceTools
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add sequence numbers
|
||||||
|
*/
|
||||||
public function checkSequenceNumber()
|
public function checkSequenceNumber()
|
||||||
{
|
{
|
||||||
$criteria = new Criteria("workflow");
|
// Instance required class
|
||||||
|
$appSequenceInstance = new AppSequence();
|
||||||
|
|
||||||
|
// Get a record from APP_SEQUENCE table
|
||||||
|
$criteria = new Criteria('workflow');
|
||||||
$rsCriteria = AppSequencePeer::doSelectRS($criteria);
|
$rsCriteria = AppSequencePeer::doSelectRS($criteria);
|
||||||
$rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
$rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
||||||
$rsCriteria->next();
|
$rsCriteria->next();
|
||||||
$appSequenceRow = $rsCriteria->getRow();
|
$appSequenceRow = $rsCriteria->getRow();
|
||||||
|
|
||||||
|
// If table APP_SEQUENCE is empty, insert two records
|
||||||
if (empty($appSequenceRow)) {
|
if (empty($appSequenceRow)) {
|
||||||
$sequenceInstance = SequencesPeer::retrieveByPK("APP_NUMBER");
|
// Check if exist a value in old table SEQUENCES
|
||||||
$appSequenceInstance = new AppSequence();
|
$sequenceInstance = SequencesPeer::retrieveByPK('APP_NUMBER');
|
||||||
|
|
||||||
if (!is_null($sequenceInstance)) {
|
if (!is_null($sequenceInstance)) {
|
||||||
|
// If exists a value in SEQUENCE table, copy the same to APP_SEQUENCES table
|
||||||
$sequenceFields = $sequenceInstance->toArray(BasePeer::TYPE_FIELDNAME);
|
$sequenceFields = $sequenceInstance->toArray(BasePeer::TYPE_FIELDNAME);
|
||||||
$appSequenceInstance->updateSequenceNumber($sequenceFields['SEQ_VALUE']);
|
$appSequenceInstance->updateSequenceNumber($sequenceFields['SEQ_VALUE']);
|
||||||
} else {
|
} else {
|
||||||
|
// If not exists a value in SEQUENCE table, insert a initial value
|
||||||
$appSequenceInstance->updateSequenceNumber(0);
|
$appSequenceInstance->updateSequenceNumber(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Insert a initial value for the web entries
|
||||||
|
$appSequenceInstance->updateSequenceNumber(0, AppSequence::APP_TYPE_WEB_ENTRY);
|
||||||
|
} else {
|
||||||
|
// Create a new instance of Criteria class
|
||||||
|
$criteria = new Criteria('workflow');
|
||||||
|
$criteria->add(AppSequencePeer::APP_TYPE, AppSequence::APP_TYPE_WEB_ENTRY);
|
||||||
|
|
||||||
|
// Check if exists a record for the web entries, if not exist insert the initial value
|
||||||
|
if (AppSequencePeer::doCount($criteria) === 0) {
|
||||||
|
$appSequenceInstance->updateSequenceNumber(0, AppSequence::APP_TYPE_WEB_ENTRY);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,26 +53,36 @@ class AppSequence extends BaseAppSequence {
|
|||||||
/**
|
/**
|
||||||
* Update sequence number
|
* Update sequence number
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @param int $number
|
||||||
|
* @param string $sequenceType
|
||||||
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function updateSequenceNumber($number)
|
public function updateSequenceNumber($number, $sequenceType = AppSequence::APP_TYPE_NORMAL)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$con = Propel::getConnection('workflow');
|
// Get the current connection
|
||||||
$stmt = $con->createStatement();
|
$connection = Propel::getConnection('workflow');
|
||||||
$c = new Criteria();
|
|
||||||
$rs = AppSequencePeer::doSelectRS($c);
|
// Create a statement instance
|
||||||
$rs->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
$statement = $connection->createStatement();
|
||||||
$rs->next();
|
|
||||||
$row = $rs->getRow();
|
// Get the record according to the sequence type
|
||||||
|
$criteria = new Criteria();
|
||||||
|
$criteria->add(AppSequencePeer::APP_TYPE, $sequenceType);
|
||||||
|
$rsCriteria = AppSequencePeer::doSelectRS($criteria);
|
||||||
|
$rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
||||||
|
$rsCriteria->next();
|
||||||
|
$row = $rsCriteria->getRow();
|
||||||
|
|
||||||
|
// Insert/Update sequence table with the number sent
|
||||||
if ($row) {
|
if ($row) {
|
||||||
$sql = "UPDATE APP_SEQUENCE SET ID=LAST_INSERT_ID('$number')";
|
$sql = "UPDATE APP_SEQUENCE SET ID=LAST_INSERT_ID('{$number}') WHERE APP_TYPE = '{$sequenceType}'";
|
||||||
} else {
|
} else {
|
||||||
$sql = "INSERT INTO APP_SEQUENCE (ID) VALUES ('$number');";
|
$sql = "INSERT INTO APP_SEQUENCE (ID, APP_TYPE) VALUES ('{$number}', '{$sequenceType}')";
|
||||||
}
|
}
|
||||||
$stmt->executeQuery($sql, ResultSet::FETCHMODE_ASSOC);
|
$statement->executeQuery($sql, ResultSet::FETCHMODE_ASSOC);
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw ($e);
|
throw ($e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ class AppSequenceMapBuilder
|
|||||||
|
|
||||||
$tMap->setUseIdGenerator(false);
|
$tMap->setUseIdGenerator(false);
|
||||||
|
|
||||||
$tMap->addPrimaryKey('ID', 'Id', 'int', CreoleTypes::INTEGER, true, null);
|
$tMap->addColumn('ID', 'Id', 'int', CreoleTypes::INTEGER, true, null);
|
||||||
|
|
||||||
$tMap->addColumn('APP_TYPE', 'AppType', 'string', CreoleTypes::VARCHAR, true, 20);
|
$tMap->addColumn('APP_TYPE', 'AppType', 'string', CreoleTypes::VARCHAR, true, 20);
|
||||||
|
|
||||||
|
|||||||
@@ -480,30 +480,33 @@ abstract class BaseAppSequence extends BaseObject implements Persistent
|
|||||||
{
|
{
|
||||||
$criteria = new Criteria(AppSequencePeer::DATABASE_NAME);
|
$criteria = new Criteria(AppSequencePeer::DATABASE_NAME);
|
||||||
|
|
||||||
$criteria->add(AppSequencePeer::ID, $this->id);
|
|
||||||
|
|
||||||
return $criteria;
|
return $criteria;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the primary key for this object (row).
|
* Returns NULL since this table doesn't have a primary key.
|
||||||
* @return int
|
* This method exists only for BC and is deprecated!
|
||||||
|
* @return null
|
||||||
*/
|
*/
|
||||||
public function getPrimaryKey()
|
public function getPrimaryKey()
|
||||||
{
|
{
|
||||||
return $this->getId();
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generic method to set the primary key (id column).
|
* Dummy primary key setter.
|
||||||
*
|
*
|
||||||
* @param int $key Primary key.
|
* This function only exists to preserve backwards compatibility. It is no longer
|
||||||
* @return void
|
* needed or required by the Persistent interface. It will be removed in next BC-breaking
|
||||||
|
* release of Propel.
|
||||||
|
*
|
||||||
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
public function setPrimaryKey($key)
|
public function setPrimaryKey($pk)
|
||||||
{
|
{
|
||||||
$this->setId($key);
|
// do nothing, because this object doesn't have any primary keys
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets contents of passed object to values from current object.
|
* Sets contents of passed object to values from current object.
|
||||||
@@ -518,13 +521,13 @@ abstract class BaseAppSequence extends BaseObject implements Persistent
|
|||||||
public function copyInto($copyObj, $deepCopy = false)
|
public function copyInto($copyObj, $deepCopy = false)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
$copyObj->setId($this->id);
|
||||||
|
|
||||||
$copyObj->setAppType($this->app_type);
|
$copyObj->setAppType($this->app_type);
|
||||||
|
|
||||||
|
|
||||||
$copyObj->setNew(true);
|
$copyObj->setNew(true);
|
||||||
|
|
||||||
$copyObj->setId(NULL); // this is a pkey column, so set to default value
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -171,8 +171,8 @@ abstract class BaseAppSequencePeer
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const COUNT = 'COUNT(APP_SEQUENCE.ID)';
|
const COUNT = 'COUNT(*)';
|
||||||
const COUNT_DISTINCT = 'COUNT(DISTINCT APP_SEQUENCE.ID)';
|
const COUNT_DISTINCT = 'COUNT(DISTINCT *)';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of rows matching criteria.
|
* Returns the number of rows matching criteria.
|
||||||
@@ -381,9 +381,6 @@ abstract class BaseAppSequencePeer
|
|||||||
if ($values instanceof Criteria) {
|
if ($values instanceof Criteria) {
|
||||||
$criteria = clone $values; // rename for clarity
|
$criteria = clone $values; // rename for clarity
|
||||||
|
|
||||||
$comparison = $criteria->getComparison(AppSequencePeer::ID);
|
|
||||||
$selectCriteria->add(AppSequencePeer::ID, $criteria->remove(AppSequencePeer::ID), $comparison);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$criteria = $values->buildCriteria(); // gets full criteria
|
$criteria = $values->buildCriteria(); // gets full criteria
|
||||||
$selectCriteria = $values->buildPkeyCriteria(); // gets criteria w/ primary key(s)
|
$selectCriteria = $values->buildPkeyCriteria(); // gets criteria w/ primary key(s)
|
||||||
@@ -441,11 +438,22 @@ abstract class BaseAppSequencePeer
|
|||||||
$criteria = clone $values; // rename for clarity
|
$criteria = clone $values; // rename for clarity
|
||||||
} elseif ($values instanceof AppSequence) {
|
} elseif ($values instanceof AppSequence) {
|
||||||
|
|
||||||
$criteria = $values->buildPkeyCriteria();
|
$criteria = $values->buildCriteria();
|
||||||
} else {
|
} else {
|
||||||
// it must be the primary key
|
// it must be the primary key
|
||||||
$criteria = new Criteria(self::DATABASE_NAME);
|
$criteria = new Criteria(self::DATABASE_NAME);
|
||||||
$criteria->add(AppSequencePeer::ID, (array) $values, Criteria::IN);
|
// primary key is composite; we therefore, expect
|
||||||
|
// the primary key passed to be an array of pkey
|
||||||
|
// values
|
||||||
|
if (count($values) == count($values, COUNT_RECURSIVE)) {
|
||||||
|
// array is not multi-dimensional
|
||||||
|
$values = array($values);
|
||||||
|
}
|
||||||
|
$vals = array();
|
||||||
|
foreach ($values as $value) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the correct dbName
|
// Set the correct dbName
|
||||||
@@ -503,54 +511,6 @@ abstract class BaseAppSequencePeer
|
|||||||
|
|
||||||
return BasePeer::doValidate(AppSequencePeer::DATABASE_NAME, AppSequencePeer::TABLE_NAME, $columns);
|
return BasePeer::doValidate(AppSequencePeer::DATABASE_NAME, AppSequencePeer::TABLE_NAME, $columns);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve a single object by pkey.
|
|
||||||
*
|
|
||||||
* @param mixed $pk the primary key.
|
|
||||||
* @param Connection $con the connection to use
|
|
||||||
* @return AppSequence
|
|
||||||
*/
|
|
||||||
public static function retrieveByPK($pk, $con = null)
|
|
||||||
{
|
|
||||||
if ($con === null) {
|
|
||||||
$con = Propel::getConnection(self::DATABASE_NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
$criteria = new Criteria(AppSequencePeer::DATABASE_NAME);
|
|
||||||
|
|
||||||
$criteria->add(AppSequencePeer::ID, $pk);
|
|
||||||
|
|
||||||
|
|
||||||
$v = AppSequencePeer::doSelect($criteria, $con);
|
|
||||||
|
|
||||||
return !empty($v) > 0 ? $v[0] : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve multiple objects by pkey.
|
|
||||||
*
|
|
||||||
* @param array $pks List of primary keys
|
|
||||||
* @param Connection $con the connection to use
|
|
||||||
* @throws PropelException Any exceptions caught during processing will be
|
|
||||||
* rethrown wrapped into a PropelException.
|
|
||||||
*/
|
|
||||||
public static function retrieveByPKs($pks, $con = null)
|
|
||||||
{
|
|
||||||
if ($con === null) {
|
|
||||||
$con = Propel::getConnection(self::DATABASE_NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
$objs = null;
|
|
||||||
if (empty($pks)) {
|
|
||||||
$objs = array();
|
|
||||||
} else {
|
|
||||||
$criteria = new Criteria();
|
|
||||||
$criteria->add(AppSequencePeer::ID, $pks, Criteria::IN);
|
|
||||||
$objs = AppSequencePeer::doSelect($criteria, $con);
|
|
||||||
}
|
|
||||||
return $objs;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user