public function updateBeanFields(\SugarBean $sugarBean, array $fields)
    {
        $changedValues = 0;
        $nonEmptyFields = array('date_entered');
        $moduleFields = $this->getModuleFields($sugarBean->module_name);
        $moduleRels = $this->getModuleRelationships($sugarBean->module_name, 'one');
        foreach ($fields as $field => $value) {
            // It does not exist in Sugar
            if (!array_key_exists($field, $moduleFields) && !array_key_exists($field, $moduleRels)
              && !array_key_exists($field, $sugarBean->field_defs)
            ) {
                $this->getLogger()->error($this->logPrefix . "$field doesn't seem to exist in Sugar");
            }

            // Field value and new value are the same
            // or I ignore empty values
            if ((isset($sugarBean->$field) && $sugarBean->$field == htmlspecialchars($value, ENT_QUOTES))
              || (in_array($field, $nonEmptyFields) && empty($value))) {
                $this->getLogger()->debug($this->logPrefix . "Skipping $field, values are same or value is empty");
                continue;
            }

            // force the update of some fields
            if ($field === 'date_modified') {
                $sugarBean->update_date_modified = false;
            }
            if ($field === 'created_by') {
                $sugarBean->set_created_by = false;
            }
            if ($field === 'modified_user_id') {
                $sugarBean->update_modified_by = false;
            }

            $sugarBean->$field = $value;
            $this->getLogger()->debug($this->logPrefix . "Saving $field, value has changed");
            $changedValues++;
        }

        return $changedValues;
    }