eliminate some false laziness in FS::Misc::send_email vs. msg_template/email.pm send_...
[freeside.git] / FS / FS / part_pkg_option.pm
1 package FS::part_pkg_option;
2 use base qw(FS::Record);
3
4 use strict;
5 use FS::Record qw( dbh ); # qw( qsearch qsearchs dbh );
6 use FS::part_pkg;
7
8 =head1 NAME
9
10 FS::part_pkg_option - Object methods for part_pkg_option records
11
12 =head1 SYNOPSIS
13
14   use FS::part_pkg_option;
15
16   $record = new FS::part_pkg_option \%hash;
17   $record = new FS::part_pkg_option { 'column' => 'value' };
18
19   $error = $record->insert;
20
21   $error = $new_record->replace($old_record);
22
23   $error = $record->delete;
24
25   $error = $record->check;
26
27 =head1 DESCRIPTION
28
29 An FS::part_pkg_option object represents an package definition option.
30 FS::part_pkg_option inherits from FS::Record.  The following fields are
31 currently supported:
32
33 =over 4
34
35 =item optionnum - primary key
36
37 =item pkgpart - package definition (see L<FS::part_pkg>)
38
39 =item optionname - option name
40
41 =item optionvalue - option value
42
43 =back
44
45 =head1 METHODS
46
47 =over 4
48
49 =item new HASHREF
50
51 Creates a new package definition option.  To add the package definition option
52 to the database, see L<"insert">.
53
54 Note that this stores the hash reference, not a distinct copy of the hash it
55 points to.  You can ask the object for a copy with the I<hash> method.
56
57 =cut
58
59 # the new method can be inherited from FS::Record, if a table method is defined
60
61 sub table { 'part_pkg_option'; }
62
63 =item insert
64
65 Adds this record to the database.  If there is an error, returns the error,
66 otherwise returns false.
67
68 =cut
69
70 # the insert method can be inherited from FS::Record
71
72 =item delete
73
74 Delete this record from the database.
75
76 =cut
77
78 # the delete method can be inherited from FS::Record
79
80 =item replace OLD_RECORD
81
82 Replaces the OLD_RECORD with this one in the database.  If there is an error,
83 returns the error, otherwise returns false.
84
85 =cut
86
87 # the replace method can be inherited from FS::Record
88
89 =item check
90
91 Checks all fields to make sure this is a valid package definition option.  If
92 there is an error, returns the error, otherwise returns false.  Called by the
93 insert and replace methods.
94
95 =cut
96
97 # the check method should currently be supplied - FS::Record contains some
98 # data checking routines
99
100 sub check {
101   my $self = shift;
102
103   my $error = 
104     $self->ut_numbern('optionnum')
105     || $self->ut_foreign_key('pkgpart', 'part_pkg', 'pkgpart')
106     || $self->ut_alpha('optionname')
107     || $self->ut_anything('optionvalue')
108   ;
109   return $error if $error;
110
111   #check options & values?
112
113   $self->SUPER::check;
114 }
115
116 =back
117
118 =cut
119
120 #
121 # Used by FS::Upgrade to migrate to a new database.
122 #
123 #
124
125 sub _upgrade_data {  # class method
126   my ($class, %opts) = @_;
127
128   my $sql = "UPDATE part_pkg_option SET optionname = 'recur_fee'".
129             " WHERE optionname = 'recur_flat'";
130   my $sth = dbh->prepare($sql) or die dbh->errstr;
131   $sth->execute or die $sth->errstr;
132
133   $sql = "UPDATE part_pkg_option SET optionname = 'recur_method',".
134             "optionvalue = 'prorate'  WHERE optionname = 'enable_prorate'";
135   $sth = dbh->prepare($sql) or die dbh->errstr;
136   $sth->execute or die $sth->errstr;
137
138   $sql = "UPDATE part_pkg_option SET optionvalue = NULL WHERE ".
139             "optionname = 'contract_end_months' AND optionvalue = '(none)'";
140   $sth = dbh->prepare($sql) or die dbh->errstr;
141   $sth->execute or die $sth->errstr;
142   '';
143
144 }
145
146 =head1 BUGS
147
148 Possibly.
149
150 =head1 SEE ALSO
151
152 L<FS::part_pkg>, L<FS::Record>, schema.html from the base documentation.
153
154 =cut
155
156 1;
157