4 use base qw( FS::cust_main_Mixin FS::Record );
5 use FS::Record qw( qsearch qsearchs );
6 use vars qw( @statuses );
10 FS::cust_msg - Object methods for cust_msg records
16 $record = new FS::cust_msg \%hash;
17 $record = new FS::cust_msg { 'column' => 'value' };
19 $error = $record->insert;
21 $error = $record->check;
25 An FS::cust_msg object represents an email message generated by Freeside
26 and sent to a customer (see L<FS::msg_template>). FS::cust_msg inherits
27 from FS::Record. The following fields are currently supported:
31 =item custmsgnum - primary key
33 =item custnum - customer number
35 =item msgnum - template number
37 =item msgtype - the message type
39 =item _date - the time the message was sent
41 =item env_from - envelope From address
43 =item env_to - envelope To addresses, including Bcc, separated by newlines
45 =item header - message header
47 =item body - message body
49 =item error - Email::Sender error message (or null for success)
63 # the new method can be inherited from FS::Record, if a table method is defined
65 sub table { 'cust_msg'; }
67 sub nohistory_fields { ('header', 'body'); }
68 # history is kind of pointless on this table
70 @statuses = qw( prepared sent failed );
74 Adds this record to the database. If there is an error, returns the error
75 and emits a warning; otherwise returns false.
80 # warn of all errors here; failing to insert/update one of these should
81 # cause a warning at worst
83 my $error = $self->SUPER::insert;
84 warn "[cust_msg] error logging message status: $error\n" if $error;
90 Delete this record from the database. There's no reason to do this.
96 warn "[cust_msg] log entry deleted\n";
97 return $self->SUPER::delete;
100 =item replace OLD_RECORD
102 Replaces the OLD_RECORD with this one in the database. If there is an error,
103 returns the error and emits a warning, otherwise returns false.
109 my $error = $self->SUPER::replace(@_);
110 warn "[cust_msg] error logging message status: $error\n" if $error;
116 Checks all fields to make sure this is a valid example. If there is
117 an error, returns the error, otherwise returns false. Called by the insert
122 # the check method should currently be supplied - FS::Record contains some
123 # data checking routines
129 $self->ut_numbern('custmsgnum')
130 || $self->ut_numbern('custnum')
131 || $self->ut_foreign_keyn('custnum', 'cust_main', 'custnum')
132 || $self->ut_numbern('msgnum')
133 || $self->ut_foreign_keyn('msgnum', 'msg_template', 'msgnum')
134 || $self->ut_numbern('_date')
135 || $self->ut_textn('env_from')
136 || $self->ut_textn('env_to')
137 || $self->ut_anything('header')
138 || $self->ut_anything('body')
139 || $self->ut_enum('status', \@statuses)
140 || $self->ut_textn('error')
141 || $self->ut_enum('msgtype', [ '',
147 return $error if $error;
156 L<FS::msg_template>, L<FS::cust_main>, L<FS::Record>.