protected static function delete_overrides_for_users(\assign $assign, array $userids = []) {
        global $DB;
        $assignid = $assign->get_instance()->id;

        $usersql = '';
        $params = ['assignid' => $assignid];
        if (!empty($userids)) {
            list($usersql, $userparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED);
            $params = array_merge($params, $userparams);
            $overrides = $DB->get_records_select('assign_overrides', "assignid = :assignid AND userid $usersql", $params);
        } else {
            $overrides = $DB->get_records('assign_overrides', $params);
        }
        if (!empty($overrides)) {
            $params = ['modulename' => 'assign', 'instance' => $assignid];
            if (!empty($userids)) {
                $params = array_merge($params, $userparams);
                $DB->delete_records_select('event', "modulename = :modulename AND instance = :instance AND userid $usersql",
                        $params);
                // Setting up for the next query.
                $params = $userparams;
                $usersql = "AND userid $usersql";
            } else {
                $DB->delete_records('event', $params);
                // Setting up for the next query.
                $params = [];
            }
            list($overridesql, $overrideparams) = $DB->get_in_or_equal(array_keys($overrides), SQL_PARAMS_NAMED);
            $params = array_merge($params, $overrideparams);
            $DB->delete_records_select('assign_overrides', "id $overridesql $usersql", $params);
        }
    }