Merge branch 'master' of git.freeside.biz:/home/git/freeside
[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   return '' unless defined $FS::CurrentUser::CurrentUser;
79
80   my $self = $class->new( {
81     'usernum' => $FS::CurrentUser::CurrentUser->usernum,
82     'path'    => $path,
83     '_date'   => time,
84   } );
85
86   my $error = $self->insert;
87   die $error if $error;
88
89 }
90
91 =item insert
92
93 Adds this record to the database.  If there is an error, returns the error,
94 otherwise returns false.
95
96 =item delete
97
98 Delete this record from the database.
99
100 =item replace OLD_RECORD
101
102 Replaces the OLD_RECORD with this one in the database.  If there is an error,
103 returns the error, otherwise returns false.
104
105 =item check
106
107 Checks all fields to make sure this is a valid log entry.  If there is
108 an error, returns the error, otherwise returns false.  Called by the insert
109 and replace methods.
110
111 =cut
112
113 sub check {
114   my $self = shift;
115
116   my $error = 
117     $self->ut_numbern('lognum')
118     || $self->ut_foreign_key('usernum', 'access_user', 'usernum')
119     || $self->ut_text('path')
120     || $self->ut_number('_date')
121   ;
122   return $error if $error;
123
124   $self->SUPER::check;
125 }
126
127 =back
128
129 =head1 BUGS
130
131 =head1 SEE ALSO
132
133 L<FS::Record>
134
135 =cut
136
137 1;
138