mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Refactoring Model::save() and adding $created parameter to afterSave()
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4465 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
194e9e09b1
commit
76548b0aad
1 changed files with 23 additions and 28 deletions
|
@ -1063,6 +1063,8 @@ class Model extends Overloadable {
|
||||||
if (!$exists) {
|
if (!$exists) {
|
||||||
$this->id = false;
|
$this->id = false;
|
||||||
}
|
}
|
||||||
|
$success = false;
|
||||||
|
$created = false;
|
||||||
|
|
||||||
if (count($fields)) {
|
if (count($fields)) {
|
||||||
if (!empty($this->id)) {
|
if (!empty($this->id)) {
|
||||||
|
@ -1070,13 +1072,7 @@ class Model extends Overloadable {
|
||||||
if (!empty($joined)) {
|
if (!empty($joined)) {
|
||||||
$this->__saveMulti($joined, $this->id);
|
$this->__saveMulti($joined, $this->id);
|
||||||
}
|
}
|
||||||
|
$success = true;
|
||||||
$this->afterSave();
|
|
||||||
$this->data = false;
|
|
||||||
$this->_clearCache();
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ($db->create($this, $fields, $values)) {
|
if ($db->create($this, $fields, $values)) {
|
||||||
|
@ -1085,7 +1081,7 @@ class Model extends Overloadable {
|
||||||
foreach ($this->belongsTo as $parent => $assoc) {
|
foreach ($this->belongsTo as $parent => $assoc) {
|
||||||
if (isset($assoc['counterCache']) && !empty($assoc['counterCache'])) {
|
if (isset($assoc['counterCache']) && !empty($assoc['counterCache'])) {
|
||||||
$parentObj =& $this->{$assoc['className']};
|
$parentObj =& $this->{$assoc['className']};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1093,26 +1089,26 @@ class Model extends Overloadable {
|
||||||
if (!empty($joined)) {
|
if (!empty($joined)) {
|
||||||
$this->__saveMulti($joined, $this->id);
|
$this->__saveMulti($joined, $this->id);
|
||||||
}
|
}
|
||||||
|
$success = $created = true;
|
||||||
if (!empty($this->behaviors)) {
|
|
||||||
$behaviors = array_keys($this->behaviors);
|
|
||||||
$ct = count($behaviors);
|
|
||||||
for ($i = 0; $i < $ct; $i++) {
|
|
||||||
$this->behaviors[$behaviors[$i]]->afterSave($this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$this->afterSave();
|
|
||||||
$this->data = false;
|
|
||||||
$this->_clearCache();
|
|
||||||
$this->validationErrors = array();
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return false;
|
if ($success) {
|
||||||
|
if (!empty($this->behaviors)) {
|
||||||
|
$behaviors = array_keys($this->behaviors);
|
||||||
|
$ct = count($behaviors);
|
||||||
|
for ($i = 0; $i < $ct; $i++) {
|
||||||
|
$this->behaviors[$behaviors[$i]]->afterSave($this, $created);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->afterSave($created);
|
||||||
|
$this->data = false;
|
||||||
|
$this->_clearCache();
|
||||||
|
$this->validationErrors = array();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return $success;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Saves model hasAndBelongsToMany data to the database.
|
* Saves model hasAndBelongsToMany data to the database.
|
||||||
|
@ -1994,10 +1990,10 @@ class Model extends Overloadable {
|
||||||
/**
|
/**
|
||||||
* After save callback
|
* After save callback
|
||||||
*
|
*
|
||||||
|
* @param boolean $created True if this save created a new record
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function afterSave() {
|
function afterSave($created) {
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Before delete callback
|
* Before delete callback
|
||||||
|
@ -2013,7 +2009,6 @@ class Model extends Overloadable {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function afterDelete() {
|
function afterDelete() {
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Before validate callback
|
* Before validate callback
|
||||||
|
|
Loading…
Reference in a new issue