mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Fixes #4467, issue with 'atomic' on saveAll not properly rolling back transaction. Thanks amit for the test.
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6702 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
b7774103f8
commit
d412d7094f
2 changed files with 91 additions and 34 deletions
|
@ -1309,6 +1309,8 @@ class Model extends Overloadable {
|
|||
}
|
||||
if (!$options['atomic']) {
|
||||
$return[] = $validates;
|
||||
} elseif (!$validates) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->validationErrors = $validationErrors;
|
||||
|
|
|
@ -2139,6 +2139,61 @@ class ModelTest extends CakeTestCase {
|
|||
$this->assertEqual(Set::extract($result['Comment'], '{n}.comment'), $expected);
|
||||
}
|
||||
|
||||
function testSaveAllTransaction() {
|
||||
$this->loadFixtures('Post', 'Author', 'Comment', 'Attachment');
|
||||
$this->model =& new Post();
|
||||
|
||||
$this->model->validate = array('title' => VALID_NOT_EMPTY);
|
||||
$data = array(
|
||||
array('author_id' => 1, 'title' => 'New Fourth Post'),
|
||||
array('author_id' => 1, 'title' => 'New Fifth Post'),
|
||||
array('author_id' => 1, 'title' => '')
|
||||
);
|
||||
$this->assertFalse($this->model->saveAll($data));
|
||||
|
||||
$result = $this->model->find('all', array('recursive' => -1));
|
||||
$expected = array(
|
||||
array('Post' => array('id' => '1', 'author_id' => 1, 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31')),
|
||||
array('Post' => array('id' => '2', 'author_id' => 3, 'title' => 'Second Post', 'body' => 'Second Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31')),
|
||||
array('Post' => array('id' => '3', 'author_id' => 1, 'title' => 'Third Post', 'body' => 'Third Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'))
|
||||
);
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$data = array(
|
||||
array('author_id' => 1, 'title' => 'New Fourth Post'),
|
||||
array('author_id' => 1, 'title' => ''),
|
||||
array('author_id' => 1, 'title' => 'New Sixth Post')
|
||||
);
|
||||
$this->assertFalse($this->model->saveAll($data));
|
||||
|
||||
$result = $this->model->find('all', array('recursive' => -1));
|
||||
$expected = array(
|
||||
array('Post' => array('id' => '1', 'author_id' => 1, 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31')),
|
||||
array('Post' => array('id' => '2', 'author_id' => 3, 'title' => 'Second Post', 'body' => 'Second Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31')),
|
||||
array('Post' => array('id' => '3', 'author_id' => 1, 'title' => 'Third Post', 'body' => 'Third Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'))
|
||||
);
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$this->model->validate = array('title' => VALID_NOT_EMPTY);
|
||||
$data = array(
|
||||
array('author_id' => 1, 'title' => 'New Fourth Post'),
|
||||
array('author_id' => 1, 'title' => 'New Fifth Post'),
|
||||
array('author_id' => 1, 'title' => 'New Sixth Post')
|
||||
);
|
||||
$this->assertTrue($this->model->saveAll($data));
|
||||
|
||||
$result = $this->model->find('all', array('recursive' => -1, 'fields' => array('author_id', 'title','body','published')));
|
||||
$expected = array(
|
||||
array('Post' => array('author_id' => 1, 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y')),
|
||||
array('Post' => array('author_id' => 3, 'title' => 'Second Post', 'body' => 'Second Post Body', 'published' => 'Y')),
|
||||
array('Post' => array('author_id' => 1, 'title' => 'Third Post', 'body' => 'Third Post Body', 'published' => 'Y')),
|
||||
array('Post' => array('author_id' => 1, 'title' => 'New Fourth Post', 'body' => '', 'published' => 'N')),
|
||||
array('Post' => array('author_id' => 1, 'title' => 'New Fifth Post', 'body' => '', 'published' => 'N')),
|
||||
array('Post' => array('author_id' => 1, 'title' => 'New Sixth Post', 'body' => '', 'published' => 'N'))
|
||||
);
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
function testSaveAllValidation() {
|
||||
$this->loadFixtures('Post', 'Author', 'Comment', 'Attachment');
|
||||
$this->model =& new Post();
|
||||
|
|
Loading…
Add table
Reference in a new issue