stray closing /TABLE in the no-ticket case
[freeside.git] / FS / FS / access_user_log.pm
1 package FS::access_user_log;
2 use base qw( FS::Record );
3
4 use strict;
5 use FS::UID qw( dbh );
6 #use FS::Record qw( qsearch qsearchs );
7 use FS::CurrentUser;
8
9 =head1 NAME
10
11 FS::access_user_log - Object methods for access_user_log records
12
13 =head1 SYNOPSIS
14
15   use FS::access_user_log;
16
17   $record = new FS::access_user_log \%hash;
18   $record = new FS::access_user_log { 'column' => 'value' };
19
20   $error = $record->insert;
21
22   $error = $new_record->replace($old_record);
23
24   $error = $record->delete;
25
26   $error = $record->check;
27
28 =head1 DESCRIPTION
29
30 An FS::access_user_log object represents a backoffice web server log entry.
31   FS::access_user_log inherits from FS::Record.  The following fields are
32 currently supported:
33
34 =over 4
35
36 =item lognum
37
38 primary key
39
40 =item usernum
41
42 usernum
43
44 =item path
45
46 path
47
48 =item _date
49
50 _date
51
52 =item render_seconds
53
54 =back
55
56 =head1 METHODS
57
58 =over 4
59
60 =item new HASHREF
61
62 Creates a new log entry.  To add the log entry to the database, see L<"insert">.
63
64 Note that this stores the hash reference, not a distinct copy of the hash it
65 points to.  You can ask the object for a copy with the I<hash> method.
66
67 =cut
68
69 sub table { 'access_user_log'; }
70
71 =item insert_new_path PATH
72
73 Adds a log entry for PATH for the current user and timestamp.
74
75 =cut
76
77 sub insert_new_path {
78   my( $class, $path, $render_seconds ) = @_;
79
80   return '' unless defined $FS::CurrentUser::CurrentUser;
81
82   my $self = $class->new( {
83     'usernum'        => $FS::CurrentUser::CurrentUser->usernum,
84     'path'           => $path,
85     '_date'          => time,
86     'render_seconds' => $render_seconds,
87   } );
88
89   #so we can still log pages after a transaction-aborting SQL error (and then
90   # show the # error page)
91   local($FS::UID::dbh) = dbh->clone;
92     #if current transaction is aborted (if we had a way to check for it)
93
94   my $error = $self->insert;
95   die $error if $error;
96
97 }
98
99 =item insert
100
101 Adds this record to the database.  If there is an error, returns the error,
102 otherwise returns false.
103
104 =item delete
105
106 Delete this record from the database.
107
108 =item replace OLD_RECORD
109
110 Replaces the OLD_RECORD with this one in the database.  If there is an error,
111 returns the error, otherwise returns false.
112
113 =item check
114
115 Checks all fields to make sure this is a valid log entry.  If there is
116 an error, returns the error, otherwise returns false.  Called by the insert
117 and replace methods.
118
119 =cut
120
121 sub check {
122   my $self = shift;
123
124   my $error = 
125     $self->ut_numbern('lognum')
126     || $self->ut_foreign_key('usernum', 'access_user', 'usernum')
127     || $self->ut_text('path')
128     || $self->ut_number('_date')
129     || $self->ut_numbern('render_seconds')
130   ;
131   return $error if $error;
132
133   $self->SUPER::check;
134 }
135
136 =back
137
138 =head1 BUGS
139
140 =head1 SEE ALSO
141
142 L<FS::Record>
143
144 =cut
145
146 1;
147