mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Adding Model::saveAll() atomic fix, closes #4400, thanks joelmoss
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6697 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
e46425f759
commit
ed51f78227
1 changed files with 22 additions and 4 deletions
|
@ -1275,7 +1275,9 @@ class Model extends Overloadable {
|
||||||
* saving, 'first' to validate *all* records before any are saved, or 'only' to only
|
* saving, 'first' to validate *all* records before any are saved, or 'only' to only
|
||||||
* validate the records, but not save them.
|
* validate the records, but not save them.
|
||||||
* - atomic: If true (default), will attempt to save all records in a single transaction.
|
* - atomic: If true (default), will attempt to save all records in a single transaction.
|
||||||
* Should be set to false if database/table does not support transactions
|
* Should be set to false if database/table does not support transactions.
|
||||||
|
* If false, we return an array similar to the $data array passed, but values are set to true/false
|
||||||
|
* depending on whether each record saved successfully.
|
||||||
* - fieldList: Equivalent to the $fieldList parameter in Model::save()
|
* - fieldList: Equivalent to the $fieldList parameter in Model::save()
|
||||||
* @return mixed True on success, or false on failure
|
* @return mixed True on success, or false on failure
|
||||||
* @access public
|
* @access public
|
||||||
|
@ -1305,6 +1307,9 @@ class Model extends Overloadable {
|
||||||
$validationErrors[$this->id] = $this->validationErrors;
|
$validationErrors[$this->id] = $this->validationErrors;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!$options['atomic']) {
|
||||||
|
$return[] = $validates;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$this->validationErrors = $validationErrors;
|
$this->validationErrors = $validationErrors;
|
||||||
|
|
||||||
|
@ -1324,7 +1329,7 @@ class Model extends Overloadable {
|
||||||
$db->rollback($this);
|
$db->rollback($this);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return $validates;
|
return $return;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1343,6 +1348,9 @@ class Model extends Overloadable {
|
||||||
$validationErrors[$association] = $this->{$association}->validationErrors;
|
$validationErrors[$association] = $this->{$association}->validationErrors;
|
||||||
$validates = false;
|
$validates = false;
|
||||||
}
|
}
|
||||||
|
if (!$options['atomic']) {
|
||||||
|
$return[$association][] = $validates;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1351,6 +1359,9 @@ class Model extends Overloadable {
|
||||||
$validationErrors[$this->alias] = $this->validationErrors;
|
$validationErrors[$this->alias] = $this->validationErrors;
|
||||||
$validates = false;
|
$validates = false;
|
||||||
}
|
}
|
||||||
|
if (!$options['atomic']) {
|
||||||
|
$return[$this->alias][] = $validates;
|
||||||
|
}
|
||||||
foreach ($data as $association => $values) {
|
foreach ($data as $association => $values) {
|
||||||
if (isset($associations[$association])) {
|
if (isset($associations[$association])) {
|
||||||
$type = $associations[$association];
|
$type = $associations[$association];
|
||||||
|
@ -1361,15 +1372,22 @@ class Model extends Overloadable {
|
||||||
$validationErrors[$association] = $this->{$association}->validationErrors;
|
$validationErrors[$association] = $this->{$association}->validationErrors;
|
||||||
$validates = false;
|
$validates = false;
|
||||||
}
|
}
|
||||||
|
if (!$options['atomic']) {
|
||||||
|
$return[$association][] = $validates;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'hasMany':
|
case 'hasMany':
|
||||||
foreach ($values as $i => $value) {
|
foreach ($values as $i => $value) {
|
||||||
$values[$i][$this->{$type}[$association]['foreignKey']] = $this->id;
|
$values[$i][$this->{$type}[$association]['foreignKey']] = $this->id;
|
||||||
}
|
}
|
||||||
if (!$this->{$association}->saveAll($values, array_merge($options, array('atomic' => false)))) {
|
$_return = $this->{$association}->saveAll($values, array_merge($options, array('atomic' => false)));
|
||||||
|
if (in_array(false, $_return)) {
|
||||||
$validationErrors[$association] = $this->{$association}->validationErrors;
|
$validationErrors[$association] = $this->{$association}->validationErrors;
|
||||||
$validates = false;
|
$validates = false;
|
||||||
}
|
}
|
||||||
|
foreach ($_return as $val) {
|
||||||
|
$return[$association][] = $val;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1392,7 +1410,7 @@ class Model extends Overloadable {
|
||||||
$db->rollback($this);
|
$db->rollback($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $validates;
|
return $return;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue