public function rescale_grades_keep_percentage($oldgrademin, $oldgrademax, $newgrademin, $newgrademax, $source = null) {
        global $DB;

        if (empty($this->id)) {
            return false;
        }

        if ($oldgrademax <= $oldgrademin) {
            // Grades cannot be scaled.
            return false;
        }
        $scale = ($newgrademax - $newgrademin) / ($oldgrademax - $oldgrademin);
        if (($newgrademax - $newgrademin) <= 1) {
            // We would lose too much precision, lets bail.
            return false;
        }

        $rs = $DB->get_recordset('grade_grades', array('itemid' => $this->id));

        foreach ($rs as $graderecord) {
            // For each record, create an object to work on.
            $grade = new grade_grade($graderecord, false);
            // Set this object in the item so it doesn't re-fetch it.
            $grade->grade_item = $this;

            if (!$this->is_category_item() || ($this->is_category_item() && $grade->is_overridden())) {
                // Updating the raw grade automatically updates the min/max.
                if ($this->is_raw_used()) {
                    $rawgrade = (($grade->rawgrade - $oldgrademin) * $scale) + $newgrademin;
                    $this->update_raw_grade(false, $rawgrade, $source, false, FORMAT_MOODLE, null, null, null, $grade);
                } else {
                    $finalgrade = (($grade->finalgrade - $oldgrademin) * $scale) + $newgrademin;
                    $this->update_final_grade($grade->userid, $finalgrade, $source);
                }
            }
        }
        $rs->close();

        // Mark this item for regrading.
        $this->force_regrading();

        return true;
    }