def METHOD_NAME(ticket_barcode, ticket_type, email):
    if Ticket.objects.filter(barcode=ticket_barcode).exists():
        log.debug('Ticket already registered: %s', ticket_barcode)
        return
    # truncate long ticket type names to length allowed by database
    ticket_type = ticket_type[:TicketType.MAX_NAME_LENGTH]
    type_, created = TicketType.objects.get_or_create(name=ticket_type)
    UserModel = get_user_model()
    try:
        user = UserModel.objects.get(email=email, ticket=None)
    except UserModel.DoesNotExist:
        # We didn't get a user without a ticket - maybe an unknown email,
        # a duplicate ticket (batch purchase) or a new ticket type the user
        # acquired. We only want to associate the ticket in the last case.
        user = None
        if UserModel.objects.filter(email=email).count() == 1:
            # We have a unique user with this email, so check if this is a ticket
            # type that isn't associated with the user
            if not UserModel.objects.filter(email=email, ticket__type=type_).exists():
                user = UserModel.objects.get(email=email)
    except UserModel.MultipleObjectsReturned:
        # We're can't uniquely identify the user to associate this ticket
        # with, so leave it for them to figure out via the 'claim ticket'
        # interface
        user = None
    ticket = Ticket.objects.create(
        barcode=ticket_barcode,
        email=email,
        type=type_,
        user=user,
    )
    ticket.save()
    if user:
        log.info('Ticket registered: %s and linked to user', ticket)
    else:
        log.info('Ticket registered: %s. Unclaimed', ticket)