1 package FS::pkg_category;
4 use vars qw( @ISA $me $DEBUG );
5 use FS::Record qw( qsearch dbh );
8 @ISA = qw( FS::Record );
10 $me = '[FS::pkg_category]';
14 FS::pkg_category - Object methods for pkg_category records
20 $record = new FS::pkg_category \%hash;
21 $record = new FS::pkg_category { 'column' => 'value' };
23 $error = $record->insert;
25 $error = $new_record->replace($old_record);
27 $error = $record->delete;
29 $error = $record->check;
33 An FS::pkg_category object represents an package category. Every package class
34 (see L<FS::pkg_class>) has, optionally, a package category. FS::pkg_category
35 inherits from FS::Record. The following fields are currently supported:
39 =item categorynum - primary key (assigned automatically for new package categoryes)
41 =item categoryname - Text name of this package category
43 =item disabled - Disabled flag, empty or 'Y'
53 Creates a new package category. To add the package category to the database, see
58 sub table { 'pkg_category'; }
62 Adds this package category to the database. If there is an error, returns the
63 error, otherwise returns false.
67 Deletes this package category from the database. Only package categoryes with no
68 associated package definitions can be deleted. If there is an error, returns
69 the error, otherwise returns false.
76 return "Can't delete an pkg_category with pkg_class records!"
77 if qsearch( 'pkg_class', { 'categorynum' => $self->categorynum } );
82 =item replace OLD_RECORD
84 Replaces OLD_RECORD with this one in the database. If there is an error,
85 returns the error, otherwise returns false.
89 Checks all fields to make sure this is a valid package category. If there is an
90 error, returns the error, otherwise returns false. Called by the insert and
98 $self->ut_numbern('categorynum')
99 or $self->ut_text('categoryname')
100 or $self->ut_snumber('weight')
101 or $self->SUPER::check;
107 # Used by FS::Upgrade to migrate to a new database.
110 my ($class, %opts) = @_;
113 warn "$me upgrading $class\n" if $DEBUG;
116 qsearch('pkg_category', { weight => { op => '!=', value => '' } } );
118 unless( scalar(@pkg_category) ) {
119 my @pkg_category = qsearch('pkg_category', {} );
121 foreach ( sort { $a->description cmp $b->description } @pkg_category ) {
123 my $error = $_->replace;
124 die "error setting pkg_category weight: $error\n" if $error;
137 L<FS::Record>, L<FS::part_pkg>, schema.html from the base documentation.