web access logging to DB
[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
52 =back
53
54 =head1 METHODS
55
56 =over 4
57
58 =item new HASHREF
59
60 Creates a new log entry.  To add the log entry to the database, see L<"insert">.
61
62 Note that this stores the hash reference, not a distinct copy of the hash it
63 points to.  You can ask the object for a copy with the I<hash> method.
64
65 =cut
66
67 sub table { 'access_user_log'; }
68
69 =item insert_new_path PATH
70
71 Adds a log entry for PATH for the current user and timestamp.
72
73 =cut
74
75 sub insert_new_path {
76   my( $class, $path ) = @_;
77
78   my $self = $class->new( {
79     'usernum' => $FS::CurrentUser::CurrentUser->usernum,
80     'path'    => $path,
81     '_date'   => time,
82   } );
83
84   my $error = $self->insert;
85   die $error if $error;
86
87 }
88
89 =item insert
90
91 Adds this record to the database.  If there is an error, returns the error,
92 otherwise returns false.
93
94 =item delete
95
96 Delete this record from the database.
97
98 =item replace OLD_RECORD
99
100 Replaces the OLD_RECORD with this one in the database.  If there is an error,
101 returns the error, otherwise returns false.
102
103 =item check
104
105 Checks all fields to make sure this is a valid log entry.  If there is
106 an error, returns the error, otherwise returns false.  Called by the insert
107 and replace methods.
108
109 =cut
110
111 sub check {
112   my $self = shift;
113
114   my $error = 
115     $self->ut_numbern('lognum')
116     || $self->ut_foreign_key('usernum', 'access_user', 'usernum')
117     || $self->ut_text('path')
118     || $self->ut_number('_date')
119   ;
120   return $error if $error;
121
122   $self->SUPER::check;
123 }
124
125 =back
126
127 =head1 BUGS
128
129 =head1 SEE ALSO
130
131 L<FS::Record>
132
133 =cut
134
135 1;
136