From 1dfd3405a420b6dd25011b036752d0e703eea046 Mon Sep 17 00:00:00 2001 From: Ceeram Date: Fri, 10 Oct 2014 14:17:16 +0200 Subject: [PATCH 1/2] TranslateBehavior now uses original atomic option value, if set --- lib/Cake/Model/Behavior/TranslateBehavior.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Model/Behavior/TranslateBehavior.php b/lib/Cake/Model/Behavior/TranslateBehavior.php index 5ae7b4855..26d86a6dc 100644 --- a/lib/Cake/Model/Behavior/TranslateBehavior.php +++ b/lib/Cake/Model/Behavior/TranslateBehavior.php @@ -437,6 +437,10 @@ class TranslateBehavior extends ModelBehavior { $tempData = $this->_prepareTranslations($Model, $tempData); } $locale = $this->_getLocale($Model); + $atomic = array(); + if (isset($options['atomic'])) { + $atomic = array('atomic' => $options['atomic']); + } foreach ($tempData as $field => $value) { unset($conditions['content']); @@ -466,10 +470,11 @@ class TranslateBehavior extends ModelBehavior { $RuntimeModel->save(array( $RuntimeModel->alias => array_merge( $conditions, array('id' => $translations[$_locale]) - ) + ), + $atomic )); } else { - $RuntimeModel->save(array($RuntimeModel->alias => $conditions)); + $RuntimeModel->save(array($RuntimeModel->alias => $conditions), $atomic); } } } From 12ebf8b427890dd1db1c32c49e087108968b3f1d Mon Sep 17 00:00:00 2001 From: Ceeram Date: Fri, 10 Oct 2014 16:44:01 +0200 Subject: [PATCH 2/2] add test for atmoic save of TranslateBehavior --- .../Model/Behavior/TranslateBehaviorTest.php | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php b/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php index 3cc8b7887..3c1fdfe76 100644 --- a/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php +++ b/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php @@ -719,6 +719,54 @@ class TranslateBehaviorTest extends CakeTestCase { $this->assertCount(2, $result['Content']); } +/** + * testSaveAssociatedAtomic method + * + * @return void + */ + public function testSaveAssociatedAtomic() { + $this->loadFixtures('Translate', 'TranslatedItem'); + + $TestModel = new TranslatedItem(); + $data = array( + 'slug' => 'fourth_translated', + 'title' => array( + 'eng' => 'Title #4' + ), + 'content' => array( + 'eng' => 'Content #4' + ), + 'translated_article_id' => 1, + ); + $Mock = $this->getMockForModel('TranslateTestModel', array('save')); + $TestModel->Behaviors->Translate->runtime[$TestModel->alias]['model'] = $Mock; + + $with = array( + 'TranslateTestModel' => array ( + 'model' => 'TranslatedItem', + 'foreign_key' => '4', + 'field' => 'content', + 'locale' => 'eng', + 'content' => 'Content #4', + ) + ); + $Mock->expects($this->at(0))->method('save')->with($with, array('atomic' => false)); + + $with = array( + 'TranslateTestModel' => array ( + 'model' => 'TranslatedItem', + 'foreign_key' => '4', + 'field' => 'title', + 'locale' => 'eng', + 'content' => 'Title #4', + ) + ); + $Mock->expects($this->at(1))->method('save')->with($with, array('atomic' => false)); + + $TestModel->create(); + $TestModel->saveAssociated($data, array('atomic' => false)); + } + /** * Test that saving only some of the translated fields allows the record to be found again. *