From 6a34c9ef3152b442dc2d24babcbfefeb1eb8dc51 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 27 Jun 2009 15:25:07 +0000 Subject: [PATCH] Fixing Model::saveAll() PHP4 compatibility. Minor API change in __save(). __save() no longer takes a model instance as the first parameter. Because of Model implementation details in PHP4 this caused broken references. Fixes #6389, #6223 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8204 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/model/model.php | 14 +++++++------- cake/tests/cases/libs/model/models.php | 1 + 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index c18d035e0..102041086 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -1475,7 +1475,7 @@ class Model extends Overloadable { if (Set::numeric(array_keys($data))) { while ($validates) { foreach ($data as $key => $record) { - if (!$currentValidates = $this->__save($this, $record, $options)) { + if (!$currentValidates = $this->__save($record, $options)) { $validationErrors[$key] = $this->validationErrors; } @@ -1528,7 +1528,7 @@ class Model extends Overloadable { if (isset($associations[$association])) { switch ($associations[$association]) { case 'belongsTo': - if ($this->__save($this->{$association}, $values, $options)) { + if ($this->{$association}->__save($values, $options)) { $data[$this->alias][$this->belongsTo[$association]['foreignKey']] = $this->{$association}->id; } else { $validationErrors[$association] = $this->{$association}->validationErrors; @@ -1541,7 +1541,7 @@ class Model extends Overloadable { } } } - if (!$this->__save($this, $data, $options)) { + if (!$this->__save($data, $options)) { $validationErrors[$this->alias] = $this->validationErrors; $validates = false; } @@ -1559,7 +1559,7 @@ class Model extends Overloadable { switch ($type) { case 'hasOne': $values[$this->{$type}[$association]['foreignKey']] = $this->id; - if (!$this->__save($this->{$association}, $values, $options)) { + if (!$this->{$association}->__save($values, $options)) { $validationErrors[$association] = $this->{$association}->validationErrors; $validates = false; } @@ -1632,12 +1632,12 @@ class Model extends Overloadable { * @access private * @see Model::saveAll() */ - function __save(&$model, $data, $options) { + function __save($data, $options) { if ($options['validate'] === 'first' || $options['validate'] === 'only') { - if (!($model->create($data) && $model->validates($options))) { + if (!($this->create($data) && $this->validates($options))) { return false; } - } elseif (!($model->create(null) !== null && $model->save($data, $options))) { + } elseif (!($this->create(null) !== null && $this->save($data, $options))) { return false; } return true; diff --git a/cake/tests/cases/libs/model/models.php b/cake/tests/cases/libs/model/models.php index 620d2c71b..20e5b6ba1 100644 --- a/cake/tests/cases/libs/model/models.php +++ b/cake/tests/cases/libs/model/models.php @@ -1864,6 +1864,7 @@ class ValidationTest1 extends CakeTestModel { */ function customValidatorWithParams($data, $validator, $or = true, $ignore_on_same = 'id') { $this->validatorParams = get_defined_vars(); + unset($this->validatorParams['this']); return true; } /**