public static function get_type_by_typename($typename) {
        global $DB;
        $cache = cache::make('core', 'repositories');
        if (($repositorytype = $cache->get('typename:'. $typename)) === false) {
            $repositorytype = null;
            if ($record = $DB->get_record('repository', array('type' => $typename))) {
                $repositorytype = new repository_type($record->type, (array)get_config($record->type), $record->visible, $record->sortorder);
                $cache->set('typeid:'. $record->id, $repositorytype);
            }
            $cache->set('typename:'. $typename, $repositorytype);
        }
        return $repositorytype;
    }