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
  • Loading branch information
markstory authored and lorenzo committed May 11, 2012
1 parent c9e59c3 commit 8334ebe
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 40 deletions.
30 changes: 28 additions & 2 deletions lib/Cake/Model/Behavior/TranslateBehavior.php
Expand Up @@ -310,8 +310,35 @@ public function afterFind(Model $model, $results, $primary) {
* @return boolean
*/
public function beforeValidate(Model $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.
*/
public 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
*/
protected 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 @@ -333,7 +360,6 @@ public function beforeValidate(Model $model) {
}
}
$this->runtime[$model->alias]['beforeSave'] = $tempData;
return true;
}

/**
Expand Down

0 comments on commit 8334ebe

Please sign in to comment.