Skip to content
This repository
Browse code

Fixing Model::saveAll() PHP4 compatibility. Minor API change in __sav…

…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...
commit 6a34c9ef3152b442dc2d24babcbfefeb1eb8dc51 1 parent 285fdc2
Mark Story authored June 27, 2009
14  cake/libs/model/model.php
@@ -1475,7 +1475,7 @@ function saveAll($data = null, $options = array()) {
1475 1475
 		if (Set::numeric(array_keys($data))) {
1476 1476
 			while ($validates) {
1477 1477
 				foreach ($data as $key => $record) {
1478  
-					if (!$currentValidates = $this->__save($this, $record, $options)) {
  1478
+					if (!$currentValidates = $this->__save($record, $options)) {
1479 1479
 						$validationErrors[$key] = $this->validationErrors;
1480 1480
 					}
1481 1481
 
@@ -1528,7 +1528,7 @@ function saveAll($data = null, $options = array()) {
1528 1528
 				if (isset($associations[$association])) {
1529 1529
 					switch ($associations[$association]) {
1530 1530
 						case 'belongsTo':
1531  
-							if ($this->__save($this->{$association}, $values, $options)) {
  1531
+							if ($this->{$association}->__save($values, $options)) {
1532 1532
 								$data[$this->alias][$this->belongsTo[$association]['foreignKey']] = $this->{$association}->id;
1533 1533
 							} else {
1534 1534
 								$validationErrors[$association] = $this->{$association}->validationErrors;
@@ -1541,7 +1541,7 @@ function saveAll($data = null, $options = array()) {
1541 1541
 					}
1542 1542
 				}
1543 1543
 			}
1544  
-			if (!$this->__save($this, $data, $options)) {
  1544
+			if (!$this->__save($data, $options)) {
1545 1545
 				$validationErrors[$this->alias] = $this->validationErrors;
1546 1546
 				$validates = false;
1547 1547
 			}
@@ -1559,7 +1559,7 @@ function saveAll($data = null, $options = array()) {
1559 1559
 					switch ($type) {
1560 1560
 						case 'hasOne':
1561 1561
 							$values[$this->{$type}[$association]['foreignKey']] = $this->id;
1562  
-							if (!$this->__save($this->{$association}, $values, $options)) {
  1562
+							if (!$this->{$association}->__save($values, $options)) {
1563 1563
 								$validationErrors[$association] = $this->{$association}->validationErrors;
1564 1564
 								$validates = false;
1565 1565
 							}
@@ -1632,12 +1632,12 @@ function saveAll($data = null, $options = array()) {
1632 1632
  * @access private
1633 1633
  * @see Model::saveAll()
1634 1634
  */
1635  
-	function __save(&$model, $data, $options) {
  1635
+	function __save($data, $options) {
1636 1636
 		if ($options['validate'] === 'first' || $options['validate'] === 'only') {
1637  
-			if (!($model->create($data) && $model->validates($options))) {
  1637
+			if (!($this->create($data) && $this->validates($options))) {
1638 1638
 				return false;
1639 1639
 			}
1640  
-		} elseif (!($model->create(null) !== null && $model->save($data, $options))) {
  1640
+		} elseif (!($this->create(null) !== null && $this->save($data, $options))) {
1641 1641
 			return false;
1642 1642
 		}
1643 1643
 		return true;
1  cake/tests/cases/libs/model/models.php
@@ -1864,6 +1864,7 @@ function customValidationMethod($data) {
1864 1864
  */
1865 1865
 	function customValidatorWithParams($data, $validator, $or = true, $ignore_on_same = 'id') {
1866 1866
 		$this->validatorParams = get_defined_vars();
  1867
+		unset($this->validatorParams['this']);
1867 1868
 		return true;
1868 1869
 	}
1869 1870
 /**

0 notes on commit 6a34c9e

Please sign in to comment.
Something went wrong with that request. Please try again.