public static function update($tagcoll, $data) {
        global $DB;
        $defaulttagcollid = self::get_default();
        $allowedfields = array('name', 'searchable', 'customurl');
        if ($tagcoll->id == $defaulttagcollid) {
            $allowedfields = array('name');
        }

        $updatedata = array();
        $data = (array)$data;
        foreach ($allowedfields as $key) {
            if (array_key_exists($key, $data) && $data[$key] !== $tagcoll->$key) {
                $updatedata[$key] = $data[$key];
            }
        }

        if (!$updatedata) {
            // Nothing to update.
            return false;
        }

        if (isset($updatedata['searchable'])) {
            $updatedata['searchable'] = (int)(bool)$updatedata['searchable'];
        }
        foreach ($updatedata as $key => $value) {
            $tagcoll->$key = $value;
        }
        $updatedata['id'] = $tagcoll->id;
        $DB->update_record('tag_coll', $updatedata);

        // Reset cache.
        cache::make('core', 'tags')->delete('tag_coll');

        \core\event\tag_collection_updated::create_from_record($tagcoll)->trigger();

        return true;
    }