move legacy messages to msgcat.pm, prevent upgrades from requiring Setup.pm and thus...
[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 = _legacy_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 sub _legacy_messages {
154
155   #  'msgcode' => {
156   #    'en_US' => 'Message',
157   #  },
158
159   (
160
161     'passwords_dont_match' => {
162       'en_US' => "Passwords don't match",
163     },
164
165     'invalid_card' => {
166       'en_US' => 'Invalid credit card number',
167     },
168
169     'unknown_card_type' => {
170       'en_US' => 'Unknown card type',
171     },
172
173     'not_a' => {
174       'en_US' => 'Not a ',
175     },
176
177     'empty_password' => {
178       'en_US' => 'Empty password',
179     },
180
181     'no_access_number_selected' => {
182       'en_US' => 'No access number selected',
183     },
184
185     'illegal_text' => {
186       'en_US' => 'Illegal (text)',
187       #'en_US' => 'Only letters, numbers, spaces, and the following punctuation symbols are permitted: ! @ # $ % & ( ) - + ; : \' " , . ? / in field',
188     },
189
190     'illegal_or_empty_text' => {
191       'en_US' => 'Illegal or empty (text)',
192       #'en_US' => 'Only letters, numbers, spaces, and the following punctuation symbols are permitted: ! @ # $ % & ( ) - + ; : \' " , . ? / in required field',
193     },
194
195     'illegal_username' => {
196       'en_US' => 'Illegal username',
197     },
198
199     'illegal_password' => {
200       'en_US' => 'Illegal password (',
201     },
202
203     'illegal_password_characters' => {
204       'en_US' => ' characters)',
205     },
206
207     'username_in_use' => {
208       'en_US' => 'Username in use',
209     },
210
211     'phonenum_in_use' => {
212       'en_US' => 'Phone number in use',
213     },
214
215     'illegal_email_invoice_address' => {
216       'en_US' => 'Illegal email invoice address',
217     },
218
219     'illegal_name' => {
220       'en_US' => 'Illegal (name)',
221       #'en_US' => 'Only letters, numbers, spaces and the following punctuation symbols are permitted: , . - \' in field',
222     },
223
224     'illegal_phone' => {
225       'en_US' => 'Illegal (phone)',
226       #'en_US' => '',
227     },
228
229     'illegal_zip' => {
230       'en_US' => 'Illegal (zip)',
231       #'en_US' => '',
232     },
233
234     'expired_card' => {
235       'en_US' => 'Expired card',
236     },
237
238     'daytime' => {
239       'en_US' => 'Day Phone',
240     },
241
242     'night' => {
243       'en_US' => 'Night Phone',
244     },
245
246     'svc_external-id' => {
247       'en_US' => 'External ID',
248     },
249
250     'svc_external-title' => {
251       'en_US' => 'Title',
252     },
253
254     'stateid' => {
255       'en_US' => 'Driver\'s License',
256     },
257
258     'stateid_state' => {
259       'en_US' => 'Driver\'s License State',
260     },
261
262     'invalid_domain' => {
263       'en_US' => 'Invalid domain',
264     },
265
266   );
267 }
268
269 =back
270
271 =head1 BUGS
272
273 i18n/l10n, eek
274
275 =head1 SEE ALSO
276
277 L<FS::Msgcat>, L<FS::Record>, schema.html from the base documentation.
278
279 =cut
280
281 1;
282