mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Adding a missing rollback when validation on an associated record fails, and validate = first. Fixes #1147
This commit is contained in:
parent
0761edecfb
commit
b08aba8e86
2 changed files with 44 additions and 2 deletions
|
@ -1665,6 +1665,7 @@ class Model extends Overloadable {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->__save($data, $options)) {
|
||||
$validationErrors[$this->alias] = $this->validationErrors;
|
||||
$validates = false;
|
||||
|
@ -1735,7 +1736,6 @@ class Model extends Overloadable {
|
|||
case ($options['validate'] === 'first'):
|
||||
$options['validate'] = true;
|
||||
$return = array();
|
||||
continue;
|
||||
break;
|
||||
default:
|
||||
if ($options['atomic']) {
|
||||
|
@ -1748,6 +1748,10 @@ class Model extends Overloadable {
|
|||
return $return;
|
||||
break;
|
||||
}
|
||||
if ($options['atomic'] && !$validates) {
|
||||
$db->rollback($this);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3039,7 +3039,7 @@ class ModelWriteTest extends BaseModelTest {
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
function testSaveAllTransactionNoRollback() {
|
||||
function testSaveAllManyRowsTransactionNoRollback() {
|
||||
$this->loadFixtures('Post');
|
||||
|
||||
Mock::generate('DboSource', 'MockTransactionDboSource');
|
||||
|
@ -3062,6 +3062,44 @@ class ModelWriteTest extends BaseModelTest {
|
|||
$Post->saveAll($data, array('atomic' => true));
|
||||
}
|
||||
|
||||
/**
|
||||
* test saveAll with transactions and ensure there is no missing rollback.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testSaveAllAssociatedTransactionNoRollback() {
|
||||
$testDb = ConnectionManager::getDataSource('test_suite');
|
||||
|
||||
Mock::generate('DboSource', 'MockTransactionAssociatedDboSource');
|
||||
$db = ConnectionManager::create('mock_transaction_assoc', array(
|
||||
'datasource' => 'MockTransactionAssociatedDbo',
|
||||
));
|
||||
$db->columns = $testDb->columns;
|
||||
|
||||
$db->expectOnce('rollback');
|
||||
|
||||
$Post =& new Post();
|
||||
$Post->useDbConfig = 'mock_transaction_assoc';
|
||||
$Post->Author->useDbConfig = 'mock_transaction_assoc';
|
||||
|
||||
$Post->Author->validate = array(
|
||||
'user' => array('rule' => array('notEmpty'))
|
||||
);
|
||||
|
||||
$data = array(
|
||||
'Post' => array(
|
||||
'title' => 'New post',
|
||||
'body' => 'Content',
|
||||
'published' => 'Y'
|
||||
),
|
||||
'Author' => array(
|
||||
'user' => '',
|
||||
'password' => "sekret"
|
||||
)
|
||||
);
|
||||
$Post->saveAll($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* testSaveAllTransaction method
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue