CommonDBTM::updateInDB PHP Method

updateInDB() public method

Update the item in the database
public updateInDB ( $updates, $oldvalues = [] ) : nothing
$updates fields to update
$oldvalues array of old values of the updated fields
return nothing
    function updateInDB($updates, $oldvalues = array())
    {
        global $DB, $CFG_GLPI;
        foreach ($updates as $field) {
            if (isset($this->fields[$field])) {
                $query = "UPDATE `" . $this->getTable() . "`\n                       SET `" . $field . "`";
                if ($this->fields[$field] == "NULL") {
                    $query .= " = " . $this->fields[$field];
                } else {
                    $query .= " = '" . $this->fields[$field] . "'";
                }
                $query .= " WHERE `id` ='" . $this->fields["id"] . "'";
                if (!$DB->query($query)) {
                    if (isset($oldvalues[$field])) {
                        unset($oldvalues[$field]);
                    }
                }
            } else {
                // Clean oldvalues
                if (isset($oldvalues[$field])) {
                    unset($oldvalues[$field]);
                }
            }
        }
        if (count($oldvalues) && isset($_SESSION['glpiactiveentities_string'])) {
            Log::constructHistory($this, $oldvalues, $this->fields);
        }
        return true;
    }
CommonDBTM