Base-62 Ticket numbers

Hello Frederik Seiffert's modification to the Random.pm module gave me the idea of using base-62 as ticket numbers (chars 0-9, a-z, A-Z) - nice and short, so your subject line is a little less cluttered. For those who find it useful, please find the code attached below. Regards Henry Combrinck Installation procedure: 0. Install the Math::BaseCalc perl module: perl -MCPAN -e shell install Math::BaseCalc 1. Copy/paste code to filename 'RandomBase62.pm'. 2. Copy file RandomBase62.pm to ~/Kernel/System/Ticket/Number/RandomBase62.pm 3. Edit your ~/Kernel/Config.pm to show: #------------------------------------ # $Self->{TicketNumberGenerator} =.... (comment the existing line out) $Self->{TicketNumberGenerator} = 'Kernel::System::Ticket::Number::RandomBase62'; #------------------------------------ # -- # Ticket/Number/RandomBase62.pm - a random Base-62 ticket number generator # Copyright (C) 2004 Henry Combrinck <[EMAIL PROTECTED]> # Based on Martin Edenhofer's Random.pm code. # -- # $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 Base-62 ticket numbers (eg 1gWdgXQ, ...) # # Requires perl module: # - Math::BaseCalc # # -- package Kernel::System::Ticket::Number::RandomBase62; use strict; use Math::BaseCalc; use vars qw($VERSION); $VERSION = '$Revision: 1.0 $'; $VERSION =~ s/^\$.*:\W(.*)\W.+?$/$1/; sub CreateTicketNr { my $Self = shift; my $b62 = new Math::BaseCalc(digits=>[0..9,'a'..'z','A'..'Z']); # get needed config options my $SystemID = $Self->{ConfigObject}->Get('SystemID'); # random counter my $Count = int(rand(0xFFFFFFFF)); # convert to base-62 $Count = $b62->to_base($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}!". " Stopped 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-fA-F]{8,40})-FW/i) { return $1; } else { if ($String =~ /$TicketHook:+.{0,1}($SystemID[0-9a-fA-F]{8,40})/i) { return $1; } else { return; } } } # -- 1; -------------------------------------------------------- This message was sent using MetroWEB's AirMail service. http://www.metroweb.co.za/ - full access for only R73. Free Web Accelerator, WebMail, Calendar, Anti-Virus, Anti-Spam, 10 emails, 100MB personal webspace, and more! Phone Now! 086 11 11 440
participants (1)
-
Henry Combrinck