MDL-57859 persistent: Add a combined create/update call

This commit is contained in:
Eric Merrill
2017-02-13 22:33:42 -05:00
parent f99313477d
commit 75e74407a3
2 changed files with 47 additions and 0 deletions
+16
View File
@@ -561,6 +561,22 @@ abstract class persistent {
protected function after_update($result) {
}
/**
* Saves the record to the database.
*
* If this record has an ID, then {@link self::update()} is called, otherwise {@link self::create()} is called.
* Before and after hooks for create() or update() will be called appropriately.
*
* @return void
*/
final public function save() {
if ($this->raw_get('id') <= 0) {
$this->create();
} else {
$this->update();
}
}
/**
* Hook to execute before a delete.
*