Skip to content

Commit

Permalink
Fix saving translate records with saveAll()
Browse files Browse the repository at this point in the history
Also fixes issues saving translated data with validation
disabled.  By enabling data backup in beforeSave() and beforeValidate()
the existing behavior is preserved, and the current issue is fixed.

Fixes #2857

Conflicts:

	cake/libs/model/behaviors/translate.php
	cake/tests/cases/libs/model/behaviors/translate.test.php
	cake/tests/fixtures/translated_item_fixture.php
	lib/Cake/Test/Case/Model/models.php
  • Loading branch information
markstory committed May 7, 2012
1 parent a0c9299 commit decd8e1
Show file tree
Hide file tree
Showing 4 changed files with 182 additions and 40 deletions.
30 changes: 28 additions & 2 deletions cake/libs/model/behaviors/translate.php
Expand Up @@ -330,8 +330,35 @@ function afterFind(&$model, $results, $primary) {
* @access public
*/
function beforeValidate(&$model) {
unset($this->runtime[$model->alias]['beforeSave']);
$this->_setRuntimeData($model);
return true;
}

/**
* beforeSave callback.
*
* @param Model $model Model save was called on.
* @return boolean true.
*/
function beforeSave(Model $model) {
$this->_setRuntimeData($model);
return true;
}

/**
* Sets the runtime data.
*
* Used from beforeValidate() and beforeSave() for compatibility issues,
* and to allow translations to be persisted even when validation
* is disabled.
*
* @param Model $model
* @return void
*/
function _setRuntimeData(Model $model) {
$locale = $this->_getLocale($model);
if (empty($locale)) {
if (empty($locale) || isset($this->runtime[$model->alias]['beforeSave'])) {
return true;
}
$fields = array_merge($this->settings[$model->alias], $this->runtime[$model->alias]['fields']);
Expand All @@ -353,7 +380,6 @@ function beforeValidate(&$model) {
}
}
$this->runtime[$model->alias]['beforeSave'] = $tempData;
return true;
}

/**
Expand Down

0 comments on commit decd8e1

Please sign in to comment.