public static function delete_comments_for_users(\core_privacy\local\request\approved_userlist $userlist,
            string $component, string $commentarea = null, int $itemid = null) {
        global $DB;

        $context = $userlist->get_context();
        $params = [
            'contextid' => $context->id,
            'component' => $component,
        ];
        $areasql = '';
        if (isset($commentarea)) {
            $params['commentarea'] = $commentarea;
            $areasql = 'AND commentarea = :commentarea';
        }
        $itemsql = '';
        if (isset($itemid)) {
            $params['itemid'] = $itemid;
            $itemsql = 'AND itemid = :itemid';
        }
        list($insql, $inparams) = $DB->get_in_or_equal($userlist->get_userids(), SQL_PARAMS_NAMED);
        $params += $inparams;

        $select = "contextid = :contextid AND component = :component {$areasql} {$itemsql} AND userid {$insql}";
        $DB->delete_records_select('comments', $select, $params);
    }