RT#37908: Convert existing email-sending code to use common interface [removals and...
[freeside.git] / FS / FS / log_context.pm
1 package FS::log_context;
2
3 use strict;
4 use base qw( FS::Record );
5 use FS::Record qw( qsearch qsearchs );
6
7 my @contexts = ( qw(
8   test
9   bill_and_collect
10   FS::cust_main::Billing::bill_and_collect
11   FS::cust_main::Billing::bill
12   FS::pay_batch::import_from_gateway
13   Cron::bill
14   Cron::backup
15   Cron::upload
16   spool_upload
17   daily
18   queue
19   upgrade
20   upgrade_taxable_billpkgnum
21 ) );
22
23 =head1 NAME
24
25 FS::log_context - Object methods for log_context records
26
27 =head1 SYNOPSIS
28
29   use FS::log_context;
30
31   $record = new FS::log_context \%hash;
32   $record = new FS::log_context { 'column' => 'value' };
33
34   $error = $record->insert;
35
36   $error = $new_record->replace($old_record);
37
38   $error = $record->delete;
39
40   $error = $record->check;
41
42 =head1 DESCRIPTION
43
44 An FS::log_context object represents a context tag attached to a log entry
45 (L<FS::log>).  FS::log_context inherits from FS::Record.  The following 
46 fields are currently supported:
47
48 =over 4
49
50 =item logcontextnum - primary key
51
52 =item lognum - lognum (L<FS::log> foreign key)
53
54 =item context - context
55
56 =back
57
58 =head1 METHODS
59
60 =over 4
61
62 =item new HASHREF
63
64 Creates a new context tag.  To add the example to the database, see 
65 L<"insert">.
66
67 Note that this stores the hash reference, not a distinct copy of the hash it
68 points to.  You can ask the object for a copy with the I<hash> method.
69
70 =cut
71
72 sub table { 'log_context'; }
73
74 =item insert
75
76 Adds this record to the database.  If there is an error, returns the error,
77 otherwise returns false.
78
79 =item delete
80
81 Delete this record from the database.
82
83 =item replace OLD_RECORD
84
85 Replaces the OLD_RECORD with this one in the database.  If there is an error,
86 returns the error, otherwise returns false.
87
88 =item check
89
90 Checks all fields to make sure this is a valid example.  If there is
91 an error, returns the error, otherwise returns false.  Called by the insert
92 and replace methods.
93
94 =cut
95
96 sub check {
97   my $self = shift;
98
99   my $error = 
100     $self->ut_numbern('logcontextnum')
101     || $self->ut_number('lognum')
102     || $self->ut_text('context') #|| $self->ut_enum('context', \@contexts)
103   ;
104   return $error if $error;
105
106   $self->SUPER::check;
107 }
108
109 =back
110
111 =head1 CLASS METHODS
112
113 =over 4
114
115 =item contexts
116
117 Returns a list of all valid contexts.
118
119 =cut
120
121 sub contexts { @contexts }
122
123 =back
124
125 =head1 BUGS
126
127 =head1 SEE ALSO
128
129 L<FS::Log>, L<FS::Record>, schema.html from the base documentation.
130
131 =cut
132
133 1;
134