eWay self-signup fixes
[freeside.git] / FS / FS / msgcat.pm
1 package FS::msgcat;
2
3 use strict;
4 use vars qw( @ISA );
5 use Exporter;
6 use FS::UID;
7 use FS::Record; # qw( qsearchs );
8
9 @ISA = qw(FS::Record);
10
11 =head1 NAME
12
13 FS::msgcat - Object methods for message catalog entries
14
15 =head1 SYNOPSIS
16
17   use FS::msgcat;
18
19   $record = new FS::msgcat \%hash;
20   $record = new FS::msgcat { 'column' => 'value' };
21
22   $error = $record->insert;
23
24   $error = $new_record->replace($old_record);
25
26   $error = $record->delete;
27
28   $error = $record->check;
29
30 =head1 DESCRIPTION
31
32 An FS::msgcat object represents an message catalog entry.  FS::msgcat inherits 
33 from FS::Record.  The following fields are currently supported:
34
35 =over 4
36
37 =item msgnum - primary key
38
39 =item msgcode - Error code
40
41 =item locale - Locale
42
43 =item msg - Message
44
45 =back
46
47 If you just want to B<use> message catalogs, see L<FS::Msgcat>.
48
49 =head1 METHODS
50
51 =over 4
52
53 =item new HASHREF
54
55 Creates a new message catalog entry.  To add the message catalog entry to the
56 database, see L<"insert">.
57
58 Note that this stores the hash reference, not a distinct copy of the hash it
59 points to.  You can ask the object for a copy with the I<hash> method.
60
61 =cut
62
63 # the new method can be inherited from FS::Record, if a table method is defined
64
65 sub table { 'msgcat'; }
66
67 =item insert
68
69 Adds this record to the database.  If there is an error, returns the error,
70 otherwise returns false.
71
72 =cut
73
74 # the insert method can be inherited from FS::Record
75
76 =item delete
77
78 Delete this record from the database.
79
80 =cut
81
82 # the delete method can be inherited from FS::Record
83
84 =item replace OLD_RECORD
85
86 Replaces the OLD_RECORD with this one in the database.  If there is an error,
87 returns the error, otherwise returns false.
88
89 =cut
90
91 # the replace method can be inherited from FS::Record
92
93 =item check
94
95 Checks all fields to make sure this is a valid message catalog entry.  If there
96 is an error, returns the error, otherwise returns false.  Called by the insert
97 and replace methods.
98
99 =cut
100
101 # the check method should currently be supplied - FS::Record contains some
102 # data checking routines
103
104 sub check {
105   my $self = shift;
106
107   my $error =
108     $self->ut_numbern('msgnum')
109     || $self->ut_text('msgcode')
110     || $self->ut_text('msg')
111   ;
112   return $error if $error;
113
114   $self->locale =~ /^([\w\@]+)$/ or return "illegal locale: ". $self->locale;
115   $self->locale($1);
116
117   $self->SUPER::check
118 }
119
120
121 sub _upgrade_data { #class method
122   my( $class, %opts) = @_;
123
124   eval "use FS::Setup;";
125   die $@ if $@;
126
127   #"repopulate_msgcat", false laziness w/FS::Setup::populate_msgcat
128
129   my %messages = FS::Setup::msgcat_messages();
130
131   foreach my $msgcode ( keys %messages ) {
132     foreach my $locale ( keys %{$messages{$msgcode}} ) {
133       my %msgcat = (
134         'msgcode' => $msgcode,
135         'locale'  => $locale,
136         #'msg'     => $messages{$msgcode}{$locale},
137       );
138       #my $msgcat = qsearchs('msgcat', \%msgcat);
139       my $msgcat = FS::Record::qsearchs('msgcat', \%msgcat); #wtf?
140       next if $msgcat;
141
142       $msgcat = new FS::msgcat( {
143         %msgcat,
144         'msg' => $messages{$msgcode}{$locale},
145       } );
146       my $error = $msgcat->insert;
147       die $error if $error;
148     }
149   }
150
151 }
152
153 =back
154
155 =head1 BUGS
156
157 i18n/l10n, eek
158
159 =head1 SEE ALSO
160
161 L<FS::Msgcat>, L<FS::Record>, schema.html from the base documentation.
162
163 =cut
164
165 1;
166