Re: model transaction on multiple models

2007-11-27 Thread honig

currently there is no chance to call $db-begin... without
modification. if model tables are stored on different databases
(global rollback)

- http://bin.cakephp.org/saved/25650

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: model transaction on multiple models

2007-11-27 Thread honig

currently there is no chance to call $db-begin... without
modification. if model tables are stored on different databases:

class AppController extends Controller
{
var $__transactions = array();

function __getDbConnections()
{
$models = ClassRegistry::mapKeys();
$dbConnections = array();

foreach ( $models as $model )
{
$modelClass = ClassRegistry::getObject($model);
$dbConnections[] = $modelClass-useDbConfig;
}

return array_unique($dbConnections);
}

function __call( $funcName, $funcArgs )
{
$allowedFuncNames = array('begin', 'commit', 'rollback');
$formattedFuncName = low($funcName);

if ( in_array($formattedFuncName, $allowedFuncNames) )
{
static $dbConnections = array();

if ( empty($dbConnections[0]) )
$dbConnections = $this-__getDbConnections();

foreach ( $dbConnections as $dbConnection )
{
$db = ConnectionManager::getDataSource( 
$dbConnection );

switch( $formattedFuncName )
{
case 'begin':

$this-__transactions[$dbConnection] = true;
$db-execute('START 
TRANSACTION');
break;

case 'commit':
if ( 
$this-__transactions[$dbConnection] )
{

unset($this-__transactions[$dbConnection]);
$db-execute('COMMIT');
}
break;

case 'rollback':
if ( 
$this-__transactions[$dbConnection] )
{

unset($this-__transactions[$dbConnection]);

$db-execute('ROLLBACK');
}
break;
}
}
if ( $db-lastError() !== null )
{
$querys = $db-_queriesLog;
$this-log('SQL ERROR: ' . env('REMOTE_ADDR') . 
$db-lastError() .
' - ' . end($querys));
die('please change the transaction sql 
command');
}
}
}
}

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: model transaction on multiple models

2007-11-15 Thread Marcin Domanski aka kabturek

 In doing this, the changes for every model rolled back fine.  Does it
 seem incorrect (maybe just conventionally) to use a model to control
 the transaction over all the other models?  Or is there a global type
 of transaction I should be using?

AFAIK there is no global types of transactions. Transaction support is
in your database.
Look at the SQL log - the methods you are using just forward start/
commit/rollback to the db.
http://api.cakephp.org/1.2/dbo__mysql_8php-source.html#l00243

It could be a problem if different models would use different db
connections/dbos but i haven't tried this so maybe someone can comment
on it:)

HTH,
kabturek
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



model transaction on multiple models

2007-11-14 Thread Greg

If I want to perform a transaction on multiple models.  In the newest
version of Cake 1.2, is there a 'right' way to do it?  It worked when
I chose any random model involved in the transaction and used:

$this-Model1-begin();
$this-Model1-save();
$this-Model2-save();
...
$this-Model1-rollback();

In doing this, the changes for every model rolled back fine.  Does it
seem incorrect (maybe just conventionally) to use a model to control
the transaction over all the other models?  Or is there a global type
of transaction I should be using?

Thanks in advance.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---