default to a session cookie instead of setting an explicit timeout, weird timezone...
[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 # Items in @default_contexts will always be included in the
8 # output of contexts() method
9 my @default_contexts = ( qw(
10   bill_and_collect
11   FS::cust_main::Billing::bill_and_collect
12   FS::cust_main::Billing::bill
13   FS::cust_main::Billing_Realtime::realtime_bop
14   FS::cust_main::Billing_Realtime::realtime_tokenize
15   FS::cust_main::Billing_Realtime::realtime_verify_bop
16   FS::cust_main::Billing_Realtime::token_check
17   FS::pay_batch::import_from_gateway
18   FS::part_pkg
19   FS::Misc::Geo::standardize_uscensus
20   FS::saved_search::send
21   FS::saved_search::render
22   FS::cust_location::process_district_update
23   Cron::bill
24   Cron::backup
25   Cron::upload
26   spool_upload
27   daily
28   queue
29   upgrade
30   upgrade_taxable_billpkgnum
31   freeside-ipifony-download
32   freeside-paymentech-upload
33   freeside-paymentech-download
34   test
35   FS::TaxEngine::billsoft
36   wa_sales
37   wa_tax_rate_update
38   tax_rate_update
39 ) );
40
41 =head1 NAME
42
43 FS::log_context - Object methods for log_context records
44
45 =head1 SYNOPSIS
46
47   use FS::log_context;
48
49   $record = new FS::log_context \%hash;
50   $record = new FS::log_context { 'column' => 'value' };
51
52   $error = $record->insert;
53
54   $error = $new_record->replace($old_record);
55
56   $error = $record->delete;
57
58   $error = $record->check;
59
60 =head1 DESCRIPTION
61
62 An FS::log_context object represents a context tag attached to a log entry
63 (L<FS::log>).  FS::log_context inherits from FS::Record.  The following 
64 fields are currently supported:
65
66 =over 4
67
68 =item logcontextnum - primary key
69
70 =item lognum - lognum (L<FS::log> foreign key)
71
72 =item context - context
73
74 =back
75
76 =head1 METHODS
77
78 =over 4
79
80 =item new HASHREF
81
82 Creates a new context tag.  To add the example to the database, see 
83 L<"insert">.
84
85 Note that this stores the hash reference, not a distinct copy of the hash it
86 points to.  You can ask the object for a copy with the I<hash> method.
87
88 =cut
89
90 sub table { 'log_context'; }
91
92 =item insert
93
94 Adds this record to the database.  If there is an error, returns the error,
95 otherwise returns false.
96
97 =item delete
98
99 Delete this record from the database.
100
101 =item replace OLD_RECORD
102
103 Replaces the OLD_RECORD with this one in the database.  If there is an error,
104 returns the error, otherwise returns false.
105
106 =item check
107
108 Checks all fields to make sure this is a valid example.  If there is
109 an error, returns the error, otherwise returns false.  Called by the insert
110 and replace methods.
111
112 =cut
113
114 sub check {
115   my $self = shift;
116
117   my $error = 
118     $self->ut_numbern('logcontextnum')
119     || $self->ut_number('lognum')
120     || $self->ut_text('context') #|| $self->ut_enum('context', \@contexts)
121   ;
122   return $error if $error;
123
124   $self->SUPER::check;
125 }
126
127 =back
128
129 =head1 CLASS METHODS
130
131 =over 4
132
133 =item contexts
134
135 Returns a list of all log contexts, by combining @default_contexts
136 with all context values seen in the log_context table
137
138 =cut
139
140 sub contexts {
141   my $self = shift;
142
143   my %contexts = map { $_ => 1 } @default_contexts;
144
145   $contexts{ $_->context } = 1
146     for qsearch({
147       select  => 'DISTINCT context AS context',
148       table   => 'log_context',
149       hashref => {},
150     });
151
152   sort { lc $a cmp lc $b } keys %contexts;
153 }
154
155 =back
156
157 =head1 BUGS
158
159 =head1 SEE ALSO
160
161 L<FS::Log>, L<FS::Record>, schema.html from the base documentation.
162
163 =cut
164
165 1;
166