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); } } } 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. * diff --git a/lib/Cake/Test/Case/Model/ModelWriteTest.php b/lib/Cake/Test/Case/Model/ModelWriteTest.php index 4f9d4bac3..529d62902 100644 --- a/lib/Cake/Test/Case/Model/ModelWriteTest.php +++ b/lib/Cake/Test/Case/Model/ModelWriteTest.php @@ -811,7 +811,7 @@ class ModelWriteTest extends BaseModelTest { /** * test callback used in testSaveTransaction method * - * @return boolean false to stop event propagation + * @return bool false to stop event propagation */ public function callbackForTestSaveTransaction($event) { $TestModel = new Article(); diff --git a/lib/Cake/Utility/Validation.php b/lib/Cake/Utility/Validation.php index dee7bfa14..a2243694d 100644 --- a/lib/Cake/Utility/Validation.php +++ b/lib/Cake/Utility/Validation.php @@ -179,12 +179,12 @@ class Validation { 'maestro' => '/^(?:5020|6\\d{3})\\d{12}$/', 'mc' => '/^5[1-5]\\d{14}$/', 'solo' => '/^(6334[5-9][0-9]|6767[0-9]{2})\\d{10}(\\d{2,3})?$/', - 'switch' => + 'switch' => '/^(?:49(03(0[2-9]|3[5-9])|11(0[1-2]|7[4-9]|8[1-2])|36[0-9]{2})\\d{10}(\\d{2,3})?)|(?:564182\\d{10}(\\d{2,3})?)|(6(3(33[0-4][0-9])|759[0-9]{2})\\d{10}(\\d{2,3})?)$/', 'visa' => '/^4\\d{12}(\\d{3})?$/', 'voyager' => '/^8699[0-9]{11}$/' ), - 'fast' => + 'fast' => '/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6011[0-9]{12}|3(?:0[0-5]|[68][0-9])[0-9]{11}|3[47][0-9]{13})$/' );