Hello!

We're currently using the DateChecksum module to generate ticket numbers, but I always felt that the numbers are way too long. As I don't see any reason for the date or the checksum in the ticket number, I changed the Random module to generate random _hex_ numbers, 8 digits long (plus system ID).

Before configuring our system to use the new module, I just wanted to ask if there are any potential problems here. I've written the GetTNByString sub to recognize old numbers generated by the DateChecksum module, as we want to change the module in a live system.

I've attached my module in case anyone finds it interesting. Feel free to use it.

Thanks,
Frederik
# --
# Ticket/Number/RandomHex.pm - a ticket number random hex generator
# Copyright (C) 2004 Frederik Seiffert <[EMAIL PROTECTED]>
# --
# $Id: $
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (GPL). If you
# did not receive this file, see http://www.gnu.org/licenses/gpl.txt.
# --
# Note: 
# available objects are: ConfigObject, LogObject and DBObject
# 
# Generates random hex ticket numbers like ss.... (e. g. 10E375A03D, 10D6858736, ...)
# --
 
package Kernel::System::Ticket::Number::RandomHex;

use strict;

use vars qw($VERSION);
$VERSION = '$Revision: 1.0 $';
$VERSION =~ s/^\$.*:\W(.*)\W.+?$/$1/;

sub CreateTicketNr {
    my $Self = shift;
    # get needed config options 
    my $SystemID = $Self->{ConfigObject}->Get('SystemID');
    # random counter
    my $Count = int(rand(0xFFFFFFFF));
    # make hex
        $Count = sprintf("%X", $Count);
    # fill up
    while (length($Count) < 8) {
        $Count = "0$Count";
    }
    # create new ticket number
    my $Tn = $SystemID.$Count;
    # Check ticket number. If exists generate new one! 
    if ($Self->CheckTicketNr(Tn=>$Tn)) {
        $Self->{LoopProtectionCounter}++;
        if ($Self->{LoopProtectionCounter} >= 1000) {
          # loop protection
          $Self->{LogObject}->Log(
            Priority => 'error',
            Message => "CounterLoopProtection is now $Self->{LoopProtectionCounter}!".
                   " Stoped CreateTicketNr()!",
          );
          return;
        }
        # create new ticket number again
        $Self->{LogObject}->Log(
          Priority => 'notice',
          Message => "Tn ($Tn) exists! Creating new one.",
        );
        $Tn = $Self->CreateTicketNr();
    }
    return $Tn;
}
# --
sub GetTNByString {
    my $Self = shift;
    my $String = shift || return;
    # get needed config options 
    my $SystemID = $Self->{ConfigObject}->Get('SystemID');
    my $TicketHook = $Self->{ConfigObject}->Get('TicketHook');
    # check ticket number
    if ($String =~ /$TicketHook:+.{0,1}($SystemID[0-9a-f]{8,40})-FW/i) {
        return $1;
    }
    else {
        if ($String =~ /$TicketHook:+.{0,1}($SystemID[0-9a-f]{8,40})/i) {
            return $1;
        }
        else {
            return;
        }
    }
}
# --
1;
_______________________________________________
OTRS mailing list: otrs - Webpage: http://otrs.org/
Archive: http://lists.otrs.org/pipermail/otrs
To unsubscribe: http://lists.otrs.org/cgi-bin/listinfo/otrs
Support oder Consulting für Ihr OTRS System?
=> http://www.otrs.de/

Reply via email to