delete fees, RT#81713
[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 =item pid
57
58 =back
59
60 =head1 METHODS
61
62 =over 4
63
64 =item new HASHREF
65
66 Creates a new log entry.  To add the log entry to the database, see L<"insert">.
67
68 Note that this stores the hash reference, not a distinct copy of the hash it
69 points to.  You can ask the object for a copy with the I<hash> method.
70
71 =cut
72
73 sub table { 'access_user_log'; }
74
75 =item insert_new_path PATH
76
77 Adds a log entry for PATH for the current user and timestamp.
78
79 =cut
80
81 sub insert_new_path {
82   my( $class, $path, $render_seconds ) = @_;
83
84   return '' unless defined $FS::CurrentUser::CurrentUser;
85
86   my $self = $class->new( {
87     'usernum'        => $FS::CurrentUser::CurrentUser->usernum,
88     'path'           => $path,
89     '_date'          => time,
90     'render_seconds' => $render_seconds,
91     'pid'            => $$,
92   } );
93
94   #so we can still log pages after a transaction-aborting SQL error (and then
95   # show the # error page)
96   local($FS::UID::dbh) = dbh->clone;
97     #if current transaction is aborted (if we had a way to check for it)
98
99   my $error = $self->insert;
100   die $error if $error;
101
102 }
103
104 =item insert
105
106 Adds this record to the database.  If there is an error, returns the error,
107 otherwise returns false.
108
109 =item delete
110
111 Delete this record from the database.
112
113 =item replace OLD_RECORD
114
115 Replaces the OLD_RECORD with this one in the database.  If there is an error,
116 returns the error, otherwise returns false.
117
118 =item check
119
120 Checks all fields to make sure this is a valid log entry.  If there is
121 an error, returns the error, otherwise returns false.  Called by the insert
122 and replace methods.
123
124 =cut
125
126 sub check {
127   my $self = shift;
128
129   my $error = 
130     $self->ut_numbern('lognum')
131     || $self->ut_foreign_key('usernum', 'access_user', 'usernum')
132     || $self->ut_text('path')
133     || $self->ut_number('_date')
134     || $self->ut_numbern('render_seconds')
135     || $self->ut_numbern('pid')
136   ;
137   return $error if $error;
138
139   $self->SUPER::check;
140 }
141
142 =back
143
144 =cut
145
146 sub _upgrade_schema {
147   my ($class, %opts) = @_;
148
149   my $sql = 'DROP TABLE IF EXISTS h_access_user_log';
150
151   my $sth = dbh->prepare($sql) or die dbh->errstr;
152   $sth->execute or die $sth->errstr;
153 }
154
155 =head1 BUGS
156
157 =head1 SEE ALSO
158
159 L<FS::Record>
160
161 =cut
162
163 1;
164