public static function delete_customfields_data(approved_contextlist $contextlist, string $component, string $area,
            string $itemidstest = 'IS NOT NULL', string $instanceidstest = 'IS NOT NULL', array $params = []) {
        global $DB;

        list($contextidstest, $contextparams) = $DB->get_in_or_equal($contextlist->get_contextids(), SQL_PARAMS_NAMED, 'cfctx');
        $sql = "SELECT d.id
            FROM {customfield_category} c
            JOIN {customfield_field} f ON f.categoryid = c.id
            JOIN {customfield_data} d ON d.fieldid = f.id AND d.instanceid $instanceidstest AND d.contextid $contextidstest
            WHERE c.component = :cfcomponent AND c.area = :cfarea AND c.itemid $itemidstest";
        $params = self::get_params($component, $area, $params) + $contextparams;

        self::before_delete_data('IN (' . $sql . ') ', $params);

        $DB->execute("DELETE FROM {customfield_data}
            WHERE instanceid $instanceidstest
            AND contextid $contextidstest
            AND fieldid IN (SELECT f.id
                FROM {customfield_category} c
                JOIN {customfield_field} f ON f.categoryid = c.id
                WHERE c.component = :cfcomponent AND c.area = :cfarea AND c.itemid $itemidstest)", $params);
    }