[rt-users] Custom RT2 addition and record.pm
Forrest Stanley
fstanley at netburner.com
Wed Jul 2 17:15:58 EDT 2003
Hello group,
I have been working on a custom modification to add a serial number system
to RT. I have created a page in the self service html directory which
manages these serial numbers. I also created SerialNumber.pm and
corresponding SerialNumber table in mysql which holds all the creation
information for the numbers. Using these, I am able to add records to the
database containing Number, Owner, ExpDate, SptExpiration, Disabled. Now
the problem comes in displaying these records on the webpage. I keep
getting unimplemented package error when I try to read a single variable
from a record (ie owner or serialnumber). Now, in User, i was able to just
do something along the lines of <%$myUser->RealName%> to print out the
RealName in html on the website. I am trying to use the same format (ie
<%$mySn->Number%>. This is when I get the error. Now, I believe I set up
SerialNumber.pm correctly, and I was under the impression that _Accessible
was what allowed me to read records and print them out. Any clues or ideas
as to what may be the cause of the error in my program? I am guessing that
I somehow skipped a minor step in setting up the addon, hopefully someone
sees the error.
Here is a snippet of files involved in the process. (ill try to condense
the files to parts only meaningful for this question)
-8<---------- Error msg generated
error: RT::SerialNumber::Owner Unimplemented in HTML::Mason::Commands.
(/opt/rt2/WebRT/html/SelfService/Elements/DisplaySN line 19)
context:
...
449: else {
450: my ($package, $filename, $line);
451: ($package, $filename, $line) = caller;
452:
453: die "$AUTOLOAD Unimplemented in $package. ($filename line $line) \n";
454: }
455:
456: }
-8<----------
-8<---------- DisplaySN Element
<& /Elements/TitleBoxStart, title => "Your registered products" &>
% my $i = 0;
% while($i < 10) {
% my $SN = new RT::SerialNumber ($session{'CurrentUser'});
% $SN->LoadById($i);
<%$SN->Owner%>
% $i++;
% }
-8<----------
-8<---------- HTML create page
<& /SelfService/Elements/DisplaySN &>
<%init>
my (@actions, $description);
my $SerialNumbers = new RT::SerialNumbers ($session{'CurrentUser'});
if ($NewSN) {
my $NewSerialNumber = new RT::SerialNumber ($session{'CurrentUser'});
$FullSN = join($Product,'',$NewSN);
my ($retval, $msg) = $NewSerialNumber->Create (
Number=>$FullSN,
);
if (defined $retval) {
push @actions, $msg;
}
else {
push @actions, $msg;
}
}
-8<----------------
-8<---------------- SerialNumber.pm
package RT::SerialNumber;
use RT::Date;
use RT::User;
use RT::Record;
use Time::Local;
@ISA = qw(RT::Record);
sub _Init {
my $self = shift;
my $handle = shift;
$self -> _Handle($handle);
$self -> {'table'} = "SerialNumbers";
return($self->SUPER::_Init(@_));
}
sub _Accessible {
my $self = shift;
my %cols = (
Number => 'read/write',
Owner => 'read/auto',
DateEntered => 'read/write',
SptExpires => 'read/write',
UpdExpires => 'read/write',
Disabled => 'read/write'
);
return $self->SUPER::_Accessible(@_, %Cols);
}
sub Create {
my $self = shift;
my %args = (@_);
my $curr_time = RT::Date->new($self->CurrentUser);
$curr_time->SetToNow();
$args{'DateEntered'} = $curr_time->ISO;
my $sptexp_time = RT::Date->new($self->CurrentUser);
$sptexp_time->SetToNow();
$sptexp_time->AddDays(90);
$args{'SptExpires'} = $sptexp_time->ISO;
my $updexp_time = RT::Date->new($self->CurrentUser);
$updexp_time->SetToNow();
$updexp_time->AddDays(365);
$args{'UpdExpires'} = $updexp_time->ISO;
$args{'Owner'} = $self->CurrentUser->Id;
$args{'Disabled'} = 0;
unless ( system ("/opt/rt2/bin/testserial $args{'Number'}") ==
"0" ) {
return (0,'Invalid Serial Number'); }
unless ( $self->ValidateNumber($args{'Number'} ) ) {
return (0,'Serial Number already in use'); }
unless (defined($args{'Number'})) {
return (0,'Must specify a Serial Number'); }
my $id = $self->SUPER::Create(%args);
unless($id) {
return (0,'Could not add Serial Number'); }
return($id, 'Serial Number added');
}
-8<----------------
-8<---------------- MYSQL output
mysql> describe SerialNumbers;
+-------------+---------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+---------------+------+-----+---------+----------------+
| id | int(11) | | PRI | NULL | auto_increment |
| Number | varchar(30) | | UNI | | |
| Owner | int(11) | YES | | NULL | |
| DateEntered | timestamp(14) | YES | | NULL | |
| SptExpires | timestamp(14) | YES | | NULL | |
| UpdExpires | timestamp(14) | YES | | NULL | |
| Disabled | smallint(6) | YES | | 0 | |
+-------------+---------------+------+-----+---------+----------------+
7 rows in set (0.00 sec)
mysql> select * from SerialNumbers;
+----+-------+-------+----------------+----------------+----------------+----------+
| id | Number| Owner | DateEntered | SptExpires | UpdExpires |
Disabled |
+----+-------+-------+----------------+----------------+----------------+----------+
| 5 | xxxxx | 34 | 20030630180325 | 20030928180325 | 20040629180325
| 0 |
+----+-------+-------+----------------+----------------+----------------+----------+
1 row in set (0.00 sec)
More information about the rt-users
mailing list