Permalink
Browse files

Fix saving translate records with saveAll()

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...
1 parent c9e59c3 commit 8334ebebed86a349b3ea4bb6560efa2f26794d3e @markstory markstory committed with lorenzo May 7, 2012
@@ -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']);
@@ -333,7 +360,6 @@ public function beforeValidate(Model $model) {
}
}
$this->runtime[$model->alias]['beforeSave'] = $tempData;
- return true;
}
/**
Oops, something went wrong.

0 comments on commit 8334ebe

Please sign in to comment.