protected static function delete_categories(array $contextids, array $categoriesids) {
        global $DB;

        if (!$categoriesids) {
            return;
        }

        list($categoryidstest, $catparams) = $DB->get_in_or_equal($categoriesids, SQL_PARAMS_NAMED, 'cfcat');
        $datasql = "SELECT d.id FROM {customfield_data} d JOIN {customfield_field} f ON f.id = d.fieldid " .
            "WHERE f.categoryid $categoryidstest";
        $fieldsql = "SELECT f.id AS fieldid FROM {customfield_field} f WHERE f.categoryid $categoryidstest";

        self::before_delete_data("IN ($datasql)", $catparams);
        self::before_delete_fields($categoryidstest, $catparams);

        $DB->execute('DELETE FROM {customfield_data} WHERE fieldid IN (' . $fieldsql . ')', $catparams);
        $DB->execute("DELETE FROM {customfield_field} WHERE categoryid $categoryidstest", $catparams);
        $DB->execute("DELETE FROM {customfield_category} WHERE id $categoryidstest", $catparams);

    }