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