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