$dataobject in insert_record() and update_record() must be objects.

Added code to detect, fix and debug array situations. Related to MDL-9751.

Merged from MOODLE_18_STABLE
This commit is contained in:
stronk7 2007-08-05 22:40:10 +00:00
parent 11d6ec1355
commit 4a8e7db55e

View File

@ -1327,7 +1327,7 @@ function delete_records_select($table, $select='') {
* @uses $db
* @uses $CFG
* @param string $table The database table to be checked against.
* @param array $dataobject A data object with values for one or more fields in the record
* @param object $dataobject A data object with values for one or more fields in the record
* @param bool $returnid Should the id of the newly created record entry be returned? If this option is not requested then true/false is returned.
* @param string $primarykey The primary key of the table we are inserting into (almost always "id")
*/
@ -1339,6 +1339,12 @@ function insert_record($table, $dataobject, $returnid=true, $primarykey='id') {
return false;
}
/// Check we are handling a proper $dataobject
if (is_array($dataobject)) {
debugging('Warning. Wrong call to insert_record(). $dataobject must be an object. array found instead', DEBUG_DEVELOPER);
$dataobject = (object)$dataobject;
}
/// Temporary hack as part of phasing out all access to obsolete user tables XXX
if (!empty($CFG->rolesactive)) {
if (in_array($table, array('user_students', 'user_teachers', 'user_coursecreators', 'user_admins'))) {
@ -1509,7 +1515,7 @@ function insert_record($table, $dataobject, $returnid=true, $primarykey='id') {
* @uses $CFG
* @uses $db
* @param string $table The database table to be checked against.
* @param array $dataobject An object with contents equal to fieldname=>fieldvalue. Must have an entry for 'id' to map to the table specified.
* @param object $dataobject An object with contents equal to fieldname=>fieldvalue. Must have an entry for 'id' to map to the table specified.
* @return bool
*/
function update_record($table, $dataobject) {
@ -1520,6 +1526,12 @@ function update_record($table, $dataobject) {
return false;
}
/// Check we are handling a proper $dataobject
if (is_array($dataobject)) {
debugging('Warning. Wrong call to update_record(). $dataobject must be an object. array found instead', DEBUG_DEVELOPER);
$dataobject = (object)$dataobject;
}
// Remove this record from record cache since it will change
if ($CFG->rcache === true) {
rcache_unset($table, $dataobject->id);