1 package FS::part_pkg_option;
2 use base qw(FS::Record);
5 use FS::Record qw( dbh ); # qw( qsearch qsearchs dbh );
10 FS::part_pkg_option - Object methods for part_pkg_option records
14 use FS::part_pkg_option;
16 $record = new FS::part_pkg_option \%hash;
17 $record = new FS::part_pkg_option { 'column' => 'value' };
19 $error = $record->insert;
21 $error = $new_record->replace($old_record);
23 $error = $record->delete;
25 $error = $record->check;
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
35 =item optionnum - primary key
37 =item pkgpart - package definition (see L<FS::part_pkg>)
39 =item optionname - option name
41 =item optionvalue - option value
51 Creates a new package definition option. To add the package definition option
52 to the database, see L<"insert">.
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.
59 # the new method can be inherited from FS::Record, if a table method is defined
61 sub table { 'part_pkg_option'; }
65 Adds this record to the database. If there is an error, returns the error,
66 otherwise returns false.
70 # the insert method can be inherited from FS::Record
74 Delete this record from the database.
78 # the delete method can be inherited from FS::Record
80 =item replace OLD_RECORD
82 Replaces the OLD_RECORD with this one in the database. If there is an error,
83 returns the error, otherwise returns false.
87 # the replace method can be inherited from FS::Record
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.
97 # the check method should currently be supplied - FS::Record contains some
98 # data checking routines
104 $self->ut_numbern('optionnum')
105 || $self->ut_foreign_key('pkgpart', 'part_pkg', 'pkgpart')
106 || $self->ut_alpha('optionname')
107 || $self->ut_anything('optionvalue')
109 return $error if $error;
111 #check options & values?
121 # Used by FS::Upgrade to migrate to a new database.
125 sub _upgrade_data { # class method
126 my ($class, %opts) = @_;
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;
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;
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;
152 L<FS::part_pkg>, L<FS::Record>, schema.html from the base documentation.