mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 01:16:44 +02:00
MDL-10103 grade_object:insert() now fetches the fresh data from db and updates itself; update_from_db() now uses the same process as new grade_object() for consistency
This commit is contained in:
parent
7bb11c76d1
commit
9b7e5a3772
2 changed files with 19 additions and 10 deletions
|
@ -697,7 +697,6 @@ class grade_category extends grade_object {
|
|||
$grade_item->courseid = $this->courseid;
|
||||
$grade_item->itemtype = 'category';
|
||||
$grade_item->insert();
|
||||
$grade_item->update_from_db();
|
||||
}
|
||||
|
||||
return $grade_item;
|
||||
|
|
|
@ -102,6 +102,8 @@ class grade_object {
|
|||
|
||||
/**
|
||||
* Records this object in the Database, sets its id to the returned value, and returns that value.
|
||||
* If successful this function also fetches the new object data from database and stores it
|
||||
* in object properties.
|
||||
* @return int PK ID if successful, false otherwise
|
||||
*/
|
||||
function insert() {
|
||||
|
@ -127,7 +129,15 @@ class grade_object {
|
|||
}
|
||||
}
|
||||
|
||||
return $this->id = insert_record($this->table, addslashes_recursive($clonethis), true);
|
||||
if (!$this->id = insert_record($this->table, addslashes_recursive($clonethis), true)) {
|
||||
debugging("Could not insert object into db");
|
||||
return false;
|
||||
}
|
||||
|
||||
// set all object properties from real db data
|
||||
$this->update_from_db();
|
||||
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -140,15 +150,15 @@ class grade_object {
|
|||
if (empty($this->id)) {
|
||||
debugging("The object could not be used in its state to retrieve a matching record from the DB, because its id field is not set.");
|
||||
return false;
|
||||
} else {
|
||||
$class = get_class($this);
|
||||
$object = new $class(array('id' => $this->id));
|
||||
foreach ($object as $var => $val) {
|
||||
if (!in_array($var, $this->nonfields) && $this->$var != $val) {
|
||||
$this->$var = $val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$params = get_record($this->table, 'id', $this->id)) {
|
||||
debugging("Object with this id does not exist, can not update from db!");
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->assign_to_this($params);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue