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 17a00eb commit 6c5255ac73df0043262782d28ef1409c0aed67cc @markstory markstory committed 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. Retry.

0 comments on commit 6c5255a

Please sign in to comment.