Skip to content

Commit

Permalink
Fixing Model::saveAll() PHP4 compatibility. Minor API change in __sav…
Browse files Browse the repository at this point in the history
…e(). __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
  • Loading branch information
markstory committed Jun 27, 2009
1 parent 285fdc2 commit 6a34c9e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
14 changes: 7 additions & 7 deletions cake/libs/model/model.php
Expand Up @@ -1475,7 +1475,7 @@ function saveAll($data = null, $options = array()) {
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;
}

Expand Down Expand Up @@ -1528,7 +1528,7 @@ function saveAll($data = null, $options = array()) {
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;
Expand All @@ -1541,7 +1541,7 @@ function saveAll($data = null, $options = array()) {
}
}
}
if (!$this->__save($this, $data, $options)) {
if (!$this->__save($data, $options)) {
$validationErrors[$this->alias] = $this->validationErrors;
$validates = false;
}
Expand All @@ -1559,7 +1559,7 @@ function saveAll($data = null, $options = array()) {
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;
}
Expand Down Expand Up @@ -1632,12 +1632,12 @@ function saveAll($data = null, $options = array()) {
* @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;
Expand Down
1 change: 1 addition & 0 deletions cake/tests/cases/libs/model/models.php
Expand Up @@ -1864,6 +1864,7 @@ function customValidationMethod($data) {
*/
function customValidatorWithParams($data, $validator, $or = true, $ignore_on_same = 'id') {
$this->validatorParams = get_defined_vars();
unset($this->validatorParams['this']);
return true;
}
/**
Expand Down

0 comments on commit 6a34c9e

Please sign in to comment.