Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / FS / FS / log_email.pm
1 package FS::log_email;
2
3 use strict;
4 use base qw( FS::Record );
5 use FS::Record qw( qsearch qsearchs dbdef );
6 use FS::UID qw( dbh driver_name );
7
8 =head1 NAME
9
10 FS::log_email - Object methods for log email records
11
12 =head1 SYNOPSIS
13
14   use FS::log_email;
15
16   $record = new FS::log_email \%hash;
17   $record = new FS::log_email { '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::log object represents the conditions for sending an email
30 when a log entry is created.  FS::log inherits from FS::Record.  
31 The following fields are currently supported:
32
33 =over 4
34
35 =item logemailnum - primary key
36
37 =item context - the context that will trigger the email (all contexts if unspecified)
38
39 =item min_level - the minimum log level that will trigger the email (all levels if unspecified)
40
41 =item msgnum - the msg_template that will be used to send the email
42
43 =item to_addr - who the email will be sent to (in addition to any bcc on the template)
44
45 =back
46
47 =head1 METHODS
48
49 =over 4
50
51 =item new HASHREF
52
53 Creates a new log_email entry.
54
55 =cut
56
57 sub table { 'log_email'; }
58
59 =item insert
60
61 Adds this record to the database.  If there is an error, returns the error,
62 otherwise returns false.
63
64 =item delete
65
66 Delete this record from the database.
67
68 =item replace OLD_RECORD
69
70 Replaces the OLD_RECORD with this one in the database.  If there is an error,
71 returns the error, otherwise returns false.
72
73 =item check
74
75 Checks all fields to make sure this is a valid record.  If there is
76 an error, returns the error, otherwise returns false.  Called by the insert
77 and replace methods.
78
79 =cut
80
81 sub check {
82   my $self = shift;
83
84   my $error = 
85     $self->ut_numbern('logemailnum')
86     || $self->ut_textn('context') # not validating against list of contexts in log_context,
87                                   # because not even log_context check currently does so
88     || $self->ut_number('min_level')
89     || $self->ut_foreign_key('msgnum', 'msg_template', 'msgnum')
90     || $self->ut_textn('to_addr')
91   ;
92   return $error if $error;
93
94   $self->SUPER::check;
95 }
96
97 =back
98
99 =head1 BUGS
100
101 =head1 SEE ALSO
102
103 L<FS::Record>, schema.html from the base documentation.
104
105 =cut
106
107 1;
108