mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Removing continue statement that did nothing.
Adding a rollback for when validation fails and atomic has been set. Tests added. Fixes #797
This commit is contained in:
parent
bca3c4ab38
commit
ad8b70cec2
2 changed files with 32 additions and 1 deletions
|
@ -1622,7 +1622,6 @@ class Model extends Overloadable {
|
||||||
case ($options['validate'] === 'first'):
|
case ($options['validate'] === 'first'):
|
||||||
$options['validate'] = true;
|
$options['validate'] = true;
|
||||||
$return = array();
|
$return = array();
|
||||||
continue;
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if ($options['atomic']) {
|
if ($options['atomic']) {
|
||||||
|
@ -1636,6 +1635,10 @@ class Model extends Overloadable {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ($options['atomic'] && !$validates) {
|
||||||
|
$db->rollback($this);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
$associations = $this->getAssociated();
|
$associations = $this->getAssociated();
|
||||||
|
|
|
@ -3034,6 +3034,34 @@ class ModelWriteTest extends BaseModelTest {
|
||||||
), array('validate' => 'only'));
|
), array('validate' => 'only'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test saveAll with transactions and ensure there is no missing rollback.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testSaveAllTransactionNoRollback() {
|
||||||
|
$this->loadFixtures('Post');
|
||||||
|
|
||||||
|
Mock::generate('DboSource', 'MockTransactionDboSource');
|
||||||
|
$db = ConnectionManager::create('mock_transaction', array(
|
||||||
|
'datasource' => 'MockTransactionDbo',
|
||||||
|
));
|
||||||
|
$db->expectOnce('rollback');
|
||||||
|
|
||||||
|
$Post =& new Post();
|
||||||
|
$Post->useDbConfig = 'mock_transaction';
|
||||||
|
|
||||||
|
$Post->validate = array(
|
||||||
|
'title' => array('rule' => array('notEmpty'))
|
||||||
|
);
|
||||||
|
|
||||||
|
$data = array(
|
||||||
|
array('author_id' => 1, 'title' => 'New Fourth Post'),
|
||||||
|
array('author_id' => 1, 'title' => '')
|
||||||
|
);
|
||||||
|
$Post->saveAll($data, array('atomic' => true));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testSaveAllTransaction method
|
* testSaveAllTransaction method
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue