This commit was generated by cvs2svn to compensate for changes in r11022,
[freeside.git] / FS / FS / pkg_category.pm
1 package FS::pkg_category;
2
3 use strict;
4 use base qw( FS::category_Common );
5 use vars qw( @ISA $me $DEBUG );
6 use FS::Record qw( qsearch dbh );
7 use FS::pkg_class;
8 use FS::part_pkg;
9
10 $DEBUG = 0;
11 $me = '[FS::pkg_category]';
12
13 =head1 NAME
14
15 FS::pkg_category - Object methods for pkg_category records
16
17 =head1 SYNOPSIS
18
19   use FS::pkg_category;
20
21   $record = new FS::pkg_category \%hash;
22   $record = new FS::pkg_category { 'column' => 'value' };
23
24   $error = $record->insert;
25
26   $error = $new_record->replace($old_record);
27
28   $error = $record->delete;
29
30   $error = $record->check;
31
32 =head1 DESCRIPTION
33
34 An FS::pkg_category object represents an package category.  Every package class
35 (see L<FS::pkg_class>) has, optionally, a package category. FS::pkg_category
36 inherits from FS::Record.  The following fields are currently supported:
37
38 =over 4
39
40 =item categorynum
41
42 primary key (assigned automatically for new package categoryes)
43
44 =item categoryname
45
46 Text name of this package category
47
48 =item weight
49
50 Weight
51
52 =item disabled
53
54 Disabled flag, empty or 'Y'
55
56 =back
57
58 =head1 METHODS
59
60 =over 4
61
62 =item new HASHREF
63
64 Creates a new package category.  To add the package category to the database,
65 see L<"insert">.
66
67 =cut
68
69 sub table { 'pkg_category'; }
70
71 =item insert
72
73 Adds this package category to the database.  If there is an error, returns the
74 error, otherwise returns false.
75
76 =item delete
77
78 Deletes this package category from the database.  Only package categoryes with
79 no associated package definitions can be deleted.  If there is an error,
80 returns the error, otherwise returns false.
81
82 =item replace [ OLD_RECORD ]
83
84 Replaces OLD_RECORD with this one in the database.  If there is an error,
85 returns the error, otherwise returns false.
86
87 =item check
88
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
91 replace methods.
92
93 =cut
94
95 # _ upgrade_data
96 #
97 # Used by FS::Upgrade to migrate to a new database.
98
99 sub _upgrade_data {
100   my ($class, %opts) = @_;
101   my $dbh = dbh;
102
103   warn "$me upgrading $class\n" if $DEBUG;
104
105   my @pkg_category =
106     qsearch('pkg_category', { weight => { op => '!=', value => '' } } );
107
108   unless( scalar(@pkg_category) ) {
109     my @pkg_category = qsearch('pkg_category', {} );
110     my $weight = 0;
111     foreach ( sort { $a->description cmp $b->description } @pkg_category ) {
112       $_->weight($weight);
113       my $error = $_->replace;
114       die "error setting pkg_category weight: $error\n" if $error;
115       $weight += 10;
116     }
117   }
118   '';
119 }
120
121 =back
122
123 =head1 BUGS
124
125 =head1 SEE ALSO
126
127 L<FS::category_Common>, L<FS::Record>
128
129 =cut
130
131 1;
132